From cc6e6f0e0a556bc1dd80faa7155138c9cdaac7fc Mon Sep 17 00:00:00 2001 From: Michael Kwan Date: Mon, 16 May 2016 12:54:57 -0700 Subject: [PATCH] Modified AlertController to allow themes to specify custom implementation. Bug: 17733928 Change-Id: I0264ee8ceee09dbc33da61365c424c74d2e3c3d6 --- core/java/android/app/AlertDialog.java | 2 +- .../android/internal/app/AlertActivity.java | 2 +- .../android/internal/app/AlertController.java | 26 ++++++++++++++----- core/res/res/values/attrs.xml | 7 +++++ .../android/server/policy/GlobalActions.java | 2 +- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java index 782407262c198..9928512de09f0 100644 --- a/core/java/android/app/AlertDialog.java +++ b/core/java/android/app/AlertDialog.java @@ -201,7 +201,7 @@ public class AlertDialog extends Dialog implements DialogInterface { createContextThemeWrapper); mWindow.alwaysReadCloseOnTouchAttr(); - mAlert = new AlertController(getContext(), this, getWindow()); + mAlert = AlertController.create(getContext(), this, getWindow()); } static int resolveDialogTheme(Context context, int themeResId) { diff --git a/core/java/com/android/internal/app/AlertActivity.java b/core/java/com/android/internal/app/AlertActivity.java index ed48b0d1610c5..35ffa71de56f8 100644 --- a/core/java/com/android/internal/app/AlertActivity.java +++ b/core/java/com/android/internal/app/AlertActivity.java @@ -49,7 +49,7 @@ public abstract class AlertActivity extends Activity implements DialogInterface protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mAlert = new AlertController(this, this, getWindow()); + mAlert = AlertController.create(this, this, getWindow()); mAlertParams = new AlertController.AlertParams(this); } diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java index b7ac6008a1fdc..9ade60dcda58a 100644 --- a/core/java/com/android/internal/app/AlertController.java +++ b/core/java/com/android/internal/app/AlertController.java @@ -64,11 +64,11 @@ public class AlertController { private final Context mContext; private final DialogInterface mDialogInterface; - private final Window mWindow; + protected final Window mWindow; private CharSequence mTitle; - private CharSequence mMessage; - private ListView mListView; + protected CharSequence mMessage; + protected ListView mListView; private View mView; private int mViewLayoutResId; @@ -91,14 +91,14 @@ public class AlertController { private CharSequence mButtonNeutralText; private Message mButtonNeutralMessage; - private ScrollView mScrollView; + protected ScrollView mScrollView; private int mIconId = 0; private Drawable mIcon; private ImageView mIconView; private TextView mTitleView; - private TextView mMessageView; + protected TextView mMessageView; private View mCustomTitleView; private boolean mForceInverseBackground; @@ -176,7 +176,19 @@ public class AlertController { return outValue.data != 0; } - public AlertController(Context context, DialogInterface di, Window window) { + public static final AlertController create(Context context, DialogInterface di, Window window) { + final TypedArray a = context.obtainStyledAttributes( + null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0); + int controllerType = a.getInt(R.styleable.AlertDialog_controllerType, 0); + a.recycle(); + + switch (controllerType) { + default: + return new AlertController(context, di, window); + } + } + + protected AlertController(Context context, DialogInterface di, Window window) { mContext = context; mDialogInterface = di; mWindow = window; @@ -643,7 +655,7 @@ public class AlertController { } } - private void setupContent(ViewGroup contentPanel) { + protected void setupContent(ViewGroup contentPanel) { mScrollView = (ScrollView) contentPanel.findViewById(R.id.scrollView); mScrollView.setFocusable(false); diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 6af9ef2271fa1..930abb10e0666 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2046,6 +2046,13 @@ i + + + + + + + diff --git a/services/core/java/com/android/server/policy/GlobalActions.java b/services/core/java/com/android/server/policy/GlobalActions.java index 5ef518e21c58c..6fc15f0216e4b 100644 --- a/services/core/java/com/android/server/policy/GlobalActions.java +++ b/services/core/java/com/android/server/policy/GlobalActions.java @@ -1145,7 +1145,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac public GlobalActionsDialog(Context context, AlertParams params) { super(context, getDialogTheme(context)); mContext = getContext(); - mAlert = new AlertController(mContext, this, getWindow()); + mAlert = AlertController.create(mContext, this, getWindow()); mAdapter = (MyAdapter) params.mAdapter; mWindowTouchSlop = ViewConfiguration.get(context).getScaledWindowTouchSlop(); params.apply(mAlert);