Search in sources :

Example 41 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AndroidChromium by JackyAndroid.

the class ChromeActivity method onMenuOrKeyboardAction.

/**
     * Handles menu item selection and keyboard shortcuts.
     *
     * @param id The ID of the selected menu item (defined in main_menu.xml) or
     *           keyboard shortcut (defined in values.xml).
     * @param fromMenu Whether this was triggered from the menu.
     * @return Whether the action was handled.
     */
public boolean onMenuOrKeyboardAction(int id, boolean fromMenu) {
    if (id == R.id.preferences_id) {
        PreferencesLauncher.launchSettingsPage(this, null);
        RecordUserAction.record("MobileMenuSettings");
    } else if (id == R.id.show_menu) {
        showAppMenuForKeyboardEvent();
    }
    if (id == R.id.update_menu_id) {
        UpdateMenuItemHelper.getInstance().onMenuItemClicked(this);
        return true;
    }
    // All the code below assumes currentTab is not null, so return early if it is null.
    final Tab currentTab = getActivityTab();
    if (currentTab == null) {
        return false;
    } else if (id == R.id.forward_menu_id) {
        if (currentTab.canGoForward()) {
            currentTab.goForward();
            RecordUserAction.record("MobileMenuForward");
            RecordUserAction.record("MobileTabClobbered");
        }
    } else if (id == R.id.bookmark_this_page_id) {
        addOrEditBookmark(currentTab);
        RecordUserAction.record("MobileMenuAddToBookmarks");
    } else if (id == R.id.offline_page_id) {
        DownloadUtils.downloadOfflinePage(this, currentTab);
        RecordUserAction.record("MobileMenuDownloadPage");
    } else if (id == R.id.reload_menu_id) {
        if (currentTab.isLoading()) {
            currentTab.stopLoading();
            RecordUserAction.record("MobileMenuStop");
        } else {
            currentTab.reload();
            RecordUserAction.record("MobileMenuReload");
        }
    } else if (id == R.id.info_menu_id) {
        WebsiteSettingsPopup.show(this, currentTab, null, WebsiteSettingsPopup.OPENED_FROM_MENU);
    } else if (id == R.id.open_history_menu_id) {
        currentTab.loadUrl(new LoadUrlParams(UrlConstants.HISTORY_URL, PageTransition.AUTO_TOPLEVEL));
        RecordUserAction.record("MobileMenuHistory");
        StartupMetrics.getInstance().recordOpenedHistory();
    } else if (id == R.id.share_menu_id || id == R.id.direct_share_menu_id) {
        onShareMenuItemSelected(id == R.id.direct_share_menu_id, getCurrentTabModel().isIncognito());
    } else if (id == R.id.print_id) {
        PrintingController printingController = PrintingControllerImpl.getInstance();
        if (printingController != null && !printingController.isBusy() && PrefServiceBridge.getInstance().isPrintingEnabled()) {
            printingController.startPrint(new TabPrinter(currentTab), new PrintManagerDelegateImpl(this));
            RecordUserAction.record("MobileMenuPrint");
        }
    } else if (id == R.id.add_to_homescreen_id) {
        AddToHomescreenManager addToHomescreenManager = new AddToHomescreenManager(this, currentTab);
        addToHomescreenManager.start();
        RecordUserAction.record("MobileMenuAddToHomescreen");
    } else if (id == R.id.request_desktop_site_id) {
        final boolean reloadOnChange = !currentTab.isNativePage();
        final boolean usingDesktopUserAgent = currentTab.getUseDesktopUserAgent();
        currentTab.setUseDesktopUserAgent(!usingDesktopUserAgent, reloadOnChange);
        RecordUserAction.record("MobileMenuRequestDesktopSite");
    } else if (id == R.id.reader_mode_prefs_id) {
        if (currentTab.getWebContents() != null) {
            RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened");
            AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
            builder.setView(DistilledPagePrefsView.create(this));
            builder.show();
        }
    } else if (id == R.id.help_id) {
        // Since reading back the compositor is asynchronous, we need to do the readback
        // before starting the GoogleHelp.
        String helpContextId = HelpAndFeedback.getHelpContextIdFromUrl(this, currentTab.getUrl(), getCurrentTabModel().isIncognito());
        HelpAndFeedback.getInstance(this).show(this, helpContextId, currentTab.getProfile(), currentTab.getUrl());
        RecordUserAction.record("MobileMenuFeedback");
    } else {
        return false;
    }
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PrintManagerDelegateImpl(org.chromium.printing.PrintManagerDelegateImpl) Tab(org.chromium.chrome.browser.tab.Tab) TabPrinter(org.chromium.chrome.browser.printing.TabPrinter) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) PrintingController(org.chromium.printing.PrintingController) AddToHomescreenManager(org.chromium.chrome.browser.webapps.AddToHomescreenManager)

