Search in sources :

Example 26 with AlertDialog

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();
}
Also used : FormController(org.odk.collect.android.logic.FormController) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ODKView(org.odk.collect.android.views.ODKView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ExternalDataManager(org.odk.collect.android.external.ExternalDataManager) FailedConstraint(org.odk.collect.android.logic.FormController.FailedConstraint) ListView(android.widget.ListView) IconMenuListAdapter(org.odk.collect.android.adapters.IconMenuListAdapter) OnClickListener(android.view.View.OnClickListener) IconMenuItem(org.odk.collect.android.adapters.model.IconMenuItem) AdapterView(android.widget.AdapterView)

Example 27 with AlertDialog

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();
}
Also used : EditText(android.widget.EditText) NavigationView(android.support.design.widget.NavigationView) Shelf(com.orgzly.android.Shelf) Bundle(android.os.Bundle) Notifications(com.orgzly.android.Notifications) FilterFragment(com.orgzly.android.ui.fragments.FilterFragment) SearchView(android.support.v7.widget.SearchView) Uri(android.net.Uri) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Note(com.orgzly.android.Note) TextInputLayout(android.support.design.widget.TextInputLayout) BooksClient(com.orgzly.android.provider.clients.BooksClient) ActivityUtils(com.orgzly.android.ui.util.ActivityUtils) CheckBox(android.widget.CheckBox) Query(com.orgzly.android.query.Query) BookPrefaceFragment(com.orgzly.android.ui.fragments.BookPrefaceFragment) Handler(android.os.Handler) Map(java.util.Map) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) Repo(com.orgzly.android.repos.Repo) ActionMode(android.support.v7.view.ActionMode) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) NotesBatch(com.orgzly.android.NotesBatch) Set(java.util.Set) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) BookFragment(com.orgzly.android.ui.fragments.BookFragment) SyncFragment(com.orgzly.android.ui.fragments.SyncFragment) Book(com.orgzly.android.Book) BuildConfig(com.orgzly.BuildConfig) SimpleOneLinerDialog(com.orgzly.android.ui.dialogs.SimpleOneLinerDialog) NoteListFragment(com.orgzly.android.ui.fragments.NoteListFragment) BooksFragment(com.orgzly.android.ui.fragments.BooksFragment) Snackbar(android.support.design.widget.Snackbar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) TextWatcher(android.text.TextWatcher) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) MiscUtils(com.orgzly.android.util.MiscUtils) Context(android.content.Context) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) AppPermissions(com.orgzly.android.util.AppPermissions) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) ArrayList(java.util.ArrayList) GravityCompat(android.support.v4.view.GravityCompat) LinkedHashMap(java.util.LinkedHashMap) AppPreferences(com.orgzly.android.prefs.AppPreferences) NoteFragment(com.orgzly.android.ui.fragments.NoteFragment) R(com.orgzly.R) Menu(android.view.Menu) AppIntent(com.orgzly.android.AppIntent) DrawerLayout(android.support.v4.widget.DrawerLayout) FiltersFragment(com.orgzly.android.ui.fragments.FiltersFragment) DialogInterface(android.content.DialogInterface) CompoundButton(android.widget.CompoundButton) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) Spinner(android.widget.Spinner) Filter(com.orgzly.android.filter.Filter) ArrayAdapter(android.widget.ArrayAdapter) ReposClient(com.orgzly.android.provider.clients.ReposClient) Toolbar(android.support.v7.widget.Toolbar) Configuration(android.content.res.Configuration) Condition(com.orgzly.android.query.Condition) ActionService(com.orgzly.android.ActionService) BookName(com.orgzly.android.BookName) Activity(android.app.Activity) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) EditText(android.widget.EditText) LogUtils(com.orgzly.android.util.LogUtils) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) Activity(android.app.Activity) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) TextView(android.widget.TextView) Book(com.orgzly.android.Book) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout)

Example 28 with AlertDialog

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);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ActivityInfo(android.content.pm.ActivityInfo) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 29 with AlertDialog

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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface)

Example 30 with AlertDialog

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)413 DialogInterface (android.content.DialogInterface)275 View (android.view.View)219 TextView (android.widget.TextView)165 Intent (android.content.Intent)117 EditText (android.widget.EditText)87 ImageView (android.widget.ImageView)68 Button (android.widget.Button)67 LayoutInflater (android.view.LayoutInflater)59 RecyclerView (android.support.v7.widget.RecyclerView)54 NonNull (android.support.annotation.NonNull)53 AdapterView (android.widget.AdapterView)51 SuppressLint (android.annotation.SuppressLint)50 ArrayList (java.util.ArrayList)48 Bundle (android.os.Bundle)46 ListView (android.widget.ListView)42 Context (android.content.Context)35 SharedPreferences (android.content.SharedPreferences)35 Uri (android.net.Uri)32 LinearLayout (android.widget.LinearLayout)29