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