Ejemplo n.º 1
0
  @Override
  public void onStart() {
    super.onStart();

    AlertDialog dialog = (AlertDialog) getDialog();

    dialog
        .getButton(AlertDialog.BUTTON_NEGATIVE)
        .setTextColor(ColorScheme.getPrimaryText(getActivity()));

    positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    positiveButton.setTextColor(ColorScheme.getAccent());
    positiveButton.setEnabled(false);

    editFileName.setOnFocusChangeListener(
        new View.OnFocusChangeListener() {

          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            fromUser = hasFocus;
          }
        });

    editScriptName.addTextChangedListener(scriptNameTextWatcher);
    editFileName.addTextChangedListener(fileNameTextWatcher);

    KeyboardUtils.showKeyboard(editScriptName, true);
  }
 @Override
 public void onStart() {
   super.onStart();
   final AlertDialog dialog = (AlertDialog) getDialog();
   // Override the onClickListeners, as the default implementation would dismiss the dialog
   if (dialog != null) {
     if (showImportAccountButton) {
       Button neutralButton = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
       neutralButton.setOnClickListener(
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               ImportAccountsDialogFragment.show(getActivity(), LoginDialogFragment.this);
             }
           });
       // Limit button width to not push positive button out of view
       neutralButton.setMaxEms(10);
     }
     Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
     positiveButton.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             attemptLogin();
           }
         });
   }
 }
Ejemplo n.º 3
0
 private void setButtonsListeners(AlertDialog dialog) {
   Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
   if (button != null) {
     button.setOnClickListener(new ClickHandler(0 | BUTTON_MASK));
   }
   button = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
   if (button != null) button.setOnClickListener(new ClickHandler(1 | BUTTON_MASK));
   button = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
   if (button != null) button.setOnClickListener(new ClickHandler(2 | BUTTON_MASK));
 }
Ejemplo n.º 4
0
 private void showDeleteDialog() {
   AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
   builder
       .setMessage(R.string.video_dialog_delete_title)
       .setPositiveButton(
           R.string.video_dialog_delete_positive_button,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
               String ids = albumId == 0 ? "-1, -2" : String.valueOf(albumId);
               VKRequest deleteRequest =
                   VKApi.video()
                       .removeFromAlbum(
                           VKParameters.from(
                               VKApiConst.VIDEO_ID, videoList.get(clickedPosition).id,
                               VKApiConst.OWNER_ID, videoList.get(clickedPosition).owner_id,
                               VKApiConst.ALBUM_IDS, ids));
               deleteRequest.executeWithListener(
                   new VKRequest.VKRequestListener() {
                     @Override
                     public void onComplete(VKResponse response) {
                       super.onComplete(response);
                       Toast.makeText(
                               getActivity(),
                               getString(
                                   R.string.video_dialog_delete_success_toast,
                                   videoList.get(clickedPosition).title),
                               Toast.LENGTH_SHORT)
                           .show();
                       videoList.remove(clickedPosition);
                       videoAdapter.notifyItemRemoved(clickedPosition);
                       videoAdapter.notifyItemRangeChanged(
                           clickedPosition, videoAdapter.getItemCount());
                     }
                   });
             }
           })
       .setNegativeButton(
           R.string.video_dialog_delete_negative_button,
           (dialog, id) -> {
             dialog.cancel();
           });
   AlertDialog alertDialog = builder.create();
   alertDialog.show();
   alertDialog
       .getButton(DialogInterface.BUTTON_NEGATIVE)
       .setTextColor(getResources().getColor(R.color.colorPrimary));
   alertDialog
       .getButton(DialogInterface.BUTTON_POSITIVE)
       .setTextColor(getResources().getColor(R.color.colorPrimary));
 }
Ejemplo n.º 5
0
 @Override
 public void onStart() {
   super.onStart();
   final AlertDialog d = (AlertDialog) getDialog();
   if (d != null) {
     Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
     positiveButton.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             name = nameEdit.getText().toString().trim();
             if (!helper.groupExists(name)) {
               helper.addEmptyCategory(name, color);
               PointEditor editor =
                   ((MapActivity) getActivity()).getContextMenu().getPointEditor(editorTag);
               if (editor != null) {
                 editor.setCategory(name);
               }
               d.dismiss();
             } else {
               AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
               b.setMessage(getString(R.string.favorite_category_dublicate_message));
               b.setNegativeButton(R.string.shared_string_ok, null);
               b.show();
             }
           }
         });
   }
 }
Ejemplo n.º 6
0
 @Override
 public void onStart() {
   super.onStart();
   AlertDialog dialog = (AlertDialog) getDialog();
   setButtonTint(dialog.getButton(Dialog.BUTTON_POSITIVE), colorBlue);
   setButtonTint(dialog.getButton(Dialog.BUTTON_NEGATIVE), colorText);
   initializeRecyclerView();
 }
  /** Disable the "Clear" button if none of the options are selected. Otherwise, enable it. */
  private void updateButtonState() {
    Button clearButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    if (clearButton == null) return;
    boolean isEnabled = !mSelectedOptions.isEmpty();
    clearButton.setEnabled(isEnabled);

    // Work around a bug in the app compat library where disabled buttons in alert dialogs
    // don't look disabled on pre-L devices. See: http://crbug.com/550784
    // TODO(newt): remove this workaround when the app compat library is fixed (b/26017217)
    clearButton.setTextColor(isEnabled ? 0xFF4285F4 : 0x335A5A5A);
  }
