Java Code Examples for android.support.v7.app.AlertDialog.getButton()

The following are Jave code examples for showing how to use getButton() of the android.support.v7.app.AlertDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: rebase-android   File: LoginFragment.java   Source Code and License Vote up 6 votes
@Override
public void onStart() {
    super.onStart();
    final AlertDialog dialog = (AlertDialog) getDialog();
    final Button loginButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onLogin(dialog);
        }
    });

    try {
        Login login = Stores.login(context).load();
        username.setText(login.username);
        password.setText(BlackBoxes.decrypt(context, login.password));
        onLogin(getDialog());
    } catch (NoSuchPreferenceFoundException e) {
        Log.e(TAG, "NoSuchPreferenceFoundException: login");
    }
}
 
Example 2
Project: add_to_evernote_note   File: CreateNoteDialogFragment.java   Source Code and License Vote up 6 votes
@Override
public void onStart() {
    super.onStart();

    AlertDialog alertDialog = (AlertDialog) getDialog();
    if (alertDialog != null) {
        Button button = alertDialog.getButton(Dialog.BUTTON_NEUTRAL);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                getActivity().startActivityForResult(intent, REQ_SELECT_IMAGE);
            }
        });
    }
}
 
Example 3
Project: BizareChat   File: MainActivity.java   Source Code and License Vote up 6 votes
@Override
public void confirmLogOut() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogStyle);
    builder.setTitle(R.string.are_you_sure);
    builder.setPositiveButton(R.string.sign_out, (dialog1, whichButton) -> {

    });

    builder.setNegativeButton(R.string.cancel, (dialog12, whichButton) -> dialog12.dismiss());
    AlertDialog dialog = builder.create();
    dialog.show();
    Button buttonSignOut = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    buttonSignOut.setOnClickListener(
            v -> presenter.logout()
    );
}
 
Example 4
Project: GitHub   File: EditItemDialog.java   Source Code and License Vote up 5 votes
private void updateOkButtonState(AlertDialog dialog, EditText editText) {
	Button buttonOK = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
	if (editText == null || (editText.getText().toString().trim()).length() == 0) {
		buttonOK.setEnabled(false);
		return;
	}
	if (mTitle != null && !mTitle.equalsIgnoreCase(editText.getText().toString().trim())) {
		buttonOK.setEnabled(true);
	} else {
		editText.setError(getActivity().getString(R.string.err_no_edit));
		buttonOK.setEnabled(false);
	}
}
 
Example 5
Project: MyCalendar   File: ColorPickerDialog.java   Source Code and License Vote up 5 votes
@Override
public void onStart() {
    super.onStart();
    AlertDialog dialog = (AlertDialog) getDialog();

    // http://stackoverflow.com/a/16972670/1048340
    //noinspection ConstantConditions
    dialog.getWindow()
            .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    // Do not dismiss the dialog when clicking the neutral button.
    Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
    if (neutralButton != null) {
        neutralButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rootView.removeAllViews();
                switch (dialogType) {
                    case TYPE_CUSTOM:
                        dialogType = TYPE_PRESETS;
                        ((Button) v).setText(
                                customButtonStringRes != 0 ? customButtonStringRes : R.string.cpv_custom);
                        rootView.addView(createPresetsView());
                        break;
                    case TYPE_PRESETS:
                        dialogType = TYPE_CUSTOM;
                        ((Button) v).setText(
                                presetsButtonStringRes != 0 ? presetsButtonStringRes : R.string.cpv_presets);
                        rootView.addView(createPickerView());
                }
            }
        });
    }
}
 
