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:com.normsstuff.maps4norm.Dialogs.java

/**
 * @param c     the Context//from w  w w.  j a va  2s.com
 * @param trace the current trace of points
 * @return the "save & share" dialog
 */
public static Dialog getSaveNShare(final Activity c, final Stack<LatLng> trace) {
    final Dialog d = new Dialog(c);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.dialog_save);
    d.findViewById(R.id.saveMarks).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View vX) {
            final File destination;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                destination = API8Wrapper.getExternalFilesDir(c);
            } else {
                destination = c.getDir("traces", Context.MODE_PRIVATE);
            }

            d.dismiss();
            AlertDialog.Builder b = new AlertDialog.Builder(c);
            b.setTitle(R.string.save);
            final View layout = c.getLayoutInflater().inflate(R.layout.dialog_enter_filename, null);
            ((TextView) layout.findViewById(R.id.location))
                    .setText(c.getString(R.string.file_path, destination.getAbsolutePath() + "/"));
            b.setView(layout);
            b.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        String fname = ((EditText) layout.findViewById(R.id.filename)).getText().toString();
                        if (fname == null || fname.length() < 1) {
                            fname = "MapsMeasure_" + System.currentTimeMillis();
                        }
                        final File f = new File(destination, fname + ".csv");
                        Util.saveToFile(f, trace);
                        d.dismiss();
                        Toast.makeText(c, c.getString(R.string.file_saved, f.getAbsolutePath()),
                                Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        Toast.makeText(c,
                                c.getString(R.string.error,
                                        e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
            b.create().show();
        }
    });
    d.findViewById(R.id.loadMarks).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {

            File[] files = c.getDir("traces", Context.MODE_PRIVATE).listFiles();

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO
                    && Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                File ext = API8Wrapper.getExternalFilesDir(c);
                // even though we checked the external storage state, ext is still sometimes null, accoring to Play Store crash reports
                if (ext != null) {
                    File[] filesExtern = ext.listFiles();
                    File[] allFiles = new File[files.length + filesExtern.length];
                    System.arraycopy(files, 0, allFiles, 0, files.length);
                    System.arraycopy(filesExtern, 0, allFiles, files.length, filesExtern.length);
                    files = allFiles;
                }
            }

            if (files.length == 0) {
                Toast.makeText(c,
                        c.getString(R.string.no_files_found,
                                c.getDir("traces", Context.MODE_PRIVATE).getAbsolutePath()),
                        Toast.LENGTH_SHORT).show();
            } else if (files.length == 1) {
                try {
                    Util.loadFromFile(Uri.fromFile(files[0]), (MyMapActivity) c);
                    d.dismiss();
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(c,
                            c.getString(R.string.error, e.getClass().getSimpleName() + "\n" + e.getMessage()),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                d.dismiss();
                AlertDialog.Builder b = new AlertDialog.Builder(c);
                b.setTitle(R.string.select_file);
                final DeleteAdapter da = new DeleteAdapter(files, (MyMapActivity) c);
                b.setAdapter(da, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Util.loadFromFile(Uri.fromFile(da.getFile(which)), (MyMapActivity) c);
                            dialog.dismiss();
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(c,
                                    c.getString(R.string.error,
                                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });
                b.create().show();
            }
        }
    });
    /*        
            d.findViewById(R.id.share).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(final View v) {
        try {
            final File f = new File(c.getCacheDir(), "MapsMeasure.csv");
            Util.saveToFile(f, trace);
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, FileProvider
                    .getUriForFile(c, "de.j4velin.mapsmeasure.fileprovider", f));
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            shareIntent.setType("text/comma-separated-values");
            d.dismiss();
            c.startActivity(Intent.createChooser(shareIntent, null));
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(c, c.getString(R.string.error,
                            e.getClass().getSimpleName() + "\n" + e.getMessage()),
                    Toast.LENGTH_LONG).show();
        }
    }
            });
    */
    return d;
}

From source file:mobisocial.musubi.ui.fragments.PrivacyProtectionDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog d = super.onCreateDialog(savedInstanceState);
    d.setContentView(R.layout.sample_stats);
    d.setTitle("Privacy Protection");
    StringBuilder html = new StringBuilder();
    html.append("<html><p>Musubi was created as a research project at the Stanford Mobisocial Computing Lab ")
            .append("to let users share data without an intermediary owning the data.  ")
            .append("All the communicated data are owned by the users, stored on their own devices, and are encrypted on transit.  ")
            .append("We help you import friends from your existing social networks like Facebook and Google, ")
            .append("but we do not save any of your friends' information.</p>");
    html.append("</html>");
    TextView sample_text = (TextView) d.findViewById(R.id.stat_text);
    sample_text.setText(Html.fromHtml(html.toString()));
    Button ok_button = (Button) d.findViewById(R.id.stat_ok);
    ok_button.setOnClickListener(new OnClickListener() {
        @Override//from  ww w . j ava 2 s.  c  o m
        public void onClick(View v) {
            dismiss();
        }
    });
    return d;
}

