use of android.support.v7.app.AlertDialog in project DogeTracker_Android by avrland.
the class wallet_view method removeWalletButtonHandler.
private void removeWalletButtonHandler() {
// Set button for deleting wallet (just from viewer, not really lol)
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(wallet_view.this);
builder.setCancelable(true);
builder.setTitle(getString(R.string.areYouSureText));
builder.setMessage(getString(R.string.removeWalletText) + viewedWalletName);
builder.setPositiveButton(getString(R.string.confirmText), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
walletMemoryObject.removeWallet(viewedWalletId);
Intent i = new Intent(getApplicationContext(), wallet_list.class);
startActivity(i);
finish();
} catch (JSONException e) {
}
}
});
builder.setNegativeButton(getString(R.string.cancelText), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
use of android.support.v7.app.AlertDialog in project Signal-Android by signalapp.
the class RegistrationLockDialog method showRegistrationLockPrompt.
@SuppressLint("StaticFieldLeak")
public static void showRegistrationLockPrompt(@NonNull Context context, @NonNull SwitchPreferenceCompat preference, @NonNull SignalServiceAccountManager accountManager) {
AlertDialog dialog = new AlertDialog.Builder(context).setTitle(R.string.RegistrationLockDialog_registration_lock).setView(R.layout.registration_lock_dialog_view).setPositiveButton(R.string.RegistrationLockDialog_enable, null).setNegativeButton(android.R.string.cancel, null).create();
dialog.setOnShowListener(created -> {
Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(v -> {
EditText pin = dialog.findViewById(R.id.pin);
EditText repeat = dialog.findViewById(R.id.repeat);
ProgressBar progressBar = dialog.findViewById(R.id.progress);
assert pin != null;
assert repeat != null;
assert progressBar != null;
String pinValue = pin.getText().toString().replace(" ", "");
String repeatValue = repeat.getText().toString().replace(" ", "");
if (pinValue.length() < 4) {
Toast.makeText(context, R.string.RegistrationLockDialog_the_registration_lock_pin_must_be_at_least_four_digits, Toast.LENGTH_LONG).show();
return;
}
if (!pinValue.equals(repeatValue)) {
Toast.makeText(context, R.string.RegistrationLockDialog_the_two_pins_you_entered_do_not_match, Toast.LENGTH_LONG).show();
return;
}
new AsyncTask<Void, Void, Boolean>() {
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
button.setEnabled(false);
}
@Override
protected Boolean doInBackground(Void... voids) {
try {
accountManager.setPin(Optional.of(pinValue));
TextSecurePreferences.setRegistrationLockPin(context, pinValue);
TextSecurePreferences.setRegistrationLockLastReminderTime(context, System.currentTimeMillis());
TextSecurePreferences.setRegistrationLockNextReminderInterval(context, RegistrationLockReminders.INITIAL_INTERVAL);
return true;
} catch (IOException e) {
Log.w(TAG, e);
return false;
}
}
@Override
protected void onPostExecute(@NonNull Boolean result) {
button.setEnabled(true);
progressBar.setVisibility(View.GONE);
if (result) {
preference.setChecked(true);
created.dismiss();
} else {
Toast.makeText(context, R.string.RegistrationLockDialog_error_connecting_to_the_service, Toast.LENGTH_LONG).show();
}
}
}.execute();
});
});
dialog.show();
}
use of android.support.v7.app.AlertDialog in project android-client by GenesisVision.
the class BaseFragment method showRationaleDialog.
protected void showRationaleDialog(String message, final PermissionRequest request) {
AlertDialog rationaleDialog = new AlertDialog.Builder(getContext()).setPositiveButton(getString(R.string.allow), (dialog, which) -> request.proceed()).setNegativeButton(getString(R.string.deny), (dialog, which) -> request.cancel()).setCancelable(false).setMessage(message).show();
rationaleDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
rationaleDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
}
use of android.support.v7.app.AlertDialog in project xDrip by NightscoutFoundation.
the class ProfileEditor method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
mContext = this;
doMgdl = (Pref.getString("units", "mgdl").equals("mgdl"));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_editor);
undoBtn = (Button) findViewById(R.id.profileUndoBtn);
saveBtn = (Button) findViewById(R.id.profileSaveBtn);
adjustallSeekBar = (SeekBar) findViewById(R.id.profileAdjustAllseekBar);
adjustPercentage = (TextView) findViewById(R.id.profileAdjustAllPercentage);
profileItemList.addAll(loadData(true));
// Toolbar toolbar = (Toolbar) findViewById(R.id.profile_toolbar);
// setSupportActionBar(toolbar);
JoH.fixActionBar(this);
// TODO add menu in xml
adjustallSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
adjustmentFactor = 1 + ((progress - 25) * 0.02);
adjustPercentage.setText(JoH.qs(adjustmentFactor * 100, 0) + "%");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
profileItemList.clear();
// we must preserve the existing object reference used by the adapter
profileItemList.addAll(loadData(false));
// allow autosliding scales downwards
mAdapter.resetTopMax();
// does temporary save
forceRefresh(true);
}
});
recyclerView = (RecyclerView) findViewById(R.id.profile_recycler_view);
mAdapter = new ProfileAdapter(this, profileItemList, doMgdl);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
if (profileItemList.size() == 0) {
profileItemList.add(new ProfileItem(0, END_OF_DAY, JoH.tolerantParseDouble(Pref.getString("profile_carb_ratio_default", "10")), JoH.tolerantParseDouble(Pref.getString("profile_insulin_sensitivity_default", "0.1"))));
}
updateAdjustmentFactor(1.0);
shuffleFit();
mAdapter.registerAdapterDataObserver(// handle incoming messages from the adapater
new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
// Log.d(TAG, "onChanged");
}
@Override
public void onItemRangeChanged(final int positionStart, int itemCount, Object payload) {
super.onItemRangeChanged(positionStart, itemCount, payload);
Log.d(TAG, "onItemRangeChanged: pos:" + positionStart + " cnt:" + itemCount + " p: " + payload.toString());
if (payload.toString().equals("time start updated")) {
if (positionStart > 0) {
// did we encroach on previous item end or open up a gap??
if ((profileItemList.get(positionStart - 1).end_min != profileItemList.get(positionStart).start_min - 1)) {
profileItemList.get(positionStart - 1).end_min = profileItemList.get(positionStart).start_min - 1;
}
} else {
// if setting the first start time also mirror this to the last end time
//
profileItemList.get(profileItemList.size() - 1).end_min = profileItemList.get(positionStart).start_min - 1;
}
forceRefresh();
} else if (payload.toString().equals("time end updated")) {
// don't apply gap calcualtion to last item when end changes
if (positionStart < profileItemList.size() - 1) {
// for all blocks other than the final one
if ((profileItemList.get(positionStart + 1).start_min != profileItemList.get(positionStart).end_min + 1)) {
profileItemList.get(positionStart + 1).start_min = profileItemList.get(positionStart).end_min + 1;
}
} else {
// if setting the last end time also mirror this to the first start time
//
profileItemList.get(0).start_min = profileItemList.get(positionStart).end_min + 1;
}
forceRefresh();
// split or delete
} else if (payload.toString().equals("long-split")) {
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
final int screen_width = dm.widthPixels;
final int screen_height = dm.heightPixels;
boolean small_screen = false;
// smaller screens or lower version don't seem to play well with long dialog button names
if ((screen_width < 720) || (screen_height < 720) || ((Build.VERSION.SDK_INT < Build.VERSION_CODES.M)))
small_screen = true;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setMessage(R.string.split_delete_or_do_nothing);
alertDialogBuilder.setPositiveButton(small_screen ? getString(R.string.split) : getString(R.string.split_this_block_in_two), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
ProfileItem old_item = profileItemList.get(positionStart);
ProfileItem new_item;
if (old_item.start_min < old_item.end_min) {
// no wrapping time
new_item = new ProfileItem(old_item.end_min - (old_item.end_min - old_item.start_min) / 2, old_item.end_min, old_item.carb_ratio, old_item.sensitivity);
} else {
// wraps around
new_item = new ProfileItem(old_item.end_min - ((old_item.end_min - MINS_PER_DAY) - old_item.start_min) / 2, old_item.end_min, old_item.carb_ratio, old_item.sensitivity);
}
old_item.end_min = new_item.start_min - 1;
profileItemList.add(positionStart + 1, new_item);
forceRefresh();
}
});
if (profileItemList.size() > 1) {
alertDialogBuilder.setNeutralButton(small_screen ? getString(R.string.delete) : getString(R.string.delete_this_time_block), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
profileItemList.remove(positionStart);
forceRefresh();
}
});
}
alertDialogBuilder.setNegativeButton(small_screen ? getString(R.string.cancel) : getString(R.string.cancel_do_nothing), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
} else {
// for other non special changes
forceRefresh();
}
}
});
DefaultItemAnimator animator = new DefaultItemAnimator() {
@Override
public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder) {
return true;
}
};
recyclerView.setItemAnimator(animator);
recyclerView.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
showcasemenu(SHOWCASE_PROFILE_SPLIT);
}
use of android.support.v7.app.AlertDialog in project KeePassDX by Kunzisoft.
the class AssignMasterKeyDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
rootView = inflater.inflate(R.layout.set_password, null);
builder.setView(rootView).setTitle(R.string.assign_master_key).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
passwordCheckBox = (CompoundButton) rootView.findViewById(R.id.password_checkbox);
passView = (TextView) rootView.findViewById(R.id.pass_password);
passView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
passwordCheckBox.setChecked(true);
}
});
passConfView = (TextView) rootView.findViewById(R.id.pass_conf_password);
keyfileCheckBox = (CompoundButton) rootView.findViewById(R.id.keyfile_checkox);
keyfileView = (TextView) rootView.findViewById(R.id.pass_keyfile);
keyfileView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
keyfileCheckBox.setChecked(true);
}
});
keyFileHelper = new KeyFileHelper(this);
rootView.findViewById(R.id.browse_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
}
});
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
masterPassword = "";
mKeyfile = null;
boolean error = verifyPassword() || verifyFile();
if (!passwordCheckBox.isChecked() && !keyfileCheckBox.isChecked()) {
error = true;
showNoKeyConfirmationDialog();
}
if (!error) {
mListener.onAssignKeyDialogPositiveClick(passwordCheckBox.isChecked(), masterPassword, keyfileCheckBox.isChecked(), mKeyfile);
dismiss();
}
}
});
Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
mListener.onAssignKeyDialogNegativeClick(passwordCheckBox.isChecked(), masterPassword, keyfileCheckBox.isChecked(), mKeyfile);
dismiss();
}
});
}
});
return dialog;
}
Aggregations