Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

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

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.privacity.PerfilActivity.java

public void agregarPerfil(View view) {
    JSONObject jsonObject = com.agregarPerfil(codigo);
    Dialog dialogo = new Dialog(this);
    //Tratamiento de errores
    if (jsonObject.has("Error")) {
        dialogo.setTitle(getResources().getString(R.string.errorDeConexion));
        try {/* w ww.ja  va  2  s . c o m*/
            String error = jsonObject.getString("Error");
            dialogo.setTitle(error);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } //IF
    else { //Si ha tenido exito
        dialogo.setTitle(getResources().getString(R.string.perfilAgregado));
        botonAceptar.setVisibility(View.INVISIBLE);
        botonCancelar.setVisibility(View.VISIBLE);
    }
    dialogo.show();

}

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);/*from w  w w.ja  v  a2s.co  m*/
    setView(context.getResources(), view, wiFiDetail, false, true);
    dialog.findViewById(R.id.popupButton).setOnClickListener(new PopupDialogListener(dialog));
    return dialog;
}

From source file:com.sastra.app.timetable.TimetableActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.timetable_main);

    Log.d(TAG, "Entered On Create");

    ActionBar Bar = getActionBar();// w  w  w. jav  a  2  s.  com
    Bar.setLogo(R.drawable.ic_launcher_1);
    //Bar.setTitle("");
    // String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/SASTRA Timetable/files/test.txt";

    SharedPreferences mPreferences = this.getSharedPreferences("AB", MODE_PRIVATE);

    boolean firstTime = mPreferences.getBoolean("firstTime", true);
    if (firstTime) {

        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putBoolean("firstTime", false);
        editor.commit();
        Dialog d2 = new Dialog(this);
        d2.setTitle("HELP");
        d2.setCanceledOnTouchOutside(true);
        TextView tv = new TextView(this);
        tv.setText(
                "This application can be used to store your timetable.First,click on Manage Subjects Icon(Wrench Icon) inorder to add all your subjects.Click on Add Subjects on top and enter the details of your subject.The fields that appear are optional and not manditory.Once you have added all the subjects,go back to the main screen and click on Add Classes icon(Plus Icon) to add the different classes to your timetable.The fields that appear are again optional and all of them need not be filled.You can long press on any particular subject to edit or delete them.You can delete all the informations using Delete All(Garbage Icon) option.");
        ScrollView sav = new ScrollView(this);
        sav.addView(tv);
        LayoutParams lap = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        d2.addContentView(sav, lap);
        d2.show();
    }

    boolean enabled = true;

    Bar.setHomeButtonEnabled(enabled);

    //File database=getApplicationContext().getDatabasePath("massey.db");
    // if (database.exists()) {
    data = new InternalDB(this);
    // }

    // add fragments
    mFragments = new ArrayList<Fragment>();

    mFragments.add(Fragment.instantiate(this, MONDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, TUESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, WEDNESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, THURSDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, FRIDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, SATURDAYFRAGMENT));

    // adapter
    mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);

    // pager
    mPager = (ViewPager) findViewById(R.id.view_pager);

    mPager.setAdapter(mAdapter);

    // indicator
    mIndicator = (TitlePageIndicator) findViewById(R.id.title_indicator);

    //mIndicator.setBackgroundColor(0x0106000e);
    //mIndicator.setFooterColor(0xffffff);
    mIndicator.setTextColor(0xFF000000);
    mIndicator.setSelectedColor(0xFF000000);
    mIndicator.setViewPager(mPager);

    intent = new Intent(getApplicationContext(), AddSubjects.class);//intent = new Intent(getApplicationContext(), AddSubjects.class);

    builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to delete all lessons?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteAllHours();
                    data.close();
                    // update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert = builder.create();

    builder2 = new AlertDialog.Builder(this);
    builder2.setMessage("Are you sure you want to delete this lesson?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteHour(OLDSName, OLDHDay, OLDHType, OLDHClass, OLDHStart, OLDHEnd);
                    data.close();
                    //update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert2 = builder2.create();

    //added

    addDialog = new Dialog(this);
    addDialog.setCancelable(false);
    action = "insert";
    addDialog.setTitle("Add Class");
    addDialog.setContentView(R.layout.timetable_addhour);

    HType = (EditText) addDialog.findViewById(R.id.typeEdit);
    HClass = (EditText) addDialog.findViewById(R.id.classroomEdit);
    arraydays = new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    HDay = (Spinner) addDialog.findViewById(R.id.day);
    arrayadapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraydays);
    arrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    HDay.setAdapter(arrayadapter);
    HDay.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedDay = arraydays[position];
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    fromDialog = new TimePickerDialog(this, fromTimeSetListener, 12, 0, true);
    toDialog = new TimePickerDialog(this, toTimeSetListener, 12, 0, true);

    //This place is important.

    SName = (Spinner) addDialog.findViewById(R.id.SName);
    SName.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedSubject = (String) arraySubjects[position];
            Log.d("AB", "We are inside the setOnItemSelectedListener for Sname : 264");
            Log.d("AB", selectedSubject);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    Button buttonFrom = (Button) addDialog.findViewById(R.id.buttonFrom);
    buttonFrom.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            fromDialog.show();
        }
    });

    Button buttonTo = (Button) addDialog.findViewById(R.id.buttonTo);
    buttonTo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toDialog.show();
        }
    });

    start = (TextView) addDialog.findViewById(R.id.start);
    end = (TextView) addDialog.findViewById(R.id.end);

    Button cancel = (Button) addDialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
        }

    });

    Button ok = (Button) addDialog.findViewById(R.id.ok);
    ok.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            int HDay = SDay2IDay(selectedDay);
            if (action.equals("insert")) {
                data.open();
                data.insertIntoHours(selectedSubject, HDay, HType.getText().toString(),
                        HClass.getText().toString(), start.getText().toString(), end.getText().toString());
                data.close();
            } else if (action.equals("edit")) {
                data.open();
                data.updateHours(OLDSName, OLDHType, OLDHClass, OLDHDay, OLDHStart, OLDHEnd, selectedSubject,
                        HDay, HType.getText().toString(), HClass.getText().toString(),
                        start.getText().toString(), end.getText().toString());
                data.close();
            }
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
            mAdapter.notifyDataSetChanged();
            //update();
            mAdapter.finishUpdate(mPager);
        }
    });

}