Ejemplo n.º 8
0
 @Override
 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
   if (mDialog != null) {
     Button button = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
     if (button != null) {
       button.performClick();
     }
     return true;
   } else {
     return false;
   }
 }
 private void updateTextCount(DialogInterface dialog, CharSequence s, ParcelableStatus status) {
   if (!(dialog instanceof AlertDialog)) return;
   final AlertDialog alertDialog = (AlertDialog) dialog;
   final Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
   if (positiveButton == null) return;
   positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet);
   final String statusLink =
       LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id).toString();
   final StatusTextCountView textCountView =
       (StatusTextCountView) alertDialog.findViewById(R.id.comment_text_count);
   textCountView.setTextCount(mValidator.getTweetLength(s + " " + statusLink));
 }
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
      // Associate the "done" button on the soft keyboard with the okay button in the view
      if (EditorInfo.IME_ACTION_DONE == actionId) {
        AlertDialog dialog = ((AlertDialog) getDialog());
        Button bt = dialog.getButton(AlertDialog.BUTTON_POSITIVE);

        bt.performClick();
        return true;
      }
      return false;
    }
 @Override
 public void onStart() {
   super.onStart();
   final AlertDialog dialog = (AlertDialog) getDialog();
   if (dialog != null) {
     // We don't want to close the dialog when the user click on OK button, only when the given
     // channelId is valid.
     Button positiveButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
     positiveButton.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             final String channelId = editChannelId.getText().toString();
             final String apiKey = editApiKey.getText().toString();
             if (isFieldValid(channelId) && isFieldValid(apiKey)) {
               if (configSetListener != null) {
                 configSetListener.onConfigSet(channelId, apiKey);
                 dialog.dismiss();
               }
             } else {
               if (!isFieldValid(channelId)) {
                 editChannelId.setError(getString(R.string.empty_field));
               }
               if (!isFieldValid(apiKey)) {
                 editApiKey.setError(getString(R.string.empty_field));
               }
             }
           }
         });
     Button negativeButton = dialog.getButton(Dialog.BUTTON_NEGATIVE);
     negativeButton.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             getActivity().finish();
           }
         });
   }
 }
 @Override
 public void onStart() {
   super.onStart();
   final AlertDialog d = (AlertDialog) getDialog();
   if (d != null) {
     Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE);
     positiveButton.setOnClickListener(
         new View.OnClickListener() {
           @Override
           public void onClick(View v) {
             if (validateInputs()) d.dismiss();
           }
         });
   }
 }
  @Override
  public void onStart() {
    super.onStart();

    AlertDialog dlg = (AlertDialog) getDialog();
    dlg.getButton(DialogInterface.BUTTON_NEGATIVE)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                mCancelled = true;
                dismiss();
              }
            });
  }
Ejemplo n.º 14
0
  private void askPasswordDialog() {
    AlertDialog.Builder passwordDialogBuilder =
        new AlertDialog.Builder(SettingsActivity.this, getDialogStyle());
    final EditText editTextPassword =
        securityObj.getInsertPasswordDialog(SettingsActivity.this, passwordDialogBuilder);
    passwordDialogBuilder.setNegativeButton(getString(R.string.cancel), null);

    passwordDialogBuilder.setPositiveButton(
        getString(R.string.ok_action),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            // This should br empty it will be overwrite later
            // to avoid dismiss of the dialog on wrong password
          }
        });

    final AlertDialog passwordDialog = passwordDialogBuilder.create();
    passwordDialog.show();

    passwordDialog
        .getButton(AlertDialog.BUTTON_POSITIVE)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (securityObj.checkPassword(editTextPassword.getText().toString())) {
                  passwordDialog.dismiss();
                  startActivity(new Intent(getApplicationContext(), SecurityActivity.class));
                } else {
                  Toast.makeText(
                          getApplicationContext(), R.string.wrong_password, Toast.LENGTH_SHORT)
                      .show();
                  editTextPassword.getText().clear();
                  editTextPassword.requestFocus();
                }
              }
            });
  }
