2010-09-27 03:55:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2012-04-13 10:53:44 +00:00
|
|
|
import android.content.Context;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
|
|
|
import android.os.Bundle;
|
2011-02-03 08:05:46 +00:00
|
|
|
import android.os.Process;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.preference.CheckBoxPreference;
|
2012-09-21 06:09:47 +00:00
|
|
|
import android.preference.Preference;
|
2012-04-13 10:53:44 +00:00
|
|
|
import android.preference.PreferenceFragment;
|
2013-01-18 07:40:55 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2010-09-27 03:55:21 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2012-03-08 06:07:00 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2012-09-21 06:09:47 +00:00
|
|
|
import com.android.inputmethod.research.ResearchLogger;
|
2012-03-08 06:07:00 +00:00
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class DebugSettings extends PreferenceFragment
|
2010-09-27 03:55:21 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2012-03-19 07:11:17 +00:00
|
|
|
private static final String TAG = DebugSettings.class.getSimpleName();
|
2013-01-08 09:26:47 +00:00
|
|
|
|
|
|
|
public static final String PREF_DEBUG_MODE = "debug_mode";
|
|
|
|
public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
|
2012-09-21 06:09:47 +00:00
|
|
|
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
|
2013-01-08 09:26:47 +00:00
|
|
|
public static final String PREF_STATISTICS_LOGGING = "enable_logging";
|
2013-01-18 07:40:55 +00:00
|
|
|
private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
|
2012-11-14 05:01:52 +00:00
|
|
|
private static final boolean SHOW_STATISTICS_LOGGING = false;
|
2010-09-27 03:55:21 +00:00
|
|
|
|
2011-02-03 09:38:55 +00:00
|
|
|
private boolean mServiceNeedsRestart = false;
|
2010-09-27 03:55:21 +00:00
|
|
|
private CheckBoxPreference mDebugMode;
|
2012-11-22 11:15:40 +00:00
|
|
|
private CheckBoxPreference mStatisticsLoggingPref;
|
2010-09-27 03:55:21 +00:00
|
|
|
|
|
|
|
@Override
|
2012-04-13 10:53:44 +00:00
|
|
|
public void onCreate(Bundle icicle) {
|
2010-09-27 03:55:21 +00:00
|
|
|
super.onCreate(icicle);
|
|
|
|
addPreferencesFromResource(R.xml.prefs_for_debug);
|
|
|
|
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
2012-09-21 06:09:47 +00:00
|
|
|
final Preference usabilityStudyPref = findPreference(PREF_USABILITY_STUDY_MODE);
|
|
|
|
if (usabilityStudyPref instanceof CheckBoxPreference) {
|
|
|
|
final CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref;
|
|
|
|
checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE,
|
|
|
|
ResearchLogger.DEFAULT_USABILITY_STUDY_MODE));
|
|
|
|
checkbox.setSummary(R.string.settings_warning_researcher_mode);
|
|
|
|
}
|
2013-01-08 09:26:47 +00:00
|
|
|
final Preference statisticsLoggingPref = findPreference(PREF_STATISTICS_LOGGING);
|
2012-11-14 05:01:52 +00:00
|
|
|
if (statisticsLoggingPref instanceof CheckBoxPreference) {
|
2012-11-22 11:15:40 +00:00
|
|
|
mStatisticsLoggingPref = (CheckBoxPreference) statisticsLoggingPref;
|
2012-11-14 05:01:52 +00:00
|
|
|
if (!SHOW_STATISTICS_LOGGING) {
|
|
|
|
getPreferenceScreen().removePreference(statisticsLoggingPref);
|
|
|
|
}
|
|
|
|
}
|
2012-09-21 06:09:47 +00:00
|
|
|
|
2013-01-18 07:40:55 +00:00
|
|
|
PreferenceScreen readExternalDictionary =
|
|
|
|
(PreferenceScreen) findPreference(PREF_READ_EXTERNAL_DICTIONARY);
|
|
|
|
if (null != readExternalDictionary) {
|
|
|
|
readExternalDictionary.setOnPreferenceClickListener(
|
|
|
|
new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(final Preference arg0) {
|
|
|
|
// TODO: actually read the dictionary
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-03 09:38:55 +00:00
|
|
|
mServiceNeedsRestart = false;
|
2013-01-08 09:26:47 +00:00
|
|
|
mDebugMode = (CheckBoxPreference) findPreference(PREF_DEBUG_MODE);
|
2010-09-27 03:55:21 +00:00
|
|
|
updateDebugMode();
|
|
|
|
}
|
|
|
|
|
2011-02-03 08:05:46 +00:00
|
|
|
@Override
|
2012-04-13 10:53:44 +00:00
|
|
|
public void onStop() {
|
2011-02-03 08:05:46 +00:00
|
|
|
super.onStop();
|
2011-02-03 09:38:55 +00:00
|
|
|
if (mServiceNeedsRestart) Process.killProcess(Process.myPid());
|
2011-02-03 08:05:46 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:46:21 +00:00
|
|
|
@Override
|
2010-09-27 03:55:21 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2013-01-08 09:26:47 +00:00
|
|
|
if (key.equals(PREF_DEBUG_MODE)) {
|
2010-09-27 03:55:21 +00:00
|
|
|
if (mDebugMode != null) {
|
2013-01-08 09:26:47 +00:00
|
|
|
mDebugMode.setChecked(prefs.getBoolean(PREF_DEBUG_MODE, false));
|
2012-11-22 11:15:40 +00:00
|
|
|
final boolean checked = mDebugMode.isChecked();
|
|
|
|
if (mStatisticsLoggingPref != null) {
|
|
|
|
if (checked) {
|
|
|
|
getPreferenceScreen().addPreference(mStatisticsLoggingPref);
|
|
|
|
} else {
|
|
|
|
getPreferenceScreen().removePreference(mStatisticsLoggingPref);
|
|
|
|
}
|
|
|
|
}
|
2010-09-27 03:55:21 +00:00
|
|
|
updateDebugMode();
|
2011-02-03 09:38:55 +00:00
|
|
|
mServiceNeedsRestart = true;
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
2013-01-08 09:26:47 +00:00
|
|
|
} else if (key.equals(PREF_FORCE_NON_DISTINCT_MULTITOUCH)
|
2012-03-08 06:07:00 +00:00
|
|
|
|| key.equals(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT)) {
|
2012-01-16 08:18:40 +00:00
|
|
|
mServiceNeedsRestart = true;
|
2010-09-27 03:55:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateDebugMode() {
|
|
|
|
if (mDebugMode == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean isDebugMode = mDebugMode.isChecked();
|
|
|
|
String version = "";
|
|
|
|
try {
|
2012-04-13 10:53:44 +00:00
|
|
|
final Context context = getActivity();
|
2013-01-10 10:57:33 +00:00
|
|
|
if (context == null) {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-13 10:53:44 +00:00
|
|
|
final String packageName = context.getPackageName();
|
|
|
|
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
|
2010-09-27 03:55:21 +00:00
|
|
|
version = "Version " + info.versionName;
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.e(TAG, "Could not find version info.");
|
|
|
|
}
|
|
|
|
if (!isDebugMode) {
|
|
|
|
mDebugMode.setTitle(version);
|
|
|
|
mDebugMode.setSummary("");
|
|
|
|
} else {
|
|
|
|
mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
|
|
|
|
mDebugMode.setSummary(version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|