SetPreferencesActivity.java revision 3c1e67e433728684b5f228c5d4f3e5b1457bb271
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.replica.replicaisland; 18 19import android.content.SharedPreferences; 20import android.os.Bundle; 21import android.preference.Preference; 22import android.preference.PreferenceActivity; 23import android.widget.Toast; 24 25 26public class SetPreferencesActivity extends PreferenceActivity implements 27 YesNoDialogPreference.YesNoDialogListener { 28 @Override 29 protected void onCreate(Bundle savedInstanceState) { 30 super.onCreate(savedInstanceState); 31 32 getPreferenceManager().setSharedPreferencesMode(MODE_PRIVATE); 33 getPreferenceManager().setSharedPreferencesName(AndouKun.PREFERENCE_NAME); 34 35 // Load the preferences from an XML resource 36 addPreferencesFromResource(R.xml.preferences); 37 38 Preference eraseGameButton = getPreferenceManager().findPreference("erasegame"); 39 if (eraseGameButton != null) { 40 YesNoDialogPreference yesNo = (YesNoDialogPreference)eraseGameButton; 41 yesNo.setListener(this); 42 } 43 44 Preference configureKeyboardPref = getPreferenceManager().findPreference("keyconfig"); 45 if (configureKeyboardPref != null) { 46 KeyboardConfigDialogPreference config = (KeyboardConfigDialogPreference)configureKeyboardPref; 47 config.setPrefs(getSharedPreferences(AndouKun.PREFERENCE_NAME, MODE_PRIVATE)); 48 config.setContext(this); 49 } 50 } 51 52 public void onDialogClosed(boolean positiveResult) { 53 if (positiveResult) { 54 SharedPreferences prefs = getSharedPreferences(AndouKun.PREFERENCE_NAME, MODE_PRIVATE); 55 SharedPreferences.Editor editor = prefs.edit(); 56 editor.remove(AndouKun.PREFERENCE_LEVEL_ROW); 57 editor.remove(AndouKun.PREFERENCE_LEVEL_INDEX); 58 editor.remove(AndouKun.PREFERENCE_LEVEL_COMPLETED); 59 editor.commit(); 60 Toast.makeText(this, R.string.saved_game_erased_notification, 61 Toast.LENGTH_SHORT).show(); 62 } 63 } 64} 65