/ime/latinime/src/com/googlecode/eyesfree/inputmethod/latin/LatinIMEDebugSettings.java

http://eyes-free.googlecode.com/ · 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. package com.googlecode.eyesfree.inputmethod.latin;
  17. import android.content.SharedPreferences;
  18. import android.content.pm.PackageInfo;
  19. import android.content.pm.PackageManager.NameNotFoundException;
  20. import android.os.Bundle;
  21. import android.preference.CheckBoxPreference;
  22. import android.preference.PreferenceActivity;
  23. import android.util.Log;
  24. public class LatinIMEDebugSettings extends PreferenceActivity
  25. implements SharedPreferences.OnSharedPreferenceChangeListener {
  26. private static final String TAG = "LatinIMEDebugSettings";
  27. private static final String DEBUG_MODE_KEY = "debug_mode";
  28. private CheckBoxPreference mDebugMode;
  29. @Override
  30. protected void onCreate(Bundle icicle) {
  31. super.onCreate(icicle);
  32. addPreferencesFromResource(R.xml.prefs_for_debug);
  33. SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
  34. prefs.registerOnSharedPreferenceChangeListener(this);
  35. mDebugMode = (CheckBoxPreference) findPreference(DEBUG_MODE_KEY);
  36. updateDebugMode();
  37. }
  38. public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
  39. if (key.equals(DEBUG_MODE_KEY)) {
  40. if (mDebugMode != null) {
  41. mDebugMode.setChecked(prefs.getBoolean(DEBUG_MODE_KEY, false));
  42. updateDebugMode();
  43. }
  44. }
  45. }
  46. private void updateDebugMode() {
  47. if (mDebugMode == null) {
  48. return;
  49. }
  50. boolean isDebugMode = mDebugMode.isChecked();
  51. String version = "";
  52. try {
  53. PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
  54. version = "Version " + info.versionName;
  55. } catch (NameNotFoundException e) {
  56. Log.e(TAG, "Could not find version info.");
  57. }
  58. if (!isDebugMode) {
  59. mDebugMode.setTitle(version);
  60. mDebugMode.setSummary("");
  61. } else {
  62. mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
  63. mDebugMode.setSummary(version);
  64. }
  65. }
  66. }