2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.deskclock;
19 import android.app.Activity;
20 import android.app.AlarmManager;
21 import android.app.AlertDialog;
22 import android.app.PendingIntent;
23 import android.content.BroadcastReceiver;
24 import android.content.Context;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.content.IntentFilter;
28 import android.content.SharedPreferences;
29 import android.content.pm.PackageManager;
30 import android.content.res.Configuration;
31 import android.content.res.Resources;
32 import android.database.Cursor;
33 import android.graphics.drawable.BitmapDrawable;
34 import android.graphics.drawable.ColorDrawable;
35 import android.graphics.drawable.Drawable;
36 import android.net.Uri;
37 import android.os.Bundle;
38 import android.os.Handler;
39 import android.os.Message;
40 import android.os.SystemClock;
41 import android.os.PowerManager;
42 import android.provider.Settings;
43 import android.text.TextUtils;
44 import android.text.format.DateFormat;
45 import android.util.DisplayMetrics;
46 import android.util.Log;
47 import android.view.ContextMenu.ContextMenuInfo;
48 import android.view.ContextMenu;
49 import android.view.LayoutInflater;
50 import android.view.Menu;
51 import android.view.MenuInflater;
52 import android.view.MenuItem;
53 import android.view.View.OnClickListener;
54 import android.view.View.OnCreateContextMenuListener;
55 import android.view.View;
56 import android.view.ViewGroup;
57 import android.view.Window;
58 import android.view.WindowManager;
59 import android.view.animation.Animation;
60 import android.view.animation.AnimationUtils;
61 import android.view.animation.TranslateAnimation;
62 import android.widget.AbsoluteLayout;
63 import android.widget.AdapterView.AdapterContextMenuInfo;
64 import android.widget.AdapterView.OnItemClickListener;
65 import android.widget.AdapterView;
66 import android.widget.Button;
67 import android.widget.CheckBox;
68 import android.widget.ImageButton;
69 import android.widget.ImageView;
70 import android.widget.TextView;
72 import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
73 import static android.os.BatteryManager.BATTERY_STATUS_FULL;
74 import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
76 import java.io.IOException;
77 import java.io.InputStream;
78 import java.util.Calendar;
79 import java.util.Date;
80 import java.util.Locale;
81 import java.util.Random;
84 * DeskClock clock view for desk docks.
86 public class DeskClock extends Activity {
87 private static final boolean DEBUG = false;
89 private static final String LOG_TAG = "DeskClock";
91 // Package ID of the music player.
92 private static final String MUSIC_PACKAGE_ID = "com.android.music";
94 // Alarm action for midnight (so we can update the date display).
95 private static final String ACTION_MIDNIGHT = "com.android.deskclock.MIDNIGHT";
97 // Interval between polls of the weather widget. Its refresh period is
98 // likely to be much longer (~3h), but we want to pick up any changes
100 private final long QUERY_WEATHER_DELAY = 5 * 60 * 1000; // 5 min
102 // Delay before engaging the burn-in protection mode (green-on-black).
103 private final long SCREEN_SAVER_TIMEOUT = 5* 60 * 1000; // 10 min
105 // Repositioning delay in screen saver.
106 private final long SCREEN_SAVER_MOVE_DELAY = 60 * 1000; // 1 min
108 // Color to use for text & graphics in screen saver mode.
109 private final int SCREEN_SAVER_COLOR = 0xFF308030;
110 private final int SCREEN_SAVER_COLOR_DIM = 0xFF183018;
112 // Opacity of black layer between clock display and wallpaper.
113 private final float DIM_BEHIND_AMOUNT_NORMAL = 0.4f;
114 private final float DIM_BEHIND_AMOUNT_DIMMED = 0.7f; // higher contrast when display dimmed
116 // Internal message IDs.
117 private final int QUERY_WEATHER_DATA_MSG = 0x1000;
118 private final int UPDATE_WEATHER_DISPLAY_MSG = 0x1001;
119 private final int SCREEN_SAVER_TIMEOUT_MSG = 0x2000;
120 private final int SCREEN_SAVER_MOVE_MSG = 0x2001;
122 // Weather widget query information.
123 private static final String GENIE_PACKAGE_ID = "com.google.android.apps.genie.geniewidget";
124 private static final String WEATHER_CONTENT_AUTHORITY = GENIE_PACKAGE_ID + ".weather";
125 private static final String WEATHER_CONTENT_PATH = "/weather/current";
126 private static final String[] WEATHER_CONTENT_COLUMNS = new String[] {
137 private static final String ACTION_GENIE_REFRESH = "com.google.android.apps.genie.REFRESH";
139 // State variables follow.
140 private DigitalClock mTime;
141 private TextView mDate;
143 private TextView mNextAlarm = null;
144 private TextView mBatteryDisplay;
146 private TextView mWeatherCurrentTemperature;
147 private TextView mWeatherHighTemperature;
148 private TextView mWeatherLowTemperature;
149 private TextView mWeatherLocation;
150 private ImageView mWeatherIcon;
152 private String mWeatherCurrentTemperatureString;
153 private String mWeatherHighTemperatureString;
154 private String mWeatherLowTemperatureString;
155 private String mWeatherLocationString;
156 private Drawable mWeatherIconDrawable;
158 private Resources mGenieResources = null;
160 private boolean mDimmed = false;
161 private boolean mScreenSaverMode = false;
163 private String mDateFormat;
165 private int mBatteryLevel = -1;
166 private boolean mPluggedIn = false;
168 private boolean mLaunchedFromDock = false;
170 private int mIdleTimeoutEpoch = 0;
174 private PendingIntent mMidnightIntent;
176 private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
178 public void onReceive(Context context, Intent intent) {
179 final String action = intent.getAction();
180 if (Intent.ACTION_DATE_CHANGED.equals(action)) {
182 } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
184 intent.getIntExtra("status", BATTERY_STATUS_UNKNOWN),
185 intent.getIntExtra("level", 0));
186 } else if (Intent.ACTION_DOCK_EVENT.equals(action)) {
187 int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1);
188 if (DEBUG) Log.d(LOG_TAG, "ACTION_DOCK_EVENT, state=" + state);
189 if (state == Intent.EXTRA_DOCK_STATE_UNDOCKED) {
190 if (mLaunchedFromDock) {
191 // moveTaskToBack(false);
194 mLaunchedFromDock = false;
200 private final Handler mHandy = new Handler() {
202 public void handleMessage(Message m) {
203 if (m.what == QUERY_WEATHER_DATA_MSG) {
204 new Thread() { public void run() { queryWeatherData(); } }.start();
205 scheduleWeatherQueryDelayed(QUERY_WEATHER_DELAY);
206 } else if (m.what == UPDATE_WEATHER_DISPLAY_MSG) {
207 updateWeatherDisplay();
208 } else if (m.what == SCREEN_SAVER_TIMEOUT_MSG) {
209 if (m.arg1 == mIdleTimeoutEpoch) {
212 } else if (m.what == SCREEN_SAVER_MOVE_MSG) {
219 private void moveScreenSaver() {
220 moveScreenSaverTo(-1,-1);
222 private void moveScreenSaverTo(int x, int y) {
223 if (!mScreenSaverMode) return;
225 final View saver_view = findViewById(R.id.saver_view);
227 DisplayMetrics metrics = new DisplayMetrics();
228 getWindowManager().getDefaultDisplay().getMetrics(metrics);
230 if (x < 0 || y < 0) {
231 int myWidth = saver_view.getMeasuredWidth();
232 int myHeight = saver_view.getMeasuredHeight();
233 x = (int)(mRNG.nextFloat()*(metrics.widthPixels - myWidth));
234 y = (int)(mRNG.nextFloat()*(metrics.heightPixels - myHeight));
237 if (DEBUG) Log.d(LOG_TAG, String.format("screen saver: %d: jumping to (%d,%d)",
238 System.currentTimeMillis(), x, y));
240 saver_view.setLayoutParams(new AbsoluteLayout.LayoutParams(
241 ViewGroup.LayoutParams.WRAP_CONTENT,
242 ViewGroup.LayoutParams.WRAP_CONTENT,
246 // Synchronize our jumping so that it happens exactly on the second.
247 mHandy.sendEmptyMessageDelayed(SCREEN_SAVER_MOVE_MSG,
248 SCREEN_SAVER_MOVE_DELAY +
249 (1000 - (System.currentTimeMillis() % 1000)));
252 private void setWakeLock(boolean hold) {
253 if (DEBUG) Log.d(LOG_TAG, (hold ? "hold" : " releas") + "ing wake lock");
254 Window win = getWindow();
255 WindowManager.LayoutParams winParams = win.getAttributes();
256 winParams.flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
257 winParams.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
258 winParams.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
260 winParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
262 winParams.flags &= (~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
263 win.setAttributes(winParams);
266 private void restoreScreen() {
267 if (!mScreenSaverMode) return;
268 if (DEBUG) Log.d(LOG_TAG, "restoreScreen");
269 mScreenSaverMode = false;
271 doDim(false); // restores previous dim mode
272 // policy: update weather info when returning from screen saver
273 if (mPluggedIn) requestWeatherDataFetch();
277 // Special screen-saver mode for OLED displays that burn in quickly
278 private void saveScreen() {
279 if (mScreenSaverMode) return;
280 if (DEBUG) Log.d(LOG_TAG, "saveScreen");
282 // quickly stash away the x/y of the current date
283 final View oldTimeDate = findViewById(R.id.time_date);
284 int oldLoc[] = new int[2];
285 oldTimeDate.getLocationOnScreen(oldLoc);
287 mScreenSaverMode = true;
288 Window win = getWindow();
289 WindowManager.LayoutParams winParams = win.getAttributes();
290 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
291 win.setAttributes(winParams);
293 // give up any internal focus before we switch layouts
294 final View focused = getCurrentFocus();
295 if (focused != null) focused.clearFocus();
297 setContentView(R.layout.desk_clock_saver);
299 mTime = (DigitalClock) findViewById(R.id.time);
300 mDate = (TextView) findViewById(R.id.date);
301 mNextAlarm = (TextView) findViewById(R.id.nextAlarm);
303 final int color = mDimmed ? SCREEN_SAVER_COLOR_DIM : SCREEN_SAVER_COLOR;
305 ((TextView)findViewById(R.id.timeDisplay)).setTextColor(color);
306 ((TextView)findViewById(R.id.am_pm)).setTextColor(color);
307 mDate.setTextColor(color);
308 mNextAlarm.setTextColor(color);
309 mNextAlarm.setCompoundDrawablesWithIntrinsicBounds(
310 getResources().getDrawable(mDimmed
311 ? R.drawable.ic_lock_idle_alarm_saver_dim
312 : R.drawable.ic_lock_idle_alarm_saver),
316 mWeatherCurrentTemperature =
317 mWeatherHighTemperature =
318 mWeatherLowTemperature =
319 mWeatherLocation = null;
325 moveScreenSaverTo(oldLoc[0], oldLoc[1]);
329 public void onUserInteraction() {
330 if (mScreenSaverMode)
334 // Tell the Genie widget to load new data from the network.
335 private void requestWeatherDataFetch() {
336 if (DEBUG) Log.d(LOG_TAG, "forcing the Genie widget to update weather now...");
337 sendBroadcast(new Intent(ACTION_GENIE_REFRESH).putExtra("requestWeather", true));
338 // update the display with any new data
339 scheduleWeatherQueryDelayed(5000);
342 private boolean supportsWeather() {
343 return (mGenieResources != null);
346 private void scheduleWeatherQueryDelayed(long delay) {
347 // cancel any existing scheduled queries
348 unscheduleWeatherQuery();
350 if (DEBUG) Log.d(LOG_TAG, "scheduling weather fetch message for " + delay + "ms from now");
352 mHandy.sendEmptyMessageDelayed(QUERY_WEATHER_DATA_MSG, delay);
355 private void unscheduleWeatherQuery() {
356 mHandy.removeMessages(QUERY_WEATHER_DATA_MSG);
359 private void queryWeatherData() {
360 // if we couldn't load the weather widget's resources, we simply
361 // assume it's not present on the device.
362 if (mGenieResources == null) return;
364 Uri queryUri = new Uri.Builder()
365 .scheme(android.content.ContentResolver.SCHEME_CONTENT)
366 .authority(WEATHER_CONTENT_AUTHORITY)
367 .path(WEATHER_CONTENT_PATH)
368 .appendPath(new Long(System.currentTimeMillis()).toString())
371 if (DEBUG) Log.d(LOG_TAG, "querying genie: " + queryUri);
377 WEATHER_CONTENT_COLUMNS,
381 } catch (RuntimeException e) {
382 Log.e(LOG_TAG, "Weather query failed", e);
386 if (cur != null && cur.moveToFirst()) {
388 java.lang.StringBuilder sb =
389 new java.lang.StringBuilder("Weather query result: {");
390 for(int i=0; i<cur.getColumnCount(); i++) {
391 if (i>0) sb.append(", ");
392 sb.append(cur.getColumnName(i))
394 .append(cur.getString(i));
397 Log.d(LOG_TAG, sb.toString());
400 mWeatherIconDrawable = mGenieResources.getDrawable(cur.getInt(
401 cur.getColumnIndexOrThrow("iconResId")));
402 mWeatherCurrentTemperatureString = String.format("%d\u00b0",
403 (cur.getInt(cur.getColumnIndexOrThrow("temperature"))));
404 mWeatherHighTemperatureString = String.format("%d\u00b0",
405 (cur.getInt(cur.getColumnIndexOrThrow("highTemperature"))));
406 mWeatherLowTemperatureString = String.format("%d\u00b0",
407 (cur.getInt(cur.getColumnIndexOrThrow("lowTemperature"))));
408 mWeatherLocationString = cur.getString(
409 cur.getColumnIndexOrThrow("location"));
411 Log.w(LOG_TAG, "No weather information available (cur="
413 mWeatherIconDrawable = null;
414 mWeatherHighTemperatureString = "";
415 mWeatherLowTemperatureString = "";
416 mWeatherLocationString = getString(R.string.weather_fetch_failure);
419 mHandy.sendEmptyMessage(UPDATE_WEATHER_DISPLAY_MSG);
422 private void refreshWeather() {
423 if (supportsWeather())
424 scheduleWeatherQueryDelayed(0);
425 updateWeatherDisplay(); // in case we have it cached
428 private void updateWeatherDisplay() {
429 if (mWeatherCurrentTemperature == null) return;
431 mWeatherCurrentTemperature.setText(mWeatherCurrentTemperatureString);
432 mWeatherHighTemperature.setText(mWeatherHighTemperatureString);
433 mWeatherLowTemperature.setText(mWeatherLowTemperatureString);
434 mWeatherLocation.setText(mWeatherLocationString);
435 mWeatherIcon.setImageDrawable(mWeatherIconDrawable);
438 // Adapted from KeyguardUpdateMonitor.java
439 private void handleBatteryUpdate(int plugStatus, int batteryLevel) {
440 final boolean pluggedIn = (plugStatus == BATTERY_STATUS_CHARGING || plugStatus == BATTERY_STATUS_FULL);
441 if (pluggedIn != mPluggedIn) {
442 setWakeLock(pluggedIn);
445 // policy: update weather info when attaching to power
446 requestWeatherDataFetch();
449 if (pluggedIn != mPluggedIn || batteryLevel != mBatteryLevel) {
450 mBatteryLevel = batteryLevel;
451 mPluggedIn = pluggedIn;
456 private void refreshBattery() {
457 if (mBatteryDisplay == null) return;
459 if (mPluggedIn /* || mBatteryLevel < LOW_BATTERY_THRESHOLD */) {
460 mBatteryDisplay.setCompoundDrawablesWithIntrinsicBounds(
461 0, 0, android.R.drawable.ic_lock_idle_charging, 0);
462 mBatteryDisplay.setText(
463 getString(R.string.battery_charging_level, mBatteryLevel));
464 mBatteryDisplay.setVisibility(View.VISIBLE);
466 mBatteryDisplay.setVisibility(View.INVISIBLE);
470 private void refreshDate() {
471 final Date now = new Date();
472 if (DEBUG) Log.d(LOG_TAG, "refreshing date..." + now);
473 mDate.setText(DateFormat.format(mDateFormat, now));
476 private void refreshAlarm() {
477 if (mNextAlarm == null) return;
479 String nextAlarm = Settings.System.getString(getContentResolver(),
480 Settings.System.NEXT_ALARM_FORMATTED);
481 if (!TextUtils.isEmpty(nextAlarm)) {
482 mNextAlarm.setText(nextAlarm);
483 //mNextAlarm.setCompoundDrawablesWithIntrinsicBounds(
484 // android.R.drawable.ic_lock_idle_alarm, 0, 0, 0);
485 mNextAlarm.setVisibility(View.VISIBLE);
487 mNextAlarm.setVisibility(View.INVISIBLE);
491 private void refreshAll() {
498 private void doDim(boolean fade) {
499 View tintView = findViewById(R.id.window_tint);
500 if (tintView == null) return;
502 Window win = getWindow();
503 WindowManager.LayoutParams winParams = win.getAttributes();
505 winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
506 winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
508 // dim the wallpaper somewhat (how much is determined below)
509 winParams.flags |= (WindowManager.LayoutParams.FLAG_DIM_BEHIND);
512 winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
513 winParams.dimAmount = DIM_BEHIND_AMOUNT_DIMMED;
515 // show the window tint
516 tintView.startAnimation(AnimationUtils.loadAnimation(this,
518 : R.anim.dim_instant));
520 winParams.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
521 winParams.dimAmount = DIM_BEHIND_AMOUNT_NORMAL;
523 // hide the window tint
524 tintView.startAnimation(AnimationUtils.loadAnimation(this,
526 : R.anim.undim_instant));
529 win.setAttributes(winParams);
533 public void onNewIntent(Intent newIntent) {
534 super.onNewIntent(newIntent);
535 if (DEBUG) Log.d(LOG_TAG, "onNewIntent with intent: " + newIntent);
537 // update our intent so that we can consult it to determine whether or
538 // not the most recent launch was via a dock event
539 setIntent(newIntent);
543 public void onResume() {
545 if (DEBUG) Log.d(LOG_TAG, "onResume with intent: " + getIntent());
547 // reload the date format in case the user has changed settings
549 mDateFormat = getString(com.android.internal.R.string.full_wday_month_day_no_year);
551 IntentFilter filter = new IntentFilter();
552 filter.addAction(Intent.ACTION_DATE_CHANGED);
553 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
554 filter.addAction(Intent.ACTION_DOCK_EVENT);
555 filter.addAction(ACTION_MIDNIGHT);
556 registerReceiver(mIntentReceiver, filter);
558 Calendar today = Calendar.getInstance();
559 today.add(Calendar.DATE, 1);
560 mMidnightIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_MIDNIGHT), 0);
561 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
562 am.setRepeating(AlarmManager.RTC, today.getTimeInMillis(), AlarmManager.INTERVAL_DAY, mMidnightIntent);
564 // un-dim when resuming
568 restoreScreen(); // disable screen saver
569 refreshAll(); // will schedule periodic weather fetch
571 setWakeLock(mPluggedIn);
574 mHandy.sendMessageDelayed(
575 Message.obtain(mHandy, SCREEN_SAVER_TIMEOUT_MSG, mIdleTimeoutEpoch, 0),
576 SCREEN_SAVER_TIMEOUT);
578 final boolean launchedFromDock
579 = getIntent().hasCategory(Intent.CATEGORY_DESK_DOCK);
581 if (supportsWeather() && launchedFromDock && !mLaunchedFromDock) {
582 // policy: fetch weather if launched via dock connection
583 if (DEBUG) Log.d(LOG_TAG, "Device now docked; forcing weather to refresh right now");
584 requestWeatherDataFetch();
587 mLaunchedFromDock = launchedFromDock;
591 public void onPause() {
592 if (DEBUG) Log.d(LOG_TAG, "onPause");
594 // Turn off the screen saver. (But don't un-dim.)
597 // Other things we don't want to be doing in the background.
598 unregisterReceiver(mIntentReceiver);
599 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
600 am.cancel(mMidnightIntent);
601 unscheduleWeatherQuery();
607 public void onStop() {
608 if (DEBUG) Log.d(LOG_TAG, "onStop");
610 // Avoid situations where the user launches Alarm Clock and is
611 // surprised to find it in dim mode (because it was last used in dim
612 // mode, but that last use is long in the past).
618 private void initViews() {
619 // give up any internal focus before we switch layouts
620 final View focused = getCurrentFocus();
621 if (focused != null) focused.clearFocus();
623 setContentView(R.layout.desk_clock);
625 mTime = (DigitalClock) findViewById(R.id.time);
626 mDate = (TextView) findViewById(R.id.date);
627 mBatteryDisplay = (TextView) findViewById(R.id.battery);
629 mTime.getRootView().requestFocus();
631 mWeatherCurrentTemperature = (TextView) findViewById(R.id.weather_temperature);
632 mWeatherHighTemperature = (TextView) findViewById(R.id.weather_high_temperature);
633 mWeatherLowTemperature = (TextView) findViewById(R.id.weather_low_temperature);
634 mWeatherLocation = (TextView) findViewById(R.id.weather_location);
635 mWeatherIcon = (ImageView) findViewById(R.id.weather_icon);
637 final View.OnClickListener alarmClickListener = new View.OnClickListener() {
638 public void onClick(View v) {
639 startActivity(new Intent(DeskClock.this, AlarmClock.class));
643 mNextAlarm = (TextView) findViewById(R.id.nextAlarm);
644 mNextAlarm.setOnClickListener(alarmClickListener);
646 final ImageButton alarmButton = (ImageButton) findViewById(R.id.alarm_button);
647 alarmButton.setOnClickListener(alarmClickListener);
649 final ImageButton galleryButton = (ImageButton) findViewById(R.id.gallery_button);
650 galleryButton.setOnClickListener(new View.OnClickListener() {
651 public void onClick(View v) {
653 startActivity(new Intent(
655 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
656 .putExtra("slideshow", true)
657 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP));
658 } catch (android.content.ActivityNotFoundException e) {
659 Log.e(LOG_TAG, "Couldn't launch image browser", e);
664 final ImageButton musicButton = (ImageButton) findViewById(R.id.music_button);
665 musicButton.setOnClickListener(new View.OnClickListener() {
666 public void onClick(View v) {
668 Intent musicAppQuery = getPackageManager()
669 .getLaunchIntentForPackage(MUSIC_PACKAGE_ID)
670 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
671 if (musicAppQuery != null) {
672 startActivity(musicAppQuery);
674 } catch (android.content.ActivityNotFoundException e) {
675 Log.e(LOG_TAG, "Couldn't launch music browser", e);
680 final ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
681 homeButton.setOnClickListener(new View.OnClickListener() {
682 public void onClick(View v) {
684 new Intent(Intent.ACTION_MAIN)
685 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP)
686 .addCategory(Intent.CATEGORY_HOME));
690 final ImageButton nightmodeButton = (ImageButton) findViewById(R.id.nightmode_button);
691 nightmodeButton.setOnClickListener(new View.OnClickListener() {
692 public void onClick(View v) {
698 nightmodeButton.setOnLongClickListener(new View.OnLongClickListener() {
699 public boolean onLongClick(View v) {
705 final View weatherView = findViewById(R.id.weather);
706 weatherView.setOnClickListener(new View.OnClickListener() {
707 public void onClick(View v) {
708 if (!supportsWeather()) return;
710 Intent genieAppQuery = getPackageManager()
711 .getLaunchIntentForPackage(GENIE_PACKAGE_ID)
712 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
713 if (genieAppQuery != null) {
714 startActivity(genieAppQuery);
721 public void onConfigurationChanged(Configuration newConfig) {
722 super.onConfigurationChanged(newConfig);
723 if (!mScreenSaverMode) {
731 public boolean onOptionsItemSelected(MenuItem item) {
732 if (item.getItemId() == R.id.menu_item_alarms) {
733 startActivity(new Intent(DeskClock.this, AlarmClock.class));
735 } else if (item.getItemId() == R.id.menu_item_add_alarm) {
736 AlarmClock.addNewAlarm(this);
743 public boolean onCreateOptionsMenu(Menu menu) {
744 MenuInflater inflater = getMenuInflater();
745 inflater.inflate(R.menu.desk_clock_menu, menu);
750 protected void onCreate(Bundle icicle) {
751 super.onCreate(icicle);
756 mGenieResources = getPackageManager().getResourcesForApplication(GENIE_PACKAGE_ID);
757 } catch (PackageManager.NameNotFoundException e) {
758 // no weather info available
759 Log.w(LOG_TAG, "Can't find "+GENIE_PACKAGE_ID+". Weather forecast will not be available.");