From source file:com.untie.daywal.activity.MainActivity.java

private void showDayPicker() {

    Calendar calender = Calendar.getInstance();
    pickedYear = calender.get(Calendar.YEAR);
    pickedMonth = calender.get(Calendar.MONTH) + 1;
    final Dialog dayPickerDialog = new Dialog(this);
    dayPickerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dayPickerDialog.setContentView(R.layout.dialog);
    Button okBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_ok);
    Button cancelBtn = (Button) dayPickerDialog.findViewById(R.id.birthday_btn_cancel);
    dialog_year_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_year_title);
    dialog_month_title = (TextView) dayPickerDialog.findViewById(R.id.dialog_month_title);
    final NumberPicker yearPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.yearPicker);
    final NumberPicker monthPicker = (NumberPicker) dayPickerDialog.findViewById(R.id.monthPicker);

    dialog_year_title.setText(String.valueOf(pickedYear) + "");
    dialog_month_title.setText(String.valueOf(pickedMonth) + "");
    yearPicker.setMinValue(pickedYear - 100);
    yearPicker.setMaxValue(pickedYear + 40);
    yearPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(yearPicker, android.R.color.white );
    yearPicker.setWrapSelectorWheel(false);
    yearPicker.setValue(pickedYear);/*from w ww .  j a  v  a 2  s.c  om*/
    yearPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_year_title.setText(String.valueOf(newVal) + "");
        }
    });

    monthPicker.setMinValue(1);
    monthPicker.setMaxValue(12);
    monthPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    //   setDividerColor(monthPicker, android.R.color.white);
    //monthPicker.setWrapSelectorWheel(false);
    monthPicker.setValue(pickedMonth);
    monthPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
            dialog_month_title.setText(String.valueOf(newVal) + "");
        }
    });

    okBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //TODO :  ?? yearPicker.getValue() monthPicker.getValue()

            //Toast.makeText(MainActivity.this, String.valueOf(yearPicker.getValue())+"/"+monthPicker.getValue(), Toast.LENGTH_SHORT).show();

            Intent intent = new Intent(MainActivity.this, MainActivity.class);
            intent.putExtra("year", yearPicker.getValue());
            intent.putExtra("month", monthPicker.getValue());
            intent.putExtra("order", 1);
            dayPickerDialog.dismiss();
            startActivity(intent);
            overridePendingTransition(0, 0);

        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dayPickerDialog.dismiss();
        }
    });
    dayPickerDialog.show();

}

