GeneralPreferences.java revision 0f52e546ef662e126b7360ad69c8c8f838789ef3
1/* 2 * Copyright (C) 2010 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.email.activity.setup; 18 19import com.android.email.Preferences; 20import com.android.email.R; 21 22import android.os.Bundle; 23import android.preference.ListPreference; 24import android.preference.PreferenceFragment; 25 26public class GeneralPreferences extends PreferenceFragment { 27 28 private static final String PREFERENCE_AUTO_ADVANCE= "auto_advance"; 29 30 private Preferences mPreferences; 31 private ListPreference mAutoAdvance; 32 33 @Override 34 public void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 37 // Load the preferences from an XML resource 38 addPreferencesFromResource(R.xml.general_preferences); 39 } 40 41 @Override 42 public void onResume() { 43 loadSettings(); 44 super.onResume(); 45 } 46 47 @Override 48 public void onPause() { 49 super.onPause(); 50 saveSettings(); 51 } 52 53 private void loadSettings() { 54 mPreferences = Preferences.getPreferences(getActivity()); 55 mAutoAdvance = (ListPreference) findPreference(PREFERENCE_AUTO_ADVANCE); 56 mAutoAdvance.setValueIndex(mPreferences.getAutoAdvanceDirection()); 57 } 58 59 private void saveSettings() { 60 mPreferences.setAutoAdvanceDirection( 61 mAutoAdvance.findIndexOfValue(mAutoAdvance.getValue())); 62 } 63} 64