Example usage for android.app AlertDialog.Builder setView

List of usage examples for android.app AlertDialog.Builder setView

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setView.

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:net.phase.wallet.Currency.java

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder;
    AlertDialog alertDialog;//from w  w w.j  av  a  2  s .c o m
    builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = null;
    final WalletActivity parentActivity = this;

    switch (id) {
    case DIALOG_URL:
        layout = inflater.inflate(R.layout.urlfetch_dialog, null);

        TextView tv = (TextView) layout.findViewById(R.id.pasteBinHelpText);
        tv.setMovementMethod(LinkMovementMethod.getInstance());

        final EditText hashEditText = (EditText) layout.findViewById(R.id.hashEditText);
        final EditText nameEditText = (EditText) layout.findViewById(R.id.nameEditText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String hash = hashEditText.getText().toString();
                String name = nameEditText.getText().toString();

                if (!hash.startsWith("http")) {
                    hash = "http://pastebin.com/raw.php?i=" + hash;
                }

                try {
                    Wallet w = new Wallet(name, new URI(hash), parentActivity);
                    addWallet(w);
                } catch (Exception e) {
                    toastMessage(e.getMessage());
                }
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        break;
    case DIALOG_FILE:
        layout = inflater.inflate(R.layout.file_dialog, null);

        TextView tvhelp = (TextView) layout.findViewById(R.id.helpText);
        tvhelp.setMovementMethod(LinkMovementMethod.getInstance());

        final Spinner fileSpinner = (Spinner) layout.findViewById(R.id.fileInput);
        final EditText nameEditText2 = (EditText) layout.findViewById(R.id.nameEditText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                File filename = (File) fileSpinner.getSelectedItem();
                String name = nameEditText2.getText().toString();
                boolean alreadyexists = false;

                if (name.length() > 0) {
                    if (wallets != null && wallets.length > 0) {
                        for (Wallet w : wallets) {
                            if (w.name.equals(name)) {
                                alreadyexists = true;
                            }
                        }
                    }

                    if (!alreadyexists) {
                        try {
                            Wallet w = new Wallet(name, filename, parentActivity);
                            addWallet(w);
                        } catch (Exception e) {
                            toastMessage(e.getMessage());
                        }
                    } else {
                        toastMessage("Wallet already exists");
                    }
                } else {
                    toastMessage("Invalid Name");
                }
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        break;
    case DIALOG_PASTE:
        layout = inflater.inflate(R.layout.paste_dialog, null);

        final EditText keysText = (EditText) layout.findViewById(R.id.keysText);
        final EditText nameEditText3 = (EditText) layout.findViewById(R.id.walletNameText);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String keys = keysText.getText().toString();
                String name = nameEditText3.getText().toString();
                boolean alreadyexists = false;

                if (name.length() > 0) {
                    if (wallets != null && wallets.length > 0) {
                        for (Wallet w : wallets) {
                            if (w.name.equals(name)) {
                                alreadyexists = true;
                            }
                        }
                    }

                    if (!alreadyexists) {
                        try {
                            Wallet w = new Wallet(name, keys, parentActivity);
                            addWallet(w);
                        } catch (Exception e) {
                            toastMessage(e.getMessage());
                        }
                    } else {
                        toastMessage("Wallet already exists");
                    }
                } else {
                    toastMessage("Invalid Name");
                }
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        break;
    case DIALOG_OPTIONS:
        layout = inflater.inflate(R.layout.options_dialog, null);

        final Spinner currencySpinner = (Spinner) layout.findViewById(R.id.currencySpinner);
        final EditText reqText = (EditText) layout.findViewById(R.id.reqText);
        final Spinner decpointSpinner = (Spinner) layout.findViewById(R.id.decpointSpinner);

        builder.setView(layout);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                String currency = (String) currencySpinner.getSelectedItem();
                decimalpoints = ((Integer) decpointSpinner.getSelectedItem()).intValue();
                setActiveCurrency(currency);
                try {
                    maxlength = Integer.parseInt(reqText.getText().toString());
                } catch (RuntimeException e) {
                    toastMessage("Invalid number");
                }
                savePreferences();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        break;

    }

    alertDialog = builder.create();

    return alertDialog;
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

private void optionChangelog() {
    WebView webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            int userId = Util.getUserId(Process.myUid());
            Version currentVersion = new Version(Util.getSelfVersionName(ActivityMain.this));
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingChangelog, currentVersion.toString());
        }//from   ww w .  j  a  v  a  2s. co  m
    });
    webview.loadUrl("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md");

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_changelog);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(webview);
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoSettings() {
    // get settings.xml view
    LayoutInflater li = LayoutInflater.from(context);
    settingsView = li.inflate(R.layout.settings, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    // set settings.xml to alertdialog builder
    alertDialogBuilder.setView(settingsView);
    // get user input for service code
    final EditText userInput = (EditText) settingsView.findViewById(R.id.editTextDialogUserInput);
    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from  w  ww  . j  ava2  s . c o  m
        public void onClick(DialogInterface dialog, int id) {
            SharedPreferences prefs = context.getSharedPreferences("Share", Context.MODE_PRIVATE);
            prefs.edit().clear();
            SharedPreferences.Editor es = prefs.edit();
            String[] mTestArray;
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs URL
                EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
                appURL = et1.getText().toString();
                es.putString("com.ezac.gliderlogs.url", appURL).apply();
            }
            // prefs PRE
            EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
            appPRE = et2.getText().toString().replace(" ", "");
            es.putString("com.ezac.gliderlogs.pre", appPRE).apply();
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs SCN
                EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
                appSCN = et3.getText().toString();
                es.putString("com.ezac.gliderlogs.scn", appSCN).apply();
                // prefs KEY
                EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
                appKEY = et4.getText().toString();
                es.putString("com.ezac.gliderlogs.key", appKEY).apply();
                // prefs KEY
                EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
                appSCT = et5.getText().toString();
                es.putString("com.ezac.gliderlogs.sct", appSCT).apply();
                // prefs Meteo

                mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
                Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
                String sel6 = (String) et6.getSelectedItem();
                //String sel6_id = "";
                for (int i = 0; i < et6.getCount(); i++) {
                    String s1 = (String) et6.getItemAtPosition(i);
                    if (s1.equalsIgnoreCase(sel6)) {
                        appMST = mTestArray[i];
                    }
                }
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
                // prefs Metar
                EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
                appMTR = et7.getText().toString();
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
            }
            // prefs Flags
            CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
            CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);

            CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
            CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
            CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
            CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
            CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
            CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
            String et9aa, et9ab;
            String v[];
            if (userInput.getText().toString().equals("To3Myd4T")) {
                et9aa = et9a.isChecked() ? "true" : "false";
                et9ab = et9b.isChecked() ? "true" : "false";
            } else {
                v = appFLG.split(";");
                et9aa = v[0];
                et9ab = v[1];
            }
            String et9ac = et9c.isChecked() ? "true" : "false";
            String et9ad = et9d.isChecked() ? "true" : "false";
            String et9ae = et9e.isChecked() ? "true" : "false";
            String et9af = et9f.isChecked() ? "true" : "false";
            String et9ag = et9g.isChecked() ? "true" : "false";
            String et9ah = et9h.isChecked() ? "true" : "false";
            appFLG = et9aa + ";" + et9ab + ";" + et9ac + ";" + et9ad + ";" + et9ae + ";" + et9af + ";" + et9ag
                    + ";" + et9ah + ";false;false";
            v = appFLG.split(";");

            menu.findItem(R.id.action_ezac).setVisible(Boolean.parseBoolean(v[2]));
            menu.findItem(R.id.action_meteo_group).setVisible(Boolean.parseBoolean(v[3]));
            menu.findItem(R.id.action_ntm_nld).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ntm_blx).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ogn_flarm).setVisible(Boolean.parseBoolean(v[5]));
            menu.findItem(R.id.action_adsb).setVisible(Boolean.parseBoolean(v[6]));
            menu.findItem(R.id.action_adsb_lcl).setVisible(Boolean.parseBoolean(v[7]));
            es.putString("com.ezac.gliderlogs.flg", appFLG).apply();
            // adjust value in menu button to value in use
            MenuItem MenuItem_dur = menu.findItem(R.id.action_45min);
            MenuItem_dur.setTitle(" " + appPRE + " Min ");
            if (userInput.getText().toString().equals("To3Myd4T")) {
                // prefs airfield heading
                mTestArray = getResources().getStringArray(R.array.heading_arrays);
                Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
                String sel10 = (String) et10.getSelectedItem();
                //String sel10_id = "";
                for (int i = 0; i < et10.getCount(); i++) {
                    String s2 = (String) et10.getItemAtPosition(i);
                    if (s2.equalsIgnoreCase(sel10)) {
                        appLND = mTestArray[i];
                        es.putString("com.ezac.gliderlogs.lnd", appLND).apply();
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create alert dialog & and load it's data
    AlertDialog alertDialog = alertDialogBuilder.create();
    EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
    EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
    EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
    EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
    EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
    Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
    EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
    //EditText et8 = (EditText) settingsView.findViewById(R.id.setting_ntp);
    CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
    CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);
    CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
    CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
    CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
    CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
    CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
    CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
    Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
    et1.setText(appURL);
    et2.setText(appPRE);
    et3.setText(appSCN);
    et4.setText(appKEY);
    et5.setText(appSCT);
    // get settings value for meteo station and set spinner
    String[] mTestArray;
    mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appMST)) {
            et6.setSelection(i);
        }
    }
    et7.setText(appMTR);
    // get settings value for menu tabs and set checkboxes
    String v[] = appFLG.split(";");
    et9a.setChecked(Boolean.parseBoolean(v[0]));
    et9b.setChecked(Boolean.parseBoolean(v[1]));
    et9c.setChecked(Boolean.parseBoolean(v[2]));
    et9d.setChecked(Boolean.parseBoolean(v[3]));
    et9e.setChecked(Boolean.parseBoolean(v[4]));
    et9f.setChecked(Boolean.parseBoolean(v[5]));
    et9g.setChecked(Boolean.parseBoolean(v[6]));
    et9h.setChecked(Boolean.parseBoolean(v[7]));
    // re-use mTestArray
    mTestArray = getResources().getStringArray(R.array.heading_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appLND)) {
            et10.setSelection(i);
        }
    }
    // show it
    alertDialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionSort() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.sort, null);
    final RadioGroup rgSMode = (RadioGroup) view.findViewById(R.id.rgSMode);
    final CheckBox cbSInvert = (CheckBox) view.findViewById(R.id.cbSInvert);

    // Initialise controls
    switch (mSortMode) {
    case SORT_BY_NAME:
        rgSMode.check(R.id.rbSName);/*from w  ww  .j  a v a  2s  .com*/
        break;
    case SORT_BY_UID:
        rgSMode.check(R.id.rbSUid);
        break;
    case SORT_BY_INSTALL_TIME:
        rgSMode.check(R.id.rbSInstalled);
        break;
    case SORT_BY_UPDATE_TIME:
        rgSMode.check(R.id.rbSUpdated);
        break;
    case SORT_BY_MODIFY_TIME:
        rgSMode.check(R.id.rbSModified);
        break;
    case SORT_BY_STATE:
        rgSMode.check(R.id.rbSState);
        break;
    }
    cbSInvert.setChecked(mSortInvert);

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
    alertDialogBuilder.setTitle(R.string.menu_sort);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (rgSMode.getCheckedRadioButtonId()) {
                    case R.id.rbSName:
                        mSortMode = SORT_BY_NAME;
                        break;
                    case R.id.rbSUid:
                        mSortMode = SORT_BY_UID;
                        break;
                    case R.id.rbSInstalled:
                        mSortMode = SORT_BY_INSTALL_TIME;
                        break;
                    case R.id.rbSUpdated:
                        mSortMode = SORT_BY_UPDATE_TIME;
                        break;
                    case R.id.rbSModified:
                        mSortMode = SORT_BY_MODIFY_TIME;
                        break;
                    case R.id.rbSState:
                        mSortMode = SORT_BY_STATE;
                        break;
                    }
                    mSortInvert = cbSInvert.isChecked();

                    int userId = Util.getUserId(Process.myUid());
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortMode,
                            Integer.toString(mSortMode));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortInverted,
                            Boolean.toString(mSortInvert));

                    applySort();
                }
            });
    alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:color.kidpaint.com.kidpaintcolor.dialog.FillToolDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = getActivity().getLayoutInflater();
    AlertDialog.Builder builder = new CustomAlertDialogBuilder(mContext);
    builder.setTitle(R.string.fill_tool_dialog_title);
    final View view = inflater.inflate(R.layout.dialog_fill_tool, null);

    mColorToleranceSeekBar = (SeekBar) view.findViewById(R.id.color_tolerance_seek_bar);
    mColorToleranceSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override//ww  w  .j a  v  a 2s. c  o  m
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mColorTolerance = progress;
            updateColorToleranceText(mColorTolerance);
            mColorToleranceEditText.setCursorVisible(false);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    mColorToleranceEditText = (EditText) view.findViewById(R.id.fill_tool_dialog_color_tolerance_input);
    mColorToleranceEditText.setCursorVisible(false);
    mColorToleranceEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                mColorTolerance = Integer.parseInt(s.toString());
                if (mColorTolerance > 100) {
                    mColorTolerance = 100;
                    updateColorToleranceText(mColorTolerance);
                }
                mColorToleranceSeekBar.setProgress(mColorTolerance);
                mOnFillToolDialogChangedListener.updateColorTolerance(mColorTolerance);
            } catch (NumberFormatException e) {
                Log.e("Error parsing tolerance", "result was null");
            }
        }
    });
    mColorToleranceEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.fill_tool_dialog_color_tolerance_input) {
                mColorToleranceEditText.setCursorVisible(true);
            }
        }
    });

    builder.setView(view);
    builder.setNeutralButton(R.string.done, this);

    return builder.create();
}

