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