|
@@ -0,0 +1,145 @@
|
|
|
+package com.wdkl.app.ncs.callingdoor.helper;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.os.CountDownTimer;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.Window;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.GridView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.wdkl.app.ncs.callingdoor.R;
|
|
|
+import com.wdkl.app.ncs.callingdoor.adapter.NumAdapter;
|
|
|
+
|
|
|
+
|
|
|
+public class PasswordDialogHelper {
|
|
|
+
|
|
|
+ private static AlertDialog dialog;
|
|
|
+ private static String pwd = "";
|
|
|
+
|
|
|
+ public static void showPasswordDialog(final Activity activity, final MyListener listener) {
|
|
|
+ pwd = "";
|
|
|
+ View contentView = LayoutInflater.from(activity).inflate(R.layout.password_dialog_lay, null);
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
|
+ builder.setView(contentView);
|
|
|
+
|
|
|
+ final String[] numbers = {"1","2","3","4","5","6","7","8","9"};
|
|
|
+ final TextView password = contentView.findViewById(R.id.tv_psw_view);
|
|
|
+ TextView countdown = contentView.findViewById(R.id.tv_count_down_time);
|
|
|
+ GridView gridView = contentView.findViewById(R.id.grid_psw);
|
|
|
+ NumAdapter adapter = new NumAdapter(numbers, activity);
|
|
|
+ gridView.setAdapter(adapter);
|
|
|
+ gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ if (pwd.length() <= 2) {
|
|
|
+ pwd = pwd + numbers[position];
|
|
|
+ password.setText(pwd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ final CountDownTimer timer = new CountDownTimer(15000, 1000) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTick(long millisUntilFinished) {
|
|
|
+ countdown.setText("" + millisUntilFinished/1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFinish() {
|
|
|
+ dismissCallDialog();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.start();
|
|
|
+
|
|
|
+ TextView delete = contentView.findViewById(R.id.btn_delete);
|
|
|
+ TextView cancel = contentView.findViewById(R.id.btn_cancel);
|
|
|
+ TextView confirm = contentView.findViewById(R.id.btn_confirm);
|
|
|
+ delete.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ Log.d("pwd", "delete password len: " + pwd.length() + "--" + pwd);
|
|
|
+ if (pwd.length() > 1) {
|
|
|
+ pwd = pwd.substring(0, pwd.length()-1);
|
|
|
+ password.setText(pwd);
|
|
|
+ } else {
|
|
|
+ pwd = "";
|
|
|
+ password.setText(pwd);
|
|
|
+ password.setHint(R.string.input_password);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ cancel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ timer.cancel();
|
|
|
+ dismissCallDialog();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ confirm.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if ("888".equals(pwd)) {
|
|
|
+ timer.cancel();
|
|
|
+ if (listener != null) {
|
|
|
+ listener.onConfirm();
|
|
|
+ }
|
|
|
+ dismissCallDialog();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(activity, R.string.invalid_password, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ dialog = builder.create();
|
|
|
+ dialog.setCanceledOnTouchOutside(false);
|
|
|
+ dialog.setCancelable(false);
|
|
|
+ dialog.show();
|
|
|
+
|
|
|
+ //设置dialog宽高及位置
|
|
|
+ try {
|
|
|
+ Window window = dialog.getWindow();
|
|
|
+ window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
|
|
|
+ WindowManager.LayoutParams lp = window.getAttributes();
|
|
|
+ lp.width = 400;
|
|
|
+ lp.height = 480;
|
|
|
+ lp.gravity = Gravity.CENTER;
|
|
|
+ window.setAttributes(lp);
|
|
|
+
|
|
|
+ window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
+ | View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
|
+ window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void dismissCallDialog() {
|
|
|
+ pwd = "";
|
|
|
+ if (dialog != null && dialog.isShowing()) {
|
|
|
+ dialog.dismiss();
|
|
|
+ dialog = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public interface MyListener{
|
|
|
+ void onConfirm();
|
|
|
+ }
|
|
|
+}
|