mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
am 84fa8043
: Merge "Add show setup wizard icon preference settings" into jb-mr2-dev
* commit '84fa8043e6bef47378b3fc32c277e33034d5c174': Add show setup wizard icon preference settings
This commit is contained in:
commit
249c887008
@ -434,4 +434,6 @@
|
||||
<string name="language_settings">Language & input</string>
|
||||
<!-- Title of the Input method picker. This should be aligned with msgid="4653387336791222978" -->
|
||||
<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>
|
||||
|
@ -145,7 +145,7 @@
|
||||
android:fragment="com.android.inputmethod.latin.AdditionalSubtypeSettings"
|
||||
android:key="custom_input_styles"
|
||||
android:title="@string/custom_input_styles_title" />
|
||||
<!-- Values for popup dismiss delay are added programatically -->
|
||||
<!-- Values for popup dismiss delay are added programmatically -->
|
||||
<CheckBoxPreference
|
||||
android:key="pref_sliding_key_input_preview"
|
||||
android:title="@string/sliding_key_input_preview"
|
||||
@ -171,6 +171,11 @@
|
||||
android:key="pref_keypress_sound_volume"
|
||||
android:title="@string/prefs_keypress_sound_volume_settings"
|
||||
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
|
||||
android:key="debug_settings"
|
||||
|
@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.res.Resources;
|
||||
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_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_SELECTED_LANGUAGES = "selected_languages";
|
||||
@ -260,4 +262,16 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
||||
public static boolean readUseFullscreenMode(final Resources res) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import android.preference.PreferenceScreen;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||
import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
|
||||
import com.android.inputmethodcommon.InputMethodSettingsFragment;
|
||||
|
||||
public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
@ -155,6 +156,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
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);
|
||||
setupKeypressVibrationDurationSettings(prefs, res);
|
||||
setupKeypressSoundVolumeSettings(prefs, res);
|
||||
@ -196,6 +201,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||
final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
|
||||
setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
|
||||
setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
|
||||
} else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
|
||||
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
|
||||
}
|
||||
ensureConsistencyOfAutoCorrectionSettings();
|
||||
updateVoiceModeSummary();
|
||||
|
@ -16,18 +16,19 @@
|
||||
|
||||
package com.android.inputmethod.latin.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Process;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.inputmethod.compat.IntentCompatUtils;
|
||||
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
|
||||
@ -60,11 +61,7 @@ public final class LauncherIconVisibilityManager extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
if (shouldHandleThisIntent(intent, context)) {
|
||||
if (isInSystemImage(context)) {
|
||||
disableActivity(context, SetupActivity.class);
|
||||
} else {
|
||||
Log.i(TAG, "This package isn't in system image: " + context.getPackageName());
|
||||
}
|
||||
updateSetupWizardIconVisibility(context);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable an activity of the specified package. Disabling an activity will also hide its
|
||||
* icon from the launcher.
|
||||
*
|
||||
* @param context package context of an activity to be disabled
|
||||
* @param activityClass activity class to be disabled
|
||||
*/
|
||||
private static void disableActivity(final Context context,
|
||||
final Class<? extends Activity> activityClass) {
|
||||
final ComponentName activityComponent = new ComponentName(context, activityClass);
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final int activityComponentState = pm.getComponentEnabledSetting(activityComponent);
|
||||
if (activityComponentState == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
|
||||
// This activity is already disabled.
|
||||
Log.i(TAG, "Activity has already been disabled: " + activityComponent);
|
||||
return;
|
||||
public static void updateSetupWizardIconVisibility(final Context context) {
|
||||
final ComponentName setupWizardActivity = new ComponentName(context, SetupActivity.class);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final boolean stateHasSet;
|
||||
if (Settings.readShowSetupWizardIcon(prefs, context)) {
|
||||
stateHasSet = setActivityState(context, setupWizardActivity,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
|
||||
Log.i(TAG, (stateHasSet ? "Enable activity: " : "Activity has already been enabled: ")
|
||||
+ setupWizardActivity);
|
||||
} else {
|
||||
stateHasSet = setActivityState(context, setupWizardActivity,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
|
||||
Log.i(TAG, (stateHasSet ? "Disable activity: " : "Activity has already been disabled: ")
|
||||
+ setupWizardActivity);
|
||||
}
|
||||
// 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) {
|
||||
final ApplicationInfo appInfo = context.getApplicationInfo();
|
||||
return (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
private static boolean setActivityState(final Context context,
|
||||
final ComponentName activityComponent, final int activityState) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user