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