Example usage for android.app Dialog setContentView

List of usage examples for android.app Dialog setContentView

Introduction

In this page you can find the example usage for android.app Dialog setContentView.

Prototype

public void setContentView(@NonNull View view) 

Source Link

Document

Set the screen content to an explicit view.

Usage

From source file:liqui.droid.activity.Base.java

/**
 * Open about dialog.//from w w w . j  a v a2s .com
 */
public void openAboutDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dlg_about);

    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String versionName = packageInfo.versionName;
        dialog.setTitle(getResources().getString(R.string.app_name) + " v" + versionName);
    } catch (PackageManager.NameNotFoundException e) {
        dialog.setTitle(getResources().getString(R.string.app_name));
    }

    Button btnByEmail = (Button) dialog.findViewById(R.id.btn_by_email);
    btnByEmail.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_EMAIL,
                    new String[] { getResources().getString(R.string.my_email) });
            sendIntent.setType("message/rfc822");
            startActivity(Intent.createChooser(sendIntent, "Select email application."));
        }
    });

    dialog.show();
}

From source file:org.wso2.cdm.agent.AuthenticationActivity.java

public void showAgreement(String message, String title) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.custom_terms_popup);
    dialog.setTitle(CommonUtilities.EULA_TITLE);
    dialog.setCancelable(false);//w  w  w . j  a  va 2 s.c o  m

    WebView web = (WebView) dialog.findViewById(R.id.webview);
    String html = "<html><body>" + message + "</body></html>";
    String mime = "text/html";
    String encoding = "utf-8";
    web.loadDataWithBaseURL(null, html, mime, encoding, null);

    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);

    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Preference.put(context, getResources().getString(R.string.shared_pref_isagreed), "1");
            dialog.dismiss();
            loadPincodeAcitvity();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            cancelEntry();
        }
    });

    dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
                return true;
            } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                return true;
            }
            return false;
        }
    });

    dialog.show();
}

From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java

public void showChangeLangDialog() {
    final Dialog dialog = new Dialog(ctx);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(false);//from w  w w  .  ja  v  a  2 s .  c  o m
    dialog.setContentView(R.layout.dialog_create_playlist);

    final EditText edt = (EditText) dialog.findViewById(R.id.edtInput);
    final TextView btnCreate = (TextView) dialog.findViewById(R.id.btnCreate);
    final TextView btnCancel = (TextView) dialog.findViewById(R.id.btnCancel);
    final ImageView btnDel = (ImageView) dialog.findViewById(R.id.btnDel);

    btnCreate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ret = edt.getText().toString();
            if (ret != null && !ret.isEmpty()) {
                try {
                    ToolsHelper.createPlaylist(ctx, ret);
                    setUpListPlaylist();
                    Log.d("CREATE_2", "COMPLETE");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                ToolsHelper.toast(ctx, getString(R.string.info_not_name_playlist));
                showChangeLangDialog();
            }
            dialog.dismiss();
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ret = null;
            dialog.cancel();
        }
    });

    btnDel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            edt.setText("");
        }
    });

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.show();
}

From source file:com.prad.yahooweather.YahooWeatherActivity.java

private void showFacebookshareDialog(String okButotnText) {

    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog_layout);
    dialog.setTitle("Post to Facebook");

    Button dialogButton = (Button) dialog.findViewById(R.id.cancel_dialog);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override/*from   w  ww.j  ava  2s  .c om*/
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    Button postButton = (Button) dialog.findViewById(R.id.post_to_facebook);
    postButton.setText(okButotnText);
    // if button is clicked, close the custom dialog
    postButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickPostStatusUpdate();
            dialog.dismiss();
        }
    });

    dialog.show();

}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *///from w  w  w.  jav a2 s.  c om
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    // UI settings for dialog pop-up
    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + name + " created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Close dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:edu.berkeley.boinc.PrefsFragment.java