From source file:com.github.tetravex_android.activity.SettingsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Navigate up to app's home screen
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.action_reset_scores:
        // reset the scores database
        DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
            @Override/*from  w  w w.j a v  a  2  s .c om*/
            public void onClick(DialogInterface dialog, int userChoice) {
                switch (userChoice) {
                case DialogInterface.BUTTON_POSITIVE:
                    // reset the scores database
                    deleteAllScores();
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    break;
                }
            }
        };

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.dialog_reset_scores_prompt));
        builder.setPositiveButton(getResources().getString(R.string.dialog_ok), dialogClickListener);
        builder.setNegativeButton(getResources().getString(R.string.dialog_cancel), dialogClickListener);
        builder.show();
        return true;
    case R.id.action_about:
        Dialog dialog = new Dialog(this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_about);

        TextView linkText = (TextView) dialog.findViewById(R.id.legal_link);
        linkText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingsActivity.this, LegalActivity.class);
                startActivity(intent);
            }
        });

        dialog.setCancelable(true);
        dialog.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:edu.cwru.apo.Directory.java

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnCall:
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + lastPhone));
        startActivity(intent);//from   ww  w. j a  v a  2s.c o m
        break;

    case R.id.btnText:
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", lastPhone, null)));
        break;

    default:
        String text = ((TextView) v).getText().toString();
        int start = text.lastIndexOf('[');
        int end = text.lastIndexOf(']');
        String caseID = text.substring(start + 1, end);
        Cursor results = database.query("phoneDB", new String[] { "first", "last", "_id", "phone" }, "_id = ?",
                new String[] { caseID }, null, null, null);
        if (results.getCount() != 1) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Error Loading Phone Number").setCancelable(false).setNeutralButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            results.moveToFirst();

            phoneDialog = new Dialog(this);
            phoneDialog.setContentView(R.layout.phone_dialog);
            phoneDialog.setTitle(results.getString(0) + " " + results.getString(1));

            TextView phoneText = (TextView) phoneDialog.findViewById((R.id.phoneText));
            String phoneNumber = removeNonDigits(results.getString(3));
            if (phoneNumber == null || phoneNumber.trim().equals("") || phoneNumber.trim().equals("null")) {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(false);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(false);
                phoneNumber = "not available";
            } else {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setOnClickListener(this);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setOnClickListener(this);
            }
            lastPhone = phoneNumber;
            phoneText.setText("Phone Number: " + lastPhone);
            phoneDialog.show();
        }
        break;
    }
}

From source file:com.memetro.android.MainActivity.java

public void showRecoverPassDialog(final Context context) {

    final Dialog mDialog = new Dialog(context);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setContentView(R.layout.dialog_recover);
    mDialog.setCancelable(true);//from w  w w. j  a v a 2 s  .c o m

    final EditText emailText = (EditText) mDialog.findViewById(R.id.email);
    Button sendButton = (Button) mDialog.findViewById(R.id.send);

    sendButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            RecoverPassUtils.recoverPass(context, emailText.getText().toString(), new OAuthHandler() {
                public void onStart() {
                    pdialog.show();
                }

                public void onSuccess() {
                    mDialog.dismiss();
                    MemetroDialog.showDialog(MainActivity.this, null, getString(R.string.recover_ok));
                }

                public void onFailure() {
                    MemetroDialog.showDialog(MainActivity.this, null, getString(R.string.recover_ko));
                }

                public void onFinish() {
                    pdialog.dismiss();
                }
            });
        }
    });

    mDialog.show();
}

From source file:com.digium.respoke.GroupListActivity.java

