|
@@ -0,0 +1,99 @@
|
|
|
|
+package com.wdkl.app.ncs.callingdoor.helper;
|
|
|
|
+
|
|
|
|
+import android.app.Activity;
|
|
|
|
+import android.app.AlertDialog;
|
|
|
|
+import android.content.Intent;
|
|
|
|
+import android.os.CountDownTimer;
|
|
|
|
+import android.view.Gravity;
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
+import android.view.View;
|
|
|
|
+import android.view.Window;
|
|
|
|
+import android.view.WindowManager;
|
|
|
|
+import android.widget.Button;
|
|
|
|
+
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.R;
|
|
|
|
+import com.wdkl.app.ncs.callingdoor.activity.AppUpdateActivity;
|
|
|
|
+import com.wdkl.ncs.android.middleware.common.Constant;
|
|
|
|
+
|
|
|
|
+public class UpdateTipsDialogHelper {
|
|
|
|
+
|
|
|
|
+ private static AlertDialog dialog;
|
|
|
|
+
|
|
|
|
+ public static void showDialog(Activity activity) {
|
|
|
|
+ if (dialog != null && dialog.isShowing()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ View contentView = LayoutInflater.from(activity).inflate(R.layout.update_tips_dialog, null);
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
|
+ builder.setView(contentView);
|
|
|
|
+ Button buttonCancel = contentView.findViewById(R.id.cancel_button);
|
|
|
|
+ Button buttonConfirm = contentView.findViewById(R.id.confirm_button);
|
|
|
|
+ final CountDownTimer timer = new CountDownTimer(15000, 1000) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onTick(long millisUntilFinished) {
|
|
|
|
+ buttonConfirm.setText("确定(" + millisUntilFinished/1000 + "s)");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFinish() {
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
+ intent.setClass(activity, AppUpdateActivity.class);
|
|
|
|
+ activity.startActivity(intent);
|
|
|
|
+
|
|
|
|
+ if (dialog != null) {
|
|
|
|
+ dialog.dismiss();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ timer.start();
|
|
|
|
+
|
|
|
|
+ buttonCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ Constant.APP_UPDATING = false;
|
|
|
|
+ if (timer != null) {
|
|
|
|
+ timer.cancel();
|
|
|
|
+ }
|
|
|
|
+ if (dialog != null) {
|
|
|
|
+ dialog.dismiss();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ buttonConfirm.setOnClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ if (timer != null) {
|
|
|
|
+ timer.cancel();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
+ intent.setClass(activity, AppUpdateActivity.class);
|
|
|
|
+ activity.startActivity(intent);
|
|
|
|
+
|
|
|
|
+ if (dialog != null) {
|
|
|
|
+ dialog.dismiss();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ dialog = builder.create();
|
|
|
|
+ dialog.setCanceledOnTouchOutside(false);
|
|
|
|
+ dialog.setCancelable(false);
|
|
|
|
+ dialog.show();
|
|
|
|
+
|
|
|
|
+ //设置dialog宽高及位置
|
|
|
|
+ try {
|
|
|
|
+ Window window = dialog.getWindow();
|
|
|
|
+ WindowManager.LayoutParams lp = window.getAttributes();
|
|
|
|
+ lp.width = 600;
|
|
|
|
+ lp.height = 320;
|
|
|
|
+ lp.gravity = Gravity.CENTER;
|
|
|
|
+ window.setAttributes(lp);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|