private void setupSelectionListDialog(final PrefsListItemWrapper item, final Dialog dialog)
        throws RemoteException {
    dialog.setContentView(R.layout.prefs_layout_dialog_selection);

    if (item.ID == R.string.prefs_client_log_flags_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        String[] array = getResources().getStringArray(R.array.prefs_client_log_flags);
        for (String option : array)
            options.add(new SelectionDialogOption(option));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override//from   ww w .j av a 2s. c o m
            public void onClick(View v) {
                ArrayList<String> selectedOptions = new ArrayList<String>();
                for (SelectionDialogOption option : options)
                    if (option.selected)
                        selectedOptions.add(option.name);
                if (Logging.DEBUG)
                    Log.d(Logging.TAG, selectedOptions.size() + " log flags selected");
                new SetCcConfigAsync().execute(formatOptionsToCcConfig(selectedOptions));
                dialog.dismiss();
            }
        });
    } else if (item.ID == R.string.prefs_power_source_header) {
        final ArrayList<SelectionDialogOption> options = new ArrayList<SelectionDialogOption>();
        options.add(new SelectionDialogOption(R.string.prefs_power_source_ac,
                BOINCActivity.monitor.getPowerSourceAc()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_usb,
                BOINCActivity.monitor.getPowerSourceUsb()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_wireless,
                BOINCActivity.monitor.getPowerSourceWireless()));
        options.add(new SelectionDialogOption(R.string.prefs_power_source_battery, clientPrefs.run_on_batteries,
                true));
        ListView lv = (ListView) dialog.findViewById(R.id.selection);
        new PrefsSelectionDialogListAdapter(getActivity(), lv, R.id.selection, options);

        // setup confirm button action
        Button confirm = (Button) dialog.findViewById(R.id.confirm);
        confirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    for (SelectionDialogOption option : options) {
                        switch (option.ID) {
                        case R.string.prefs_power_source_ac:
                            BOINCActivity.monitor.setPowerSourceAc(option.selected);
                            break;
                        case R.string.prefs_power_source_usb:
                            BOINCActivity.monitor.setPowerSourceUsb(option.selected);
                            break;
                        case R.string.prefs_power_source_wireless:
                            BOINCActivity.monitor.setPowerSourceWireless(option.selected);
                            break;
                        case R.string.prefs_power_source_battery:
                            clientPrefs.run_on_batteries = option.selected;
                            new WriteClientPrefsAsync().execute(clientPrefs); //async task triggers layout update
                            break;
                        }
                        ;
                    }
                    dialog.dismiss();
                } catch (RemoteException e) {
                }
            }
        });
    }

    // generic cancel button
    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 *//*from   w w w .  j a va 2s.c  om*/
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer position = mListView.getPositionForView(view);
    final Dialog editDialog = new Dialog(this);

    // UI settings for dialog pop-up
    editDialog.setContentView(R.layout.add_edit_dialog);
    editDialog.setTitle("Edit Todo");
    TextView textView = (TextView) editDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    editDialog.setCancelable(true);
    EditText currentText = (EditText) editDialog.findViewById(R.id.todo);

    // Get selected TodoItem values
    final String name = mTodoItemList.get(position).text;
    final boolean isDone = mTodoItemList.get(position).isDone;
    final int id = mTodoItemList.get(position).idNumber;
    currentText.setText(name);

    Button editDone = (Button) editDialog.findViewById(R.id.Add);
    editDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    editDone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) editDialog.findViewById(R.id.todo);

            final String updatedName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!updatedName.isEmpty()) {
                String json = "{\"text\":\"" + updatedName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + updatedName + " updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            editDialog.dismiss();
        }
    });
}

From source file:liqui.droid.activity.Base.java

/**
 * Open donate dialog.//  w w  w.  j av  a  2  s  .co  m
 */
public void openDonateDialog() {
    Dialog dialog = new Dialog(this);
    dialog.setTitle(getResources().getString(R.string.donate));
    dialog.setContentView(R.layout.dlg_donate);
    Button btn = (Button) dialog.findViewById(R.id.btn_donate);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            String url = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=CLFEUAAXKXLLU&lc=MY&item_name=Donate%20for%20Gh4a&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });
    dialog.show();
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Display track name dialog//  w  w  w.  ja v a  2s.c  o m
 */
private void showTrackDialog() {
    final Dialog dialog = new Dialog(MainActivity.this);
    dialog.setTitle(R.string.title_newtrack);
    dialog.setContentView(R.layout.newtrack_dialog);
    final EditText editText = (EditText) dialog.findViewById(R.id.newtrack_edittext);
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss", Locale.getDefault());
    sdf.setTimeZone(TimeZone.getDefault());
    final String dateSuffix = sdf.format(Calendar.getInstance().getTime());
    final String autoName = "Auto_" + dateSuffix;
    editText.setText(autoName);
    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            editText.selectAll();
        }
    });
    dialog.show();

    final Button submit = (Button) dialog.findViewById(R.id.newtrack_button_submit);
    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String trackName = editText.getText().toString();
            if (trackName.length() == 0) {
                return;
            }
            db.newTrack(trackName);
            LoggerService.resetUpdateRealtime();
            updateTrackLabel(trackName);
            updateStatus();
            dialog.cancel();
        }
    });

    final Button cancel = (Button) dialog.findViewById(R.id.newtrack_button_cancel);
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
        }
    });
}

From source file:org.ohmage.reminders.types.location.LocTrigMapsActivity.java

private void showHelpDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.trigger_loc_maps_tips);
    dialog.setTitle(R.string.trigger_loc_defining_locations);
    dialog.setOwnerActivity(this);
    dialog.show();/*from   w  w  w .  j  a  va 2 s .c  o m*/

    WebView webView = (WebView) dialog.findViewById(R.id.web_view);
    webView.loadUrl("file:///android_res/raw/trigger_loc_maps_help.html");

    CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.check_do_not_show);
    checkBox.setChecked(shouldSkipToolTip());
    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            SharedPreferences pref = LocTrigMapsActivity.this.getSharedPreferences(TOOL_TIP_PREF_NAME,
                    Context.MODE_PRIVATE);

            SharedPreferences.Editor editor = pref.edit();
            editor.putBoolean(KEY_TOOL_TIP_DO_NT_SHOW, isChecked);
            editor.commit();
        }
    });

    Button button = (Button) dialog.findViewById(R.id.button_close);
    button.setTag(dialog);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Object tag = v.getTag();
            if (tag != null && tag instanceof Dialog) {
                ((Dialog) tag).dismiss();
            }
        }
    });
}