Example usage for android.app AlertDialog setView

List of usage examples for android.app AlertDialog setView

Introduction

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

Prototype

public void setView(View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight,
        int viewSpacingBottom) 

Source Link

Document

Set the view to display in that dialog, specifying the spacing to appear around that view.

Usage

From source file:com.ninetwozero.battlelog.MainActivity.java

public final Dialog createChangelogDialog() {

    // Attributes
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.changelog_dialog, (ViewGroup) findViewById(R.id.dialog_root));

    // Set the title and the view
    builder.setTitle(getString(R.string.general_changelog_version).replace("{version}",
            Constants.CHANGELOG_VERSION + ""));

    // Grab the fields
    final TextView textView = (TextView) layout.findViewById(R.id.text_changelog);
    textView.setText(Html.fromHtml(getString(R.string.changelog)));

    // Set the button
    builder.setPositiveButton(/*from   w  w w .  ja  v a 2  s . com*/

            android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                    sharedPreferences.edit().putInt(Constants.SP_V_CHANGELOG, Constants.CHANGELOG_VERSION)
                            .commit();

                }

            }

    );

    // CREATE
    AlertDialog theDialog = builder.create();
    theDialog.setView(layout, 0, 0, 0, 0);
    return theDialog;

}

From source file:abanoubm.dayra.main.Main.java

private void register() {
    LayoutInflater li = LayoutInflater.from(getApplicationContext());
    final View view = li.inflate(R.layout.dialogue_create, null, false);
    final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
    ad.setView(view, 0, 0, 0, 0);
    ad.show();/*from   ww w.  j a v  a  2  s.co m*/

    view.findViewById(R.id.yesBtn).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String str = ((EditText) view.findViewById(R.id.input)).getText().toString().trim();

            if (Utility.isInvlaidDBName(str)) {
                Toast.makeText(getApplicationContext(), R.string.err_msg_dayra_name, Toast.LENGTH_SHORT).show();
            } else {

                if (DB.isDBExists(getApplicationContext(), str)) {
                    Toast.makeText(getApplicationContext(), R.string.err_msg_duplicate_dayra,
                            Toast.LENGTH_SHORT).show();
                } else {
                    new RegisterTask().execute(str);
                    ad.dismiss();

                }
            }
        }
    });

}

From source file:abanoubm.dayra.main.Main.java

private void sign() {
    String inpath;//from www  .j  av a  2 s.  com
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        inpath = getApplicationContext().getApplicationInfo().dataDir + "/databases/";
    } else {
        inpath = "/data/data/" + getApplicationContext().getPackageName() + "/databases/";
    }
    File folder = new File(inpath);
    File[] listOfFiles = folder.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        Toast.makeText(getApplicationContext(), R.string.msg_no_dayra, Toast.LENGTH_SHORT).show();
    } else {
        ArrayList<String> names = new ArrayList<>(listOfFiles.length);
        for (File file : listOfFiles) {
            if (!file.getName().contains("journal"))
                names.add(file.getName());
        }

        LayoutInflater li = LayoutInflater.from(getApplicationContext());
        View signView = li.inflate(R.layout.dialogue_signin, null, false);
        final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
        ad.setView(signView, 0, 0, 0, 0);
        ad.show();

        ListView nameslv = (ListView) signView.findViewById(R.id.databases_lv);
        nameslv.setAdapter(new ArrayAdapter<>(getApplicationContext(), R.layout.item_string, R.id.item, names));

        nameslv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String str = (String) parent.getItemAtPosition(position);
                new SignTask().execute(str);
                ad.dismiss();
            }
        });

    }

}

