Home | History | Annotate | Download | only in deskclock
      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.ActionBar;
     20 import android.content.Intent;
     21 import android.media.AudioManager;
     22 import android.os.Bundle;
     23 import android.preference.CheckBoxPreference;
     24 import android.preference.ListPreference;
     25 import android.preference.Preference;
     26 import android.preference.PreferenceActivity;
     27 import android.preference.PreferenceScreen;
     28 import android.provider.Settings;
     29 import android.view.Menu;
     30 import android.view.MenuItem;
     31 
     32 /**
     33  * Settings for the Alarm Clock Dream (com.android.deskclock.Screensaver).
     34  */
     35 public class ScreensaverSettingsActivity extends PreferenceActivity
     36         implements Preference.OnPreferenceChangeListener {
     37 
     38     static final String KEY_CLOCK_STYLE =
     39             "screensaver_clock_style";
     40     static final String KEY_NIGHT_MODE =
     41             "screensaver_night_mode";
     42 
     43     @Override
     44     protected void onCreate(Bundle savedInstanceState) {
     45         super.onCreate(savedInstanceState);
     46         addPreferencesFromResource(R.xml.dream_settings);
     47     }
     48 
     49     @Override
     50     protected void onResume() {
     51         super.onResume();
     52         refresh();
     53     }
     54 
     55     @Override
     56     public boolean onPreferenceChange(Preference pref, Object newValue) {
     57         if (KEY_CLOCK_STYLE.equals(pref.getKey())) {
     58             final ListPreference listPref = (ListPreference) pref;
     59             final int idx = listPref.findIndexOfValue((String) newValue);
     60             listPref.setSummary(listPref.getEntries()[idx]);
     61         } else if (KEY_NIGHT_MODE.equals(pref.getKey())) {
     62             boolean state = ((CheckBoxPreference) pref).isChecked();
     63         }
     64         return true;
     65     }
     66 
     67     private void refresh() {
     68         ListPreference listPref = (ListPreference) findPreference(KEY_CLOCK_STYLE);
     69         listPref.setSummary(listPref.getEntry());
     70         listPref.setOnPreferenceChangeListener(this);
     71 
     72         Preference pref = findPreference(KEY_NIGHT_MODE);
     73         boolean state = ((CheckBoxPreference) pref).isChecked();
     74         pref.setOnPreferenceChangeListener(this);
     75     }
     76 
     77 }
     78