Example 6
Project: Android-DFU-App   File: UARTEditDialog.java   Source Code and License Vote up 5 votes
@NonNull
   @Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
	final LayoutInflater inflater = LayoutInflater.from(getActivity());

	// Read button configuration
	final Bundle args = getArguments();
	final int index = args.getInt(ARG_INDEX);
	final String command = args.getString(ARG_COMMAND);
	final int eol = args.getInt(ARG_EOL);
	final int iconIndex = args.getInt(ARG_ICON_INDEX);
	final boolean active = true; // change to active by default
	mActiveIcon = iconIndex;

	// Create view
	final View view = inflater.inflate(R.layout.feature_uart_dialog_edit, null);
	final EditText field = mField = (EditText) view.findViewById(R.id.field);
	final GridView grid = (GridView) view.findViewById(R.id.grid);
	final CheckBox checkBox = mActiveCheckBox = (CheckBox) view.findViewById(R.id.active);
	checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
			field.setEnabled(isChecked);
			grid.setEnabled(isChecked);
			if (mIconAdapter != null)
				mIconAdapter.notifyDataSetChanged();
		}
	});

	final RadioGroup eolGroup = mEOLGroup = (RadioGroup) view.findViewById(R.id.uart_eol);
	switch (Command.Eol.values()[eol]) {
		case CR_LF:
			eolGroup.check(R.id.uart_eol_cr_lf);
			break;
		case CR:
			eolGroup.check(R.id.uart_eol_cr);
			break;
		case LF:
		default:
			eolGroup.check(R.id.uart_eol_lf);
			break;
	}

	field.setText(command);
	field.setEnabled(active);
	checkBox.setChecked(active);
	grid.setOnItemClickListener(this);
	grid.setEnabled(active);
	grid.setAdapter(mIconAdapter = new IconAdapter());

	// As we want to have some validation we can't user the DialogInterface.OnClickListener as it's always dismissing the dialog.
	final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setCancelable(false).setTitle(R.string.uart_edit_title).setPositiveButton(R.string.ok, null)
			.setNegativeButton(R.string.cancel, null).setView(view).show();
	final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
	okButton.setOnClickListener(this);
	return dialog;
}
 
Example 7
Project: Android-DFU-App   File: UARTNewConfigurationDialogFragment.java   Source Code and License Vote up 5 votes
@Override
@NonNull
public Dialog onCreateDialog(final Bundle savedInstanceState) {
	final Context context = getActivity();

	final Bundle args = getArguments();
	final String oldName = args.getString(NAME);
	final boolean duplicate = args.getBoolean(DUPLICATE);
	final int titleResId = duplicate || oldName == null ? R.string.uart_new_configuration_title : R.string.uart_rename_configuration_title;

	final LayoutInflater inflater = LayoutInflater.from(getActivity());
	final View view = inflater.inflate(R.layout.feature_uart_dialog_new_configuration, null);
	final EditText editText = mEditText = (EditText) view.findViewById(R.id.name);
	editText.setText(args.getString(NAME));
	final View actionClear = view.findViewById(R.id.action_clear);
	actionClear.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(final View v) {
			editText.setText(null);
		}
	});

	final AlertDialog dialog = new AlertDialog.Builder(context).setTitle(titleResId).setView(view).setNegativeButton(R.string.cancel, null)
			.setPositiveButton(R.string.ok, null).setCancelable(false).show(); // this must be show() or the getButton() below will return null.

	final Button okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
	okButton.setOnClickListener(this);

	return dialog;
}
 
Example 8
Project: SubwayTooter   File: ColorPickerDialog.java   Source Code and License Vote up 5 votes
@Override public void onStart() {
  super.onStart();
  AlertDialog dialog = (AlertDialog) getDialog();

  // http://stackoverflow.com/a/16972670/1048340
  //noinspection ConstantConditions
  dialog.getWindow()
      .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
  dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

  // Do not dismiss the dialog when clicking the neutral button.
  Button neutralButton = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
  if (neutralButton != null) {
    neutralButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        rootView.removeAllViews();
        switch (dialogType) {
          case TYPE_CUSTOM:
            dialogType = TYPE_PRESETS;
            ((Button) v).setText(R.string.cpv_custom);
            rootView.addView(createPresetsView());
            break;
          case TYPE_PRESETS:
            dialogType = TYPE_CUSTOM;
            ((Button) v).setText(R.string.cpv_presets);
            rootView.addView(createPickerView());
        }
      }
    });
  }
}