From source file:abanoubm.dayra.main.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (Utility.getArabicLang(getApplicationContext()) == 1) {
        Utility.setArabicLang(getApplicationContext(), 2);

        Locale myLocale = new Locale("ar");
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;/*from   w  w  w  . j  a v a2s.  c  o  m*/
        res.updateConfiguration(conf, dm);

        finish();
        startActivity(new Intent(getIntent()));
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_main);
    ((TextView) findViewById(R.id.subhead1)).setText(R.string.app_name);
    ((TextView) findViewById(R.id.subhead2)).setText(BuildConfig.VERSION_NAME);
    findViewById(R.id.nav_back).setOnClickListener(new View.OnClickListener() {

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

        }
    });
    ((TextView) findViewById(R.id.footer)).setText("dayra " + BuildConfig.VERSION_NAME + " @"
            + new SimpleDateFormat("yyyy", Locale.getDefault()).format(new Date()) + " Abanoub M.");

    if (!Utility.getDayraName(getApplicationContext()).equals("")) {
        startActivity(new Intent(getApplicationContext(), Home.class));
        finish();
    }

    ListView lv = (ListView) findViewById(R.id.home_list);

    mMenuItemAdapter = new MenuItemAdapter(getApplicationContext(),
            new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.sign_menu))), 1);
    lv.setAdapter(mMenuItemAdapter);

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                sign();
                break;
            case 1:
                register();
                break;
            case 2:
                if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this,
                        Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    importDB();
                } else {
                    ActivityCompat.requestPermissions(Main.this,
                            new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, IMPORT_REQUEST);
                }
                break;
            case 3:
                startActivity(new Intent(Intent.ACTION_VIEW).setData(
                        Uri.parse("https://drive.google.com/file/d/0B1rNCm5K9cvwVXJTTzNqSFdrVk0/view")));
                break;
            case 4:
                startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(
                        "https://drive.google.com/open?id=1flSRdoiIT_hNd96Kxz3Ww3EhXDLZ45FhwFJ2hF9vl7g")));
                break;
            case 5: {

                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                builder.setTitle(R.string.label_choose_language);
                builder.setItems(getResources().getStringArray(R.array.language_menu),
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String temp;
                                if (which == 1) {
                                    temp = "en";
                                    Utility.setArabicLang(getApplicationContext(), 0);
                                } else {
                                    temp = "ar";
                                    Utility.setArabicLang(getApplicationContext(), 2);
                                }
                                Locale myLocale = new Locale(temp);
                                Resources res = getResources();
                                DisplayMetrics dm = res.getDisplayMetrics();
                                Configuration conf = res.getConfiguration();
                                conf.locale = myLocale;
                                res.updateConfiguration(conf, dm);

                                finish();
                                startActivity(new Intent(getIntent()));
                            }

                        });
                builder.create().show();

            }
                break;
            case 6:
                try {
                    getPackageManager().getPackageInfo("com.facebook.katana", 0);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/453595434816965"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/dayraapp"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;

            case 7:

                try {
                    getPackageManager().getPackageInfo("com.facebook.katana", 0);
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1363784786"))
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/EngineeroBono"))
                                    .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
            case 8:
                Uri uri = Uri.parse("market://details?id=" + getPackageName());
                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                try {
                    startActivity(goToMarket);
                } catch (Exception e) {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
                }
                break;
            case 9:
                if (Build.VERSION.SDK_INT < 23 || ContextCompat.checkSelfPermission(Main.this,
                        android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*");
                    startActivity(
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                } else {
                    ActivityCompat.requestPermissions(Main.this,
                            new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            FOLDER_REQUEST);
                }
                break;
            case 10:
                LayoutInflater li = LayoutInflater.from(getApplicationContext());
                final View aboutView = li.inflate(R.layout.dialogue_about, null, false);
                final AlertDialog ad = new AlertDialog.Builder(Main.this).setCancelable(true).create();
                ad.setView(aboutView, 0, 0, 0, 0);
                ad.show();
                ((TextView) aboutView.findViewById(R.id.about))
                        .setText(String.format(getResources().getString(R.string.copyright),
                                Calendar.getInstance().get(Calendar.YEAR)));

                ((TextView) aboutView.findViewById(R.id.notice)).setText(GoogleApiAvailability.getInstance()
                        .getOpenSourceSoftwareLicenseInfo(getApplicationContext()));
                aboutView.findViewById(R.id.btn).setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ad.cancel();
                    }
                });
                break;
            }
        }
    });

}

