List of usage examples for android.content Intent FLAG_ACTIVITY_NO_USER_ACTION
int FLAG_ACTIVITY_NO_USER_ACTION
To view the source code for android.content Intent FLAG_ACTIVITY_NO_USER_ACTION.
Click Source Link
From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java
@SuppressWarnings("deprecation") @Override/* w w w .jav a 2 s . c o m*/ public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); int pos = intent.getIntExtra(PreferenceHelper.BAT_VALS, 0); level = intent.getIntExtra(PreferenceHelper.CURR_RING, 72); //Log.Toast(context, level + " in receiver", Toast.LENGTH_LONG); // int id = intent.getIntExtra(Intents.EXTRA_ID, -1); if (action.equals(Intents.ALARM_ALERT_ACTION)) { /* Close dialogs and window shade */ Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDialogs); // Decide which activity to start based on the state of the // keyguard. /* * KeyguardManager km = (KeyguardManager) * context.getSystemService(Context.KEYGUARD_SERVICE); if * (km.inKeyguardRestrictedInputMode()) { // Use the full screen * activity for security. c = AlarmAlertFullScreen.class; } */ // Trigger a notification that, when clicked, will show the alarm // alert // dialog. No need to check for fullscreen since this will always be // launched from a user action. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { Intent notify = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); notify.putExtra(PreferenceHelper.BAT_VALS, pos); PendingIntent pendingNotify = PendingIntent.getActivity(context, ID, notify, 0); // Alarm alarm = AlarmsManager.getAlarmsManager().getAlarm(id); Notification n = new Notification(R.drawable.stat_notify_alarm, "abc", System.currentTimeMillis()); n.setLatestEventInfo(context, "Battery Alarm", "Battery Level is " + level, pendingNotify); n.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT; n.defaults |= Notification.DEFAULT_LIGHTS; // NEW: Embed the full-screen UI here. The notification manager // will // take care of displaying it if it's OK to do so. Intent alarmAlert = new Intent(context, saphion.fragments.alarm.AlarmAlert.class); alarmAlert.putExtra(PreferenceHelper.CURR_RING, level); alarmAlert.putExtra(PreferenceHelper.BAT_VALS, pos); alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); n.fullScreenIntent = PendingIntent.getActivity(context, ID, alarmAlert, 0); // Send the notification using the alarm id to easily identify // the // correct notification. NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); // mNotificationManager.notify(ID, builder.build()); nm.notify(ID, n); } else { // Log.Toast(context, "Recieved", Toast.LENGTH_LONG); newMethod(context, pos); } } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(ID); } }
From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(TAG, "Received intent " + intent.toString()); }/*from w ww . j a v a 2 s.co m*/ String actionType = intent.getAction(); // This action does not need the timers data if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) { cancelInUseNotification(context); return; } // Get the updated timers data. if (mTimers == null) { mTimers = new ArrayList<TimerObj>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); // These actions do not provide a timer ID, but do use the timers data if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) { showInUseNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) { showTimesUpNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) { cancelTimesUpNotification(context); return; } // Remaining actions provide a timer Id if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) { // No data to work with, do nothing Log.e(TAG, "got intent without Timer data"); return; } // Get the timer out of the Intent int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1); if (timerId == -1) { Log.d(TAG, "OnReceive:intent without Timer data for " + actionType); } TimerObj t = Timers.findTimer(mTimers, timerId); if (Timers.TIMES_UP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer not found in list - do nothing"); return; } t.mState = TimerObj.STATE_TIMESUP; t.writeToSharedPref(prefs); // Play ringtone by using TimerRingService service with a default alarm. Log.d(TAG, "playing ringtone"); Intent si = new Intent(); si.setClass(context, TimerRingService.class); context.startService(si); // Update the in-use notification if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) { // Found no running timers. cancelInUseNotification(context); } else { showInUseNotification(context); } // Start the TimerAlertFullScreen activity. Intent timersAlert = new Intent(context, TimerAlertFullScreen.class); timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(timersAlert); } else if (Timers.TIMER_RESET.equals(actionType) || Timers.DELETE_TIMER.equals(actionType) || Timers.TIMER_DONE.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to stop not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to stop but timer not in times-up state - do nothing"); return; } // Update timer state t.mState = t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_DONE; t.mTimeLeft = t.mOriginalLength - (Utils.getTimeNow() - t.mStartTime); t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.FROM_NOTIFICATION, true).apply(); cancelTimesUpNotification(context, t); // Done with timer - delete from data base if (t.getDeleteAfterUse()) { t.deleteFromSharedPref(prefs); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to +1m not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to +1m but timer not in times up state - do nothing"); return; } // Restarting the timer with 1 minute left. t.mState = TimerObj.STATE_RUNNING; t.mStartTime = Utils.getTimeNow(); t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.FROM_NOTIFICATION, true).apply(); cancelTimesUpNotification(context, t); // If the app is not open, refresh the in-use notification if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) { showInUseNotification(context); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.TIMER_UPDATE.equals(actionType)) { // Refresh buzzing notification if (t.mState == TimerObj.STATE_TIMESUP) { // Must cancel the previous notification to get all updates displayed correctly cancelTimesUpNotification(context, t); showTimesUpNotification(context, t); } } // Update the next "Times up" alarm updateNextTimesup(context); }
From source file:se.oort.clockify.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(LOG_TAG, "Received intent " + intent.toString()); }/*from w ww . j ava 2 s. co m*/ String actionType = intent.getAction(); // This action does not need the timers data if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) { cancelInUseNotification(context); return; } // Get the updated timers data. if (mTimers == null) { mTimers = new ArrayList<TimerObj>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); // These actions do not provide a timer ID, but do use the timers data if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) { showInUseNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) { showTimesUpNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) { cancelTimesUpNotification(context); return; } // Remaining actions provide a timer Id if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) { // No data to work with, do nothing Log.e(LOG_TAG, "got intent without Timer data"); return; } // Get the timer out of the Intent int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1); if (timerId == -1) { Log.d(LOG_TAG, "OnReceive:intent without Timer data for " + actionType); } TimerObj t = Timers.findTimer(mTimers, timerId); if (Timers.TIMES_UP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(LOG_TAG, " timer not found in list - do nothing"); return; } t.mState = TimerObj.STATE_TIMESUP; t.writeToSharedPref(prefs); // Play ringtone by using TimerRingService service with a default alarm. Log.d(LOG_TAG, "playing ringtone"); Intent si = new Intent(); si.setClass(context, TimerRingService.class); context.startService(si); // Update the in-use notification if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) { // Found no running timers. cancelInUseNotification(context); } else { showInUseNotification(context); } // Start the TimerAlertFullScreen activity. Intent timersAlert = new Intent(context, TimerAlertFullScreen.class); timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(timersAlert); } else if (Timers.TIMER_RESET.equals(actionType) || Timers.DELETE_TIMER.equals(actionType) || Timers.TIMER_DONE.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(LOG_TAG, "timer to stop not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(LOG_TAG, "action to stop but timer not in times-up state - do nothing"); return; } // Update timer state t.mState = t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_DONE; t.mTimeLeft = t.mOriginalLength - (Utils.getTimeNow() - t.mStartTime); t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.FROM_NOTIFICATION, true).apply(); cancelTimesUpNotification(context, t); // Done with timer - delete from data base if (t.getDeleteAfterUse()) { t.deleteFromSharedPref(prefs); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(LOG_TAG, "timer to +1m not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(LOG_TAG, "action to +1m but timer not in times up state - do nothing"); return; } // Restarting the timer with 1 minute left. t.mState = TimerObj.STATE_RUNNING; t.mStartTime = Utils.getTimeNow(); t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.FROM_NOTIFICATION, true).apply(); cancelTimesUpNotification(context, t); // If the app is not open, refresh the in-use notification if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) { showInUseNotification(context); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.TIMER_UPDATE.equals(actionType)) { // Refresh buzzing notification if (t.mState == TimerObj.STATE_TIMESUP) { // Must cancel the previous notification to get all updates displayed correctly cancelTimesUpNotification(context, t); showTimesUpNotification(context, t); } } // Update the next "Times up" alarm updateNextTimesup(context); }
From source file:org.android.gcm.client.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { final SharedPreferences prefs = getSharedPreferences("gcmclient", Context.MODE_PRIVATE); pushpak = prefs.getString("push_pak", ""); pushact = prefs.getString("push_act", ""); final boolean pushon = prefs.getBoolean("push_on", true); final boolean pushnotif = prefs.getBoolean("push_notification", true); if (pushnotif) { final String notifact = prefs.getString("notification_act", ""); Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // Send a notification. if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/* w ww . j a v a 2 s . c om*/ * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification(getString(R.string.send_error) + ": " + extras.toString(), notifact); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification(getString(R.string.deleted) + ": " + extras.toString(), notifact); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. sendNotification( getString(R.string.received, extras.getString("name"), extras.getString("num")), notifact); Log.i(TAG, "Received: " + extras.toString()); } } } // End if push is not enabled. if (!pushon) { // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); return; } final boolean fullwake = prefs.getBoolean("full_wake", false); final boolean endoff = prefs.getBoolean("end_off", true); // Manage the screen. PowerManager mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = mPowerManager .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); boolean misScreenOn = mPowerManager.isScreenOn(); int mScreenTimeout = 0; if (!misScreenOn) { if (endoff) { // Change the screen timeout setting. mScreenTimeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0); if (mScreenTimeout != 0) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 3000); } } // Full wake lock if (fullwake) { mWakeLock.acquire(); } } // Start the activity. try { startActivity(getPushactIntent(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)); // Wait to register. Thread.sleep(REGISTER_DURATION); } catch (android.content.ActivityNotFoundException e) { RING_DURATION = 0; Log.i(TAG, "Activity not started"); } catch (InterruptedException e) { } // Release the wake lock. if (!misScreenOn && fullwake) { mWakeLock.release(); } GcmBroadcastReceiver.completeWakefulIntent(intent); // Restore the screen timeout setting. if (endoff && mScreenTimeout != 0) { try { Thread.sleep(RING_DURATION); } catch (InterruptedException e) { } Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, mScreenTimeout); } }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doAlarm(Context context, BaseProfile profile, String number, String message) { // Maintain a cpu wake lock until the AlarmActivity and AlarmService can // pick it up. AlarmAlertWakeLock.acquireCpuWakeLock(context); /* Close dialogs and window shade */ Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeDialogs); // Play the alarm alert and vibrate the device. Intent playAlarm = new Intent(Intents.ACTION_ALERT); playAlarm.putExtra(Intents.EXTRA_PROFILE, profile); context.startService(playAlarm);// w ww . j a v a2s . c o m Intent dismissIntent = new Intent(Intents.ACTION_DISMISS); dismissIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingDismiss = PendingIntent.getBroadcast(context, profile.getId(), dismissIntent, 0); Intent replyIntent = new Intent(Intents.ACTION_REPLY); replyIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingReply = PendingIntent.getBroadcast(context, profile.getId(), replyIntent, 0); Intent callIntent = new Intent(Intents.ACTION_CALL); callIntent.putExtra(Intents.EXTRA_PROFILE, profile); PendingIntent pendingCall = PendingIntent.getBroadcast(context, profile.getId(), callIntent, 0); Intent activityIntent = new Intent(context, AlarmActivity.class); activityIntent.setAction(String.valueOf(System.currentTimeMillis())); activityIntent.putExtra(Intents.EXTRA_PROFILE, profile); activityIntent.putExtra(Intents.EXTRA_NUMBER, number); activityIntent.putExtra(Intents.EXTRA_MESSAGE, message); activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); PendingIntent pendingActivity = PendingIntent.getActivity(context, profile.getId(), activityIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(profile.getName()).setSmallIcon(R.drawable.ic_stat_alarm).setAutoCancel(false) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS) .addAction(android.R.drawable.ic_menu_close_clear_cancel, context.getString(R.string.notif_action_dismiss), pendingDismiss) .addAction(android.R.drawable.ic_menu_send, context.getString(R.string.notif_action_reply), pendingReply) .addAction(android.R.drawable.ic_menu_call, context.getString(R.string.notif_action_call), pendingCall) .setFullScreenIntent(pendingActivity, true).setContentIntent(pendingActivity) .setDeleteIntent(pendingDismiss); Notification notif = builder.build(); // Send the notification using the alarm id to easily identify the // correct notification. NotificationManager nm = getNotificationManager(context); nm.notify(profile.getId(), notif); // full screen intent doesn't do anything pre-honeycomb if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { context.startActivity(activityIntent); } }
From source file:com.android.deskclock.timer.TimerReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { if (Timers.LOGGING) { Log.v(TAG, "Received intent " + intent.toString()); }//from w ww .j av a 2s . co m String actionType = intent.getAction(); // This action does not need the timers data if (Timers.NOTIF_IN_USE_CANCEL.equals(actionType)) { cancelInUseNotification(context); return; } // Get the updated timers data. if (mTimers == null) { mTimers = new ArrayList<>(); } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); TimerObj.getTimersFromSharedPrefs(prefs, mTimers); if (AlarmService.PRE_SHUTDOWN_ACTION.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status TimerObj timerRing = Timers.findExpiredTimer(mTimers); if (timerRing != null) { timerRing.mState = TimerObj.STATE_STOPPED; stopRingtoneIfNoTimesup(context); } return; } // These actions do not provide a timer ID, but do use the timers data if (Timers.NOTIF_IN_USE_SHOW.equals(actionType)) { showInUseNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_SHOW.equals(actionType)) { showTimesUpNotification(context); return; } else if (Timers.NOTIF_TIMES_UP_CANCEL.equals(actionType)) { cancelTimesUpNotification(context); return; } // Remaining actions provide a timer Id if (!intent.hasExtra(Timers.TIMER_INTENT_EXTRA)) { // No data to work with, do nothing Log.e(TAG, "got intent without Timer data"); return; } // Get the timer out of the Intent int timerId = intent.getIntExtra(Timers.TIMER_INTENT_EXTRA, -1); if (timerId == -1) { Log.d(TAG, "OnReceive:intent without Timer data for " + actionType); } TimerObj t = Timers.findTimer(mTimers, timerId); if (Timers.TIMES_UP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer not found in list - do nothing"); return; } t.setState(TimerObj.STATE_TIMESUP); t.writeToSharedPref(prefs); Events.sendEvent(R.string.category_timer, R.string.action_fire, 0); /// M: We acquire the lock here because in some rare scenario, the wake lock is release /// by alarm before it could be acquired by Timer activity causing state to be suspended AlarmAlertWakeLock.acquireScreenCpuWakeLock(context); // Play ringtone by using TimerRingService service with a default alarm. Log.d(TAG, "playing ringtone"); Intent si = new Intent(); si.setClass(context, TimerRingService.class); context.startService(si); // Update the in-use notification if (getNextRunningTimer(mTimers, false, Utils.getTimeNow()) == null) { // Found no running timers. cancelInUseNotification(context); } else { showInUseNotification(context); } /** * M: To show time up notification to avoid the case: pausing the * current activity(eg: touch home key) when time is up, it cause * the TimerAlertFullScreen can not be started, and this cause no * notification in status bar but the timer has sound. @{ */ Utils.showTimesUpNotifications(context); /** @} */ // Start the TimerAlertFullScreen activity. Intent timersAlert = new Intent(context, TimerAlertFullScreen.class); timersAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); context.startActivity(timersAlert); } else if (Timers.RESET_TIMER.equals(actionType) || Timers.DELETE_TIMER.equals(actionType) || Timers.TIMER_DONE.equals(actionType)) { // Stop Ringtone if all timers are not in times-up status stopRingtoneIfNoTimesup(context); if (t != null) { cancelTimesUpNotification(context, t); } } else if (Timers.NOTIF_TIMES_UP_STOP.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to stop not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to stop but timer not in times-up state - do nothing"); return; } // Update timer state t.setState(t.getDeleteAfterUse() ? TimerObj.STATE_DELETED : TimerObj.STATE_RESTART); t.mTimeLeft = t.mOriginalLength = t.mSetupLength; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // Done with timer - delete from data base if (t.getDeleteAfterUse()) { t.deleteFromSharedPref(prefs); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.NOTIF_TIMES_UP_PLUS_ONE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, "timer to +1m not found in list - do nothing"); return; } else if (t.mState != TimerObj.STATE_TIMESUP) { Log.d(TAG, "action to +1m but timer not in times up state - do nothing"); return; } // Restarting the timer with 1 minute left. t.setState(TimerObj.STATE_RUNNING); t.mStartTime = Utils.getTimeNow(); t.mTimeLeft = t.mOriginalLength = TimerObj.MINUTE_IN_MILLIS; t.writeToSharedPref(prefs); // Flag to tell DeskClock to re-sync with the database prefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, true).apply(); cancelTimesUpNotification(context, t); // If the app is not open, refresh the in-use notification if (!prefs.getBoolean(Timers.NOTIF_APP_OPEN, false)) { showInUseNotification(context); } // Stop Ringtone if no timers are in times-up status stopRingtoneIfNoTimesup(context); } else if (Timers.TIMER_UPDATE.equals(actionType)) { // Find the timer (if it doesn't exists, it was probably deleted). if (t == null) { Log.d(TAG, " timer to update not found in list - do nothing"); return; } // Refresh buzzing notification if (t.mState == TimerObj.STATE_TIMESUP) { // Must cancel the previous notification to get all updates displayed correctly cancelTimesUpNotification(context, t); showTimesUpNotification(context, t); } } if (intent.getBooleanExtra(Timers.UPDATE_NEXT_TIMESUP, true)) { // Update the next "Times up" alarm unless explicitly told not to. updateNextTimesup(context); } }
From source file:se.erichansander.retrotimer.TimerKlaxon.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { TinyTracelog.trace("4"); // No intent, tell the system not to restart us. if (intent == null) { TinyTracelog.trace("4.e"); stopSelf();/* w ww . j a v a 2s. c o m*/ return START_NOT_STICKY; } boolean ring = mPrefs.getBoolean(RetroTimer.PREF_RING_ON_ALARM, true); boolean vibrate = mPrefs.getBoolean(RetroTimer.PREF_VIBRATE_ON_ALARM, true); long timeoutMillis = mPrefs.getLong(RetroTimer.PREF_ALARM_TIMEOUT_MILLIS, 10 * 1000); mAlarmTime = intent.getLongExtra(RetroTimer.ALARM_TIME_EXTRA, 0); // Close dialogs and window shade sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); // Trigger a notification that, when clicked, will dismiss the alarm. Intent notify = new Intent(RetroTimer.ALARM_DISMISS_ACTION); PendingIntent pendingNotify = PendingIntent.getBroadcast(this, 0, notify, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentIntent(pendingNotify) .setDefaults(Notification.DEFAULT_LIGHTS).setOngoing(true) .setSmallIcon(R.drawable.ic_stat_alarm_triggered) .setContentTitle(getString(R.string.notify_triggered_label)) .setContentText(getString(R.string.notify_triggered_text)); /* * Send the notification using the alarm id to easily identify the * correct notification. */ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(RetroTimer.NOTIF_SET_ID); nm.notify(RetroTimer.NOTIF_TRIGGERED_ID, mBuilder.build()); /* * launch UI, explicitly stating that this is not due to user action so * that the current app's notification management is not disturbed */ Intent timerAlert = new Intent(this, TimerAlert.class); timerAlert.putExtra(RetroTimer.ALARM_TIME_EXTRA, mAlarmTime); timerAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); startActivity(timerAlert); play(ring, vibrate); startTimeoutCountdown(timeoutMillis); // Record the initial call state here so that the new alarm has the // newest state. mInitialCallState = mTelephonyManager.getCallState(); // Update the shared state RetroTimer.clearAlarm(this); return START_STICKY; }
From source file:com.android.deskclock.data.TimerNotificationBuilderPreN.java
@Override public Notification buildHeadsUp(Context context, List<Timer> expired) { // Generate some descriptive text, a title, and an action name based on the timer count. final int timerId; final String contentText; final String contentTitle; final String resetActionTitle; final int count = expired.size(); if (count == 1) { final Timer timer = expired.get(0); timerId = timer.getId();// www. j a v a 2 s. com resetActionTitle = context.getString(R.string.timer_stop); contentText = context.getString(R.string.timer_times_up); final String label = timer.getLabel(); if (TextUtils.isEmpty(label)) { contentTitle = context.getString(R.string.timer_notification_label); } else { contentTitle = label; } } else { timerId = -1; contentText = context.getString(R.string.timer_multi_times_up, count); contentTitle = context.getString(R.string.timer_notification_label); resetActionTitle = context.getString(R.string.timer_stop_all); } // Content intent shows the expired timers full screen when clicked. final Intent content = new Intent(context, ExpiredTimersActivity.class); final PendingIntent pendingContent = Utils.pendingActivityIntent(context, content); // Full screen intent has flags so it is different than the content intent. final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen); // Left button: Reset timer / Reset all timers final Intent reset = TimerService.createResetExpiredTimersIntent(context); final PendingIntent pendingReset = Utils.pendingServiceIntent(context, reset); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true) .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText) .setContentTitle(contentTitle).setContentIntent(pendingContent) .setColor(ContextCompat.getColor(context, R.color.default_background)) .setSmallIcon(R.drawable.stat_notify_timer).setFullScreenIntent(pendingFullScreen, true) .setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_LIGHTS) .addAction(R.drawable.ic_stop_24dp, resetActionTitle, pendingReset); // Add a second action if only a single timer is expired. if (count == 1) { // Right button: Add minute final Intent addMinute = TimerService.createAddMinuteTimerIntent(context, timerId); final PendingIntent pendingAddMinute = Utils.pendingServiceIntent(context, addMinute); final String addMinuteTitle = context.getString(R.string.timer_plus_1_min); builder.addAction(R.drawable.ic_add_24dp, addMinuteTitle, pendingAddMinute); } return builder.build(); }
From source file:com.android.deskclock.alarms.AlarmNotifications.java
public static void showAlarmNotification(Service service, AlarmInstance instance) { LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId); Resources resources = service.getResources(); NotificationCompat.Builder notification = new NotificationCompat.Builder(service) .setContentTitle(instance.getLabelOrDefault(service)) .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime())) .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false) .setDefaults(NotificationCompat.DEFAULT_LIGHTS).setWhen(0) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true);/* w ww . j a va 2 s. c om*/ // Setup Snooze Action Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_SNOOZE_TAG, instance, AlarmInstance.SNOOZE_STATE); snoozeIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true); PendingIntent snoozePendingIntent = PendingIntent.getService(service, instance.hashCode(), snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_snooze_24dp, resources.getString(R.string.alarm_alert_snooze_text), snoozePendingIntent); // Setup Dismiss Action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); dismissIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true); PendingIntent dismissPendingIntent = PendingIntent.getService(service, instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.addAction(R.drawable.ic_alarm_off_24dp, resources.getString(R.string.alarm_alert_dismiss_text), dismissPendingIntent); // Setup Content Action Intent contentIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId); notification.setContentIntent(PendingIntent.getActivity(service, instance.hashCode(), contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup fullscreen intent Intent fullScreenIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId); // set action, so we can be different then content pending intent fullScreenIntent.setAction("fullscreen_activity"); fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); notification.setFullScreenIntent(PendingIntent.getActivity(service, instance.hashCode(), fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT), true); notification.setPriority(NotificationCompat.PRIORITY_MAX); clearNotification(service, instance); service.startForeground(instance.hashCode(), notification.build()); }
From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderPreN.java
@Override public Notification buildHeadsUp(Context context, List<Timer> expired) { // Generate some descriptive text, a title, and an action name based on the timer count. final int timerId; final String contentText; final String contentTitle; final String resetActionTitle; final int count = expired.size(); if (count == 1) { final Timer timer = expired.get(0); timerId = timer.getId();/*from w ww .j av a 2s .c o m*/ resetActionTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_stop); contentText = context.getString(com.wizardsofm.deskclock.R.string.timer_times_up); final String label = timer.getLabel(); if (TextUtils.isEmpty(label)) { contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); } else { contentTitle = label; } } else { timerId = -1; contentText = context.getString(com.wizardsofm.deskclock.R.string.timer_multi_times_up, count); contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); resetActionTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_stop_all); } // Content intent shows the expired timers full screen when clicked. final Intent content = new Intent(context, ExpiredTimersActivity.class); final PendingIntent pendingContent = Utils.pendingActivityIntent(context, content); // Full screen intent has flags so it is different than the content intent. final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION); final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen); // Left button: Reset timer / Reset all timers final Intent reset = TimerService.createResetExpiredTimersIntent(context); final PendingIntent pendingReset = Utils.pendingServiceIntent(context, reset); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true) .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText) .setContentTitle(contentTitle).setContentIntent(pendingContent) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer) .setFullScreenIntent(pendingFullScreen, true).setPriority(NotificationCompat.PRIORITY_MAX) .setDefaults(NotificationCompat.DEFAULT_LIGHTS) .addAction(com.wizardsofm.deskclock.R.drawable.ic_stop_24dp, resetActionTitle, pendingReset); // Add a second action if only a single timer is expired. if (count == 1) { // Right button: Add minute final Intent addMinute = TimerService.createAddMinuteTimerIntent(context, timerId); final PendingIntent pendingAddMinute = Utils.pendingServiceIntent(context, addMinute); final String addMinuteTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_plus_1_min); builder.addAction(com.wizardsofm.deskclock.R.drawable.ic_add_24dp, addMinuteTitle, pendingAddMinute); } return builder.build(); }