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:dtu.ds.warnme.app.dialog.LoginDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_login, null);
    builder.setView(view);
    builder.setTitle(R.string.login);/*  www .  ja va  2 s.  com*/
    builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here...
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here...
        }
    });

    progressView = view.findViewById(R.id.dialog_login_progress);
    formView = view.findViewById(R.id.dialog_login_form);

    usernameEditText = (EditText) view.findViewById(R.id.dialog_login_edit_text_username);
    usernameEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            usernameEditText.setError(null);
        }
    });

    passwordEditText = (EditText) view.findViewById(R.id.dialog_login_edit_text_password);
    passwordEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Nothing to do here...
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Nothing to do here...
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            passwordEditText.setError(null);
        }
    });

    dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    final String username = usernameEditText.getText().toString();
                    String password = passwordEditText.getText().toString();

                    boolean formOk = true;

                    if (StringUtils.isBlank(username)) {
                        usernameEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }
                    if (StringUtils.isBlank(password)) {
                        passwordEditText.setError(getString(R.string.cannot_be_empty));
                        formOk = false;
                    }

                    if (!formOk) {
                        Log.d(TAG, "Form contains errors.");
                        return;
                    }

                    final String hashedPassword = SecurityUtils.hashSHA512Base64(password);

                    tempRestClient = new RestClient(Prefs.getHost(), Prefs.getPort(), Prefs.getWsContextPath(),
                            username, hashedPassword, Prefs.getRealm());
                    tempRestClient.getProfile(dialog.getContext(),
                            new GsonHttpResponseHandler<User>(new TypeToken<User>() {
                            }.getType()) {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, String responseBody,
                                        Throwable error) {
                                    Log.e(TAG, "Login failed. [statusCode = " + statusCode + ", error=" + error
                                            + "]");

                                    if (statusCode == 0) {
                                        Toast.makeText(dialog.getOwnerActivity(), R.string.check_connection,
                                                Toast.LENGTH_LONG).show();
                                        return;
                                    }

                                    usernameEditText.setError(
                                            getResources().getText(R.string.bad_username_or_password));
                                    passwordEditText.setError(
                                            getResources().getText(R.string.bad_username_or_password));
                                    listener.onLoginFailure();
                                }

                                @Override
                                public void onFinish() {
                                    positiveButton.setEnabled(true);
                                    UiUtilities.fadeInFadeOut(formView, progressView);
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    UiUtilities.fadeInFadeOut(progressView, formView);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, User user) {
                                    Log.i(TAG, "Login succeeded. [statusCode = " + statusCode + "]");
                                    UserProfileHolder.setUserProfile(user);
                                    Prefs.setUsername(username);
                                    Prefs.setPasswordHash(hashedPassword);
                                    dialog.dismiss();

                                    listener.onLoginSuccess();
                                }

                            });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (tempRestClient != null) {
                        tempRestClient.cancelRequests(dialog.getOwnerActivity(), true);
                    }
                    dialog.dismiss();
                }
            });
        }
    });

    return dialog;
}

From source file:edu.asu.bsse.vtanders.finalproject.MainActivity.java

