Support RTL layout in custom input style settings
Bug: 17322353 Change-Id: I3b211ab8729121271563a8a243558a58ee7847c2main
parent
4e28a6a844
commit
f507d1febb
|
@ -18,39 +18,60 @@
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:columnCount="2"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginLeft="8dip"
|
android:padding="16dip">
|
||||||
android:layout_marginRight="8dip"
|
<LinearLayout
|
||||||
android:padding="8dip">
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="30"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="left|center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:gravity="start|left"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
style="?android:attr/textAppearanceSmall"
|
style="?android:attr/textAppearanceSmall"
|
||||||
android:text="@string/subtype_locale" />
|
android:text="@string/subtype_locale" />
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/subtype_locale_spinner"
|
android:id="@+id/subtype_locale_spinner"
|
||||||
android:layout_width="wrap_content"
|
android:spinnerMode="dialog"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="70"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dip"
|
android:layout_marginLeft="8dip"
|
||||||
android:layout_marginBottom="8dip"
|
android:layout_marginBottom="8dip"
|
||||||
android:layout_marginTop="8dip"
|
android:layout_marginTop="8dip"
|
||||||
android:layout_gravity="fill_horizontal|center_vertical"
|
android:layout_gravity="fill_horizontal|center_vertical"
|
||||||
|
android:gravity="start|left"
|
||||||
android:prompt="@string/subtype_locale" />
|
android:prompt="@string/subtype_locale" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="30"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="left|center_vertical"
|
android:layout_gravity="start|center_vertical"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
style="?android:attr/textAppearanceSmall"
|
style="?android:attr/textAppearanceSmall"
|
||||||
android:text="@string/keyboard_layout_set" />
|
android:text="@string/keyboard_layout_set" />
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/keyboard_layout_set_spinner"
|
android:id="@+id/keyboard_layout_set_spinner"
|
||||||
android:layout_width="wrap_content"
|
android:spinnerMode="dialog"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="70"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dip"
|
android:layout_marginLeft="8dip"
|
||||||
android:layout_marginBottom="8dip"
|
android:layout_marginBottom="8dip"
|
||||||
android:layout_marginTop="8dip"
|
android:layout_marginTop="8dip"
|
||||||
android:layout_gravity="fill_horizontal|center_vertical"
|
android:layout_gravity="fill_horizontal|center_vertical"
|
||||||
|
android:gravity="start|left"
|
||||||
android:prompt="@string/keyboard_layout_set" />
|
android:prompt="@string/keyboard_layout_set" />
|
||||||
</GridLayout>
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
|
@ -34,6 +34,9 @@ public final class ViewCompatUtils {
|
||||||
// Note that View.setElevation(float) has been introduced in API level 21.
|
// Note that View.setElevation(float) has been introduced in API level 21.
|
||||||
private static final Method METHOD_setElevation = CompatUtils.getMethod(
|
private static final Method METHOD_setElevation = CompatUtils.getMethod(
|
||||||
View.class, "setElevation", float.class);
|
View.class, "setElevation", float.class);
|
||||||
|
// Note that View.setTextAlignment(int) has been introduced in API level 17.
|
||||||
|
private static final Method METHOD_setTextAlignment = CompatUtils.getMethod(
|
||||||
|
View.class, "setTextAlignment", int.class);
|
||||||
|
|
||||||
private ViewCompatUtils() {
|
private ViewCompatUtils() {
|
||||||
// This utility class is not publicly instantiable.
|
// This utility class is not publicly instantiable.
|
||||||
|
@ -56,9 +59,19 @@ public final class ViewCompatUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setElevation(final View view, final float elevation) {
|
public static void setElevation(final View view, final float elevation) {
|
||||||
if (METHOD_setElevation == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CompatUtils.invoke(view, null, METHOD_setElevation, elevation);
|
CompatUtils.invoke(view, null, METHOD_setElevation, elevation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These TEXT_ALIGNMENT_* constants have been introduced in API 17.
|
||||||
|
public static final int TEXT_ALIGNMENT_INHERIT = 0;
|
||||||
|
public static final int TEXT_ALIGNMENT_GRAVITY = 1;
|
||||||
|
public static final int TEXT_ALIGNMENT_TEXT_START = 2;
|
||||||
|
public static final int TEXT_ALIGNMENT_TEXT_END = 3;
|
||||||
|
public static final int TEXT_ALIGNMENT_CENTER = 4;
|
||||||
|
public static final int TEXT_ALIGNMENT_VIEW_START = 5;
|
||||||
|
public static final int TEXT_ALIGNMENT_VIEW_END = 6;
|
||||||
|
|
||||||
|
public static void setTextAlignment(final View view, final int textAlignment) {
|
||||||
|
CompatUtils.invoke(view, null, METHOD_setTextAlignment, textAlignment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,14 @@ import android.preference.DialogPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
@ -43,6 +46,7 @@ import android.widget.SpinnerAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
|
||||||
|
import com.android.inputmethod.compat.ViewCompatUtils;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.RichInputMethodManager;
|
import com.android.inputmethod.latin.RichInputMethodManager;
|
||||||
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
|
||||||
|
@ -233,6 +237,12 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
mSubtypeLocaleSpinner.setAdapter(mProxy.getSubtypeLocaleAdapter());
|
mSubtypeLocaleSpinner.setAdapter(mProxy.getSubtypeLocaleAdapter());
|
||||||
mKeyboardLayoutSetSpinner = (Spinner) v.findViewById(R.id.keyboard_layout_set_spinner);
|
mKeyboardLayoutSetSpinner = (Spinner) v.findViewById(R.id.keyboard_layout_set_spinner);
|
||||||
mKeyboardLayoutSetSpinner.setAdapter(mProxy.getKeyboardLayoutSetAdapter());
|
mKeyboardLayoutSetSpinner.setAdapter(mProxy.getKeyboardLayoutSetAdapter());
|
||||||
|
// All keyboard layout names are in the Latin script and thus left to right. That means
|
||||||
|
// the view would align them to the left even if the system locale is RTL, but that
|
||||||
|
// would look strange. To fix this, we align them to the view's start, which will be
|
||||||
|
// natural for any direction.
|
||||||
|
ViewCompatUtils.setTextAlignment(
|
||||||
|
mKeyboardLayoutSetSpinner, ViewCompatUtils.TEXT_ALIGNMENT_VIEW_START);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +407,16 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||||
|
final Bundle savedInstanceState) {
|
||||||
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
|
// For correct display in RTL locales, we need to set the layout direction of the
|
||||||
|
// fragment's top view.
|
||||||
|
ViewCompat.setLayoutDirection(view, ViewCompat.LAYOUT_DIRECTION_LOCALE);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
|
@ -422,7 +442,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
|
KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
|
||||||
final SubtypePreference subtypePref = (SubtypePreference)findPreference(
|
final SubtypePreference subtypePref = (SubtypePreference)findPreference(
|
||||||
mSubtypePreferenceKeyForSubtypeEnabler);
|
mSubtypePreferenceKeyForSubtypeEnabler);
|
||||||
mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
|
mSubtypeEnablerNotificationDialog = createDialog();
|
||||||
mSubtypeEnablerNotificationDialog.show();
|
mSubtypeEnablerNotificationDialog.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,7 +496,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
if (findDuplicatedSubtype(subtype) == null) {
|
if (findDuplicatedSubtype(subtype) == null) {
|
||||||
mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
|
mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
|
||||||
mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
|
mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
|
||||||
mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
|
mSubtypeEnablerNotificationDialog = createDialog();
|
||||||
mSubtypeEnablerNotificationDialog.show();
|
mSubtypeEnablerNotificationDialog.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +533,7 @@ public final class CustomInputStyleSettingsFragment extends PreferenceFragment {
|
||||||
localeString, keyboardLayoutSetName);
|
localeString, keyboardLayoutSetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AlertDialog createDialog(final SubtypePreference subtypePref) {
|
private AlertDialog createDialog() {
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(
|
final AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
DialogUtils.getPlatformDialogThemeContext(getActivity()));
|
DialogUtils.getPlatformDialogThemeContext(getActivity()));
|
||||||
builder.setTitle(R.string.custom_input_styles_title)
|
builder.setTitle(R.string.custom_input_styles_title)
|
||||||
|
|
Loading…
Reference in New Issue