From 80062c06c707c71ff8cdf052c2ffe331f68cd82e Mon Sep 17 00:00:00 2001 From: Rolf Smit Date: Thu, 30 Apr 2015 12:03:10 +0200 Subject: [PATCH 1/2] - Better support for dialog sizes across different screen configurations; - Added default android:windowWidthMajor and android:windowWidthMinor values (the default android values may vary per device and Android version); - Added back-ported support for windowWidthMajor and windowWidthMinor for android API 8, 9 and 10; - Theme clean-up; --- .../internal/AlertController.java | 62 ++++++++++++++++++- .../main/res/layout/adp_alert_dialog_base.xml | 7 +++ .../main/res/values-large/adp_core_dimens.xml | 5 ++ .../main/res/values-v11/adp_core_themes.xml | 13 ++-- .../res/values-xlarge/adp_core_dimens.xml | 5 ++ .../src/main/res/values/adp_core_dimens.xml | 5 ++ .../src/main/res/values/adp_core_themes.xml | 47 ++------------ 7 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 alertdialogpro-core/src/main/res/layout/adp_alert_dialog_base.xml create mode 100644 alertdialogpro-core/src/main/res/values-large/adp_core_dimens.xml create mode 100644 alertdialogpro-core/src/main/res/values-xlarge/adp_core_dimens.xml create mode 100644 alertdialogpro-core/src/main/res/values/adp_core_dimens.xml diff --git a/alertdialogpro-core/src/main/java/com/alertdialogpro/internal/AlertController.java b/alertdialogpro-core/src/main/java/com/alertdialogpro/internal/AlertController.java index 515142e..9337337 100644 --- a/alertdialogpro-core/src/main/java/com/alertdialogpro/internal/AlertController.java +++ b/alertdialogpro-core/src/main/java/com/alertdialogpro/internal/AlertController.java @@ -5,8 +5,10 @@ import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Handler; import android.os.Message; +import android.support.v7.internal.widget.ContentFrameLayout; import android.text.TextUtils; import android.util.AttributeSet; import android.util.TypedValue; @@ -190,10 +192,68 @@ static boolean canTextInput(View v) { public void installContent() { /* We use a custom title so never request a window title */ mWindow.requestFeature(Window.FEATURE_NO_TITLE); - mWindow.setContentView(mAlertDialogLayout); + + /* On API 11 and below: + * Inflate the base DecorView of all dialogs, + * this is used to backport the windowMinWidthMajor,windowMinWidthMinor etc. attributes, + * in the same way AppCompat does + * */ + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { + + //FitWindowsLinearLayout decorView = (FitWindowsLinearLayout) mWindow.getLayoutInflater().inflate(R.layout.adp_alert_dialog_base, null, false); + ContentFrameLayout frameLayout = (ContentFrameLayout) mWindow.getLayoutInflater().inflate(R.layout.adp_alert_dialog_base, null, false); + + //ContentFrameLayout frameLayout = (ContentFrameLayout) mWindow.getDecorView(); + LayoutInflater.from(frameLayout.getContext()).inflate(mAlertDialogLayout, frameLayout, true); + //mWindow.setContentView(mAlertDialogLayout); + mWindow.setContentView(frameLayout); + + applyFixedSizeWindow(frameLayout); + } else { + mWindow.setContentView(mAlertDialogLayout); + } + + setupView(); } + private void applyFixedSizeWindow(ContentFrameLayout contentFrameLayout) { + /* + // This is a bit weird. In the framework, the window sizing attributes control + // the decor view's size, meaning that any padding is inset for the min/max widths below. + // We don't control measurement at that level, so we need to workaround it by making sure + // that the decor view's padding is taken into account. + + contentFrameLayout.setDecorPadding(mWindowDecor.getPaddingLeft(), + mWindowDecor.getPaddingTop(), mWindowDecor.getPaddingRight(), + mWindowDecor.getPaddingBottom()); + */ + + TypedArray a = contentFrameLayout.getContext().obtainStyledAttributes(R.styleable.Theme); + a.getValue(R.styleable.Theme_windowMinWidthMajor, contentFrameLayout.getMinWidthMajor()); + a.getValue(R.styleable.Theme_windowMinWidthMinor, contentFrameLayout.getMinWidthMinor()); + + if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) { + a.getValue(R.styleable.Theme_windowFixedWidthMajor, + contentFrameLayout.getFixedWidthMajor()); + } + if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) { + a.getValue(R.styleable.Theme_windowFixedWidthMinor, + contentFrameLayout.getFixedWidthMinor()); + } + if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) { + a.getValue(R.styleable.Theme_windowFixedHeightMajor, + contentFrameLayout.getFixedHeightMajor()); + } + if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) { + a.getValue(R.styleable.Theme_windowFixedHeightMinor, + contentFrameLayout.getFixedHeightMinor()); + } + a.recycle(); + + contentFrameLayout.requestLayout(); + } + public void setTitle(CharSequence title) { mTitle = title; if (mTitleView != null) { diff --git a/alertdialogpro-core/src/main/res/layout/adp_alert_dialog_base.xml b/alertdialogpro-core/src/main/res/layout/adp_alert_dialog_base.xml new file mode 100644 index 0000000..326af3b --- /dev/null +++ b/alertdialogpro-core/src/main/res/layout/adp_alert_dialog_base.xml @@ -0,0 +1,7 @@ + + diff --git a/alertdialogpro-core/src/main/res/values-large/adp_core_dimens.xml b/alertdialogpro-core/src/main/res/values-large/adp_core_dimens.xml new file mode 100644 index 0000000..b2adcbf --- /dev/null +++ b/alertdialogpro-core/src/main/res/values-large/adp_core_dimens.xml @@ -0,0 +1,5 @@ + + + 55% + 80% + \ No newline at end of file diff --git a/alertdialogpro-core/src/main/res/values-v11/adp_core_themes.xml b/alertdialogpro-core/src/main/res/values-v11/adp_core_themes.xml index 1abd852..c5cdd13 100644 --- a/alertdialogpro-core/src/main/res/values-v11/adp_core_themes.xml +++ b/alertdialogpro-core/src/main/res/values-v11/adp_core_themes.xml @@ -1,13 +1,16 @@ + - \ No newline at end of file + diff --git a/alertdialogpro-core/src/main/res/values-xlarge/adp_core_dimens.xml b/alertdialogpro-core/src/main/res/values-xlarge/adp_core_dimens.xml new file mode 100644 index 0000000..5a084e0 --- /dev/null +++ b/alertdialogpro-core/src/main/res/values-xlarge/adp_core_dimens.xml @@ -0,0 +1,5 @@ + + + 45% + 72% + \ No newline at end of file diff --git a/alertdialogpro-core/src/main/res/values/adp_core_dimens.xml b/alertdialogpro-core/src/main/res/values/adp_core_dimens.xml new file mode 100644 index 0000000..b63ce50 --- /dev/null +++ b/alertdialogpro-core/src/main/res/values/adp_core_dimens.xml @@ -0,0 +1,5 @@ + + + 65% + 95% + \ No newline at end of file diff --git a/alertdialogpro-core/src/main/res/values/adp_core_themes.xml b/alertdialogpro-core/src/main/res/values/adp_core_themes.xml index 84388c5..43b36b5 100644 --- a/alertdialogpro-core/src/main/res/values/adp_core_themes.xml +++ b/alertdialogpro-core/src/main/res/values/adp_core_themes.xml @@ -1,49 +1,14 @@ -