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:Main.java

/**
 * create dialog with layout content designed in XML. can used such as a common method.
 * This dialog will full screen/*ww  w  .jav  a  2 s  . co  m*/
 * 
 * @param context
 * @param idLayout
 * @return
 */
public static Dialog createDialogFullScreen(Context context, int idLayout) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
    dialog.setContentView(idLayout);
    return dialog;
}

From source file:Main.java

public static Dialog creativeDialog(Context context, int layout) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Holo_Light_Dialog);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dialog.setContentView(layout);
    return dialog;
}

From source file:com.memetro.android.alerts.CommentDialog.java

public static void showDialog(final Context context, String comment, String creator, boolean isMine,
        final Long id) {

    final Dialog mDialog = new Dialog(context);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setContentView(R.layout.comment_dialog);
    mDialog.setCancelable(true);//from   w  w w . j  ava2  s .c om

    TextView titleText = (TextView) mDialog.findViewById(R.id.title);
    TextView messageText = (TextView) mDialog.findViewById(R.id.message);
    Button closeButton = (Button) mDialog.findViewById(R.id.close);
    Button deleteButton = (Button) mDialog.findViewById(R.id.delete);

    titleText.setText(titleText.getText().toString() + " " + creator);
    messageText.setMovementMethod(ScrollingMovementMethod.getInstance());
    messageText.setText(comment);

    if (isMine) {
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DeleteInBg(context, String.valueOf(id)).execute();
                mDialog.dismiss();
                // TODO Refrescar las alertas
            }
        });
    }

    closeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mDialog.dismiss();
        }
    });

    mDialog.show();

}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param m        the Map/* w ww .  j a v  a  2 s  .  com*/
 * @param distance the current distance
 * @param area     the current area
 * @return the units dialog
 */
public static Dialog getUnits(final Map m, float distance, double area) {
    final Dialog d = new Dialog(m);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.setContentView(R.layout.dialog_unit);
    CheckBox metricCb = (CheckBox) d.findViewById(R.id.metric);
    metricCb.setChecked(m.metric);
    metricCb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            m.metric = !m.metric;
            m.getSharedPreferences("settings", Context.MODE_PRIVATE).edit().putBoolean("metric", isChecked)
                    .commit();
            m.updateValueText();
        }
    });
    ((TextView) d.findViewById(R.id.distance)).setText(Map.formatter_two_dec.format(Math.max(0, distance))
            + " m\n" + Map.formatter_two_dec.format(distance / 1000) + " km\n\n"
            + Map.formatter_two_dec.format(Math.max(0, distance / 0.3048f)) + " ft\n"
            + Map.formatter_two_dec.format(Math.max(0, distance / 0.9144)) + " yd\n"
            + Map.formatter_two_dec.format(distance / 1609.344f) + " mi\n"
            + Map.formatter_two_dec.format(distance / 1852f) + " nautical miles");

    ((TextView) d.findViewById(R.id.area)).setText(Map.formatter_two_dec.format(Math.max(0, area)) + " m\n"
            + Map.formatter_two_dec.format(area / 10000) + " ha\n"
            + Map.formatter_two_dec.format(area / 1000000) + " km\n\n"
            + Map.formatter_two_dec.format(Math.max(0, area / 0.09290304d)) + " ft\n"
            + Map.formatter_two_dec.format(area / 4046.8726099d) + " ac (U.S. Survey)\n"
            + Map.formatter_two_dec.format(area / 2589988.110336d) + " mi");
    d.findViewById(R.id.close).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            d.dismiss();
        }
    });
    return d;
}

From source file:com.eyekabob.util.EyekabobHelper.java

