|
@@ -2,10 +2,13 @@ package com.jixin.im.view.redDialog;
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.view.Gravity;
|
|
|
+import android.view.View;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager;
|
|
|
+import android.view.animation.AccelerateInterpolator;
|
|
|
import android.view.animation.Animation;
|
|
|
import android.view.animation.AnimationUtils;
|
|
|
import android.widget.ImageView;
|
|
@@ -14,34 +17,19 @@ import android.widget.TextView;
|
|
|
|
|
|
import com.jixin.im.MyApplication;
|
|
|
import com.jixin.im.R;
|
|
|
+import com.jixin.im.animation.Rotate3DAnimation;
|
|
|
import com.jixin.im.bean.redpacket.RedDialogBean;
|
|
|
import com.jixin.im.helper.AvatarHelper;
|
|
|
|
|
|
public class RedDialog extends Dialog {
|
|
|
|
|
|
- private RelativeLayout mRedRl;
|
|
|
- private ImageView mAvatarIv, mOpenIv, mCloseIv;
|
|
|
- private TextView mNameTv, mContentTv;
|
|
|
+ private ImageView mAvatarIv, mOpenIv;
|
|
|
+ private TextView mNameTv, mContentTv,mTypeTv;
|
|
|
private RedDialogBean mRedDialogBean;
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
- private FrameAnimation mFrameAnimation;
|
|
|
- private int[] mImgResIds = new int[]{
|
|
|
- R.mipmap.icon_open_red_packet1,
|
|
|
- R.mipmap.icon_open_red_packet2,
|
|
|
- R.mipmap.icon_open_red_packet3,
|
|
|
- R.mipmap.icon_open_red_packet4,
|
|
|
- R.mipmap.icon_open_red_packet5,
|
|
|
- R.mipmap.icon_open_red_packet6,
|
|
|
- R.mipmap.icon_open_red_packet7,
|
|
|
- R.mipmap.icon_open_red_packet7,
|
|
|
- R.mipmap.icon_open_red_packet8,
|
|
|
- R.mipmap.icon_open_red_packet9,
|
|
|
- R.mipmap.icon_open_red_packet4,
|
|
|
- R.mipmap.icon_open_red_packet10,
|
|
|
- R.mipmap.icon_open_red_packet11,
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
private OnClickRedListener mOnClickRedListener;
|
|
|
|
|
@@ -70,72 +58,81 @@ public class RedDialog extends Dialog {
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
- mRedRl = findViewById(R.id.rl_red);
|
|
|
- mAvatarIv = findViewById(R.id.iv_avatar);
|
|
|
- mNameTv = findViewById(R.id.tv_name);
|
|
|
- mContentTv = findViewById(R.id.tv_msg);
|
|
|
+ mAvatarIv = findViewById(R.id.iv_receive_avatar);
|
|
|
+ mNameTv = findViewById(R.id.tv_nickname);
|
|
|
+ mContentTv = findViewById(R.id.tv_dialog_content);
|
|
|
+ mTypeTv = findViewById(R.id.tv_dialog_type);
|
|
|
mOpenIv = findViewById(R.id.iv_open);
|
|
|
- mCloseIv = findViewById(R.id.iv_close);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
- AvatarHelper.getInstance().displayAvatar(mRedDialogBean.getUserName(), mRedDialogBean.getUserId(),
|
|
|
+ AvatarHelper.getInstance().displayAvatar(mRedDialogBean.getUserName(), mRedDialogBean.getSendUserId(),
|
|
|
mAvatarIv, true);
|
|
|
mNameTv.setText(MyApplication.getContext().getString(R.string.red_someone, mRedDialogBean.getUserName()));
|
|
|
mContentTv.setText(mRedDialogBean.getWords());
|
|
|
+ if (mRedDialogBean.getType()== 4){
|
|
|
+ mTypeTv.setText("专属红包");
|
|
|
+ }else if (mRedDialogBean.getType()== 3){
|
|
|
+ mTypeTv.setText("口令红包");
|
|
|
+ }else {
|
|
|
+ mTypeTv.setText("");
|
|
|
+ }
|
|
|
|
|
|
- Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_red);
|
|
|
- mRedRl.setAnimation(animation);
|
|
|
}
|
|
|
|
|
|
private void initEvent() {
|
|
|
mOpenIv.setOnClickListener(v -> {
|
|
|
- if (mFrameAnimation != null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- startAnim();
|
|
|
- if (mOnClickRedListener != null) {
|
|
|
- mOnClickRedListener.clickRed();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- mCloseIv.setOnClickListener(v -> {
|
|
|
- stopAnim();
|
|
|
- dismiss();
|
|
|
+ applyRotation(mOpenIv, 0, 180);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void startAnim() {
|
|
|
- mFrameAnimation = new FrameAnimation(mOpenIv, mImgResIds, 125, true);
|
|
|
- mFrameAnimation.setAnimationListener(new FrameAnimation.AnimationListener() {
|
|
|
- @Override
|
|
|
- public void onAnimationStart() {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行翻转第一个视图动画
|
|
|
+ * @param start 起始角度
|
|
|
+ * @param end 结束角度
|
|
|
+ */
|
|
|
+ private void applyRotation(View aniView , float start, float end) {
|
|
|
+ // 得到中心点(以中心翻转)
|
|
|
+ final float centerX = aniView.getWidth() / 2.0f;
|
|
|
+ final float centerY = aniView.getHeight() / 2.0f;
|
|
|
+ // 根据参数创建一个新的三维动画,并且监听触发下一个动画
|
|
|
+ final Rotate3DAnimation rotation = new Rotate3DAnimation(start, end, centerX, centerY,310.0f, true);
|
|
|
+ rotation.setDuration(300);//设置动画持续时间
|
|
|
+ rotation.setInterpolator(new AccelerateInterpolator());//设置动画变化速度
|
|
|
+ rotation.setAnimationListener(new Animation.AnimationListener() {
|
|
|
@Override
|
|
|
- public void onAnimationEnd() {
|
|
|
+ public void onAnimationStart(Animation animation) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onAnimationRepeat() {
|
|
|
-
|
|
|
+ public void onAnimationEnd(Animation animation) {
|
|
|
+ dismiss();
|
|
|
+ if (mOnClickRedListener!=null){
|
|
|
+ mOnClickRedListener.clickRed();
|
|
|
+ }
|
|
|
+// Intent intent = new Intent(getContext(), RedEnvelopeActivity.class);
|
|
|
+// intent.putExtra(RedEnvelopeActivity.STATUS,RedEnvelopeActivity.STATUS_OPEN);
|
|
|
+// intent.putExtra(RedEnvelopeActivity.TYPE,RedEnvelopeActivity.TYPE_PRIVATE);
|
|
|
+// getContext().startActivity(intent);
|
|
|
+// dismiss();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onAnimationPause() {
|
|
|
- mOpenIv.setBackgroundResource(R.mipmap.icon_open_red_packet1);
|
|
|
+ public void onAnimationRepeat(Animation animation) {
|
|
|
+
|
|
|
}
|
|
|
- });
|
|
|
+ });//显示下一个视图
|
|
|
+ aniView.startAnimation(rotation);
|
|
|
}
|
|
|
|
|
|
- private void stopAnim() {
|
|
|
- if (mFrameAnimation != null) {
|
|
|
- mFrameAnimation.release();
|
|
|
- mFrameAnimation = null;
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public interface OnClickRedListener {
|
|
|
void clickRed();
|