OSDN Git Service

Temp fix to split header and position count behaviour for watches.
authorMichael Kwan <mkwan@google.com>
Thu, 9 Jun 2016 18:59:21 +0000 (11:59 -0700)
committerMichael Kwan <mkwan@google.com>
Fri, 10 Jun 2016 19:01:23 +0000 (12:01 -0700)
Bug: 29010414
Bug: 29244476
Change-Id: I5c8616304e7d44f423636612670d9187ad030679

core/java/com/android/internal/app/AlertController.java

index c5ed29f..2a40aeb 100644 (file)
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.res.Configuration;
 import android.content.res.TypedArray;
 import android.database.Cursor;
 import android.graphics.drawable.Drawable;
@@ -177,6 +178,11 @@ public class AlertController {
         return outValue.data != 0;
     }
 
+    private static boolean isWatch(Context context) {
+        return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_WATCH)
+                == Configuration.UI_MODE_TYPE_WATCH;
+    }
+
     public static final AlertController create(Context context, DialogInterface di, Window window) {
         final TypedArray a = context.obtainStyledAttributes(
                 null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
@@ -886,8 +892,14 @@ public class AlertController {
             listView.setAdapter(mAdapter);
             final int checkedItem = mCheckedItem;
             if (checkedItem > -1) {
-                listView.setItemChecked(checkedItem + listView.getHeaderViewsCount(), true);
-                listView.setSelection(checkedItem + listView.getHeaderViewsCount());
+                // TODO: Remove temp watch specific code
+                if (isWatch(mContext)) {
+                    listView.setItemChecked(checkedItem + listView.getHeaderViewsCount(), true);
+                    listView.setSelection(checkedItem + listView.getHeaderViewsCount());
+                } else {
+                    listView.setItemChecked(checkedItem, true);
+                    listView.setSelection(checkedItem);
+                }
             }
         }
     }
@@ -1066,8 +1078,13 @@ public class AlertController {
                             if (mCheckedItems != null) {
                                 boolean isItemChecked = mCheckedItems[position];
                                 if (isItemChecked) {
-                                    listView.setItemChecked(
-                                            position + listView.getHeaderViewsCount(), true);
+                                    // TODO: Remove temp watch specific code
+                                    if (isWatch(mContext)) {
+                                        listView.setItemChecked(
+                                                position + listView.getHeaderViewsCount(), true);
+                                    } else {
+                                        listView.setItemChecked(position, true);
+                                    }
                                 }
                             }
                             return view;
@@ -1088,9 +1105,16 @@ public class AlertController {
                         public void bindView(View view, Context context, Cursor cursor) {
                             CheckedTextView text = (CheckedTextView) view.findViewById(R.id.text1);
                             text.setText(cursor.getString(mLabelIndex));
-                            listView.setItemChecked(
-                                    cursor.getPosition() + listView.getHeaderViewsCount(),
-                                    cursor.getInt(mIsCheckedIndex) == 1);
+                            // TODO: Remove temp watch specific code
+                            if (isWatch(mContext)) {
+                                listView.setItemChecked(
+                                        cursor.getPosition() + listView.getHeaderViewsCount(),
+                                        cursor.getInt(mIsCheckedIndex) == 1);
+                            } else {
+                                listView.setItemChecked(
+                                        cursor.getPosition(),
+                                        cursor.getInt(mIsCheckedIndex) == 1);
+                            }
                         }
 
                         @Override
@@ -1133,7 +1157,10 @@ public class AlertController {
                 listView.setOnItemClickListener(new OnItemClickListener() {
                     @Override
                     public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
-                        position -= listView.getHeaderViewsCount();
+                        // TODO: Remove temp watch specific code
+                        if (isWatch(mContext)) {
+                            position -= listView.getHeaderViewsCount();
+                        }
                         mOnClickListener.onClick(dialog.mDialogInterface, position);
                         if (!mIsSingleChoice) {
                             dialog.mDialogInterface.dismiss();
@@ -1144,7 +1171,10 @@ public class AlertController {
                 listView.setOnItemClickListener(new OnItemClickListener() {
                     @Override
                     public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
-                        position -= listView.getHeaderViewsCount();
+                        // TODO: Remove temp watch specific code
+                        if (isWatch(mContext)) {
+                            position -= listView.getHeaderViewsCount();
+                        }
                         if (mCheckedItems != null) {
                             mCheckedItems[position] = listView.isItemChecked(position);
                         }