Merge "Add show setup wizard icon preference settings" into jb-mr2-dev

This commit is contained in:
Tadashi G. Takaoka 2013-03-05 06:23:37 +00:00 committed by Android (Google) Code Review
commit 84fa8043e6
5 changed files with 57 additions and 32 deletions

View file

@ -434,4 +434,6 @@
<string name="language_settings">Language &amp; input</string> <string name="language_settings">Language &amp; input</string>
<!-- Title of the Input method picker. This should be aligned with msgid="4653387336791222978" --> <!-- Title of the Input method picker. This should be aligned with msgid="4653387336791222978" -->
<string name="select_input_method">Choose input method</string> <string name="select_input_method">Choose input method</string>
<!-- Option to show setup wizard icon. [CHAR LIMIT=30]-->
<string name="show_setup_wizard_icon" translatable="false">Show setup wizard icon</string>
</resources> </resources>

View file

@ -145,7 +145,7 @@
android:fragment="com.android.inputmethod.latin.AdditionalSubtypeSettings" android:fragment="com.android.inputmethod.latin.AdditionalSubtypeSettings"
android:key="custom_input_styles" android:key="custom_input_styles"
android:title="@string/custom_input_styles_title" /> android:title="@string/custom_input_styles_title" />
<!-- Values for popup dismiss delay are added programatically --> <!-- Values for popup dismiss delay are added programmatically -->
<CheckBoxPreference <CheckBoxPreference
android:key="pref_sliding_key_input_preview" android:key="pref_sliding_key_input_preview"
android:title="@string/sliding_key_input_preview" android:title="@string/sliding_key_input_preview"
@ -171,6 +171,11 @@
android:key="pref_keypress_sound_volume" android:key="pref_keypress_sound_volume"
android:title="@string/prefs_keypress_sound_volume_settings" android:title="@string/prefs_keypress_sound_volume_settings"
latin:maxValue="100" /> <!-- percent --> latin:maxValue="100" /> <!-- percent -->
<!-- The show setup wizard icon settings shouldn't be persistent and the default value
is added programmatically. -->
<CheckBoxPreference
android:key="pref_show_setup_wizard_icon"
android:title="@string/show_setup_wizard_icon" />
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:key="debug_settings" android:key="debug_settings"

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -64,6 +65,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_GESTURE_PREVIEW_TRAIL = "pref_gesture_preview_trail"; public static final String PREF_GESTURE_PREVIEW_TRAIL = "pref_gesture_preview_trail";
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT =
"pref_gesture_floating_preview_text"; "pref_gesture_floating_preview_text";
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "pref_show_setup_wizard_icon";
public static final String PREF_INPUT_LANGUAGE = "input_language"; public static final String PREF_INPUT_LANGUAGE = "input_language";
public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
@ -260,4 +262,16 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean readUseFullscreenMode(final Resources res) { public static boolean readUseFullscreenMode(final Resources res) {
return res.getBoolean(R.bool.config_use_fullscreen_mode); return res.getBoolean(R.bool.config_use_fullscreen_mode);
} }
public static boolean readShowSetupWizardIcon(final SharedPreferences prefs,
final Context context) {
if (!prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
final ApplicationInfo appInfo = context.getApplicationInfo();
final boolean isApplicationInSystemImage =
(appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
// Default value
return !isApplicationInSystemImage;
}
return prefs.getBoolean(Settings.PREF_SHOW_SETUP_WIZARD_ICON, false);
}
} }

View file