From source file:org.smap.smapTask.android.activities.MainTabsActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case PROGRESS_DIALOG:
        mProgressDialog = new ProgressDialog(this);
        DialogInterface.OnClickListener loadingButtonListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();/* w  w  w .ja  va  2s  .c o m*/
                mDownloadTasks.setDownloaderListener(null, mContext);
                mDownloadTasks.cancel(true);
                // Refresh the task list
                Intent intent = new Intent("refresh");
                LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
            }
        };
        mProgressDialog.setTitle(getString(R.string.downloading_data));
        mProgressDialog.setMessage(mProgressMsg);
        mProgressDialog.setIcon(android.R.drawable.ic_dialog_info);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setCancelable(false);
        mProgressDialog.setButton(getString(R.string.cancel), loadingButtonListener);
        return mProgressDialog;
    case ALERT_DIALOG:
        mAlertDialog = new AlertDialog.Builder(this).create();
        mAlertDialog.setMessage(mAlertMsg);
        mAlertDialog.setTitle(getString(R.string.smap_get_tasks));
        DialogInterface.OnClickListener quitListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int i) {
                dialog.dismiss();
            }
        };
        mAlertDialog.setCancelable(false);
        mAlertDialog.setButton(getString(R.string.ok), quitListener);
        mAlertDialog.setIcon(android.R.drawable.ic_dialog_info);
        return mAlertDialog;
    case PASSWORD_DIALOG:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final AlertDialog passwordDialog = builder.create();

        passwordDialog.setTitle(getString(R.string.enter_admin_password));
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
        input.setTransformationMethod(PasswordTransformationMethod.getInstance());
        passwordDialog.setView(input, 20, 10, 20, 10);

        passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        String pw = mAdminPreferences.getString(AdminPreferencesActivity.KEY_ADMIN_PW, "");
                        if (pw.compareTo(value) == 0) {
                            Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                            startActivity(i);
                            input.setText("");
                            passwordDialog.dismiss();
                        } else {
                            Toast.makeText(MainTabsActivity.this, getString(R.string.admin_password_incorrect),
                                    Toast.LENGTH_SHORT).show();
                            Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                    "PASSWORD_INCORRECT");
                        }
                    }
                });

        passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                "cancel");
                        input.setText("");
                        return;
                    }
                });

        passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return passwordDialog;
    }
    return null;
}

From source file:roommateapp.info.droid.ActivityBuilding.java

/**
 * Show symbol legend./*from w  w w .j a v a  2 s  . c  o m*/
 */
public void showSymbolLegend() {

    AlertDialog.Builder legende = new AlertDialog.Builder(this);
    legende.setTitle(getString(R.string.legend_hl));

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog_legende, null);

    AlertDialog alert = legende.create();
    alert.setView(layout, 0, 0, 0, 0);
    alert.show();
}

From source file:org.odk.collect.android.activities.MainMenuActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case PASSWORD_DIALOG:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final AlertDialog passwordDialog = builder.create();
        passwordDialog.setTitle(getString(R.string.enter_admin_password));
        LayoutInflater inflater = this.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialogbox_layout, null);
        passwordDialog.setView(dialogView, 20, 10, 20, 10);
        final CheckBox checkBox = (CheckBox) dialogView.findViewById(R.id.checkBox);
        final EditText input = (EditText) dialogView.findViewById(R.id.editText);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override//from  ww  w.  jav a  2  s .  co  m
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!checkBox.isChecked()) {
                    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                } else {
                    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
        passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        String pw = adminPreferences.getString(AdminKeys.KEY_ADMIN_PW, "");
                        if (pw.compareTo(value) == 0) {
                            Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                            startActivity(i);
                            input.setText("");
                            passwordDialog.dismiss();
                        } else {
                            ToastUtils.showShortToast(R.string.admin_password_incorrect);
                            Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                    "PASSWORD_INCORRECT");
                        }
                    }
                });

        passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog",
                                "cancel");
                        input.setText("");
                        return;
                    }
                });

        passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        return passwordDialog;

    }
    return null;
}

