• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.TimerFullScreenFragment.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 TimerFullScreenFragment 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
onCreate(Bundle savedInstanceState)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             TimerFullScreenFragment timerFragment = new TimerFullScreenFragment();
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
onResume()77     protected void onResume() {
78         super.onResume();
79 
80         getWindow().getDecorView().setBackgroundColor(Utils.getCurrentHourColor());
81 
82         // Only show notifications for times-up when this activity closed.
83         Utils.cancelTimesUpNotifications(this);
84     }
85 
86     @Override
onPause()87     public void onPause() {
88         Utils.showTimesUpNotifications(this);
89 
90         super.onPause();
91     }
92 
93     @Override
dispatchKeyEvent(KeyEvent event)94     public boolean dispatchKeyEvent(KeyEvent event) {
95         // Handle key down and key up on a few of the system keys.
96         boolean up = event.getAction() == KeyEvent.ACTION_UP;
97         switch (event.getKeyCode()) {
98         // Volume keys and camera keys stop all the timers
99         case KeyEvent.KEYCODE_VOLUME_UP:
100         case KeyEvent.KEYCODE_VOLUME_DOWN:
101         case KeyEvent.KEYCODE_VOLUME_MUTE:
102         case KeyEvent.KEYCODE_CAMERA:
103         case KeyEvent.KEYCODE_FOCUS:
104             if (up) {
105                 stopAllTimesUpTimers();
106             }
107             return true;
108 
109         default:
110             break;
111         }
112         return super.dispatchKeyEvent(event);
113     }
114 
115     /**
116      * this is called when a second timer is triggered while a previous alert
117      * window is still active.
118      */
119     @Override
onNewIntent(Intent intent)120     protected void onNewIntent(Intent intent) {
121         TimerFullScreenFragment timerFragment = getFragment();
122         if (timerFragment != null) {
123             timerFragment.restartAdapter();
124         }
125         super.onNewIntent(intent);
126     }
127 
128     @Override
onConfigurationChanged(Configuration newConfig)129     public void onConfigurationChanged(Configuration newConfig) {
130         ViewGroup viewContainer = (ViewGroup)findViewById(R.id.fragment_container);
131         viewContainer.requestLayout();
132         super.onConfigurationChanged(newConfig);
133     }
134 
stopAllTimesUpTimers()135     protected void stopAllTimesUpTimers() {
136         TimerFullScreenFragment timerFragment = getFragment();
137         if (timerFragment != null) {
138             timerFragment.updateAllTimesUpTimers(true /* stop */);
139         }
140     }
141 
142     @Override
onEmptyList()143     public void onEmptyList() {
144         if (Timers.LOGGING) {
145             Log.v(TAG, "onEmptyList");
146         }
147         onListChanged();
148         finish();
149     }
150 
151     @Override
onListChanged()152     public void onListChanged() {
153         Utils.showInUseNotifications(this);
154     }
155 
getFragment()156     private TimerFullScreenFragment getFragment() {
157         return (TimerFullScreenFragment) getFragmentManager().findFragmentByTag(FRAGMENT);
158     }
159 }
160