package razerdp.demo.popup;
import android.animation.Animator;
import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.widget.TextView;
import razerdp.basepopup.BasePopupWindow;
import razerdp.basepopup.R;
import razerdp.demo.utils.ToastUtils;
/**
* Created by 大灯泡 on 2016/1/22.
* 菜单。
*/
public class MenuPopup extends BasePopupWindow implements View.OnClickListener {
private TextView tx1;
private TextView tx2;
private TextView tx3;
public MenuPopup(Activity context) {
super(context, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
findViewById(R.id.tx_1).setOnClickListener(this);
findViewById(R.id.tx_2).setOnClickListener(this);
findViewById(R.id.tx_3).setOnClickListener(this);
}
@Override
protected Animation initShowAnimation() {
AnimationSet set = new AnimationSet(true);
set.setInterpolator(new DecelerateInterpolator());
set.addAnimation(getScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0));
set.addAnimation(getDefaultAlphaAnimation());
return set;
//return null;
}
@Override
public Animator initShowAnimator() {
/* AnimatorSet set=new AnimatorSet();
set.playTogether(
ObjectAnimator.ofFloat(mAnimaView,"scaleX",0.0f,1.0f).setDuration(300),
ObjectAnimator.ofFloat(mAnimaView,"scaleY",0.0f,1.0f).setDuration(300),
ObjectAnimator.ofFloat(mAnimaView,"alpha",0.0f,1.0f).setDuration(300*3/2));*/
return null;
}
@Override
public void showPopupWindow(View v) {
setOffsetX(-(getPopupViewWidth() - v.getWidth() / 2));
setOffsetY(v.getHeight() / 2);
super.showPopupWindow(v);
}
@Override
public View getClickToDismissView() {
return null;
}
@Override
public View onCreatePopupView() {
return createPopupById(R.layout.popup_menu);
}
@Override
public View initAnimaView() {
return getPopupWindowView().findViewById(R.id.popup_contianer);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tx_1:
ToastUtils.ToastMessage(getContext(), "click tx_1");
break;
case R.id.tx_2:
ToastUtils.ToastMessage(getContext(), "click tx_2");
break;
case R.id.tx_3:
ToastUtils.ToastMessage(getContext(), "click tx_3");
break;
default:
break;
}
}
}