From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java

public Dialog generateDialogLinkList(final Context context, final List<String> links) {

    // Attributes
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.dialog_thread_link,
            (ViewGroup) getActivity().findViewById(R.id.dialog_root));

    // Set the title
    builder.setTitle(R.string.info_forum_link_title);

    // Dialog options
    builder.setNegativeButton(//w w  w . j av  a2  s . c  o m

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

                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();

                }

            }

    );

    // Padding fix
    final AlertDialog theDialog = builder.create();
    theDialog.setView(layout, 0, 0, 0, 0);

    // Grab the fields
    ListView listView = (ListView) layout.findViewById(R.id.list_links);
    listView.setAdapter(new ArrayAdapter<String>(context, R.layout.list_item_plain, android.R.id.text1, links));
    listView.setOnItemClickListener(

            new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

                    // Get the current link
                    String currentLink = links.get(arg2);
                    new AsyncLinkHandling(context).execute(currentLink,
                            sharedPreferences.getString(Constants.SP_BL_PROFILE_CHECKSUM, ""));

                    // Dismiss the dialog
                    theDialog.dismiss();

                }

            }

    );

    return theDialog;

}

From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java

public Dialog generateDialogPage(final Context context) {

    // Attributes
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.dialog_thread_page_select,
            (ViewGroup) ((Activity) context).findViewById(R.id.dialog_root));

    // Set the title and the view
    builder.setTitle(R.string.info_txt_pageselect);
    builder.setView(layout);/*from  www.  j a  va 2 s. co  m*/

    // How many pages do we have?
    if (pageArray == null || (pageArray.length != threadData.getNumPages())) {

        pageArray = new Integer[threadData.getNumPages()];
        for (int i = 0, max = pageArray.length; i < max; i++) {

            pageArray[i] = i;

        }

    }

    // Grab the elements
    final TextView textView = (TextView) layout.findViewById(R.id.text_desc);
    final EditText textPage = (EditText) layout.findViewById(R.id.text_page);

    // Set the text
    textView.setText(getString(R.string.info_xml_enternumber).replace("{min}", "1").replace("{max}",
            threadData.getNumPages() + ""));

    // Dialog options
    builder.setPositiveButton(

            android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                    String pageString = textPage.getText().toString();
                    if (!pageString.equals("")) {

                        int page = Integer.parseInt(pageString);
                        if (0 < page && page <= threadData.getNumPages()) {

                            currentPage = page;
                            new AsyncLoadPage(context, threadId).execute(currentPage);

                        } else {

                            Toast.makeText(context, R.string.info_forum_page_invalid, Toast.LENGTH_SHORT)
                                    .show();

                        }

                    }

                }

            }

    );

    // Padding fix
    AlertDialog theDialog = builder.create();
    theDialog.setView(layout, 0, 0, 0, 0);
    return theDialog;

}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

protected void createPasswordDialog() {
    if (mAlertDialog != null) {
        mAlertDialog.dismiss();/*  w  ww  .jav a  2 s  .  c  o m*/
        mAlertDialog = null;
    }
    final AlertDialog passwordDialog = new AlertDialog.Builder(this).create();

    passwordDialog.setTitle(getString(R.string.enter_admin_password));
    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
    input.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordDialog.setView(input, 20, 10, 20, 10);

    passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    String pw = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ADMIN_PW);
                    if (pw != null && pw.compareTo(value) == 0) {
                        Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
                        // TODO: convert this activity into a preferences fragment
                        i.putExtra(APP_NAME, getAppName());
                        startActivity(i);
                        input.setText("");
                        passwordDialog.dismiss();
                    } else {
                        Toast.makeText(MainMenuActivity.this, getString(R.string.admin_password_incorrect),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

    passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    input.setText("");
                    return;
                }
            });

    passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    mAlertDialog = passwordDialog;
    mAlertDialog.show();
}