License:asdf

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_config) {
        AlertDialog.Builder connInfoDialogBuilder = new AlertDialog.Builder(this);
        connInfoDialogBuilder.setTitle("Server Information");
        final View view = getLayoutInflater().inflate(R.layout.server_config, null);
        connInfoDialogBuilder.setView(view);
        final AlertDialog connInfoDialog = connInfoDialogBuilder.create();
        connInfoDialog.show();/*from  w  w  w  .ja  v a  2 s .co  m*/
        Button apply = (Button) view.findViewById(R.id.apply_settings_button);
        apply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText hostET = (EditText) view.findViewById(R.id.host_content);
                String host = hostET.getText().toString();

                EditText portET = (EditText) view.findViewById(R.id.port_content);
                int port = Integer.valueOf(portET.getText().toString());

                EditText nickET = (EditText) view.findViewById(R.id.nickname_content);
                String nick = nickET.getText().toString();

                Log.d("ASDF", host + " " + port + " " + nick);

                new SetupConnectionTask(host, port, nick).execute();
                connInfoDialog.dismiss();
            }
        });

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:cn.edu.nuc.seeworld.fg.ColorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_dummy, container, false);
    Bundle bdl = getArguments();//from  ww w  . j  a va 2s  .  c  o  m
    mContext = this.getActivity();
    mMainLayout = (FrameLayout) v.findViewById(R.id.main_layout);

    LayerDrawable bgDrawable = (LayerDrawable) mMainLayout.getBackground();
    GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(bdl.getInt(EXTRA_COLOR));
    imageView = (ImageView) v.findViewById(R.id.iv_camera);
    pic_imageView = (ImageView) v.findViewById(R.id.iv_pic);
    et_site = (EditText) v.findViewById(R.id.et_site);
    et_text = (EditText) v.findViewById(R.id.et_writeword);
    btn_publish = (Button) v.findViewById(R.id.btn_publish);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            LayoutInflater layoutInflater = LayoutInflater.from(v.getContext());
            View v1 = layoutInflater.inflate(R.layout.camera_dialog, null);
            builder.setView(v1);
            camera_log_buttons[0] = (Button) v1.findViewById(R.id.bt_camera_dialog_1);
            camera_log_buttons[1] = (Button) v1.findViewById(R.id.bt_camera_dialog_2);
            camera_log_buttons[2] = (Button) v1.findViewById(R.id.bt_camera_dialog_3);
            for (int i = 0; i < 3; i++) {
                camera_log_buttons[i].setOnClickListener(new cameraonclicklistener());

            }
            dialog = builder.create();
            dialog.show();
        }
    });
    btn_publish.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            publish();
        }
    });
    return v;
}

From source file:de.trier.infsec.koch.droidsheep.activities.HijackActivity.java

private void selectURL() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(getString(R.string.changeurl));
    alert.setMessage(getString(R.string.customurl));

    // Set an EditText view to get user input   
    final EditText inputName = new EditText(this);
    inputName.setText(HijackActivity.this.webview.getUrl());
    alert.setView(inputName);

    alert.setPositiveButton("Go", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            HijackActivity.this.webview.loadUrl(inputName.getText().toString());
        }//from w  w  w . jav  a2 s . c om
    });

    alert.show();
}

From source file:com.bordengrammar.bordengrammarapp.ParentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_parents, container, false);
    mail = (LinearLayout) root.findViewById(R.id.linmail);
    call = (LinearLayout) root.findViewById(R.id.lincall);
    call.setOnClickListener(new View.OnClickListener() {
        @Override//from ww  w  .ja v  a2s  .com
        public void onClick(View arg0) {
            Intent cally = new Intent(Intent.ACTION_CALL);
            cally.setData(Uri.parse("tel:01795424192"));
            startActivity(cally);
        }
    });
    mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle("Send a email to Borden Grammar");
            alert.setMessage("Message: ");
            final EditText input = new EditText(getActivity());
            alert.setView(input);
            alert.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    // Do something with value!
                    Intent email = new Intent(Intent.ACTION_SEND);
                    email.setType("plain/text");
                    email.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { "school@bordengrammar.kent.sch.uk" });
                    email.putExtra(Intent.EXTRA_SUBJECT, "Email (Sent From BGS APP) ");
                    email.putExtra(Intent.EXTRA_TEXT, value);
                    startActivity(Intent.createChooser(email, "Choose an Email client :"));
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                }
            });
            alert.show();
        }

    });

    URL url = null;
    try {
        url = new URL(
                "http://website.bordengrammar.kent.sch.uk/index.php?option=com_rubberdoc&view=category&id=63%3Aletters&Itemid=241&format=feed&type=rss");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Feed feed = null;
    try {
        feed = FeedParser.parse(url);
    } catch (FeedIOException e) {
        e.printStackTrace();
    } catch (FeedXMLParseException e) {
        e.printStackTrace();
    } catch (UnsupportedFeedException e) {
        e.printStackTrace();
    }
    Boolean nully = false;
    for (int i = 0; i < 3; i++) {
        try {
            FeedItem item = feed.getItem(i);
        } catch (NullPointerException e) {
            e.printStackTrace();
            nully = true;
            Toast.makeText(getActivity().getApplicationContext(),
                    "Some features of this app require a internet connection", Toast.LENGTH_LONG).show();
        }
    }
    if (!nully) {
        final FeedItem post1 = feed.getItem(1);
        final FeedItem post2 = feed.getItem(2);
        final FeedItem post3 = feed.getItem(3);
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText(post1.getTitle());
        title2.setText(post2.getTitle());
        title3.setText(post3.getTitle());
        TextView link1 = (TextView) root.findViewById(R.id.link1);
        TextView link2 = (TextView) root.findViewById(R.id.link2);
        TextView link3 = (TextView) root.findViewById(R.id.link3);
        link1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post1.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post2.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post3.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });

    } else {
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText("No connection");
        title2.setText("No connection");
        title3.setText("No connection");
    }
    TextView reader = (TextView) root.findViewById(R.id.reader);
    reader.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String appPackageName = "com.adobe.reader"; // getPackageName() from Context or Activity object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }
    });

    return root;
}

