summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2014-11-10 17:18:48 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-11-10 17:18:49 +0000
commit82aaf332b62c5a276c4046d1339441d68d817371 (patch)
tree9266aa679771904e019f1a0f08b250bf53d22ef5 /core/java/android/widget
parent7d447f734d334dfdd953fdcd45b38fabbeec58dc (diff)
parentce8c358712414e4fa98e4504e6a1b8ad36d37c6c (diff)
downloadframeworks_base-82aaf332b62c5a276c4046d1339441d68d817371.zip
frameworks_base-82aaf332b62c5a276c4046d1339441d68d817371.tar.gz
frameworks_base-82aaf332b62c5a276c4046d1339441d68d817371.tar.bz2
Merge "Update above/below backgrounds in PopupWindow.setBackground()" into lmp-mr1-dev
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/PopupWindow.java84
1 files changed, 42 insertions, 42 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 54a7940..396c0b9 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -198,54 +198,17 @@ public class PopupWindow {
mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
final TypedArray a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.PopupWindow, defStyleAttr, defStyleRes);
-
- mBackground = a.getDrawable(R.styleable.PopupWindow_popupBackground);
+ attrs, R.styleable.PopupWindow, defStyleAttr, defStyleRes);
+ final Drawable bg = a.getDrawable(R.styleable.PopupWindow_popupBackground);
mElevation = a.getDimension(R.styleable.PopupWindow_popupElevation, 0);
mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);
final int animStyle = a.getResourceId(R.styleable.PopupWindow_popupAnimationStyle, -1);
- mAnimationStyle = animStyle == com.android.internal.R.style.Animation_PopupWindow ? -1 :
- animStyle;
+ mAnimationStyle = animStyle == R.style.Animation_PopupWindow ? -1 : animStyle;
- // If this is a StateListDrawable, try to find and store the drawable to be
- // used when the drop-down is placed above its anchor view, and the one to be
- // used when the drop-down is placed below its anchor view. We extract
- // the drawables ourselves to work around a problem with using refreshDrawableState
- // that it will take into account the padding of all drawables specified in a
- // StateListDrawable, thus adding superfluous padding to drop-down views.
- //
- // We assume a StateListDrawable will have a drawable for ABOVE_ANCHOR_STATE_SET and
- // at least one other drawable, intended for the 'below-anchor state'.
- if (mBackground instanceof StateListDrawable) {
- StateListDrawable background = (StateListDrawable) mBackground;
-
- // Find the above-anchor view - this one's easy, it should be labeled as such.
- int aboveAnchorStateIndex = background.getStateDrawableIndex(ABOVE_ANCHOR_STATE_SET);
-
- // Now, for the below-anchor view, look for any other drawable specified in the
- // StateListDrawable which is not for the above-anchor state and use that.
- int count = background.getStateCount();
- int belowAnchorStateIndex = -1;
- for (int i = 0; i < count; i++) {
- if (i != aboveAnchorStateIndex) {
- belowAnchorStateIndex = i;
- break;
- }
- }
-
- // Store the drawables we found, if we found them. Otherwise, set them both
- // to null so that we'll just use refreshDrawableState.
- if (aboveAnchorStateIndex != -1 && belowAnchorStateIndex != -1) {
- mAboveAnchorBackgroundDrawable = background.getStateDrawable(aboveAnchorStateIndex);
- mBelowAnchorBackgroundDrawable = background.getStateDrawable(belowAnchorStateIndex);
- } else {
- mBelowAnchorBackgroundDrawable = null;
- mAboveAnchorBackgroundDrawable = null;
- }
- }
-
a.recycle();
+
+ setBackgroundDrawable(bg);
}
/**
@@ -346,6 +309,43 @@ public class PopupWindow {
*/
public void setBackgroundDrawable(Drawable background) {
mBackground = background;
+
+ // If this is a StateListDrawable, try to find and store the drawable to be
+ // used when the drop-down is placed above its anchor view, and the one to be
+ // used when the drop-down is placed below its anchor view. We extract
+ // the drawables ourselves to work around a problem with using refreshDrawableState
+ // that it will take into account the padding of all drawables specified in a
+ // StateListDrawable, thus adding superfluous padding to drop-down views.
+ //
+ // We assume a StateListDrawable will have a drawable for ABOVE_ANCHOR_STATE_SET and
+ // at least one other drawable, intended for the 'below-anchor state'.
+ if (mBackground instanceof StateListDrawable) {
+ StateListDrawable stateList = (StateListDrawable) mBackground;
+
+ // Find the above-anchor view - this one's easy, it should be labeled as such.
+ int aboveAnchorStateIndex = stateList.getStateDrawableIndex(ABOVE_ANCHOR_STATE_SET);
+
+ // Now, for the below-anchor view, look for any other drawable specified in the
+ // StateListDrawable which is not for the above-anchor state and use that.
+ int count = stateList.getStateCount();
+ int belowAnchorStateIndex = -1;
+ for (int i = 0; i < count; i++) {
+ if (i != aboveAnchorStateIndex) {
+ belowAnchorStateIndex = i;
+ break;
+ }
+ }
+
+ // Store the drawables we found, if we found them. Otherwise, set them both
+ // to null so that we'll just use refreshDrawableState.
+ if (aboveAnchorStateIndex != -1 && belowAnchorStateIndex != -1) {
+ mAboveAnchorBackgroundDrawable = stateList.getStateDrawable(aboveAnchorStateIndex);
+ mBelowAnchorBackgroundDrawable = stateList.getStateDrawable(belowAnchorStateIndex);
+ } else {
+ mBelowAnchorBackgroundDrawable = null;
+ mAboveAnchorBackgroundDrawable = null;
+ }
+ }
}
/**