From source file:mobisocial.musubi.ui.fragments.AnonymousStatsSampleDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog d = super.onCreateDialog(savedInstanceState);
    d.setContentView(R.layout.sample_stats);
    d.setTitle("Anonymous Statistics");
    StringBuilder html = new StringBuilder();
    html.append("<html><p>Your privacy is important to us. You can help us build a better Musubi ")
            .append("by sharing anonymous usage statistics, which includes things like:</p>").append("<p>")
            .append("\t&#149;Number of accounts connected<br/>")
            .append("\t&#149;Number of conversations started<br/>")
            .append("\t&#149;Number of messages sent<br/>").append("\t&#149;Number of sketches drawn<br/>")
            .append("\t&#149;When you update your profile<br/>").append("</p>");
    SharedPreferences p = getActivity().getSharedPreferences(SettingsActivity.PREFS_NAME, 0);
    if (p.getBoolean(SettingsActivity.PREF_ANONYMOUS_STATS, true)) {
        html.append("<p><b>Thank you for helping us improve Musubi!</b></p>");
    }//from w  w  w . jav  a2s .co  m
    html.append("</html>");
    TextView sample_text = (TextView) d.findViewById(R.id.stat_text);
    sample_text.setText(Html.fromHtml(html.toString()));
    Button ok_button = (Button) d.findViewById(R.id.stat_ok);
    ok_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    return d;
}

From source file:click.kobaken.rxirohaandroid_sample.view.fragment.SplashFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Dialog dialog = getDialog();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.fragment_splash);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

From source file:org.zakky.memopad.MyDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setContentView(R.layout.dialog);
    dialog.setTitle(R.string.app_name);/*from ww  w .j  a  v  a2 s. co  m*/

    dialog.findViewById(R.id.ok_button).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            v.setEnabled(false);
            final CheckBox box = (CheckBox) dialog.findViewById(R.id.show_this_dialog_at_startup);

            final SharedPreferences pref = dialog.getContext().getSharedPreferences(PREF_FILE_NAME,
                    Context.MODE_PRIVATE);
            final Editor editor = pref.edit();
            try {
                editor.putBoolean(PREF_KEY_SHOW_AT_STARTUP, box.isChecked());
            } finally {
                editor.commit();
            }
            dialog.dismiss();
        }
    });
    return dialog;
}

From source file:ca.cmput301w14t09.PopUpEdit.java

/**
 * Creates a popup edit window with the given input parameters.
 * @param comment - edited comment.//from w  w w  .  ja  v  a 2 s  .  com
 */
public void popUpEdit(final Comment comment) {
    //Creates a dialog box
    final Dialog dialog = new Dialog(caller);
    dialog.setContentView(R.layout.pop_up_edit);
    dialog.setTitle("Comment Text");

    Button Submit = (Button) dialog.findViewById(R.id.Submit);
    final EditText commentText = (EditText) dialog.findViewById(R.id.editComment);

    commentText.setHint(comment.getCommentText());
    dialog.show();

    Submit.setOnClickListener(new View.OnClickListener() {

        //when submit is pressed everything is pused to the server
        @Override
        public void onClick(View v) {
            String str = "commentText = \\\"" + commentText.getText() + "\\\"\"";

            if (Server.getInstance().isServerReachable(caller)) {
                try {
                    ElasticSearchOperations.updateComment(comment, str);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            dialog.dismiss();
        }
    });
}

From source file:by.android.dailystatus.dialog.LicenseDialog.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    final FragmentActivity activity = getActivity();
    final Dialog dialog = new Dialog(activity);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_license);
    TextView description = (TextView) dialog.findViewById(R.id.txt_dialog_version_description);
    if (text != null && !TextUtils.isEmpty(text)) {
        description.setText(text);// www  . j  a v a 2 s. c  o  m
    }

    dialog.findViewById(R.id.but_dialog_version_ok).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();

        }
    });

    return dialog;
}

From source file:com.aqnote.app.wifianalyzer.wifi.AccessPointsDetail.java

@NonNull
public Dialog popupDialog(@NonNull Context context, @NonNull LayoutInflater inflater,
        @NonNull WiFiDetail wiFiDetail) {
    View view = inflater.inflate(R.layout.access_points_details_popup, null);
    Dialog dialog = new Dialog(context);
    dialog.setContentView(view);
    setView(context.getResources(), view, wiFiDetail, false);
    dialog.findViewById(R.id.popupButton).setOnClickListener(new PopupDialogListener(dialog));
    return dialog;
}

From source file:com.vrem.wifianalyzer.wifi.AccessPointsDetail.java

public Dialog popupDialog(@NonNull Context context, @NonNull LayoutInflater inflater,
        @NonNull WiFiDetail wiFiDetail) {
    View view = inflater.inflate(R.layout.access_points_details_popup, null);
    Dialog dialog = new Dialog(context);
    dialog.setContentView(view);
    setView(context.getResources(), view, wiFiDetail, false, true);
    dialog.findViewById(R.id.popupButton).setOnClickListener(new PopupDialogListener(dialog));
    return dialog;
}

From source file:com.example.stefan.movies.Fragments.Others.OpenSourceLicenses.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    final Dialog dialog = new Dialog(getActivity());

    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.fragment_opensource_licenses);

    searchTitleIcon = (ImageView) dialog.findViewById(R.id.searchTitleProfile);
    searchTitleIcon.setImageResource(R.drawable.ic_security_black_24dp);
    searchTitleIcon.setColorFilter(ContextCompat.getColor(getContext(), R.color.redOrange));

    searchTitleName = (TextView) dialog.findViewById(R.id.searchTitleName);
    searchTitleName.setText(R.string.licenses_header_title);

    // Closes the Dialog
    Button dialogBtnCancel = (Button) dialog.findViewById(R.id.license_BtnCancel);
    dialogBtnCancel.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w  w  . ja v a  2  s  .  c o m
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
    return dialog;
}