Show dialog to guide the user to input subtype enabler
Bug: 6370433 Change-Id: Ic5777c1d95fe2ce9f48c72b8cc05c7ac250f4cdfmain
parent
f91739b41e
commit
7566448ddf
|
@ -275,18 +275,24 @@
|
||||||
|
|
||||||
<!-- Title of the preference settings for custom input styles (language and keyboard layout pairs) [CHAR LIMIT=35]-->
|
<!-- Title of the preference settings for custom input styles (language and keyboard layout pairs) [CHAR LIMIT=35]-->
|
||||||
<string name="custom_input_styles_title">Custom input styles</string>
|
<string name="custom_input_styles_title">Custom input styles</string>
|
||||||
<!-- Title of the option menu to add a new style entry in the preference settings [CHAR_LIMIT=16] -->
|
<!-- Title of the option menu to add a new style entry in the preference settings [CHAR LIMIT=16] -->
|
||||||
<string name="add_style">Add style</string>
|
<string name="add_style">Add style</string>
|
||||||
<!-- Title of the button to add custom style entry in the settings dialog [CHAR_LIMIT=12] -->
|
<!-- Title of the button to add custom style entry in the settings dialog [CHAR LIMIT=12] -->
|
||||||
<string name="add">Add</string>
|
<string name="add">Add</string>
|
||||||
<!-- Title of the button to remove a custom style entry in the settings dialog [CHAR_LIMIT=12] -->
|
<!-- Title of the button to remove a custom style entry in the settings dialog [CHAR LIMIT=12] -->
|
||||||
<string name="remove">Remove</string>
|
<string name="remove">Remove</string>
|
||||||
<!-- Title of the button to save a custom style entry in the settings dialog [CHAR_LIMIT=12] -->
|
<!-- Title of the button to save a custom style entry in the settings dialog [CHAR LIMIT=12] -->
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<!-- Title of the spinner for choosing a language of custom style in the settings dialog [CHAR_LIMIT=12] -->
|
<!-- Title of the spinner for choosing a language of custom style in the settings dialog [CHAR LIMIT=12] -->
|
||||||
<string name="subtype_locale">Language</string>
|
<string name="subtype_locale">Language</string>
|
||||||
<!-- Title of the spinner for choosing a keyboard layout of custom style in the settings dialog [CHAR_LIMIT=12] -->
|
<!-- Title of the spinner for choosing a keyboard layout of custom style in the settings dialog [CHAR LIMIT=12] -->
|
||||||
<string name="keyboard_layout_set">Layout</string>
|
<string name="keyboard_layout_set">Layout</string>
|
||||||
|
<!-- The message of the dialog to note that a custom input style needs to be enabled. [CHAR LIMIT=64] -->
|
||||||
|
<string name="custom_input_style_note_message">"Your custom input style needs to be enabled before you start using it. Do you want to enable it now?"</string>
|
||||||
|
<!-- Title of the button to enable a custom input style entry in the settings dialog [CHAR LIMIT=12] -->
|
||||||
|
<string name="enable">Enable</string>
|
||||||
|
<!-- Title of the button to postpone enabling a custom input style entry in the settings dialog [CHAR LIMIT=12] -->
|
||||||
|
<string name="not_now">Not now</string>
|
||||||
|
|
||||||
<!-- Title of an option for usability study mode -->
|
<!-- Title of an option for usability study mode -->
|
||||||
<string name="prefs_usability_study_mode">Usability study mode</string>
|
<string name="prefs_usability_study_mode">Usability study mode</string>
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
@ -41,6 +42,8 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.SpinnerAdapter;
|
import android.widget.SpinnerAdapter;
|
||||||
|
|
||||||
|
import com.android.inputmethod.compat.CompatUtils;
|
||||||
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class AdditionalSubtypeSettings extends PreferenceFragment {
|
public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
|
@ -49,9 +52,14 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter;
|
private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter;
|
||||||
|
|
||||||
private boolean mIsAddingNewSubtype;
|
private boolean mIsAddingNewSubtype;
|
||||||
|
private AlertDialog mSubtypeEnablerNotificationDialog;
|
||||||
|
private String mSubtypePreferenceKeyForSubtypeEnabler;
|
||||||
|
|
||||||
private static final int MENU_ADD_SUBTYPE = Menu.FIRST;
|
private static final int MENU_ADD_SUBTYPE = Menu.FIRST;
|
||||||
private static final String SAVE_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
|
private static final String KEY_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
|
||||||
|
private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN =
|
||||||
|
"is_subtype_enabler_notification_dialog_open";
|
||||||
|
private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler";
|
||||||
|
|
||||||
static class SubtypeLocaleItem extends Pair<String, String>
|
static class SubtypeLocaleItem extends Pair<String, String>
|
||||||
implements Comparable<SubtypeLocaleItem> {
|
implements Comparable<SubtypeLocaleItem> {
|
||||||
|
@ -368,20 +376,36 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
setPrefSubtypes(prefSubtypes, context);
|
setPrefSubtypes(prefSubtypes, context);
|
||||||
|
|
||||||
mIsAddingNewSubtype = (savedInstanceState != null)
|
mIsAddingNewSubtype = (savedInstanceState != null)
|
||||||
&& savedInstanceState.containsKey(SAVE_IS_ADDING_NEW_SUBTYPE);
|
&& savedInstanceState.containsKey(KEY_IS_ADDING_NEW_SUBTYPE);
|
||||||
if (mIsAddingNewSubtype) {
|
if (mIsAddingNewSubtype) {
|
||||||
getPreferenceScreen().addPreference(
|
getPreferenceScreen().addPreference(
|
||||||
SubtypePreference.newIncompleteSubtypePreference(context, mSubtypeProxy));
|
SubtypePreference.newIncompleteSubtypePreference(context, mSubtypeProxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState != null && savedInstanceState.containsKey(
|
||||||
|
KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN)) {
|
||||||
|
mSubtypePreferenceKeyForSubtypeEnabler = savedInstanceState.getString(
|
||||||
|
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
|
||||||
|
final SubtypePreference subtypePref = (SubtypePreference)findPreference(
|
||||||
|
mSubtypePreferenceKeyForSubtypeEnabler);
|
||||||
|
mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
|
||||||
|
mSubtypeEnablerNotificationDialog.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
if (mIsAddingNewSubtype) {
|
if (mIsAddingNewSubtype) {
|
||||||
outState.putBoolean(SAVE_IS_ADDING_NEW_SUBTYPE, true);
|
outState.putBoolean(KEY_IS_ADDING_NEW_SUBTYPE, true);
|
||||||
|
}
|
||||||
|
if (mSubtypeEnablerNotificationDialog != null
|
||||||
|
&& mSubtypeEnablerNotificationDialog.isShowing()) {
|
||||||
|
outState.putBoolean(KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN, true);
|
||||||
|
outState.putString(
|
||||||
|
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER, mSubtypePreferenceKeyForSubtypeEnabler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,6 +422,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onAddPressed(SubtypePreference subtypePref) {
|
public void onAddPressed(SubtypePreference subtypePref) {
|
||||||
mIsAddingNewSubtype = false;
|
mIsAddingNewSubtype = false;
|
||||||
|
setAdditionalInputMethodSubtypes(getPrefSubtypes());
|
||||||
|
mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
|
||||||
|
mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
|
||||||
|
mSubtypeEnablerNotificationDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -411,6 +439,29 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private AlertDialog createDialog(SubtypePreference subtypePref) {
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(R.string.custom_input_styles_title)
|
||||||
|
.setMessage(R.string.custom_input_style_note_message)
|
||||||
|
.setNegativeButton(R.string.not_now, null)
|
||||||
|
.setPositiveButton(R.string.enable, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
final Intent intent = CompatUtils.getInputLanguageSelectionIntent(
|
||||||
|
ImfUtils.getInputMethodIdOfThisIme(getActivity()),
|
||||||
|
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
// TODO: Add newly adding subtype to extra value of the intent as a hint
|
||||||
|
// for the input language selection activity.
|
||||||
|
// intent.putExtra("newlyAddedSubtype", subtypePref.getSubtype());
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
private void setPrefSubtypes(String prefSubtypes, Context context) {
|
private void setPrefSubtypes(String prefSubtypes, Context context) {
|
||||||
final PreferenceGroup group = getPreferenceScreen();
|
final PreferenceGroup group = getPreferenceScreen();
|
||||||
group.removeAll();
|
group.removeAll();
|
||||||
|
@ -458,6 +509,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
} finally {
|
} finally {
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
setAdditionalInputMethodSubtypes(prefSubtypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAdditionalInputMethodSubtypes(final String prefSubtypes) {
|
||||||
final InputMethodSubtype[] subtypes =
|
final InputMethodSubtype[] subtypes =
|
||||||
AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes);
|
AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes);
|
||||||
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes);
|
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes);
|
||||||
|
|
Loading…
Reference in New Issue