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.settings; 18 19 import android.os.Bundle; 20 import android.preference.ListPreference; 21 import android.preference.Preference; 22 import android.preference.PreferenceFragment; 23 import android.support.v7.app.AppCompatActivity; 24 import android.view.MenuItem; 25 26 import com.android.deskclock.R; 27 28 /** 29 * Settings for Clock Daydream 30 */ 31 public final class ScreensaverSettingsActivity extends AppCompatActivity { 32 33 public static final String KEY_CLOCK_STYLE = "screensaver_clock_style"; 34 public static final String KEY_NIGHT_MODE = "screensaver_night_mode"; 35 36 @Override onCreate(Bundle savedInstanceState)37 protected void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setContentView(R.layout.screensaver_settings); 40 } 41 42 @Override onOptionsItemSelected(MenuItem item)43 public boolean onOptionsItemSelected (MenuItem item) { 44 switch (item.getItemId()) { 45 case android.R.id.home: 46 finish(); 47 return true; 48 default: 49 break; 50 } 51 return super.onOptionsItemSelected(item); 52 } 53 54 55 public static class PrefsFragment extends PreferenceFragment 56 implements Preference.OnPreferenceChangeListener { 57 58 @Override onCreate(Bundle savedInstanceState)59 public void onCreate(Bundle savedInstanceState) { 60 super.onCreate(savedInstanceState); 61 addPreferencesFromResource(R.xml.dream_settings); 62 } 63 64 @Override onResume()65 public void onResume() { 66 super.onResume(); 67 refresh(); 68 } 69 70 @Override onPreferenceChange(Preference pref, Object newValue)71 public boolean onPreferenceChange(Preference pref, Object newValue) { 72 if (KEY_CLOCK_STYLE.equals(pref.getKey())) { 73 final ListPreference clockStylePref = (ListPreference) pref; 74 final int index = clockStylePref.findIndexOfValue((String) newValue); 75 clockStylePref.setSummary(clockStylePref.getEntries()[index]); 76 } 77 return true; 78 } 79 refresh()80 private void refresh() { 81 final ListPreference clockStylePref = (ListPreference) findPreference(KEY_CLOCK_STYLE); 82 clockStylePref.setSummary(clockStylePref.getEntry()); 83 clockStylePref.setOnPreferenceChangeListener(this); 84 } 85 } 86 } 87