use of android.support.v7.app.AlertDialog in project collect by opendatakit.
the class FormEntryActivity method createQuitDialog.
/**
* Create a dialog with options to save and exit or quit without
* saving
*/
private void createQuitDialog() {
String title;
{
FormController formController = getFormController();
title = (formController == null) ? null : formController.getFormTitle();
if (title == null) {
title = getString(R.string.no_form_loaded);
}
}
List<IconMenuItem> items;
if ((boolean) AdminSharedPreferences.getInstance().get(AdminKeys.KEY_SAVE_MID)) {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save_grey_32dp_wrapped, R.string.keep_changes), new IconMenuItem(R.drawable.ic_delete_grey_32dp_wrapped, R.string.do_not_save));
} else {
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_delete_grey_32dp_wrapped, R.string.do_not_save));
}
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "show");
ListView listView = DialogUtils.createActionListView(this);
final IconMenuListAdapter adapter = new IconMenuListAdapter(this, items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IconMenuItem item = (IconMenuItem) adapter.getItem(position);
if (item.getTextResId() == R.string.keep_changes) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "saveAndExit");
saveDataToDisk(EXIT, InstancesDaoHelper.isInstanceComplete(false), null);
} else {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "discardAndExit");
// close all open databases of external data.
ExternalDataManager manager = Collect.getInstance().getExternalDataManager();
if (manager != null) {
manager.close();
}
FormController formController = getFormController();
if (formController != null) {
formController.getTimerLogger().logTimerEvent(TimerLogger.EventTypes.FORM_EXIT, 0, null, false, true);
}
removeTempInstance();
finishReturnInstance();
}
alertDialog.dismiss();
}
});
alertDialog = new AlertDialog.Builder(this).setTitle(getString(R.string.quit_application, title)).setPositiveButton(getString(R.string.do_not_exit), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "createQuitDialog", "cancel");
dialog.cancel();
}
}).setView(listView).create();
alertDialog.show();
}
use of android.support.v7.app.AlertDialog in project orgzly-android by orgzly.
the class MainActivity method onBookRenameRequest.
@Override
public void onBookRenameRequest(final long bookId) {
final Book book = BooksClient.get(this, bookId);
if (book == null) {
return;
}
final View dialogView = View.inflate(this, R.layout.dialog_book_rename, null);
final TextInputLayout nameInputLayout = dialogView.findViewById(R.id.name_input_layout);
final EditText name = dialogView.findViewById(R.id.name);
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
switch(which) {
case DialogInterface.BUTTON_POSITIVE:
doRenameBook(book, name.getText().toString(), nameInputLayout);
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.rename_book, MiscUtils.quotedString(book.getName()))).setPositiveButton(R.string.rename, dialogClickListener).setNegativeButton(R.string.cancel, dialogClickListener).setView(dialogView);
name.setText(book.getName());
final AlertDialog dialog = builder.create();
/* Finish on keyboard action press. */
name.setOnEditorActionListener((v, actionId, event) -> {
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
return true;
});
final Activity activity = this;
dialog.setOnShowListener(d -> ActivityUtils.INSTANCE.openSoftKeyboard(activity, name));
dialog.setOnDismissListener(d -> ActivityUtils.INSTANCE.closeSoftKeyboard(activity));
name.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable str) {
/* Disable the button is nothing is entered. */
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!TextUtils.isEmpty(str));
}
});
dialog.show();
}
use of android.support.v7.app.AlertDialog in project AndroidChromium by JackyAndroid.
the class ShareHelper method showShareDialog.
/**
* Creates and shows a share intent picker dialog.
*
* @param saveLastUsed Whether to save the chosen activity for future direct sharing.
* @param activity Activity that is used to access package manager.
* @param title Title of the page to be shared.
* @param text Text to be shared. If both |text| and |url| are supplied, they are concatenated
* with a space.
* @param url URL of the page to be shared.
* @oaram offlineUri URI of the offline page to be shared.
* @param screenshotUri Uri of the screenshot of the page to be shared.
* @param callback Optional callback to be called when user makes a choice. Will not be called
* if receiving a response when the user makes a choice is not supported (on
* older Android versions).
*/
private static void showShareDialog(final boolean saveLastUsed, final Activity activity, final String title, final String text, final String url, final Uri offlineUri, final Uri screenshotUri, @Nullable final TargetChosenCallback callback) {
Intent intent = getShareIntent(activity, title, text, url, null, null);
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> resolveInfoList = manager.queryIntentActivities(intent, 0);
assert resolveInfoList.size() > 0;
if (resolveInfoList.size() == 0)
return;
Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(manager));
final ShareDialogAdapter adapter = new ShareDialogAdapter(activity, manager, resolveInfoList);
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme);
builder.setTitle(activity.getString(R.string.share_link_chooser_title));
builder.setAdapter(adapter, null);
// Need a mutable object to record whether the callback has been fired.
final boolean[] callbackCalled = new boolean[1];
final AlertDialog dialog = builder.create();
dialog.show();
dialog.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ResolveInfo info = adapter.getItem(position);
ActivityInfo ai = info.activityInfo;
ComponentName component = new ComponentName(ai.applicationInfo.packageName, ai.name);
if (callback != null && !callbackCalled[0]) {
callback.onTargetChosen(component);
callbackCalled[0] = true;
}
if (saveLastUsed)
setLastShareComponentName(component);
makeIntentAndShare(false, activity, title, text, url, offlineUri, screenshotUri, component, null);
dialog.dismiss();
}
});
if (callback != null) {
dialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (!callbackCalled[0]) {
callback.onCancel();
callbackCalled[0] = true;
}
}
});
}
if (sFakeIntentReceiverForTesting != null) {
sFakeIntentReceiverForTesting.onCustomChooserShown(dialog);
}
}
use of android.support.v7.app.AlertDialog in project apps-android-commons by commons-app.
the class CategorizationFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch(menuItem.getItemId()) {
case R.id.menu_save_categories:
int numberSelected = 0;
for (CategoryItem item : categoriesAdapter.getItems()) {
if (item.selected) {
selectedCategories.add(item.name);
numberSelected++;
}
}
//If no categories selected, display warning to user
if (numberSelected == 0) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Images without categories are rarely usable. Are you sure you want to submit without selecting categories?").setTitle("No Categories Selected");
builder.setPositiveButton("No, go back", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Exit menuItem so user can select their categories
return;
}
});
builder.setNegativeButton("Yes, submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Proceed to submission
onCategoriesSaveHandler.onCategoriesSave(selectedCategories);
return;
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else {
//Proceed to submission
onCategoriesSaveHandler.onCategoriesSave(selectedCategories);
return true;
}
}
return super.onOptionsItemSelected(menuItem);
}
use of android.support.v7.app.AlertDialog in project apps-android-commons by commons-app.
the class CategorizationFragment method backButtonDialog.
public void backButtonDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Are you sure you want to go back? The image will not have any categories saved.").setTitle("Warning");
builder.setPositiveButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//No need to do anything, user remains on categorization screen
}
});
builder.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
getActivity().finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
Aggregations