Ejemplo n.º 15
0
  @Override
  public void onStart() {
    super.onStart();
    final AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
      Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
      positiveButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              boolean chkForm = true;

              if (operation.getAmount() == 0) { // Проверка ввода суммы
                holder.amount.setError(getString(R.string.errMsgAmount));
                chkForm = false;
              }

              if (mAdapter.isEmpty()) {
                holder.PAN.setError("");
                chkForm = false;
              }

              // Dismiss once everything is OK.
              if (chkForm) {

                operation.setCardId(mAdapter.getSelectedCardId());
                operation.setPan(mAdapter.getSelectedCardPAN());
                operation.setState(1);
                d.dismiss();

                Sign newFragment = Sign.newInstance(operation);
                MainActivity.switchFragment(newFragment, "SIGN", true);
              }
            }
          });
    }
  }
  @SmallTest
  @Feature({"Sync"})
  public void testPassphraseCreation() throws Exception {
    setUpTestAccountAndSignIn();
    SyncTestUtil.waitForSyncActive();
    final SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            fragment.onPassphraseTypeSelected(PassphraseType.CUSTOM_PASSPHRASE);
          }
        });
    getInstrumentation().waitForIdleSync();
    PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment();
    AlertDialog dialog = (AlertDialog) pcdf.getDialog();
    Button okButton = dialog.getButton(Dialog.BUTTON_POSITIVE);
    EditText enterPassphrase = (EditText) dialog.findViewById(R.id.passphrase);
    EditText confirmPassphrase = (EditText) dialog.findViewById(R.id.confirm_passphrase);

    // Error if you try to submit empty passphrase.
    assertNull(confirmPassphrase.getError());
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNotNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit with only the first box filled.
    clearError(confirmPassphrase);
    setText(enterPassphrase, "foo");
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // Remove first box should only show empty error message
    setText(enterPassphrase, "");
    clickButton(okButton);
    assertNotNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit with only the second box filled.
    clearError(confirmPassphrase);
    setText(confirmPassphrase, "foo");
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // No error if text doesn't match without button press.
    setText(enterPassphrase, "foo");
    clearError(confirmPassphrase);
    setText(confirmPassphrase, "bar");
    assertNull(enterPassphrase.getError());
    assertNull(confirmPassphrase.getError());

    // Error if you try to submit unmatching text.
    clearError(confirmPassphrase);
    clickButton(okButton);
    assertTrue(pcdf.isResumed());
    assertNull(enterPassphrase.getError());
    assertNotNull(confirmPassphrase.getError());

    // Success if text matches.
    setText(confirmPassphrase, "foo");
    clickButton(okButton);
    assertFalse(pcdf.isResumed());
  }
Ejemplo n.º 17
0
  @SuppressLint({"InlinedApi", "NewApi"})
  public void launchChangeIcon() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.prop_change_icon);

    changeIconLayout =
        (ScrollView)
            View.inflate(
                new ContextThemeWrapper(this, R.style.Theme_AppCompat_Dialog),
                R.layout.change_icon,
                null);

    iconFile = (EditText) changeIconLayout.findViewById(R.id.change_icon_file);
    final ImageButton iconFileSelect =
        (ImageButton) changeIconLayout.findViewById(R.id.change_icon_file_select);

    // Scale format radio group
    final RadioGroup scaleFormat = (RadioGroup) changeIconLayout.findViewById(R.id.format_scale);

    for (int i = 0; i < scaleFormat.getChildCount(); i++) {
      ((RadioButton) scaleFormat.getChildAt(i)).setEnabled(false);
    }

    scaleFormat.setOnCheckedChangeListener(
        new RadioGroup.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            rebuildIconChange();
          }
        });

    // Alt text for the big icon
    final TextView bigIconAltText =
        (TextView) changeIconLayout.findViewById(R.id.big_icon_alt_text);

    bigIconAltText.setAllCaps(true);

    builder.setView(changeIconLayout);

    builder.setNegativeButton(
        R.string.cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {}
        });

    builder.setPositiveButton(
        R.string.ok,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            Bitmap bitmap = BitmapFactory.decodeFile(iconFile.getText().toString());
            int minDim = Math.min(bitmap.getWidth(), bitmap.getHeight());

            int[] dims = {36, 48, 72, 96, 144, 192};

            for (int dim : dims) {
              File out = new File(getGlobalState().getSketchLocation(), "icon-" + dim + ".png");

              // Don't scale the image up
              if (dim <= minDim) {
                FileOutputStream stream = null;

                try {
                  stream = new FileOutputStream(out);

                  // Replace the old icon
                  formatIcon(bitmap, dim, getScaleFormat(scaleFormat))
                      .compress(Bitmap.CompressFormat.PNG, 100, stream);
                } catch (FileNotFoundException e) {
                  e.printStackTrace();
                  // ...
                } finally {
                  // Always close the stream...
                  if (stream != null) {
                    try {
                      stream.close();
                    } catch (IOException e) {
                      e.printStackTrace();
                      // Whatever at this point...
                    }
                  }
                }
              } else {
                // Get rid of the old icon...
                out.delete();
              }
            }
          }
        });

    AlertDialog dialog = builder.create();
    dialog.show();

    changeIconOK = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    changeIconOK.setEnabled(false);

    iconFileSelect.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent intent =
                Intent.createChooser(
                    FileUtils.createGetContentIntent(),
                    getResources().getString(R.string.select_file));
            startActivityForResult(intent, REQUEST_ICON_FILE);
          }
        });

    iconFile.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void afterTextChanged(Editable arg0) {
            rebuildIconChange();
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });

    rebuildIconChange();
  }