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

This commit is contained in:
Michael Kwan
2016-05-17 18:03:37 +00:00
committed by Android (Google) Code Review
5 changed files with 29 additions and 10 deletions

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -2046,6 +2046,13 @@ i
<attr name="showTitle" format="boolean" />
<!-- @hide Whether fullDark, etc. should use default values if null. -->
<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>
<!-- @hide -->

View File

@@ -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);