Search in sources :

Example 71 with Dialog

use of android.app.Dialog in project Lightning-Browser by anthonycr.

the class GeneralSettingsFragment method manualProxyPicker.

private void manualProxyPicker() {
    View v = mActivity.getLayoutInflater().inflate(R.layout.dialog_manual_proxy, null);
    final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost);
    final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort);
    // Limit the number of characters since the port needs to be of type int
    // Use input filters to limite the EditText length and determine the max
    // length by using length of integer MAX_VALUE
    int maxCharacters = Integer.toString(Integer.MAX_VALUE).length();
    InputFilter[] filterArray = new InputFilter[1];
    filterArray[0] = new InputFilter.LengthFilter(maxCharacters - 1);
    eProxyPort.setFilters(filterArray);
    eProxyHost.setText(mPreferenceManager.getProxyHost());
    eProxyPort.setText(Integer.toString(mPreferenceManager.getProxyPort()));
    Dialog dialog = new AlertDialog.Builder(mActivity).setTitle(R.string.manual_proxy).setView(v).setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            String proxyHost = eProxyHost.getText().toString();
            int proxyPort;
            try {
                // Try/Catch in case the user types an empty string or a number
                // larger than max integer
                proxyPort = Integer.parseInt(eProxyPort.getText().toString());
            } catch (NumberFormatException ignored) {
                proxyPort = mPreferenceManager.getProxyPort();
            }
            mPreferenceManager.setProxyHost(proxyHost);
            mPreferenceManager.setProxyPort(proxyPort);
            proxy.setSummary(proxyHost + ':' + proxyPort);
        }
    }).show();
    BrowserDialog.setDialogSize(mActivity, dialog);
}
Also used : EditText(android.widget.EditText) InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) View(android.view.View)

Example 72 with Dialog

use of android.app.Dialog in project Lightning-Browser by anthonycr.

the class LightningDialogBuilder method showEditBookmarkDialog.

private void showEditBookmarkDialog(@NonNull final Activity activity, @NonNull final UIController uiController, @NonNull final HistoryItem item) {
    final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
    editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
    final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
    final EditText getTitle = (EditText) dialogLayout.findViewById(R.id.bookmark_title);
    getTitle.setText(item.getTitle());
    final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url);
    getUrl.setText(item.getUrl());
    final AutoCompleteTextView getFolder = (AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
    getFolder.setHint(R.string.folder);
    getFolder.setText(item.getFolder());
    mBookmarkManager.getFolderNames().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<String>>() {

        @Override
        public void onItem(@Nullable List<String> folders) {
            Preconditions.checkNonNull(folders);
            final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_dropdown_item_1line, folders);
            getFolder.setThreshold(1);
            getFolder.setAdapter(suggestionsAdapter);
            editBookmarkDialog.setView(dialogLayout);
            editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    HistoryItem editedItem = new HistoryItem();
                    editedItem.setTitle(getTitle.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setFolder(getFolder.getText().toString());
                    mBookmarkManager.editBookmark(item, editedItem).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                        @Override
                        public void onComplete() {
                            uiController.handleBookmarksChange();
                        }
                    });
                }
            });
            Dialog dialog = editBookmarkDialog.show();
            BrowserDialog.setDialogSize(activity, dialog);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) HistoryItem(acr.browser.lightning.database.HistoryItem) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) List(java.util.List) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 73 with Dialog

use of android.app.Dialog in project Lightning-Browser by anthonycr.

the class DownloadHandler method onDownloadStartNoStream.

/**
     * Notify the host application a download should be done, even if there is a
     * streaming viewer available for thise type.
     *
     * @param context            The context in which the download is requested.
     * @param url                The full url to the content that should be downloaded
     * @param userAgent          User agent of the downloading application.
     * @param contentDisposition Content-disposition http header, if present.
     * @param mimetype           The mimetype of the content reported by the server
     */