public static Dialog createAboutDialog(Context context) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.about_dialog);
    dialog.setTitle(R.string.about_eyekabob_caps);

    ImageView imageView = (ImageView) dialog.findViewById(R.id.aboutDialogImage);
    imageView.setImageResource(R.drawable.ic_launcher);

    String message = context.getResources().getString(R.string.eyekabob_version);
    String versionName = "";
    try {//www  .j  av  a 2 s  . c o m
        versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(context.getClass().getSimpleName(), e.getMessage());
    }

    message += versionName;
    message += "\n\n" + context.getResources().getString(R.string.about_eyekabob_app);
    message += "\n\n" + context.getResources().getString(R.string.about_last_fm);

    TextView textView = (TextView) dialog.findViewById(R.id.aboutDialogText);
    textView.setText(message);

    dialog.findViewById(R.id.aboutDialogButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    return dialog;
}

From source file:com.aaplab.android.roboboost.RoboBoost.java

/**
 * Sets content for specified dialog and injects all fields and methods marked by injection annotations in object.
 * <p>/*from w ww  .j  a  v  a  2 s.c  o  m*/
 * See full list of injection annotations in javadoc for this class.
 * </p>
 *
 * @param dialog   Dialog a dialog to be processed and which content will be used for resolving injections, can't be
 *                 <code>null</code>
 * @param layoutId int layout id to be inflated
 * @throws IllegalArgumentException if <code>dialog</code> is <code>null</code>
 * @throws InflateException         if any injection error has occured
 */
public static void setInjectedContentView(Dialog dialog, int layoutId) {
    dialog.setContentView(layoutId);
    doInjections(dialog);
}

From source file:com.aaplab.android.roboboost.RoboBoost.java

/**
 * Sets content for specified dialog and injects all fields and methods marked by injection annotations in object.
 * <p>//w ww.j  a v a 2 s .co  m
 * See full list of injection annotations in javadoc for this class.
 * </p>
 *
 * @param dialog      Dialog a dialog to be processed and which content will be used for resolving injections, can't be
 *                    <code>null</code>
 * @param contentView View view to be inflated
 * @throws IllegalArgumentException if <code>dialog</code> is <code>null</code>
 * @throws InflateException         if any injection error has occured
 */
public static void setInjectedContentView(Dialog dialog, View contentView) {
    dialog.setContentView(contentView);
    doInjections(dialog);
}

From source file:fi.tuukka.weather.utils.Utils.java

public static void showImage(Activity activity, View view, Bitmap bmp) {
    final Dialog imageDialog = new Dialog(activity);
    imageDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    imageDialog.setContentView(R.layout.showimage);
    imageDialog.setCancelable(true);//from  www .ja v a2s. co  m

    ImageView imageView = (ImageView) imageDialog.findViewById(R.id.imageView);
    // Getting width & height of the given image.
    DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
    int wn = displayMetrics.widthPixels;
    int hn = displayMetrics.heightPixels;
    int wo = bmp.getWidth();
    int ho = bmp.getHeight();
    Matrix mtx = new Matrix();
    // Setting rotate to 90
    mtx.preRotate(90);
    // Setting resize
    mtx.postScale(((float) 1.3 * wn) / ho, ((float) 1.3 * hn) / wo);
    // Rotating Bitmap
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, wo, ho, mtx, true);
    BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

    imageView.setImageDrawable(bmd);

    imageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View button) {
            imageDialog.dismiss();
        }
    });

    imageDialog.show();
}

From source file:de.j4velin.mapsmeasure.Dialogs.java

/**
 * @param c     the Context/*from w  w w  .j ava2  s  .c o m*/
 * @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.save).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            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.load).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 sometims 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]), (Map) 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, (Map) c);
                b.setAdapter(da, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Util.loadFromFile(Uri.fromFile(da.getFile(which)), (Map) 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:com.spoiledmilk.ibikecph.util.Util.java

public static void launchNoConnectionDialog(Context ctx) {
    final Dialog dialog = new Dialog(ctx);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_no_connection);
    TextView text = (TextView) dialog.findViewById(R.id.textNetworkError);
    text.setTypeface(IbikeApplication.getNormalFont());
    text.setText(IbikeApplication.getString("network_error_text"));
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.show();//  w  w w.ja  va  2  s. c om
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            try {
                dialog.dismiss();
            } catch (Exception e) {
                // dialog not attached to window
            }
        }
    }, 3000);
}