From source file:com.azure.webapi.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * //from   w ww.  ja va2 s .c  o  m
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl,
        final String endUrl, final Context context, LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setTitle("Connecting to a service");
    builder.setCancelable(true);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    // Set cancel button's action
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
            wv.destroy();
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionFilter() {
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.filters, null);
    final CheckBox cbFUsed = (CheckBox) view.findViewById(R.id.cbFUsed);
    final CheckBox cbFInternet = (CheckBox) view.findViewById(R.id.cbFInternet);
    final CheckBox cbFPermission = (CheckBox) view.findViewById(R.id.cbFPermission);
    final CheckBox cbFRestriction = (CheckBox) view.findViewById(R.id.cbFRestriction);
    final CheckBox cbFRestrictionNot = (CheckBox) view.findViewById(R.id.cbFRestrictionNot);
    final CheckBox cbFOnDemand = (CheckBox) view.findViewById(R.id.cbFOnDemand);
    final CheckBox cbFOnDemandNot = (CheckBox) view.findViewById(R.id.cbFOnDemandNot);
    final CheckBox cbFUser = (CheckBox) view.findViewById(R.id.cbFUser);
    final CheckBox cbFSystem = (CheckBox) view.findViewById(R.id.cbFSystem);
    final Button btnDefault = (Button) view.findViewById(R.id.btnDefault);

    // Get settings
    final int userId = Util.getUserId(Process.myUid());
    boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false);
    boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false);
    boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true);
    boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false);
    boolean fRestrictionNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestrictionNot,
            false);/*from   w  w  w.jav a2  s . c om*/
    boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false);
    boolean fOnDemandNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemandNot, false);
    boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true);
    boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false);

    boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);

    // Setup checkboxes
    cbFUsed.setChecked(fUsed);
    cbFInternet.setChecked(fInternet);
    cbFPermission.setChecked(fPermission);
    cbFRestriction.setChecked(fRestriction);
    cbFRestrictionNot.setChecked(fRestrictionNot);
    cbFOnDemand.setChecked(fOnDemand && ondemand);
    cbFOnDemandNot.setChecked(fOnDemandNot && ondemand);
    cbFUser.setChecked(fUser);
    cbFSystem.setChecked(fSystem);

    cbFRestrictionNot.setEnabled(fRestriction);

    cbFOnDemand.setEnabled(ondemand);
    cbFOnDemandNot.setEnabled(fOnDemand && ondemand);

    // Manage user/system filter exclusivity
    OnCheckedChangeListener checkListener = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView == cbFUser) {
                if (isChecked)
                    cbFSystem.setChecked(false);
            } else if (buttonView == cbFSystem) {
                if (isChecked)
                    cbFUser.setChecked(false);
            } else if (buttonView == cbFRestriction)
                cbFRestrictionNot.setEnabled(cbFRestriction.isChecked());
            else if (buttonView == cbFOnDemand)
                cbFOnDemandNot.setEnabled(cbFOnDemand.isChecked());
        }
    };
    cbFUser.setOnCheckedChangeListener(checkListener);
    cbFSystem.setOnCheckedChangeListener(checkListener);
    cbFRestriction.setOnCheckedChangeListener(checkListener);
    cbFOnDemand.setOnCheckedChangeListener(checkListener);

    // Clear button
    btnDefault.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            cbFUsed.setChecked(false);
            cbFInternet.setChecked(false);
            cbFPermission.setChecked(true);
            cbFRestriction.setChecked(false);
            cbFRestrictionNot.setChecked(false);
            cbFOnDemand.setChecked(false);
            cbFOnDemandNot.setChecked(false);
            cbFUser.setChecked(true);
            cbFSystem.setChecked(false);
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
    alertDialogBuilder.setTitle(R.string.menu_filter);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUsed,
                            Boolean.toString(cbFUsed.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFInternet,
                            Boolean.toString(cbFInternet.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestriction,
                            Boolean.toString(cbFRestriction.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestrictionNot,
                            Boolean.toString(cbFRestrictionNot.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFPermission,
                            Boolean.toString(cbFPermission.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemand,
                            Boolean.toString(cbFOnDemand.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemandNot,
                            Boolean.toString(cbFOnDemandNot.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUser,
                            Boolean.toString(cbFUser.isChecked()));
                    PrivacyManager.setSetting(userId, PrivacyManager.cSettingFSystem,
                            Boolean.toString(cbFSystem.isChecked()));

                    invalidateOptionsMenu();
                    applyFilter();
                }
            });
    alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.dish.browser.activity.BrowserActivity.java

/**
 * method that shows a dialog asking what string the user wishes to search
 * for. It highlights the text entered.//from  w w w . j  a va2s.c  om
 */
private void findInPage() {
    final AlertDialog.Builder finder = new AlertDialog.Builder(mActivity);
    finder.setTitle(getResources().getString(R.string.action_find));
    final EditText getHome = new EditText(this);
    getHome.setHint(getResources().getString(R.string.search_hint));
    finder.setView(getHome);
    finder.setPositiveButton(getResources().getString(R.string.search_hint),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String query = getHome.getText().toString();
                    if (query.length() > 0)
                        showSearchInterfaceBar(query);
                }
            });
    finder.show();
}

From source file:com.microsoft.windowsazure.mobileservices.authentication.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 *
 * @param startUrl The initial URL for the authentication process
 * @param endUrl   The final URL for the authentication process
 * @param context  The context used to create the authentication dialog
 * @param callback Callback to invoke when the authentication process finishes
 *///from   w w  w  . j  av  a2  s . c  o m
private void showLoginUIInternal(final String startUrl, final String endUrl, final Context context,
        LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels - 100;

    wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished

            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

From source file:com.bubblegum.traceratops.app.ui.fragments.AddDebugPreferenceDialogFragment.java

@NonNull
@Override/*from  w w w .  j  ava2  s  .c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Add new preference")
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    addPreference();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View layout = inflater.inflate(R.layout.dialog_new_debug_preference, null);

    tvKeyName = (EditText) layout.findViewById(R.id.debug_key);
    tvKeyValue = (EditText) layout.findViewById(R.id.debug_value_string);
    swBoolean = (Switch) layout.findViewById(R.id.debug_value_boolean);
    rbBoolean = (RadioButton) layout.findViewById(R.id.radio_debug_boolean);
    rbString = (RadioButton) layout.findViewById(R.id.radio_debug_string);

    if (getArguments() != null) {
        boolean isEditMode = getArguments().getBoolean(DEBUG_ARG_EDIT_MODE, false);
        final String keyName = getArguments().getString(DEBUG_KEY_NAME, null);
        final String keyValue = getArguments().getString(DEBUG_VALUE, null);
        if (keyName == null) {
            isEditMode = false;
        }
        if (isEditMode) {
            tvKeyName.setText(keyName);
            tvKeyName.setEnabled(false);
            tvKeyValue.setText(keyValue);
            rbBoolean.setVisibility(View.GONE);
            rbString.setVisibility(View.GONE);

            builder.setNeutralButton(R.string.delete, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences preferences = getSharedPreferences();
                    if (preferences == null) {
                        return;
                    }
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.remove(keyName).commit();
                }
            });
        }
    }

    rbString.setOnCheckedChangeListener(this);
    rbBoolean.setOnCheckedChangeListener(this);

    builder.setView(layout);

    return builder.create();
}