/* package */
private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences, String url, String userAgent, String contentDisposition, @Nullable String mimetype) {
    final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
    // Check to see if we have an SDCard
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        int title;
        String msg;
        // Check to see if the SDCard is busy, same as the music app
        if (status.equals(Environment.MEDIA_SHARED)) {
            msg = context.getString(R.string.download_sdcard_busy_dlg_msg);
            title = R.string.download_sdcard_busy_dlg_title;
        } else {
            msg = context.getString(R.string.download_no_sdcard_dlg_msg);
            title = R.string.download_no_sdcard_dlg_title;
        }
        Dialog dialog = new AlertDialog.Builder(context).setTitle(title).setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg).setPositiveButton(R.string.action_ok, null).show();
        BrowserDialog.setDialogSize(context, dialog);
        return;
    }
    // java.net.URI is a lot stricter than KURL so we have to encode some
    // extra characters. Fix for b 2538060 and b 1634719
    WebAddress webAddress;
    try {
        webAddress = new WebAddress(url);
        webAddress.setPath(encodePath(webAddress.getPath()));
    } catch (Exception e) {
        // This only happens for very bad urls, we want to catch the
        // exception here
        Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
        Utils.showSnackbar(context, R.string.problem_download);
        return;
    }
    String addressString = webAddress.toString();
    Uri uri = Uri.parse(addressString);
    final DownloadManager.Request request;
    try {
        request = new DownloadManager.Request(uri);
    } catch (IllegalArgumentException e) {
        Utils.showSnackbar(context, R.string.cannot_download);
        return;
    }
    // set downloaded file destination to /sdcard/Download.
    // or, should it be set to one of several Environment.DIRECTORY* dirs
    // depending on mimetype?
    String location = preferences.getDownloadDirectory();
    Uri downloadFolder;
    location = addNecessarySlashes(location);
    downloadFolder = Uri.parse(location);
    File dir = new File(downloadFolder.getPath());
    if (!dir.isDirectory() && !dir.mkdirs()) {
        // Cannot make the directory
        Utils.showSnackbar(context, R.string.problem_location_download);
        return;
    }
    if (!isWriteAccessAvailable(downloadFolder)) {
        Utils.showSnackbar(context, R.string.problem_location_download);
        return;
    }
    String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(Utils.guessFileExtension(filename));
    Log.d(TAG, "New mimetype: " + newMimeType);
    request.setMimeType(newMimeType);
    request.setDestinationUri(Uri.parse(Constants.FILE + location + filename));
    // let this downloaded file be scanned by MediaScanner - so that it can
    // show up in Gallery app, for example.
    request.setVisibleInDownloadsUi(true);
    request.allowScanningByMediaScanner();
    request.setDescription(webAddress.getHost());
    // XXX: Have to use the old url since the cookies were stored using the
    // old percent-encoded url.
    String cookies = CookieManager.getInstance().getCookie(url);
    request.addRequestHeader(COOKIE_REQUEST_HEADER, cookies);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    //noinspection VariableNotUsedInsideIf
    if (mimetype == null) {
        Log.d(TAG, "Mimetype is null");
        if (TextUtils.isEmpty(addressString)) {
            return;
        }
        // We must have long pressed on a link or image to download it. We
        // are not sure of the mimetype in this case, so do a head request
        new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
    } else {
        Log.d(TAG, "Valid mimetype, attempting to download");
        final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        try {
            manager.enqueue(request);
        } catch (IllegalArgumentException e) {
            // Probably got a bad URL or something
            Log.e(TAG, "Unable to enqueue request", e);
            Utils.showSnackbar(context, R.string.cannot_download);
        } catch (SecurityException e) {
            // TODO write a download utility that downloads files rather than rely on the system
            // because the system can only handle Environment.getExternal... as a path
            Utils.showSnackbar(context, R.string.problem_location_download);
        }
        Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) File(java.io.File)

Example 74 with Dialog

use of android.app.Dialog in project Lightning-Browser by anthonycr.

the class BookmarkSettingsFragment method showChooserDialog.

private void showChooserDialog(final Activity activity, List<String> list) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1);
    for (String title : list) {
        adapter.add(title);
    }
    builder.setTitle(R.string.supported_browsers_title);
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String title = adapter.getItem(which);
            Preconditions.checkNonNull(title);
            Source source = null;
            if (title.equals(getString(R.string.stock_browser))) {
                source = Source.STOCK;
            } else if (title.equals(getTitle(activity, "com.android.chrome"))) {
                source = Source.CHROME_STABLE;
            } else if (title.equals(getTitle(activity, "com.android.beta"))) {
                source = Source.CHROME_BETA;
            } else if (title.equals(getTitle(activity, "com.android.dev"))) {
                source = Source.CHROME_DEV;
            }
            if (source != null) {
                new ImportBookmarksTask(activity, source).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    });
    Dialog dialog = builder.show();
    BrowserDialog.setDialogSize(activity, dialog);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Source(acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) ArrayAdapter(android.widget.ArrayAdapter)

Example 75 with Dialog

use of android.app.Dialog in project Lightning-Browser by anthonycr.

the class BrowserDialog method showEditText.

public static void showEditText(@NonNull Activity activity, @StringRes int title, @StringRes int hint, @Nullable String currentText, @StringRes int action, @NonNull final EditorListener listener) {
    View dialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_edit_text, null);
    final EditText editText = (EditText) dialogView.findViewById(R.id.dialog_edit_text);
    editText.setHint(hint);
    if (currentText != null) {
        editText.setText(currentText);
    }
    final AlertDialog.Builder editorDialog = new AlertDialog.Builder(activity).setTitle(title).setView(dialogView).setPositiveButton(action, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            listener.onClick(editText.getText().toString());
        }
    });
    Dialog dialog = editorDialog.show();
    setDialogSize(activity, dialog);
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

Dialog (android.app.Dialog)792 View (android.view.View)317 AlertDialog (android.app.AlertDialog)256 TextView (android.widget.TextView)219 DialogInterface (android.content.DialogInterface)200 Intent (android.content.Intent)97 Bundle (android.os.Bundle)94 Context (android.content.Context)93 AlertDialog (android.support.v7.app.AlertDialog)93 ListView (android.widget.ListView)87 EditText (android.widget.EditText)84 Button (android.widget.Button)80 AdapterView (android.widget.AdapterView)79 NonNull (android.support.annotation.NonNull)77 LayoutInflater (android.view.LayoutInflater)75 ImageView (android.widget.ImageView)70 ArrayList (java.util.ArrayList)64 LinearLayout (android.widget.LinearLayout)54 WindowManager (android.view.WindowManager)52 ProgressDialog (android.app.ProgressDialog)51