Merge "Modified AlertController to allow themes to specify custom implementation." into nyc-mr1-dev

am: 59bce44aaa

* commit '59bce44aaaad61c5bd57ddcc1225e69ad5d0500b':
  Modified AlertController to allow themes to specify custom implementation.

Change-Id: Ice8251602843a6a98552bcb85272d8cc9eefae2b
This commit is contained in:
Michael Kwan
2016-05-17 18:14:47 +00:00
committed by android-build-merger
5 changed files with 29 additions and 10 deletions

View File

@@ -201,7 +201,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
createContextThemeWrapper); createContextThemeWrapper);
mWindow.alwaysReadCloseOnTouchAttr(); mWindow.alwaysReadCloseOnTouchAttr();
mAlert = new AlertController(getContext(), this, getWindow()); mAlert = AlertController.create(getContext(), this, getWindow());
} }
static int resolveDialogTheme(Context context, int themeResId) { static int resolveDialogTheme(Context context, int themeResId) {

View File

@@ -49,7 +49,7 @@ public abstract class AlertActivity extends Activity implements DialogInterface
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mAlert = new AlertController(this, this, getWindow()); mAlert = AlertController.create(this, this, getWindow());
mAlertParams = new AlertController.AlertParams(this); mAlertParams = new AlertController.AlertParams(this);
} }

View File

@@ -64,11 +64,11 @@ public class AlertController {
private final Context mContext; private final Context mContext;
private final DialogInterface mDialogInterface; private final DialogInterface mDialogInterface;
private final Window mWindow; protected final Window mWindow;
private CharSequence mTitle; private CharSequence mTitle;
private CharSequence mMessage; protected CharSequence mMessage;
private ListView mListView; protected ListView mListView;
private View mView; private View mView;
private int mViewLayoutResId; private int mViewLayoutResId;
@@ -91,14 +91,14 @@ public class AlertController {
private CharSequence mButtonNeutralText; private CharSequence mButtonNeutralText;
private Message mButtonNeutralMessage; private Message mButtonNeutralMessage;
private ScrollView mScrollView; protected ScrollView mScrollView;
private int mIconId = 0; private int mIconId = 0;
private Drawable mIcon; private Drawable mIcon;
private ImageView mIconView; private ImageView mIconView;
private TextView mTitleView; private TextView mTitleView;
private TextView mMessageView; protected TextView mMessageView;
private View mCustomTitleView; private View mCustomTitleView;
private boolean mForceInverseBackground; private boolean mForceInverseBackground;
@@ -176,7 +176,19 @@ public class AlertController {
return outValue.data != 0; 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; mContext = context;
mDialogInterface = di; mDialogInterface = di;
mWindow = window; 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 = (ScrollView) contentPanel.findViewById(R.id.scrollView);
mScrollView.setFocusable(false); mScrollView.setFocusable(false);

View File

@@ -2046,6 +2046,13 @@ i
<attr name="showTitle" format="boolean" /> <attr name="showTitle" format="boolean" />
<!-- @hide Whether fullDark, etc. should use default values if null. --> <!-- @hide Whether fullDark, etc. should use default values if null. -->
<attr name="needsDefaultBackgrounds" format="boolean" /> <attr name="needsDefaultBackgrounds" format="boolean" />
<!-- @hide Workaround until we replace AlertController with custom layout. -->
<attr name="controllerType">
<!-- The default controller. -->
<enum name="normal" value="0" />
<!-- Controller for micro specific layout. -->
<enum name="micro" value="1" />
</attr>
</declare-styleable> </declare-styleable>
<!-- @hide --> <!-- @hide -->

View File

@@ -1145,7 +1145,7 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac
public GlobalActionsDialog(Context context, AlertParams params) { public GlobalActionsDialog(Context context, AlertParams params) {
super(context, getDialogTheme(context)); super(context, getDialogTheme(context));
mContext = getContext(); mContext = getContext();
mAlert = new AlertController(mContext, this, getWindow()); mAlert = AlertController.create(mContext, this, getWindow());
mAdapter = (MyAdapter) params.mAdapter; mAdapter = (MyAdapter) params.mAdapter;
mWindowTouchSlop = ViewConfiguration.get(context).getScaledWindowTouchSlop(); mWindowTouchSlop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
params.apply(mAlert); params.apply(mAlert);