From source file:co.edu.uniajc.vtf.content.MapSitesFragment.java

public Dialog createDialog() {
    LayoutInflater loInflater = this.getActivity().getLayoutInflater();

    AlertDialog.Builder loAlert = new AlertDialog.Builder(getActivity());
    loAlert.setView(loInflater.inflate(R.layout.dialog_search, null));
    loAlert.setPositiveButton(R.string.general_menus_search, new DialogInterface.OnClickListener() {
        @Override//from   w  w  w.  j a v a2  s . c o  m
        public void onClick(DialogInterface dialog, int id) {
            OptionsManager loOptions = new OptionsManager(MapSitesFragment.this.getActivity());
            OptionsEntity loOptionsData = loOptions.getOptions();
            EditText loSearchControl = (EditText) ((AlertDialog) dialog).findViewById(R.id.txtSearch);
            loOptionsData.setSearch(loSearchControl.getText().toString());
            loOptions.createOrUpdateOptions(loOptionsData);
            MapSitesFragment.this.cboForceUpdate = true;
            MapSitesFragment.this.loadList(LoadActions.LOAD_DATA);
            dialog.dismiss();
        }
    });

    loAlert.setNegativeButton(R.string.general_menus_cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            dialog.dismiss();
        }
    });

    loAlert.setNeutralButton(R.string.general_menus_clear, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            OptionsManager loOptions = new OptionsManager(MapSitesFragment.this.getActivity());
            OptionsEntity loOptionsData = loOptions.getOptions();
            loOptionsData.setSearch("");
            loOptions.createOrUpdateOptions(loOptionsData);
            EditText loSearchControl = (EditText) ((AlertDialog) dialog).findViewById(R.id.txtSearch);
            loSearchControl.setText("");
            MapSitesFragment.this.cboForceUpdate = true;
            MapSitesFragment.this.loadList(LoadActions.LOAD_DATA);
            dialog.dismiss();
        }
    });
    loAlert.setCancelable(false);
    return loAlert.create();
}

