コード例 #1
0
  public void show_dialogAlterarSenha() {

    dialog =
        DialogPlus.newDialog(context)
            .setOnCancelListener(
                new OnCancelListener() {
                  @Override
                  public void onCancel(DialogPlus dialogPlus) {}
                })
            .setContentHolder(new ViewHolder(R.layout.dialog_alterar_senha))
            .setHeader(R.layout.dialog_header)
            .setFooter(R.layout.dialog_login_footer)
            .setExpanded(
                false) // This will enable the expand feature, (similar to android L share dialog)
            .setOnClickListener(onClickListenerAlterarPinCode)
            .setGravity(Gravity.CENTER)
            .setOnDismissListener(
                new OnDismissListener() {
                  @Override
                  public void onDismiss(DialogPlus dialogPlus) {}
                })
            .setCancelable(false)
            .create();
    View headerHolder = dialog.getHeaderView();

    ((TextView) headerHolder.findViewById(R.id.tvDialogHeaderTitle)).setText("Alterar Codigo PIN");

    View footerHolder = dialog.getFooterView();

    ((Button) footerHolder.findViewById(R.id.btn_cadastrar)).setText("Cancelar");
    ((Button) footerHolder.findViewById(R.id.btn_login)).setText("Alterar");

    View holder = dialog.getHolderView();

    EditText edPinNovo = (EditText) holder.findViewById(R.id.edPinNovo);

    edPinNovo.setOnKeyListener(
        new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            vibrator.vibrate(200);
            return false;
          }
        });
    EditText edPinAtual = (EditText) holder.findViewById(R.id.edPinAtual);

    edPinAtual.setOnKeyListener(
        new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            vibrator.vibrate(200);
            return false;
          }
        });
    EditText edPinRedigitar = (EditText) holder.findViewById(R.id.edPinRedigitar);

    edPinRedigitar.setOnKeyListener(
        new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            vibrator.vibrate(200);
            return false;
          }
        });
    dialog.show();
  }
コード例 #2
0
        @Override
        public void onClick(DialogPlus dialogPlus, View view) {
          int id = view.getId();

          switch (id) {
            case R.id.btn_login:
              boolean err = false;
              View holder = dialogPlus.getHolderView();

              EditText edPinNovo = (EditText) holder.findViewById(R.id.edPinNovo);
              EditText edPinAtual = (EditText) holder.findViewById(R.id.edPinAtual);
              EditText edPinRedigitar = (EditText) holder.findViewById(R.id.edPinRedigitar);

              String pinNovo = edPinNovo.getText().toString();
              String pinAtual = edPinAtual.getText().toString();
              String pinRedigitar = edPinRedigitar.getText().toString();

              if (pinNovo.equals("") || pinNovo.length() < 4) {
                vibrator.vibrate(200);
                YoYo.with(Techniques.Shake).duration(500).playOn(edPinNovo);
                err = true;
              }
              if (pinAtual.equals("") || pinNovo.length() < 4) {
                vibrator.vibrate(200);
                YoYo.with(Techniques.Shake).duration(500).playOn(edPinAtual);
                err = true;
              }

              if (!pinAtual.equals(AndroidSystemUtil.getPinCode(context)) || pinNovo.length() < 4) {
                YoYo.with(Techniques.Shake).duration(500).playOn(edPinRedigitar);

                Toast.makeText(context, "Codigo PIN Incorreto.", Toast.LENGTH_LONG).show();

                err = true;
              } else if (!pinRedigitar.equals(pinNovo)) {
                YoYo.with(Techniques.Shake).duration(500).playOn(edPinRedigitar);

                Toast.makeText(context, "Codigo PIN verificador incorreto.", Toast.LENGTH_LONG)
                    .show();

                err = true;
              }

              if (!err) {

                HttpPost httpPost = new HttpPost(context);

                JSONObject changePwJson = new JSONObject();

                try {
                  changePwJson.put("regid", AndroidSystemUtil.getRegistrationId(context));
                  changePwJson.put("pwOld", pinAtual);
                  changePwJson.put("pwNew", pinNovo);

                } catch (JSONException e) {
                  e.printStackTrace();
                }

                httpPost.execute(
                    AndroidSystemUtil.getHostAdress(context) + "/changeUserPw",
                    changePwJson.toString());
                dialogPlus.dismiss();
              }

              break;

            case R.id.btn_cadastrar:
              dialogPlus.dismiss();
              break;
          }
        }