2010-09-27 03:55:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2010-09-27 03:55:21 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-09-27 03:55:21 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2010-09-27 03:55:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
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
|
|
|
|
2012-03-08 06:07:00 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2013-07-05 09:23:22 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ApplicationUtils;
|
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,
|
2013-02-28 19:18:42 +00:00
|
|
|
LatinImeLogger.getUsabilityStudyMode(prefs)));
|
2012-09-21 06:09:47 +00:00
|
|
|
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) {
|
2013-01-18 09:55:40 +00:00
|
|
|
ExternalDictionaryGetterForDebug.chooseAndInstallDictionary(
|
|
|
|
getActivity());
|
2013-01-18 10:21:14 +00:00
|
|
|
mServiceNeedsRestart = true;
|
2013-01-18 07:40:55 +00:00
|
|
|
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();
|
2013-04-22 09:00:59 +00:00
|
|
|
final String version = getResources().getString(
|
2013-07-05 09:23:22 +00:00
|
|
|
R.string.version_text, ApplicationUtils.getVersionName(getActivity()));
|
2010-09-27 03:55:21 +00:00
|
|
|
if (!isDebugMode) {
|
|
|
|
mDebugMode.setTitle(version);
|
|
|
|
mDebugMode.setSummary("");
|
|
|
|
} else {
|
|
|
|
mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
|
|
|
|
mDebugMode.setSummary(version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|