Merge "Bidi wrap keyboard names before displaying them." into oc-dev am: b8d6222e23
am: 6a2fa09ff4
Change-Id: Ic185accac95ae48dd5f1a1e184b438db9920550a
diff --git a/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java b/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
index b7bf3dc..5436901 100644
--- a/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
+++ b/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceController.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v7.preference.Preference;
+import android.text.BidiFormatter;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -76,12 +77,15 @@
return;
}
+ final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
+
String summary = null;
for (String label : labels) {
if (summary == null) {
- summary = label;
+ summary = bidiFormatter.unicodeWrap(label);
} else {
- summary = mContext.getString(R.string.join_many_items_middle, summary, label);
+ summary = mContext.getString(R.string.join_many_items_middle, summary,
+ bidiFormatter.unicodeWrap(label));
}
}
preference.setSummary(summary);
diff --git a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
index 3256950..1332445 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/VirtualKeyboardPreferenceControllerTest.java
@@ -18,6 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -26,6 +28,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.support.v4.text.BidiFormatter;
import android.support.v7.preference.Preference;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -39,6 +42,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -96,4 +100,35 @@
verify(mPreference).setSummary("label");
}
+
+ @Test
+ public void updateState_multiImeWithMixedLocale_setImeLabelToSummary() {
+ final BidiFormatter formatter = BidiFormatter.getInstance();
+ final ComponentName componentName = new ComponentName("pkg", "cls");
+ final List<InputMethodInfo> imis = new ArrayList<>();
+ final String label1 = "label";
+ final String label2 = "Keyboard מִקְלֶדֶת";
+ imis.add(mock(InputMethodInfo.class));
+ imis.add(mock(InputMethodInfo.class));
+
+ when(mDpm.getPermittedInputMethodsForCurrentUser()).thenReturn(null);
+ when(mImm.getEnabledInputMethodList()).thenReturn(imis);
+ when(imis.get(0).getPackageName()).thenReturn(componentName.getPackageName());
+ when(imis.get(0).loadLabel(mPm)).thenReturn(label1);
+ when(imis.get(1).getPackageName()).thenReturn(componentName.getPackageName());
+ when(imis.get(1).loadLabel(mPm)).thenReturn(label2);
+ when(mContext.getString(eq(R.string.join_many_items_middle), anyString(), anyString()))
+ .thenAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ final String str1 = (String) args[1];
+ final String str2 = (String) args[2];
+ return RuntimeEnvironment.application.getString(R.string.join_many_items_middle,
+ str1, str2);
+ });
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(
+ formatter.unicodeWrap(label1) + ", " + formatter.unicodeWrap(label2));
+ }
}