diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-01-11 23:45:09 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2011-01-12 10:33:13 -0800 |
commit | 6014527c350895383b99ba91d3d009a32b1d22a6 (patch) | |
tree | 2849dd8613126ad6d5f7321a678ef474c3d37830 /policy | |
parent | 92a9a3c5ef9774863b4cee93d43b67582a02c2f0 (diff) | |
download | frameworks_base-6014527c350895383b99ba91d3d009a32b1d22a6.zip frameworks_base-6014527c350895383b99ba91d3d009a32b1d22a6.tar.gz frameworks_base-6014527c350895383b99ba91d3d009a32b1d22a6.tar.bz2 |
Add "min size" facility to the Window class.
This allows us to have a new dialog theme that behaves like an alert dialog
for both Dialog and Activity versions. Very useful with so many more things
being displayed as dialogs on our nice large screen.
Note I didn't change the existing dialog themes to have this behavior, since
it will probably break things. Instead there is a new variation. And the
DialogWhenLarge variations now use this for their dialog form, to fix many
of the real new dialogs we have that need this behavior.
Removed the public definition of the one alert dialog theme. None of the
others have ever been public, this one shouldn't be.
Added new .Panel versions of the Holo themes, like we already had for the
original themes.
Changed the alert dialog layout to no longer use WeightedLinearLayout,
since the window now takes care of that. This allowed for the removal
of the xlarge version of those layouts.
Change-Id: I0c8372bde25eb9af47404a719b3f07230baf73bf
Diffstat (limited to 'policy')
-rw-r--r-- | policy/src/com/android/internal/policy/impl/PhoneWindow.java | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java index 6232afd..1fc2e6c 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java @@ -15,6 +15,9 @@ package com.android.internal.policy.impl; +import static android.view.View.MeasureSpec.AT_MOST; +import static android.view.View.MeasureSpec.EXACTLY; +import static android.view.View.MeasureSpec.getMode; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; @@ -52,6 +55,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.util.AndroidRuntimeException; import android.util.Config; +import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; import android.util.SparseArray; @@ -72,6 +76,7 @@ import android.view.ViewManager; import android.view.ViewStub; import android.view.Window; import android.view.WindowManager; +import android.view.View.MeasureSpec; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.view.animation.Animation; @@ -98,7 +103,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { * Simple callback used by the context menu and its submenus. The options * menu submenus do not use this (their behavior is more complex). */ - DialogMenuCallback mContextMenuCallback = new DialogMenuCallback(FEATURE_CONTEXT_MENU); + final DialogMenuCallback mContextMenuCallback = new DialogMenuCallback(FEATURE_CONTEXT_MENU); + + final TypedValue mMinWidthMajor = new TypedValue(); + final TypedValue mMinWidthMinor = new TypedValue(); // This is the top-level view of the window, containing the window decor. private DecorView mDecor; @@ -1866,6 +1874,45 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); + final boolean isPortrait = metrics.widthPixels < metrics.heightPixels; + + final int widthMode = getMode(widthMeasureSpec); + + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int width = getMeasuredWidth(); + boolean measure = false; + + widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY); + + final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor; + + if (widthMode == AT_MOST && tv.type != TypedValue.TYPE_NULL) { + final int min; + if (tv.type == TypedValue.TYPE_DIMENSION) { + min = (int)tv.getDimension(metrics); + } else if (tv.type == TypedValue.TYPE_FRACTION) { + min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels); + } else { + min = 0; + } + + if (width < min) { + widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY); + measure = true; + } + } + + // TODO: Support height? + + if (measure) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + } + + @Override public void draw(Canvas canvas) { super.draw(canvas); @@ -2274,6 +2321,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags())); } + a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMajor, mMinWidthMajor); + a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMinor, mMinWidthMinor); + if (getContext().getApplicationInfo().targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { addFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY); |