@ -31,6 +31,7 @@ import android.preference.PreferenceScreen;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
import com.android.inputmethodcommon.InputMethodSettingsFragment; import com.android.inputmethodcommon.InputMethodSettingsFragment;
public final class SettingsFragment extends InputMethodSettingsFragment public final class SettingsFragment extends InputMethodSettingsFragment
@ -155,6 +156,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment
removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen()); removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen());
} }
final CheckBoxPreference showSetupWizardIcon =
(CheckBoxPreference)findPreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON);
showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, context));
setupKeyLongpressTimeoutSettings(prefs, res); setupKeyLongpressTimeoutSettings(prefs, res);
setupKeypressVibrationDurationSettings(prefs, res); setupKeypressVibrationDurationSettings(prefs, res);
setupKeypressSoundVolumeSettings(prefs, res); setupKeypressSoundVolumeSettings(prefs, res);
@ -196,6 +201,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled); setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled); setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
} else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
} }
ensureConsistencyOfAutoCorrectionSettings(); ensureConsistencyOfAutoCorrectionSettings();
updateVoiceModeSummary(); updateVoiceModeSummary();

View file

@ -16,18 +16,19 @@
package com.android.inputmethod.latin.setup; package com.android.inputmethod.latin.setup;
import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Process; import android.os.Process;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.compat.IntentCompatUtils; import com.android.inputmethod.compat.IntentCompatUtils;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.Settings;
/** /**
* This class detects the {@link Intent#ACTION_MY_PACKAGE_REPLACED} broadcast intent when this IME * This class detects the {@link Intent#ACTION_MY_PACKAGE_REPLACED} broadcast intent when this IME
@ -60,11 +61,7 @@ public final class LauncherIconVisibilityManager extends BroadcastReceiver {
@Override @Override
public void onReceive(final Context context, final Intent intent) { public void onReceive(final Context context, final Intent intent) {
if (shouldHandleThisIntent(intent, context)) { if (shouldHandleThisIntent(intent, context)) {
if (isInSystemImage(context)) { updateSetupWizardIconVisibility(context);
disableActivity(context, SetupActivity.class);
} else {
Log.i(TAG, "This package isn't in system image: " + context.getPackageName());
}
} }
// The process that hosts this broadcast receiver is invoked and remains alive even after // The process that hosts this broadcast receiver is invoked and remains alive even after
@ -94,32 +91,32 @@ public final class LauncherIconVisibilityManager extends BroadcastReceiver {
return false; return false;
} }
/** public static void updateSetupWizardIconVisibility(final Context context) {
* Disable an activity of the specified package. Disabling an activity will also hide its final ComponentName setupWizardActivity = new ComponentName(context, SetupActivity.class);
* icon from the launcher. final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
* final boolean stateHasSet;
* @param context package context of an activity to be disabled if (Settings.readShowSetupWizardIcon(prefs, context)) {
* @param activityClass activity class to be disabled stateHasSet = setActivityState(context, setupWizardActivity,
*/ PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
private static void disableActivity(final Context context, Log.i(TAG, (stateHasSet ? "Enable activity: " : "Activity has already been enabled: ")
final Class<? extends Activity> activityClass) { + setupWizardActivity);
final ComponentName activityComponent = new ComponentName(context, activityClass); } else {
final PackageManager pm = context.getPackageManager(); stateHasSet = setActivityState(context, setupWizardActivity,
final int activityComponentState = pm.getComponentEnabledSetting(activityComponent); PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
if (activityComponentState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { Log.i(TAG, (stateHasSet ? "Disable activity: " : "Activity has already been disabled: ")
// This activity is already disabled. + setupWizardActivity);
Log.i(TAG, "Activity has already been disabled: " + activityComponent);
return;
} }
// Disabling an activity will also hide its icon from the launcher.
pm.setComponentEnabledSetting(activityComponent,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
Log.i(TAG, "Disable activity: " + activityComponent);
} }
private static boolean isInSystemImage(final Context context) { private static boolean setActivityState(final Context context,
final ApplicationInfo appInfo = context.getApplicationInfo(); final ComponentName activityComponent, final int activityState) {
return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; final PackageManager pm = context.getPackageManager();
final int activityComponentState = pm.getComponentEnabledSetting(activityComponent);
if (activityComponentState == activityState) {
return false;
}
pm.setComponentEnabledSetting(
activityComponent, activityState, PackageManager.DONT_KILL_APP);
return true;
} }
} }