package com.tejia.lijin.app.util;
|
|
import android.app.AlertDialog;
|
import android.content.Context;
|
import android.os.CountDownTimer;
|
import android.view.View;
|
import android.view.animation.Animation;
|
import android.view.animation.AnimationSet;
|
import android.view.animation.RotateAnimation;
|
import android.view.animation.ScaleAnimation;
|
import android.widget.TextView;
|
|
import com.tejia.lijin.app.R;
|
|
/**
|
* Toast Dialog 弹窗提醒
|
*/
|
public class Toast_Dialog {
|
private CountDownTimer timer;//计时器
|
private AlertDialog.Builder alterDiaglog;
|
private View view;
|
private AlertDialog dialog;
|
|
public Toast_Dialog(Context context) {
|
alterDiaglog = new AlertDialog.Builder(context, R.style.dialog_activationinvitecode);
|
view = View.inflate(context, R.layout.dialog_activationinvite1, null);
|
alterDiaglog.setView(view);//加载进去布局视图
|
dialog = alterDiaglog.create();
|
}
|
|
/**
|
* @param str 提示语
|
* @param boo 是否 点击dialog外部消失 true不消失 false消失
|
*/
|
public void MyDialog(String str, boolean boo) {
|
if (dialog != null) {
|
//显示
|
dialog.show();
|
((TextView) dialog.findViewById(R.id.dialog_activationinvitetxt)).setText(str);
|
if (str != null && boo) {
|
dialog.setCanceledOnTouchOutside(false);//点击不消失
|
dialogShouw(dialog, true);//计时器 关闭 dialog
|
} else { // 失败提示
|
dialogShouw(dialog, false);//计时器 关闭 dialog
|
// startShakeByView(view, 0.5f, 1f, 1.7f, 8L);//抖动动画
|
}
|
}
|
}
|
|
|
/**
|
* 倒计时
|
*
|
* @param dialog
|
* @param b 是否触摸外面关闭dialog
|
*/
|
private void dialogShouw(final AlertDialog dialog, final boolean b) {
|
if (timer != null) {
|
timer.cancel();
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog.cancel();
|
}
|
}
|
if (dialog != null) {
|
//显示
|
if (!dialog.isShowing()) {
|
dialog.show();
|
}
|
timer = new CountDownTimer(1015, 1000) {
|
public void onTick(long millisUntilFinished) {
|
}
|
|
public void onFinish() {
|
if (b) {
|
dialog.setCanceledOnTouchOutside(true);
|
}
|
dialog_dismiss();//关闭
|
}
|
}.start();
|
}
|
}
|
|
|
/**
|
* 抖动效果的实现
|
*
|
* @param view
|
* @param scaleSmall
|
* @param scaleLarge
|
* @param shakeDegrees
|
* @param duration
|
*/
|
private void startShakeByView(View view, float scaleSmall, float scaleLarge, float shakeDegrees, long duration) {
|
//由小变大
|
Animation scaleAnim = new ScaleAnimation(scaleSmall, scaleLarge, scaleSmall, scaleLarge);
|
//从左向右
|
Animation rotateAnim = new RotateAnimation(-shakeDegrees, shakeDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
|
scaleAnim.setDuration(duration);
|
rotateAnim.setDuration(duration / 10);
|
rotateAnim.setRepeatMode(Animation.REVERSE);
|
rotateAnim.setRepeatCount(10);
|
|
AnimationSet smallAnimationSet = new AnimationSet(false);
|
smallAnimationSet.addAnimation(scaleAnim);
|
smallAnimationSet.addAnimation(rotateAnim);
|
|
view.startAnimation(smallAnimationSet);
|
}
|
|
/**
|
* 关闭dialog
|
*/
|
public void dialog_dismiss() {
|
if (dialog != null && dialog.isShowing()) {
|
dialog.dismiss();
|
dialog.cancel();
|
}
|
if (timer != null) {
|
timer.cancel();
|
}
|
/// 如果报错注释掉
|
// timer = null;//计时器
|
// dialog = null;
|
// alterDiaglog = null;
|
// view = null;
|
}
|
}
|