/**
* Called when an intent is received.
*/
public void onReceive(Context context, Intent intent) {
//Save context-specific objects needed in other methods
settings = PreferenceManager.getDefaultSharedPreferences(context);
resources = context.getResources();
vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
final String action = intent.getAction();
final Bundle extras = intent.getExtras();
if (action.equals(EventReceiver.VIBRATE_IN_MORSE)) {
this.vibrateMorse(this.convertToVibrations(extras.getString(EventReceiver.VIBRATE_IN_MORSE_KEY)));
}
/*else if (action.equals(PARSE_MORSE)) {
Log.i(EventReceiver.TAG, "Parsed to: " + EventReceiver.parseMorse(extras.getLongArray(PARSE_MORSE_KEY)));
}*/
else if (action.equals(EventReceiver.SMS_RECEIVED)) {
final boolean smsValid = extras != null;
final boolean enabled = this.settings.getBoolean(this.resources.getString(R.string.preference_enabled), EventReceiver.DEFAULT_ENABLED);
final boolean keygaurdOn = ((KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode();
final boolean screenOffOnly = this.settings.getBoolean(this.resources.getString(R.string.preference_screen_off_only), EventReceiver.DEFAULT_SCREEN_OFF_ONLY);
final int audioMode = ((AudioManager)context.getSystemService(Context.AUDIO_SERVICE)).getRingerMode();
final boolean activeAudioMode = (
((audioMode == AudioManager.RINGER_MODE_NORMAL) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_normal), EventReceiver.DEFAULT_VIBRATE_NORMAL)) ||
((audioMode == AudioManager.RINGER_MODE_VIBRATE) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_vibrate), EventReceiver.DEFAULT_VIBRATE_VIBRATE)) ||
((audioMode == AudioManager.RINGER_MODE_SILENT) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_silent), EventReceiver.DEFAULT_VIBRATE_SILENT))
);
if (smsValid && enabled && activeAudioMode && (keygaurdOn || !screenOffOnly)) {
//Create SMSMessages from PDUs in the Bundle
final Object[] pdus = (Object[])extras.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++)
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
//Assemble
final ArrayList<Long> vibrations = new ArrayList<Long>();
final int vibrateParts = Integer.parseInt(settings.getString(resources.getString(R.string.preference_vibrate_parts), EventReceiver.DEFAULT_VIBRATE_PARTS));
for (SmsMessage message : messages) {
if ((vibrateParts == EventReceiver.VIBRATE_CONTENT_SENDER) || (vibrateParts == EventReceiver.VIBRATE_CONTENT_SENDER_MESSAGE))
vibrations.addAll(this.convertSenderToVibrations(context, message.getOriginatingAddress()));
if (vibrateParts != EventReceiver.VIBRATE_CONTENT_SENDER)
vibrations.addAll(this.convertToVibrations(message.getMessageBody()));
if (vibrateParts == EventReceiver.VIBRATE_CONTENT_MESSAGE_SENDER)
vibrations.addAll(this.convertSenderToVibrations(context, message.getOriginatingAddress()));
}
this.vibrateMorse(vibrations);
}
}
}
EventReceiver.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:buildAPKsApps
作者:
评论列表
文章目录