@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();
    if (id == R.id.action_join) {
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog_join_group);
        dialog.setTitle("Join a group");

        Button dialogButton = (Button) dialog.findViewById(R.id.button1);
        TextView errorText = (TextView) dialog.findViewById(R.id.errorText);
        errorText.setText("");

        // if button is clicked, close the custom dialog
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override/*from  w  ww. ja  v  a 2  s  . com*/
            public void onClick(View v) {
                Button connectButton = (Button) dialog.findViewById(R.id.button1);
                ProgressBar progressCircle = (ProgressBar) dialog.findViewById(R.id.progress_circle);
                EditText userInput = (EditText) dialog.findViewById(R.id.editTextDialogUserInput);
                String groupID = userInput.getText().toString();

                if (groupID.length() > 0) {
                    TextView errorText = (TextView) dialog.findViewById(R.id.errorText);
                    errorText.setText("");
                    connectButton.setText("");
                    progressCircle.setVisibility(View.VISIBLE);

                    ContactManager.sharedInstance().joinGroup(groupID, new Respoke.TaskCompletionListener() {
                        @Override
                        public void onSuccess() {
                            dialog.dismiss();
                        }

                        @Override
                        public void onError(final String errorMessage) {
                            Button connectButton = (Button) dialog.findViewById(R.id.button1);
                            ProgressBar progressCircle = (ProgressBar) dialog
                                    .findViewById(R.id.progress_circle);
                            TextView errorText = (TextView) dialog.findViewById(R.id.errorText);

                            errorText.setText(errorMessage);
                            connectButton.setText("Connect");
                            progressCircle.setVisibility(View.INVISIBLE);
                        }
                    });
                } else {
                    TextView errorText = (TextView) dialog.findViewById(R.id.errorText);
                    errorText.setText("Group name may not be blank");
                }
            }
        });

        dialog.show();

        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getActivity() != null) {
        final Dialog dialog = new Dialog(getActivity());
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.activity_image_zoom);
        dialog.getWindow().setBackgroundDrawableResource(R.color.Transparent);
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.copyFrom(dialog.getWindow().getAttributes());
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        dialog.getWindow().setAttributes(layoutParams);
        initToolbar(dialog);/* w  w w .  j av a  2 s  .c  o  m*/
        progressBar = dialog.findViewById(R.id.zoom_loader);
        zoomableImageView = (PhotoView) dialog.findViewById(R.id.image_zoom_photoview);
        if (bitmap != null) {
            if (rect != null) {
                animateIn(dialog);
            }
        } else if (fileUri != null) {
            showLoader();
            Glide.with(getActivity()).load(fileUri).fitCenter()
                    .listener(new RequestListener<Uri, GlideDrawable>() {
                        @Override
                        public boolean onException(Exception e, Uri model, Target<GlideDrawable> target,
                                boolean isFirstResource) {
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(GlideDrawable resource, Uri model,
                                Target<GlideDrawable> target, boolean isFromMemoryCache,
                                boolean isFirstResource) {
                            hideLoader();
                            return false;
                        }
                    }).into(zoomableImageView);
        } else {
            dismiss();
        }
        photoViewAttacher = new PhotoViewAttacher(zoomableImageView);
        photoViewAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                dismiss();
            }
        });
        return dialog;
    } else {
        return null;
    }
}

From source file:com.ivalentin.margolariak.SettingsLayout.java

private void showDialog(String title, String text) {
    //Create the dialog
    final Dialog dialog = new Dialog(getActivity());

    //Set up dialog window
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_settings);

    //Set the custom dialog components - text, image and button
    TextView tvTitle = (TextView) dialog.findViewById(R.id.tv_dialog_settings_title);
    WebView wvText = (WebView) dialog.findViewById(R.id.wv_dialog_settings_text);

    if (Build.VERSION.SDK_INT >= 19) {
        wvText.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else {/*from w ww  .j av a 2s. co  m*/
        wvText.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    Button btClose = (Button) dialog.findViewById(R.id.bt_dialog_settings_close);

    //Set text
    tvTitle.setText(title);
    wvText.loadDataWithBaseURL(null, text, "text/html", "utf-8", null);

    //Set close button
    btClose.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    //Set parameters
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.CENTER;
    lp.dimAmount = 0.4f;
    dialog.getWindow().setAttributes(lp);

    //Show dialog
    dialog.show();

}