From source file:com.dsi.ant.antplus.pluginsampler.fitnessequipment.Dialog_ConfigSettings.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("Settings Configuration");
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View detailsView = inflater.inflate(R.layout.dialog_fe_settings, null);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(detailsView);

    // Add action buttons
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*from   w  ww .  j a  va 2 s. c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            Intent i = new Intent(Dialog_ConfigSettings.this.getActivity(),
                    Activity_FitnessEquipmentSampler.class);
            Bundle b = new Bundle();
            b.putString(SETTINGS_NAME, et_friendlyName.getText().toString());
            b.putShort(SETTINGS_AGE, Short.parseShort(et_age.getText().toString()));
            b.putFloat(SETTINGS_HEIGHT, Float.parseFloat(et_height.getText().toString()) / 100f); // Convert to m
            b.putFloat(SETTINGS_WEIGHT, Float.parseFloat(et_weight.getText().toString()));
            b.putBoolean(SETTINGS_GENDER, rb_male.isChecked());
            b.putBoolean(INCLUDE_WORKOUT, cb_workout.isChecked());
            i.putExtras(b);
            startActivity(i);
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Let dialog dismiss
        }
    });

    et_friendlyName = (EditText) detailsView.findViewById(R.id.editText_FriendlyName);
    et_age = (EditText) detailsView.findViewById(R.id.editText_Age);
    et_height = (EditText) detailsView.findViewById(R.id.editText_Height);
    et_weight = (EditText) detailsView.findViewById(R.id.editText_Weight);
    rb_female = (RadioButton) detailsView.findViewById(R.id.radioButton_Female);
    rb_male = (RadioButton) detailsView.findViewById(R.id.radioButton_Male);
    cb_workout = (CheckBox) detailsView.findViewById(R.id.checkBox_Workout);

    return builder.create();
}

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private void handleHiddenCode() {
    if (++developerFeatureCounter >= 10) {
        developerFeatureCounter = 0;//from   w ww  .j  av a2 s. c  o m
        final EditText input = new EditText(getActivity());
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(input);
        builder.setTitle(R.string.about_hidden_feature_dialog_title);
        builder.setMessage(R.string.about_hidden_feature_dialog_enter_code);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {

                try {
                    final String data = input.getText().toString();
                    if (!data.matches("\\d{8}")) {
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    final int dataInt = Integer.parseInt(data);
                    if (dataInt == 0) // deactivate all features
                    {
                        ConfigHelper.setUserLoopModeState(getActivity(), false);
                        ConfigHelper.setDevModeState(getActivity(), false);
                        ConfigHelper.setServerSelectionState(getActivity(), false);
                        ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_deactivated,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    if (ConfigHelper.isValidCheckSum(dataInt)) { // developer mode
                        if (dataInt == AppConstants.DEVELOPER_UNLOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.DEVELOPER_LOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // loop mode
                        else if (dataInt == AppConstants.LOOP_MODE_UNLOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.LOOP_MODE_LOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // server selection
                        else if (dataInt == AppConstants.SERVER_SELECTION_UNLOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), true);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_activated,
                                    Toast.LENGTH_LONG).show();
                        } else if (dataInt == AppConstants.SERVER_SELECTION_LOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), false);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // code not used
                        else {
                            Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                    Toast.LENGTH_LONG).show();
                        }
                    } else
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                } catch (Exception e) // ignore errors
                {
                    e.printStackTrace();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, null);

        dialog = builder.create();
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        dialog.show();
    }
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

@Override
public void onResume() {
    super.onResume();
    initRecorderFragment();/* w  ww .  j av a2  s .c  o m*/
    final SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!defaultPrefs.getBoolean("LICENSES_ACCEPTED", false)) {
        final AlertDialog.Builder acceptLicenses = new AlertDialog.Builder(this);
        View v = getLayoutInflater().inflate(R.layout.alertdialog_license_prompt, null);
        acceptLicenses.setView(v);

        WebView cpol = (WebView) v.findViewById(R.id.CPOL_view),
                apache = (WebView) v.findViewById(R.id.APACHE_2_0_view);
        cpol.loadUrl("file:///android_res/raw/cpol.html");
        cpol.getSettings().setLoadWithOverviewMode(true);
        cpol.getSettings().setBuiltInZoomControls(true);
        cpol.getSettings().setUseWideViewPort(true);
        apache.loadUrl("file:///android_res/raw/apache.html");
        apache.getSettings().setLoadWithOverviewMode(true);
        apache.getSettings().setBuiltInZoomControls(true);
        apache.getSettings().setUseWideViewPort(true);

        acceptLicenses.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                defaultPrefs.edit().putBoolean("LICENSES_ACCEPTED", true).apply();
                dialog.dismiss();

                PreferenceManager.setDefaultValues(MainMenuActivity.this, R.xml.data_viewer_phone_options,
                        false);
            }
        });

        acceptLicenses.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        acceptLicenses.setCancelable(false);
        acceptLicenses.show();
    }
}

