OSDN Git Service

51ebbdba3d9277111c30b8f685b0cde65a63f8e9
[android-x86/packages-apps-DeskClock.git] / src / com / android / deskclock / DeskClock.java
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.deskclock;
18
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.content.BroadcastReceiver;
22 import android.content.Context;
23 import android.content.DialogInterface;
24 import android.content.Intent;
25 import android.content.IntentFilter;
26 import android.content.SharedPreferences;
27 import android.content.pm.PackageManager;
28 import android.content.res.Configuration;
29 import android.content.res.Resources;
30 import android.database.Cursor;
31 import android.graphics.drawable.BitmapDrawable;
32 import android.graphics.drawable.ColorDrawable;
33 import android.graphics.drawable.Drawable;
34 import android.net.Uri;
35 import android.os.Bundle;
36 import android.os.Handler;
37 import android.os.Message;
38 import android.os.SystemClock;
39 import android.os.PowerManager;
40 import android.provider.Settings;
41 import android.text.TextUtils;
42 import android.util.DisplayMetrics;
43 import android.util.Log;
44 import android.view.ContextMenu.ContextMenuInfo;
45 import android.view.ContextMenu;
46 import android.view.LayoutInflater;
47 import android.view.Menu;
48 import android.view.MenuItem;
49 import android.view.View.OnClickListener;
50 import android.view.View.OnCreateContextMenuListener;
51 import android.view.View;
52 import android.view.ViewGroup;
53 import android.view.Window;
54 import android.view.WindowManager;
55 import android.view.animation.Animation;
56 import android.view.animation.AnimationUtils;
57 import android.view.animation.TranslateAnimation;
58 import android.widget.AbsoluteLayout;
59 import android.widget.AdapterView.AdapterContextMenuInfo;
60 import android.widget.AdapterView.OnItemClickListener;
61 import android.widget.AdapterView;
62 import android.widget.Button;
63 import android.widget.CheckBox;
64 import android.widget.ImageButton;
65 import android.widget.ImageView;
66 import android.widget.TextView;
67
68 import static android.os.BatteryManager.BATTERY_STATUS_CHARGING;
69 import static android.os.BatteryManager.BATTERY_STATUS_FULL;
70 import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
71
72 import java.io.IOException;
73 import java.io.InputStream;
74 import java.text.DateFormat;
75 import java.util.Date;
76 import java.util.Locale;
77 import java.util.Random;
78
79 /**
80  * DeskClock clock view for desk docks.
81  */
82 public class DeskClock extends Activity {
83     private static final boolean DEBUG = false;
84
85     private static final String LOG_TAG = "DeskClock";
86
87     // Intent used to start the music player.
88     private static final String MUSIC_NOW_PLAYING = "com.android.music.PLAYBACK_VIEWER";
89
90     // Interval between polls of the weather widget. Its refresh period is
91     // likely to be much longer (~3h), but we want to pick up any changes
92     // within 5 minutes.
93     private final long FETCH_WEATHER_DELAY = 5 * 60 * 1000; // 5 min
94
95     // Delay before engaging the burn-in protection mode (green-on-black).
96     private final long SCREEN_SAVER_TIMEOUT = 10 * 60 * 1000; // 10 min
97
98     // Repositioning delay in screen saver.
99     private final long SCREEN_SAVER_MOVE_DELAY = 60 * 1000; // 1 min
100
101     // Color to use for text & graphics in screen saver mode.
102     private final int SCREEN_SAVER_COLOR = 0xFF008000;
103     private final int SCREEN_SAVER_COLOR_DIM = 0xFF003000;
104
105     // Internal message IDs.
106     private final int FETCH_WEATHER_DATA_MSG     = 0x1000;
107     private final int UPDATE_WEATHER_DISPLAY_MSG = 0x1001;
108     private final int SCREEN_SAVER_TIMEOUT_MSG   = 0x2000;
109     private final int SCREEN_SAVER_MOVE_MSG      = 0x2001;
110
111     // Weather widget query information.
112     private static final String GENIE_PACKAGE_ID = "com.google.android.apps.genie.geniewidget";
113     private static final String WEATHER_CONTENT_AUTHORITY = GENIE_PACKAGE_ID + ".weather";
114     private static final String WEATHER_CONTENT_PATH = "/weather/current";
115     private static final String[] WEATHER_CONTENT_COLUMNS = new String[] {
116             "location",
117             "timestamp",
118             "highTemperature",
119             "lowTemperature",
120             "iconUrl",
121             "iconResId",
122             "description",
123         };
124
125     // State variables follow.
126     private DigitalClock mTime;
127     private TextView mDate;
128
129     private TextView mNextAlarm = null;
130     private TextView mBatteryDisplay;
131
132     private TextView mWeatherHighTemperature;
133     private TextView mWeatherLowTemperature;
134     private TextView mWeatherLocation;
135     private ImageView mWeatherIcon;
136
137     private String mWeatherHighTemperatureString;
138     private String mWeatherLowTemperatureString;
139     private String mWeatherLocationString;
140     private Drawable mWeatherIconDrawable;
141
142     private Resources mGenieResources = null;
143
144     private boolean mDimmed = false;
145     private boolean mScreenSaverMode = false;
146
147     private DateFormat mDateFormat;
148
149     private int mBatteryLevel = -1;
150     private boolean mPluggedIn = false;
151
152     private int mIdleTimeoutEpoch = 0;
153
154     private boolean mWeatherFetchScheduled = false;
155
156     private Random mRNG;
157
158     private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
159         @Override
160         public void onReceive(Context context, Intent intent) {
161             final String action = intent.getAction();
162             if (Intent.ACTION_DATE_CHANGED.equals(action)) {
163                 refreshDate();
164             } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
165                 handleBatteryUpdate(
166                     intent.getIntExtra("status", BATTERY_STATUS_UNKNOWN),
167                     intent.getIntExtra("level", 0));
168             }
169         }
170     };
171
172     private final Handler mHandy = new Handler() {
173         @Override
174         public void handleMessage(Message m) {
175             if (m.what == FETCH_WEATHER_DATA_MSG) {
176                 if (!mWeatherFetchScheduled) return;
177                 mWeatherFetchScheduled = false;
178                 new Thread() { public void run() { fetchWeatherData(); } }.start();
179                 scheduleWeatherFetchDelayed(FETCH_WEATHER_DELAY);
180             } else if (m.what == UPDATE_WEATHER_DISPLAY_MSG) {
181                 updateWeatherDisplay();
182             } else if (m.what == SCREEN_SAVER_TIMEOUT_MSG) {
183                 if (m.arg1 == mIdleTimeoutEpoch) {
184                     saveScreen();
185                 }
186             } else if (m.what == SCREEN_SAVER_MOVE_MSG) {
187                 moveScreenSaver();
188             }
189         }
190     };
191
192
193     private void moveScreenSaver() {
194         moveScreenSaverTo(-1,-1);
195     }
196     private void moveScreenSaverTo(int x, int y) {
197         if (!mScreenSaverMode) return;
198
199         final View time_date = findViewById(R.id.time_date);
200
201         /*
202         final TranslateAnimation anim = new TranslateAnimation(
203             Animation.RELATIVE_TO_SELF,   0, // fromX
204             Animation.RELATIVE_TO_PARENT, 0.5f, // toX
205             Animation.RELATIVE_TO_SELF,   0, // fromY
206             Animation.RELATIVE_TO_PARENT, 0.5f // toY
207         );
208         anim.setDuration(1000);
209         anim.setInterpolator(new android.view.animation.AccelerateDecelerateInterpolator());
210         anim.setFillEnabled(true);
211         anim.setFillAfter(true);
212         time_date.startAnimation(anim);
213         */
214
215         DisplayMetrics metrics = new DisplayMetrics();
216         getWindowManager().getDefaultDisplay().getMetrics(metrics);
217
218         if (x < 0 || y < 0) {
219             int myWidth = time_date.getMeasuredWidth();
220             int myHeight = time_date.getMeasuredHeight();
221             x = (int)(mRNG.nextFloat()*(metrics.widthPixels - myWidth));
222             y = (int)(mRNG.nextFloat()*(metrics.heightPixels - myHeight));
223         }
224
225         if (DEBUG) Log.d(LOG_TAG, String.format("screen saver: %d: jumping to (%d,%d)",
226                 System.currentTimeMillis(), x, y));
227
228         time_date.setLayoutParams(new AbsoluteLayout.LayoutParams(
229             ViewGroup.LayoutParams.WRAP_CONTENT,
230             ViewGroup.LayoutParams.WRAP_CONTENT,
231             x,
232             y));
233
234         // Synchronize our jumping so that it happens exactly on the second.
235         mHandy.sendEmptyMessageDelayed(SCREEN_SAVER_MOVE_MSG,
236             SCREEN_SAVER_MOVE_DELAY +
237             (1000 - (System.currentTimeMillis() % 1000)));
238     }
239
240     private void setWakeLock(boolean hold) {
241         if (DEBUG) Log.d(LOG_TAG, (hold ? "hold" : " releas") + "ing wake lock");
242         Window win = getWindow();
243         WindowManager.LayoutParams winParams = win.getAttributes();
244         winParams.flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
245         winParams.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
246         winParams.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
247         if (hold)
248             winParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
249         else
250             winParams.flags &= (~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
251         win.setAttributes(winParams);
252     }
253
254     private void restoreScreen() {
255         if (!mScreenSaverMode) return;
256         if (DEBUG) Log.d(LOG_TAG, "restoreScreen");
257         mScreenSaverMode = false;
258         initViews();
259         doDim(false); // restores previous dim mode
260         refreshAll();
261     }
262
263     // Special screen-saver mode for OLED displays that burn in quickly
264     private void saveScreen() {
265         if (mScreenSaverMode) return;
266         if (DEBUG) Log.d(LOG_TAG, "saveScreen");
267
268         // quickly stash away the x/y of the current date
269         final View oldTimeDate = findViewById(R.id.time_date);
270         int oldLoc[] = new int[2];
271         oldTimeDate.getLocationOnScreen(oldLoc);
272
273         mScreenSaverMode = true;
274         Window win = getWindow();
275         WindowManager.LayoutParams winParams = win.getAttributes();
276         winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
277         win.setAttributes(winParams);
278
279         // give up any internal focus before we switch layouts
280         final View focused = getCurrentFocus();
281         if (focused != null) focused.clearFocus();
282
283         setContentView(R.layout.desk_clock_saver);
284
285         mTime = (DigitalClock) findViewById(R.id.time);
286         mDate = (TextView) findViewById(R.id.date);
287
288         final int color = mDimmed ? SCREEN_SAVER_COLOR_DIM : SCREEN_SAVER_COLOR;
289
290         ((TextView)findViewById(R.id.timeDisplay)).setTextColor(color);
291         ((TextView)findViewById(R.id.am_pm)).setTextColor(color);
292         mDate.setTextColor(color);
293
294         mBatteryDisplay =
295         mNextAlarm =
296         mWeatherHighTemperature =
297         mWeatherLowTemperature =
298         mWeatherLocation = null;
299         mWeatherIcon = null;
300
301         refreshDate();
302
303         moveScreenSaverTo(oldLoc[0], oldLoc[1]);
304     }
305
306     @Override
307     public void onUserInteraction() {
308         if (mScreenSaverMode)
309             restoreScreen();
310     }
311
312     private boolean supportsWeather() {
313         return (mGenieResources != null);
314     }
315
316     private void scheduleWeatherFetchDelayed(long delay) {
317         if (mWeatherFetchScheduled) return;
318
319         if (DEBUG) Log.d(LOG_TAG, "scheduling weather fetch message for " + delay + "ms from now");
320
321         mWeatherFetchScheduled = true;
322
323         mHandy.sendEmptyMessageDelayed(FETCH_WEATHER_DATA_MSG, delay);
324     }
325
326     private void unscheduleWeatherFetch() {
327         mWeatherFetchScheduled = false;
328     }
329
330     private static final boolean sCelsius;
331     static {
332         String cc = Locale.getDefault().getCountry().toLowerCase();
333         sCelsius = !("us".equals(cc) || "bz".equals(cc) || "jm".equals(cc));
334     }
335
336     private static int celsiusToLocal(int tempC) {
337         return sCelsius ? tempC : (int) Math.round(tempC * 1.8f + 32);
338     }
339
340     private void fetchWeatherData() {
341         // if we couldn't load the weather widget's resources, we simply
342         // assume it's not present on the device.
343         if (mGenieResources == null) return;
344
345         Uri queryUri = new Uri.Builder()
346             .scheme(android.content.ContentResolver.SCHEME_CONTENT)
347             .authority(WEATHER_CONTENT_AUTHORITY)
348             .path(WEATHER_CONTENT_PATH)
349             .appendPath(new Long(System.currentTimeMillis()).toString())
350             .build();
351
352         if (DEBUG) Log.d(LOG_TAG, "querying genie: " + queryUri);
353
354         Cursor cur;
355         try {
356             cur = managedQuery(
357                 queryUri,
358                 WEATHER_CONTENT_COLUMNS,
359                 null,
360                 null,
361                 null);
362         } catch (RuntimeException e) {
363             Log.e(LOG_TAG, "Weather query failed", e);
364             cur = null;
365         }
366
367         if (cur != null && cur.moveToFirst()) {
368             if (DEBUG) {
369                 java.lang.StringBuilder sb =
370                     new java.lang.StringBuilder("Weather query result: {");
371                 for(int i=0; i<cur.getColumnCount(); i++) {
372                     if (i>0) sb.append(", ");
373                     sb.append(cur.getColumnName(i))
374                         .append("=")
375                         .append(cur.getString(i));
376                 }
377                 sb.append("}");
378                 Log.d(LOG_TAG, sb.toString());
379             }
380
381             mWeatherIconDrawable = mGenieResources.getDrawable(cur.getInt(
382                 cur.getColumnIndexOrThrow("iconResId")));
383             mWeatherHighTemperatureString = String.format("%d\u00b0",
384                 celsiusToLocal(cur.getInt(cur.getColumnIndexOrThrow("highTemperature"))));
385             mWeatherLowTemperatureString = String.format("%d\u00b0",
386                 celsiusToLocal(cur.getInt(cur.getColumnIndexOrThrow("lowTemperature"))));
387             mWeatherLocationString = cur.getString(
388                 cur.getColumnIndexOrThrow("location"));
389         } else {
390             Log.w(LOG_TAG, "No weather information available (cur="
391                 + cur +")");
392             mWeatherIconDrawable = null;
393             mWeatherHighTemperatureString = "";
394             mWeatherLowTemperatureString = "";
395             mWeatherLocationString = "Weather data unavailable."; // TODO: internationalize
396         }
397
398         mHandy.sendEmptyMessage(UPDATE_WEATHER_DISPLAY_MSG);
399     }
400
401     private void refreshWeather() {
402         if (supportsWeather())
403             scheduleWeatherFetchDelayed(0);
404         updateWeatherDisplay(); // in case we have it cached
405     }
406
407     private void updateWeatherDisplay() {
408         if (mWeatherHighTemperature == null) return;
409
410         mWeatherHighTemperature.setText(mWeatherHighTemperatureString);
411         mWeatherLowTemperature.setText(mWeatherLowTemperatureString);
412         mWeatherLocation.setText(mWeatherLocationString);
413         mWeatherIcon.setImageDrawable(mWeatherIconDrawable);
414     }
415
416     // Adapted from KeyguardUpdateMonitor.java
417     private void handleBatteryUpdate(int plugStatus, int batteryLevel) {
418         final boolean pluggedIn = (plugStatus == BATTERY_STATUS_CHARGING || plugStatus == BATTERY_STATUS_FULL);
419         if (pluggedIn != mPluggedIn) {
420             setWakeLock(pluggedIn);
421         }
422         if (pluggedIn != mPluggedIn || batteryLevel != mBatteryLevel) {
423             mBatteryLevel = batteryLevel;
424             mPluggedIn = pluggedIn;
425             refreshBattery();
426         }
427     }
428
429     private void refreshBattery() {
430         if (mBatteryDisplay == null) return;
431
432         if (mPluggedIn /* || mBatteryLevel < LOW_BATTERY_THRESHOLD */) {
433             mBatteryDisplay.setCompoundDrawablesWithIntrinsicBounds(
434                 0, 0, android.R.drawable.ic_lock_idle_charging, 0);
435             mBatteryDisplay.setText(
436                 getString(R.string.battery_charging_level, mBatteryLevel));
437             mBatteryDisplay.setVisibility(View.VISIBLE);
438         } else {
439             mBatteryDisplay.setVisibility(View.INVISIBLE);
440         }
441     }
442
443     private void refreshDate() {
444         mDate.setText(mDateFormat.format(new Date()));
445     }
446
447     private void refreshAlarm() {
448         if (mNextAlarm == null) return;
449
450         String nextAlarm = Settings.System.getString(getContentResolver(),
451                 Settings.System.NEXT_ALARM_FORMATTED);
452         if (!TextUtils.isEmpty(nextAlarm)) {
453             mNextAlarm.setText(nextAlarm);
454             //mNextAlarm.setCompoundDrawablesWithIntrinsicBounds(
455             //    android.R.drawable.ic_lock_idle_alarm, 0, 0, 0);
456             mNextAlarm.setVisibility(View.VISIBLE);
457         } else {
458             mNextAlarm.setVisibility(View.INVISIBLE);
459         }
460     }
461
462     private void refreshAll() {
463         refreshDate();
464         refreshAlarm();
465         refreshBattery();
466         refreshWeather();
467     }
468
469     private void doDim(boolean fade) {
470         View tintView = findViewById(R.id.window_tint);
471         if (tintView == null) return;
472
473         Window win = getWindow();
474         WindowManager.LayoutParams winParams = win.getAttributes();
475
476         // secret!
477         winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
478         winParams.flags |= (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
479
480         // dim the wallpaper somewhat (how much is determined below)
481         winParams.flags |= (WindowManager.LayoutParams.FLAG_DIM_BEHIND);
482
483         if (mDimmed) {
484             winParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
485             winParams.dimAmount = 0.5f; // pump up contrast in dim mode
486
487             // show the window tint
488             tintView.startAnimation(AnimationUtils.loadAnimation(this,
489                 fade ? R.anim.dim
490                      : R.anim.dim_instant));
491         } else {
492             winParams.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
493             winParams.dimAmount = 0.2f; // lower contrast in normal mode
494
495             // hide the window tint
496             tintView.startAnimation(AnimationUtils.loadAnimation(this,
497                 fade ? R.anim.undim
498                      : R.anim.undim_instant));
499         }
500
501         win.setAttributes(winParams);
502     }
503
504     @Override
505     public void onResume() {
506         super.onResume();
507         if (DEBUG) Log.d(LOG_TAG, "onResume");
508
509         // reload the date format in case the user has changed settings
510         // recently
511         mDateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL);
512
513         IntentFilter filter = new IntentFilter();
514         filter.addAction(Intent.ACTION_DATE_CHANGED);
515         filter.addAction(Intent.ACTION_BATTERY_CHANGED);
516         registerReceiver(mIntentReceiver, filter);
517
518         doDim(false);
519         restoreScreen();
520         refreshAll(); // will schedule periodic weather fetch
521
522         setWakeLock(mPluggedIn);
523
524         mIdleTimeoutEpoch++;
525         mHandy.sendMessageDelayed(
526             Message.obtain(mHandy, SCREEN_SAVER_TIMEOUT_MSG, mIdleTimeoutEpoch, 0),
527             SCREEN_SAVER_TIMEOUT);
528     }
529
530     @Override
531     public void onPause() {
532         if (DEBUG) Log.d(LOG_TAG, "onPause");
533
534         // Turn off the screen saver.
535         restoreScreen();
536
537         // Avoid situations where the user launches Alarm Clock and is
538         // surprised to find it in dim mode (because it was last used in dim
539         // mode, but that last use is long in the past).
540         mDimmed = false;
541
542         // Other things we don't want to be doing in the background.
543         unregisterReceiver(mIntentReceiver);
544         unscheduleWeatherFetch();
545
546         super.onPause();
547     }
548
549
550     private void initViews() {
551         // give up any internal focus before we switch layouts
552         final View focused = getCurrentFocus();
553         if (focused != null) focused.clearFocus();
554
555         setContentView(R.layout.desk_clock);
556
557         mTime = (DigitalClock) findViewById(R.id.time);
558         mDate = (TextView) findViewById(R.id.date);
559         mBatteryDisplay = (TextView) findViewById(R.id.battery);
560
561         mTime.getRootView().requestFocus();
562
563         mWeatherHighTemperature = (TextView) findViewById(R.id.weather_high_temperature);
564         mWeatherLowTemperature = (TextView) findViewById(R.id.weather_low_temperature);
565         mWeatherLocation = (TextView) findViewById(R.id.weather_location);
566         mWeatherIcon = (ImageView) findViewById(R.id.weather_icon);
567
568         mNextAlarm = (TextView) findViewById(R.id.nextAlarm);
569
570         final ImageButton alarmButton = (ImageButton) findViewById(R.id.alarm_button);
571         alarmButton.setOnClickListener(new View.OnClickListener() {
572             public void onClick(View v) {
573                 startActivity(new Intent(DeskClock.this, AlarmClock.class));
574             }
575         });
576
577         final ImageButton galleryButton = (ImageButton) findViewById(R.id.gallery_button);
578         galleryButton.setOnClickListener(new View.OnClickListener() {
579             public void onClick(View v) {
580                 try {
581                     startActivity(new Intent(
582                         Intent.ACTION_VIEW,
583                         android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
584                             .putExtra("slideshow", true));
585                 } catch (android.content.ActivityNotFoundException e) {
586                     Log.e(LOG_TAG, "Couldn't launch image browser", e);
587                 }
588             }
589         });
590
591         final ImageButton musicButton = (ImageButton) findViewById(R.id.music_button);
592         musicButton.setOnClickListener(new View.OnClickListener() {
593             public void onClick(View v) {
594                 try {
595                     startActivity(new Intent(MUSIC_NOW_PLAYING));
596                 } catch (android.content.ActivityNotFoundException e) {
597                     Log.e(LOG_TAG, "Couldn't launch music browser", e);
598                 }
599             }
600         });
601
602         final ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
603         homeButton.setOnClickListener(new View.OnClickListener() {
604             public void onClick(View v) {
605                 startActivity(
606                     new Intent(Intent.ACTION_MAIN)
607                         .addCategory(Intent.CATEGORY_HOME));
608             }
609         });
610
611         final ImageButton nightmodeButton = (ImageButton) findViewById(R.id.nightmode_button);
612         nightmodeButton.setOnClickListener(new View.OnClickListener() {
613             public void onClick(View v) {
614                 mDimmed = ! mDimmed;
615                 doDim(true);
616             }
617         });
618
619         nightmodeButton.setOnLongClickListener(new View.OnLongClickListener() {
620             public boolean onLongClick(View v) {
621                 saveScreen();
622                 return true;
623             }
624         });
625
626         final View weatherView = findViewById(R.id.weather);
627         weatherView.setOnClickListener(new View.OnClickListener() {
628             public void onClick(View v) {
629                 if (!supportsWeather()) return;
630
631                 Intent genieAppQuery = getPackageManager().getLaunchIntentForPackage(GENIE_PACKAGE_ID);
632                 if (genieAppQuery != null) {
633                     startActivity(genieAppQuery);
634                 }
635             }
636         });
637     }
638
639     @Override
640     public void onConfigurationChanged(Configuration newConfig) {
641         super.onConfigurationChanged(newConfig);
642         if (!mScreenSaverMode) {
643             initViews();
644             doDim(false);
645             refreshAll();
646         }
647     }
648
649     @Override
650     protected void onCreate(Bundle icicle) {
651         super.onCreate(icicle);
652
653         mRNG = new Random();
654
655         try {
656             mGenieResources = getPackageManager().getResourcesForApplication(GENIE_PACKAGE_ID);
657         } catch (PackageManager.NameNotFoundException e) {
658             // no weather info available
659             Log.w(LOG_TAG, "Can't find "+GENIE_PACKAGE_ID+". Weather forecast will not be available.");
660         }
661
662         initViews();
663     }
664
665 }