Update IME selection dialog layout for Material

Also cleans up simple_list_item_2.xml formatting.

BUG: 18314215
Change-Id: I12b6ff19fca891524da7137b85dd576f85ee266a
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index edea274..4d0868a 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -66,6 +66,7 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.database.ContentObserver;
+import android.graphics.drawable.Drawable;
 import android.inputmethodservice.InputMethodService;
 import android.net.Uri;
 import android.os.Binder;
@@ -2830,23 +2831,30 @@
                     }
                 }
             }
-            final Context themedContext = new ContextThemeWrapper(context,
-                    android.R.style.Theme_DeviceDefault_Settings);
-            mDialogBuilder = new AlertDialog.Builder(themedContext);
-            final TypedArray a = themedContext.obtainStyledAttributes(null,
-                    com.android.internal.R.styleable.DialogPreference,
-                    com.android.internal.R.attr.alertDialogStyle, 0);
-            mDialogBuilder.setIcon(a.getDrawable(
-                    com.android.internal.R.styleable.DialogPreference_dialogIcon));
-            a.recycle();
+
+            final Context settingsContext = new ContextThemeWrapper(context,
+                    com.android.internal.R.style.Theme_DeviceDefault_Settings);
+
+            mDialogBuilder = new AlertDialog.Builder(settingsContext);
             mDialogBuilder.setOnCancelListener(new OnCancelListener() {
                 @Override
                 public void onCancel(DialogInterface dialog) {
                     hideInputMethodMenu();
                 }
             });
-            final LayoutInflater inflater =
-                    (LayoutInflater)themedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+            final Context dialogContext = mDialogBuilder.getContext();
+            final TypedArray a = dialogContext.obtainStyledAttributes(null,
+                    com.android.internal.R.styleable.DialogPreference,
+                    com.android.internal.R.attr.alertDialogStyle, 0);
+            final Drawable dialogIcon = a.getDrawable(
+                    com.android.internal.R.styleable.DialogPreference_dialogIcon);
+            a.recycle();
+
+            mDialogBuilder.setIcon(dialogIcon);
+
+            final LayoutInflater inflater = (LayoutInflater) dialogContext.getSystemService(
+                    Context.LAYOUT_INFLATER_SERVICE);
             final View tv = inflater.inflate(
                     com.android.internal.R.layout.input_method_switch_dialog_title, null);
             mDialogBuilder.setCustomTitle(tv);
@@ -2857,7 +2865,7 @@
                     .findViewById(com.android.internal.R.id.hard_keyboard_section)
                     .setVisibility(mWindowManagerService.isHardKeyboardAvailable()
                             ? View.VISIBLE : View.GONE);
-            final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
+            final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(
                     com.android.internal.R.id.hard_keyboard_switch);
             hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
             hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@@ -2870,7 +2878,7 @@
                 }
             });
 
-            final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(themedContext,
+            final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext,
                     com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
             final OnClickListener choiceListener = new OnClickListener() {
                 @Override
@@ -2926,10 +2934,11 @@
         public ImeSubtypeListAdapter(Context context, int textViewResourceId,
                 List<ImeSubtypeListItem> itemsList, int checkedItem) {
             super(context, textViewResourceId, itemsList);
+
             mTextViewResourceId = textViewResourceId;
             mItemsList = itemsList;
             mCheckedItem = checkedItem;
-            mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         }
 
         @Override