From source file:chaitanya.im.searchforreddit.GenericAlertDialog.java

@SuppressLint("InflateParams")
@Override//from w w w . java  2s  .  c  o  m
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View dialogView;
    setRetainInstance(true);

    switch (whichDialog) {
    case 0:
        dialogView = inflater.inflate(R.layout.dialog_purchase, null);
        builder.setView(dialogView).setPositiveButton(R.string.ok_purchase, buttonListener);

        final TextView dialogPurchaseTitle = (TextView) dialogView.findViewById(R.id.dialog_purchase_title);
        final TextView purchaseDescription = (TextView) dialogView.findViewById(R.id.purchase_description);
        final TextView priceDisplay = (TextView) dialogView.findViewById(R.id.price_display);
        final TextView coffeePitchText = (TextView) dialogView.findViewById(R.id.coffee_pitch_text);
        coffeePitchText.setTypeface(fontAwesome);
        coffeePitchText.setText(Html.fromHtml(getResources().getString(R.string.donate_coffee_pitch)));

        // SeekBar settings
        AppCompatSeekBar seekBar = (AppCompatSeekBar) dialogView.findViewById(R.id.price_seekbar);
        seekBar.setKeyProgressIncrement(1);
        seekBar.setMax(2);
        seekBar.setProgress(1);

        if (allPrices != null && allPrices.size() != 0) {
            // We can do a purchase since allPrices isn't null
            assert priceDisplay != null;
            priceDisplay.setText(allPrices.get(1));

            if (purchaseDialog == 1) {
                dialogPurchaseTitle
                        .setText(Html.fromHtml(getResources().getString(R.string.donate_dialog_title_2)));
                purchaseDescription.setText(Html.fromHtml(getResources().getString(R.string.donate_features2)));
            }

            skuCode = 1;
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
                    skuCode = progress;
                    priceDisplay.setText(allPrices.get(progress));
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {

                }
            });
        } else {
            // Aw shucks! We cannot do a purchase.
            skuCode = 1;
            seekBar.setEnabled(false);
            priceDisplay.setText(getResources().getString(R.string.donate_impossible));
        }
        return builder.create();
    case 1:
        skuCode = -1;
        dialogView = inflater.inflate(R.layout.dialog_license, null);
        builder.setView(dialogView).setTitle("Licenses").setPositiveButton(R.string.ok_string, buttonListener);
        return builder.create();

    case 2:
        skuCode = -1;
        dialogView = inflater.inflate(R.layout.dialog_about, null);

        builder.setView(dialogView).setPositiveButton(R.string.ok_string, buttonListener);

        int versionCode = BuildConfig.VERSION_CODE;
        String versionName = BuildConfig.VERSION_NAME;
        String versionText = "Version Code <font color=#FF6F00>" + versionCode + "</font><br/>"
                + "Version Name <font color=#FF6F00>" + versionName + "</font><br/>";

        TextView aboutText = (TextView) dialogView.findViewById(R.id.about_text);
        TextView aboutVersion = (TextView) dialogView.findViewById(R.id.about_version);
        TextView aboutCopyright = (TextView) dialogView.findViewById(R.id.about_copyright);
        aboutText.setTypeface(fontAwesome);
        aboutCopyright.setTypeface(fontAwesome);
        aboutText.setText(Html.fromHtml(getResources().getString(R.string.about_text)));
        aboutVersion.setText(Html.fromHtml(versionText));
        aboutCopyright.setText(getResources().getString(R.string.about_copyright));
        return builder.create();

    case 3:
        skuCode = -1;
        dialogView = inflater.inflate(R.layout.dialog_whats_new, null);
        builder.setView(dialogView).setTitle("What's New?").setPositiveButton(R.string.ok_string,
                buttonListener);
        TextView whatsNewText = (TextView) dialogView.findViewById(R.id.whats_new_text);
        whatsNewText.setText(Html.fromHtml(StringResources.whatsNew));
        return builder.create();

    default:
        return builder.create();

    }
}