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.view.KeyEvent; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.view.Window; 25 import android.view.WindowManager; 26 27 import com.android.deskclock.R; 28 import com.android.deskclock.Utils; 29 import com.android.deskclock.timer.TimerFragment.OnEmptyListListener; 30 31 /** 32 * Timer alarm alert: pops visible indicator. This activity is the version which 33 * shows over the lock screen. 34 */ 35 public class TimerAlertFullScreen extends Activity implements OnEmptyListListener { 36 37 // private static final String TAG = "TimerAlertFullScreen"; 38 private static final String FRAGMENT = "timer"; 39 40 @Override onCreate(Bundle savedInstanceState)41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 setContentView(R.layout.timer_alert_full_screen); 45 final View view = findViewById(R.id.fragment_container); 46 view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 47 48 final Window win = getWindow(); 49 win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 50 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 51 // Turn on the screen unless we are being launched from the AlarmAlert 52 // subclass as a result of the screen turning off. 53 win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 54 | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON 55 | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON); 56 57 // Don't create overlapping fragments. 58 if (getFragment() == null) { 59 TimerFragment timerFragment = new TimerFragment(); 60 61 // Create fragment and give it an argument to only show 62 // timers in STATE_TIMESUP state 63 Bundle args = new Bundle(); 64 args.putBoolean(Timers.TIMESUP_MODE, true); 65 66 timerFragment.setArguments(args); 67 68 // Add the fragment to the 'fragment_container' FrameLayout 69 getFragmentManager().beginTransaction() 70 .add(R.id.fragment_container, timerFragment, FRAGMENT).commit(); 71 } 72 } 73 74 @Override dispatchKeyEvent(KeyEvent event)75 public boolean dispatchKeyEvent(KeyEvent event) { 76 // Handle key down and key up on a few of the system keys. 77 boolean up = event.getAction() == KeyEvent.ACTION_UP; 78 switch (event.getKeyCode()) { 79 // Volume keys and camera keys stop all the timers 80 case KeyEvent.KEYCODE_VOLUME_UP: 81 case KeyEvent.KEYCODE_VOLUME_DOWN: 82 case KeyEvent.KEYCODE_VOLUME_MUTE: 83 case KeyEvent.KEYCODE_CAMERA: 84 case KeyEvent.KEYCODE_FOCUS: 85 if (up) { 86 stopAllTimesUpTimers(); 87 } 88 return true; 89 90 default: 91 break; 92 } 93 return super.dispatchKeyEvent(event); 94 } 95 96 /** 97 * this is called when a second timer is triggered while a previous alert 98 * window is still active. 99 */ 100 @Override onNewIntent(Intent intent)101 protected void onNewIntent(Intent intent) { 102 TimerFragment timerFragment = getFragment(); 103 if (timerFragment != null) { 104 timerFragment.restartAdapter(); 105 } 106 super.onNewIntent(intent); 107 } 108 109 @Override onConfigurationChanged(Configuration newConfig)110 public void onConfigurationChanged(Configuration newConfig) { 111 ViewGroup viewContainer = (ViewGroup)findViewById(R.id.fragment_container); 112 viewContainer.requestLayout(); 113 super.onConfigurationChanged(newConfig); 114 } 115 116 @Override onStop()117 protected void onStop() { 118 super.onStop(); 119 } 120 stopAllTimesUpTimers()121 protected void stopAllTimesUpTimers() { 122 TimerFragment timerFragment = getFragment(); 123 if (timerFragment != null) { 124 timerFragment.stopAllTimesUpTimers(); 125 } 126 } 127 128 @Override onEmptyList()129 public void onEmptyList() { 130 onListChanged(); 131 finish(); 132 } 133 134 @Override onListChanged()135 public void onListChanged() { 136 Utils.showInUseNotifications(this); 137 } 138 getFragment()139 private TimerFragment getFragment() { 140 return (TimerFragment) getFragmentManager().findFragmentByTag(FRAGMENT); 141 } 142 } 143