/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/LatinIMEDebugSettings.java
Java | 75 lines | 51 code | 9 blank | 15 comment | 7 complexity | 790cc74ecf11c64f33c9957c79f334f8 MD5 | raw file
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * 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, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.googlecode.eyesfree.inputmethod.latin; 18 19import android.content.SharedPreferences; 20import android.content.pm.PackageInfo; 21import android.content.pm.PackageManager.NameNotFoundException; 22import android.os.Bundle; 23import android.preference.CheckBoxPreference; 24import android.preference.PreferenceActivity; 25import android.util.Log; 26 27public class LatinIMEDebugSettings extends PreferenceActivity 28 implements SharedPreferences.OnSharedPreferenceChangeListener { 29 30 private static final String TAG = "LatinIMEDebugSettings"; 31 private static final String DEBUG_MODE_KEY = "debug_mode"; 32 33 private CheckBoxPreference mDebugMode; 34 35 @Override 36 protected void onCreate(Bundle icicle) { 37 super.onCreate(icicle); 38 addPreferencesFromResource(R.xml.prefs_for_debug); 39 SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); 40 prefs.registerOnSharedPreferenceChangeListener(this); 41 42 mDebugMode = (CheckBoxPreference) findPreference(DEBUG_MODE_KEY); 43 updateDebugMode(); 44 } 45 46 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { 47 if (key.equals(DEBUG_MODE_KEY)) { 48 if (mDebugMode != null) { 49 mDebugMode.setChecked(prefs.getBoolean(DEBUG_MODE_KEY, false)); 50 updateDebugMode(); 51 } 52 } 53 } 54 55 private void updateDebugMode() { 56 if (mDebugMode == null) { 57 return; 58 } 59 boolean isDebugMode = mDebugMode.isChecked(); 60 String version = ""; 61 try { 62 PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); 63 version = "Version " + info.versionName; 64 } catch (NameNotFoundException e) { 65 Log.e(TAG, "Could not find version info."); 66 } 67 if (!isDebugMode) { 68 mDebugMode.setTitle(version); 69 mDebugMode.setSummary(""); 70 } else { 71 mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode)); 72 mDebugMode.setSummary(version); 73 } 74 } 75}