package com.rey.material.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import com.rey.material.R;
public class PopupWindow extends android.widget.PopupWindow {
private final boolean mOverlapAnchor;
public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PopupWindow, defStyleAttr, 0);
mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);
a.recycle();
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) {
// If we're pre-L, emulate overlapAnchor by modifying the yOff
yoff -= anchor.getHeight();
}
super.showAsDropDown(anchor, xoff, yoff);
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) {
// If we're pre-L, emulate overlapAnchor by modifying the yOff
yoff -= anchor.getHeight();
}
super.showAsDropDown(anchor, xoff, yoff, gravity);
}
@Override
public void update(View anchor, int xoff, int yoff, int width, int height) {
if (Build.VERSION.SDK_INT < 21 && mOverlapAnchor) {
// If we're pre-L, emulate overlapAnchor by modifying the yOff
yoff -= anchor.getHeight();
}
super.update(anchor, xoff, yoff, width, height);
}
}