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.preference.PreferenceScreen; 24import android.widget.Toast; 25 26 27public class SetPreferencesActivity extends PreferenceActivity implements 28 YesNoDialogPreference.YesNoDialogListener { 29 @Override 30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 33 getPreferenceManager().setSharedPreferencesMode(MODE_PRIVATE); 34 getPreferenceManager().setSharedPreferencesName(PreferenceConstants.PREFERENCE_NAME); 35 36 // Load the preferences from an XML resource 37 addPreferencesFromResource(R.xml.preferences); 38 39 Preference eraseGameButton = getPreferenceManager().findPreference("erasegame"); 40 if (eraseGameButton != null) { 41 YesNoDialogPreference yesNo = (YesNoDialogPreference)eraseGameButton; 42 yesNo.setListener(this); 43 } 44 45 Preference configureKeyboardPref = getPreferenceManager().findPreference("keyconfig"); 46 if (configureKeyboardPref != null) { 47 KeyboardConfigDialogPreference config = (KeyboardConfigDialogPreference)configureKeyboardPref; 48 config.setPrefs(getSharedPreferences(PreferenceConstants.PREFERENCE_NAME, MODE_PRIVATE)); 49 config.setContext(this); 50 } 51 52 if (getIntent().getBooleanExtra("controlConfig", false)) { 53 PreferenceScreen controlConfig = (PreferenceScreen)getPreferenceManager().findPreference("controlConfigScreen"); 54 if (controlConfig != null) { 55 setPreferenceScreen(controlConfig); 56 } 57 } 58 } 59 60 public void onDialogClosed(boolean positiveResult) { 61 if (positiveResult) { 62 SharedPreferences prefs = getSharedPreferences(PreferenceConstants.PREFERENCE_NAME, MODE_PRIVATE); 63 SharedPreferences.Editor editor = prefs.edit(); 64 editor.remove(PreferenceConstants.PREFERENCE_LEVEL_ROW); 65 editor.remove(PreferenceConstants.PREFERENCE_LEVEL_INDEX); 66 editor.remove(PreferenceConstants.PREFERENCE_LEVEL_COMPLETED); 67 editor.remove(PreferenceConstants.PREFERENCE_LINEAR_MODE); 68 editor.remove(PreferenceConstants.PREFERENCE_TOTAL_GAME_TIME); 69 editor.remove(PreferenceConstants.PREFERENCE_PEARLS_COLLECTED); 70 editor.remove(PreferenceConstants.PREFERENCE_PEARLS_TOTAL); 71 editor.remove(PreferenceConstants.PREFERENCE_ROBOTS_DESTROYED); 72 editor.remove(PreferenceConstants.PREFERENCE_DIFFICULTY); 73 74 editor.commit(); 75 Toast.makeText(this, R.string.saved_game_erased_notification, 76 Toast.LENGTH_SHORT).show(); 77 } 78 } 79} 80