Example 42 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AndroidChromium by JackyAndroid.

the class RepostFormWarningDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme).setMessage(R.string.http_post_warning);
    if (savedInstanceState == null) {
        assert mTab != null;
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                if (!mTab.isInitialized())
                    return;
                mTab.getWebContents().getNavigationController().cancelPendingReload();
            }
        });
        builder.setPositiveButton(R.string.http_post_warning_resend, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                if (!mTab.isInitialized())
                    return;
                mTab.getWebContents().getNavigationController().continuePendingReload();
            }
        });
    }
    Dialog dialog = builder.create();
    setCurrentDialogForTesting(dialog);
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) AlertDialog(android.support.v7.app.AlertDialog) Dialog(android.app.Dialog) SuppressLint(android.annotation.SuppressLint)

Example 43 with Builder

use of android.support.v7.app.AlertDialog.Builder 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 44 with Builder

use of android.support.v7.app.AlertDialog.Builder in project LeafPic by HoraApps.

the class SelectAlbumBottomSheet method setupDialog.

@Override
public void setupDialog(Dialog dialog, int style) {
    super.setupDialog(dialog, style);
    View contentView = View.inflate(getContext(), R.layout.select_folder_bottom_sheet, null);
    theme = new ThemeHelper(getContext());
    RecyclerView mRecyclerView = (RecyclerView) contentView.findViewById(R.id.folders);
    mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 1));
    adapter = new BottomSheetAlbumsAdapter();
    mRecyclerView.setAdapter(adapter);
    exploreModePanel = (LinearLayout) contentView.findViewById(R.id.explore_mode_panel);
    currentFolderPath = (TextView) contentView.findViewById(R.id.bottom_sheet_sub_title);
    imgExploreMode = (IconicsImageView) contentView.findViewById(R.id.toggle_hidden_icon);
    imgExploreMode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleExplorerMode(!exploreMode);
        }
    });
    toggleExplorerMode(false);
    /**SET UP THEME**/
    theme.setColorScrollBarDrawable(ContextCompat.getDrawable(dialog.getContext(), R.drawable.ic_scrollbar));
    contentView.findViewById(R.id.ll_bottom_sheet_title).setBackgroundColor(theme.getPrimaryColor());
    contentView.findViewById(R.id.ll_select_folder).setBackgroundColor(theme.getCardBackgroundColor());
    ((TextView) contentView.findViewById(R.id.bottom_sheet_title)).setText(title);
    ((IconicsImageView) contentView.findViewById(R.id.create_new_folder)).setColor(theme.getIconColor());
    ((TextView) contentView.findViewById(R.id.create_new_folder_text)).setTextColor(theme.getSubTextColor());
    ((IconicsImageView) contentView.findViewById(R.id.done)).setColor(theme.getIconColor());
    contentView.findViewById(R.id.done).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selectAlbumInterface.folderSelected(currentFolderPath.getText().toString());
        }
    });
    contentView.findViewById(R.id.ll_create_new_folder).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final EditText editText = new EditText(getContext());
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), theme.getDialogStyle());
            AlertDialogsHelper.getInsertTextDialog(((ThemedActivity) getActivity()), builder, editText, R.string.new_folder);
            builder.setPositiveButton(R.string.ok_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    File folderPath = new File(currentFolderPath.getText().toString() + File.separator + editText.getText().toString());
                    if (folderPath.mkdir())
                        displayContentFolder(folderPath);
                }
            });
            builder.show();
        }
    });
    dialog.setContentView(contentView);
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        ((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }
    adapter.notifyDataSetChanged();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) ThemeHelper(org.horaapps.leafpic.util.ThemeHelper) DialogInterface(android.content.DialogInterface) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) BottomSheetBehavior(android.support.design.widget.BottomSheetBehavior) GridLayoutManager(android.support.v7.widget.GridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) File(java.io.File)

Example 45 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AndroidChromium by JackyAndroid.

the class AccessibilityUtil method showOldTalkbackVersionAlertOnce.

private static void showOldTalkbackVersionAlertOnce(final Context context) {
    if (sOldTalkBackVersionAlertShown)
        return;
    sOldTalkBackVersionAlertShown = true;
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AlertDialogTheme).setTitle(R.string.old_talkback_title).setPositiveButton(R.string.update_from_market, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            Uri marketUri = Uri.parse(TALKBACK_MARKET_LINK);
            Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
            context.startActivity(marketIntent);
        }
    }).setNegativeButton(R.string.cancel_talkback_alert, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
        // Do nothing, this alert is only shown once either way.
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) Uri(android.net.Uri)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10