1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.android.deskclock.timer; 16 17 import android.app.Activity; 18 import android.content.Intent; 19 import android.content.res.Configuration; 20 import android.os.Bundle; 21 import android.util.Log; 22 import android.view.KeyEvent; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.view.Window; 26 import android.view.WindowManager; 27 28 import com.android.deskclock.R; 29 import com.android.deskclock.Utils; 30 import com.android.deskclock.timer.TimerFragment.OnEmptyListListener; 31 32 /** 33 * Timer alarm alert: pops visible indicator. This activity is the version which 34 * shows over the lock screen. 35 * This activity re-uses TimerFragment GUI 36 */ 37 public class TimerAlertFullScreen extends Activity implements OnEmptyListListener { 38 39 private static final String TAG = "TimerAlertFullScreen"; 40 private static final String FRAGMENT = "timer"; 41 42 @Override 43 protected void onCreate(Bundle savedInstanceState) { 44 super.onCreate(savedInstanceState); 45 46 setContentView(R.layout.timer_alert_full_screen); 47 final View view = findViewById(R.id.fragment_container); 48 view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 49 50 final Window win = getWindow(); 51 win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 52 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 53 // Turn on the screen unless we are being launched from the AlarmAlert 54 // subclass as a result of the screen turning off. 55 win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 56 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 57 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); 58 59 // Don't create overlapping fragments. 60 if (getFragment() == null) { 61 TimerFragment timerFragment = new TimerFragment(); 62 63 // Create fragment and give it an argument to only show 64 // timers in STATE_TIMESUP state 65 Bundle args = new Bundle(); 66 args.putBoolean(Timers.TIMESUP_MODE, true); 67 68 timerFragment.setArguments(args); 69 70 // Add the fragment to the 'fragment_container' FrameLayout 71 getFragmentManager().beginTransaction() 72 .add(R.id.fragment_container, timerFragment, FRAGMENT).commit(); 73 } 74 } 75 76 @Override 77 protected void onResume() { 78 super.onResume(); 79 80 // Only show notifications for times-up when this activity closed. 81 Utils.cancelTimesUpNotifications(this); 82 } 83 84 @Override 85 public void onPause() { 86 Utils.showTimesUpNotifications(this); 87 88 super.onPause(); 89 } 90 91 @Override 92 public boolean dispatchKeyEvent(KeyEvent event) { 93 // Handle key down and key up on a few of the system keys. 94 boolean up = event.getAction() == KeyEvent.ACTION_UP; 95 switch (event.getKeyCode()) { 96 // Volume keys and camera keys stop all the timers 97 case KeyEvent.KEYCODE_VOLUME_UP: 98 case KeyEvent.KEYCODE_VOLUME_DOWN: 99 case KeyEvent.KEYCODE_VOLUME_MUTE: 100 case KeyEvent.KEYCODE_CAMERA: 101 case KeyEvent.KEYCODE_FOCUS: 102 if (up) { 103 stopAllTimesUpTimers(); 104 } 105 return true; 106 107 default: 108 break; 109 } 110 return super.dispatchKeyEvent(event); 111 } 112 113 /** 114 * this is called when a second timer is triggered while a previous alert 115 * window is still active. 116 */ 117 @Override 118 protected void onNewIntent(Intent intent) { 119 TimerFragment timerFragment = getFragment(); 120 if (timerFragment != null) { 121 timerFragment.restartAdapter(); 122 } 123 super.onNewIntent(intent); 124 } 125 126 @Override 127 public void onConfigurationChanged(Configuration newConfig) { 128 ViewGroup viewContainer = (ViewGroup)findViewById(R.id.fragment_container); 129 viewContainer.requestLayout(); 130 super.onConfigurationChanged(newConfig); 131 } 132 133 @Override 134 protected void onStop() { 135 super.onStop(); 136 } 137 138 protected void stopAllTimesUpTimers() { 139 TimerFragment timerFragment = getFragment(); 140 if (timerFragment != null) { 141 timerFragment.stopAllTimesUpTimers(); 142 } 143 } 144 145 @Override 146 public void onEmptyList() { 147 if (Timers.LOGGING) { 148 Log.v(TAG, "onEmptyList"); 149 } 150 onListChanged(); 151 finish(); 152 } 153 154 @Override 155 public void onListChanged() { 156 Utils.showInUseNotifications(this); 157 } 158 159 private TimerFragment getFragment() { 160 return (TimerFragment) getFragmentManager().findFragmentByTag(FRAGMENT); 161 } 162 } 163