15ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes/* 25ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * Copyright (C) 2014 The Android Open Source Project 35ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * 45ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * Licensed under the Apache License, Version 2.0 (the "License"); 55ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * you may not use this file except in compliance with the License. 65ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * You may obtain a copy of the License at 75ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * 85ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * http://www.apache.org/licenses/LICENSE-2.0 95ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * 105ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * Unless required by applicable law or agreed to in writing, software 115ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * distributed under the License is distributed on an "AS IS" BASIS, 125ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * See the License for the specific language governing permissions and 145ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * limitations under the License. 155ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes */ 165ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 175ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banespackage android.support.v7.internal.widget; 185ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 195ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.annotation.TargetApi; 205ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.content.Context; 215ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.content.res.TypedArray; 22469286122bcbbecbdd0bef74fb50f9d8920e77b9Chris Banesimport android.graphics.drawable.Drawable; 235ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.os.Build; 245ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.support.v7.appcompat.R; 255ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.util.AttributeSet; 265ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.view.View; 275ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banesimport android.widget.PopupWindow; 285ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 295ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes/** 305ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes * @hide 315ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes */ 325ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banespublic class AppCompatPopupWindow extends PopupWindow { 335ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 345ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes private final boolean mOverlapAnchor; 355ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 365ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes public AppCompatPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) { 375ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes super(context, attrs, defStyleAttr); 385ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 39469286122bcbbecbdd0bef74fb50f9d8920e77b9Chris Banes TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, 40469286122bcbbecbdd0bef74fb50f9d8920e77b9Chris Banes R.styleable.PopupWindow, defStyleAttr, 0); 415ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false); 42469286122bcbbecbdd0bef74fb50f9d8920e77b9Chris Banes // We re-set this for tinting purposes 43469286122bcbbecbdd0bef74fb50f9d8920e77b9Chris Banes setBackgroundDrawable(a.getDrawable(R.styleable.PopupWindow_android_popupBackground)); 445ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes a.recycle(); 455ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 465ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 475ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes @Override 485ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes public void showAsDropDown(View anchor, int xoff, int yoff) { 495ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) { 505ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes // If we're pre-L, emulate overlapAnchor by modifying the yOff 515ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes yoff -= anchor.getHeight(); 525ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 535ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes super.showAsDropDown(anchor, xoff, yoff); 545ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 555ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 565ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes @TargetApi(Build.VERSION_CODES.KITKAT) 575ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes @Override 585ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) { 595ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) { 605ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes // If we're pre-L, emulate overlapAnchor by modifying the yOff 615ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes yoff -= anchor.getHeight(); 625ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 635ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes super.showAsDropDown(anchor, xoff, yoff, gravity); 645ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 655ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes 665ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes @Override 675ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes public void update(View anchor, int xoff, int yoff, int width, int height) { 685ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) { 695ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes // If we're pre-L, emulate overlapAnchor by modifying the yOff 705ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes yoff -= anchor.getHeight(); 715ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 725ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes super.update(anchor, xoff, yoff, width, height); 735ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes } 745ec2faa01bc6790bc015e0d5748dc0482ae8c0f2Chris Banes} 75