Java Code Examples for androidx.appcompat.app.AlertDialog#setMessage()

The following examples show how to use androidx.appcompat.app.AlertDialog#setMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DoodleDrawActivity.java    From djl-demo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        paintView.init(metrics, imageView, textView, predictor);
        progressBar.setVisibility(View.GONE);
        containerView.setVisibility(View.VISIBLE);
    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(DoodleDrawActivity.this).create();
        alertDialog.setTitle("Error");
        alertDialog.setMessage("Failed to load model");
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                (dialog, which) -> finish());
    }
}
 
Example 2
Source File: MainActivity.java    From cythara with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    if (requestCode == RECORD_AUDIO_PERMISSION) {
        if (grantResults.length > 0) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                startRecording();
            } else {
                AlertDialog alertDialog = new Builder(MainActivity.this).create();
                alertDialog.setTitle(R.string.permission_required);
                alertDialog.setMessage(getString(R.string.microphone_permission_required));
                alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok),
                        (dialog, which) -> {
                            dialog.dismiss();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                                finishAffinity();
                            } else {
                                finish();
                            }
                        });
                alertDialog.show();
            }
        }
    }
}
 
Example 3
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 6 votes vote down vote up
public void homepageTutorial() {
    if (!sp.getBoolean("homepageLearned", false)) {
        AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.setTitle(context.getString(R.string.home));
        dialog.setMessage(context.getString(R.string.homePageHelp));
        dialog.setCancelable(false);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
                (dialog1, buttonId) -> {
                    dialog1.dismiss();
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("homepageLearned", true);
                    editor.apply();
                });
        dialog.show();
    }
}
 
Example 4
Source File: SortFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
public void onItemDismiss(final int position) {
    final Times times = Times.getTimesAt(position);

    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);
    dialog.setMessage(getString(R.string.delCityConfirm, times.getName()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> {
        times.delete();
        mAdapter.notifyItemRemoved(position);
    });
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> {
        dialogInterface.cancel();
        mAdapter.notifyDataSetChanged();
    });
    dialog.show();
}
 
Example 5
Source File: SortFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
public void onItemDismiss(final int position) {
    final Times times = Times.getTimesAt(position);

    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);
    dialog.setMessage(getString(R.string.delCityConfirm, times.getName()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> {
        times.delete();
        mAdapter.notifyItemRemoved(position);
    });
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> {
        dialogInterface.cancel();
        mAdapter.notifyDataSetChanged();
    });
    dialog.show();
}
 
Example 6
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 6 votes vote down vote up
public void homepageTutorial() {
    if (!sp.getBoolean("homepageLearned", false)) {
        AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.setTitle(context.getString(R.string.home));
        dialog.setMessage(context.getString(R.string.homePageHelp));
        dialog.setCancelable(false);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
                (dialog1, buttonId) -> {
                    dialog1.dismiss();
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("homepageLearned", true);
                    editor.apply();
                });
        dialog.show();
    }
}
 
Example 7
Source File: FormFragment.java    From shaky-android with Apache License 2.0 6 votes vote down vote up
/**
 * Validates the message and returns true if the form is valid.
 */
private boolean validate(@NonNull String message) {
    if (message.trim().length() == 0) {
        AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
        alertDialog.setMessage(getString(R.string.shaky_empty_feedback_message));
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.shaky_empty_feedback_confirm),
                              new DialogInterface.OnClickListener() {
                                  public void onClick(DialogInterface dialog, int which) {
                                      dialog.dismiss();
                                  }
                              });
        alertDialog.show();
        return false;
    }

    return true;
}
 
Example 8
Source File: MainActivity.java    From Once with Apache License 2.0 5 votes vote down vote up
private void showDialog(String message) {
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setMessage(message);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
}
 
Example 9
Source File: AddMembersActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static void updateAlertMessage(@NonNull AlertDialog alertDialog, @NonNull AddMembersViewModel.AddMemberDialogMessageState state) {
  Context   context   = alertDialog.getContext();
  Recipient recipient = Util.firstNonNull(state.getRecipient(), Recipient.UNKNOWN);

  alertDialog.setMessage(context.getResources().getQuantityString(R.plurals.AddMembersActivity__add_d_members_to_s, state.getSelectionCount(),
                                                                  recipient.getDisplayName(context), state.getGroupTitle(), state.getSelectionCount()));
}
 
Example 10
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 5 votes vote down vote up
private void show_noVideo_dialog() {
    AlertDialog dialog = new AlertDialog.Builder(context/**/).create();
    dialog.setTitle(context.getString(R.string.error_no_video));
    dialog.setMessage(context.getString(R.string.error_select_video_and_retry));
    dialog.setCancelable(true);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(),
            (dialog1, buttonId) -> dialog1.dismiss());
    dialog.show();
}
 
Example 11
Source File: DhikrFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private void deleteDhikr() {
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);
    dialog.setMessage(getString(R.string.delConfirmDhikr, mDhikrs.get(0).getTitle()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> mViewModel.deleteDhikr(mDhikrs.get(0)));
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> {
    });
    dialog.show();
}
 
Example 12
Source File: MenuHelper.java    From webTube with GNU General Public License v3.0 5 votes vote down vote up
private void show_noVideo_dialog() {
    AlertDialog dialog = new AlertDialog.Builder(context/**/).create();
    dialog.setTitle(context.getString(R.string.error_no_video));
    dialog.setMessage(context.getString(R.string.error_select_video_and_retry));
    dialog.setCancelable(true);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(),
            (dialog1, buttonId) -> dialog1.dismiss());
    dialog.show();
}
 
Example 13
Source File: DhikrFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private void deleteDhikr() {
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);
    dialog.setMessage(getString(R.string.delConfirmDhikr, mDhikrs.get(0).getTitle()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> mViewModel.deleteDhikr(mDhikrs.get(0)));
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> {
    });
    dialog.show();
}
 
Example 14
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}
 
Example 15
Source File: MainActivity.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    String lang = LocaleUtils.getLanguage("en", "de", "tr");
    final String file = lang + "/hadis.db";
    final String url = App.API_URL + "/files/hadis." + lang + ".db";
    File f = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file);
    
    
    if (f.exists()) {
        try {
            if (SqliteHelper.get().getCount() == 0) {
                SqliteHelper.get().close();
                ((Object) null).toString();
            }
        } catch (Exception e) {
            if (f.exists() && !f.delete()) {
                Log.e("BaseActivity", "could not delete " + f.getAbsolutePath());
            }
            finish();
        }
        setDefaultFragment(new HadithFragment());
        moveToFrag(getDefaultFragment());
    } else if (!App.isOnline()) {
        Toast.makeText(this, R.string.no_internet, Toast.LENGTH_SHORT).show();
    } else {
        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle(R.string.hadith);
        dialog.setMessage(getString(R.string.dlHadith));
        dialog.setCancelable(false);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> {

            File f1 = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file);


            if (!f1.getParentFile().mkdirs()) {
                Log.e("BaseActivity", "could not mkdirs " + f1.getParent());
            }
            final ProgressDialog dlg = new ProgressDialog(MainActivity.this);
            dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dlg.setCancelable(false);
            dlg.setCanceledOnTouchOutside(false);
            dlg.show();
            Ion.with(MainActivity.this).load(url).progressDialog(dlg).write(f1).setCallback((e, result) -> {

                dlg.dismiss();
                if (e != null) {
                    e.printStackTrace();
                    Crashlytics.logException(e);
                    Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_LONG).show();
                    finish();
                } else if (result.exists()) {
                    openHadithFrag();
                }
            });
        });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> dialogInterface.cancel());
        dialog.show();
    }
    
}
 
Example 16
Source File: MainActivity.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    String lang = LocaleUtils.getLanguage("en", "de", "tr");
    final String file = lang + "/hadis.db";
    final String url = App.API_URL + "/files/hadis." + lang + ".db";
    File f = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file);
    
    
    if (f.exists()) {
        try {
            if (SqliteHelper.get().getCount() == 0) {
                SqliteHelper.get().close();
                ((Object) null).toString();
            }
        } catch (Exception e) {
            if (f.exists() && !f.delete()) {
                Log.e("BaseActivity", "could not delete " + f.getAbsolutePath());
            }
            finish();
        }
        setDefaultFragment(new HadithFragment());
        moveToFrag(getDefaultFragment());
    } else if (!App.isOnline()) {
        Toast.makeText(this, R.string.no_internet, Toast.LENGTH_SHORT).show();
    } else {
        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle(R.string.hadith);
        dialog.setMessage(getString(R.string.dlHadith));
        dialog.setCancelable(false);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes), (dialogInterface, i) -> {

            File f1 = new File(App.get().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), file);


            if (!f1.getParentFile().mkdirs()) {
                Log.e("BaseActivity", "could not mkdirs " + f1.getParent());
            }
            final ProgressDialog dlg = new ProgressDialog(MainActivity.this);
            dlg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dlg.setCancelable(false);
            dlg.setCanceledOnTouchOutside(false);
            dlg.show();
            Ion.with(MainActivity.this).load(url).progressDialog(dlg).write(f1).setCallback((e, result) -> {

                dlg.dismiss();
                if (e != null) {
                    e.printStackTrace();
                    Crashlytics.logException(e);
                    Toast.makeText(MainActivity.this, R.string.error, Toast.LENGTH_LONG).show();
                    finish();
                } else if (result.exists()) {
                    openHadithFrag();
                }
            });
        });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no), (dialogInterface, i) -> dialogInterface.cancel());
        dialog.show();
    }
    
}
 
Example 17
Source File: MainActivity.java    From YouTube-In-Background with MIT License 4 votes vote down vote up
/**
 * Handles selected item from action bar
 *
 * @param item the selected item from the action bar
 * @return boolean
 */
@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();
    Locale locale = getResources().getConfiguration().locale;

    //noinspection SimplifiableIfStatement
    switch (id) {
        case R.id.action_about:
            DateFormat monthFormat = new SimpleDateFormat("MMMM", locale);
            DateFormat yearFormat = new SimpleDateFormat("yyyy", locale);
            Date date = new Date();

            AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
            alertDialog.setTitle("Teocci");
            alertDialog.setIcon(R.mipmap.ic_launcher);
            alertDialog.setMessage(
                    "Dedicated to the person who gives me a reason to smile even on the dullest of days." + ".\n" +
                    "누리 고마워~ Thanks for been in my life." + "\n\n" +
                    "YiB v" + BuildConfig.VERSION_NAME + "\n\[email protected]\n\n" +
                            monthFormat.format(date) + " " + yearFormat.format(date) + ".\n"
            );
            alertDialog.setButton(
                    AlertDialog.BUTTON_NEUTRAL,
                    "OK",
                    (dialog, which) -> dialog.dismiss()
            );
            alertDialog.show();

            return true;
        case R.id.action_clear_list:
            YouTubeSqlDb.getInstance()
                    .videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED)
                    .deleteAll();
            recentlyPlayedFragment.clearRecentlyPlayedList();
            return true;
        case R.id.action_remove_account:
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
            String chosenAccountName = sp.getString(ACCOUNT_NAME, null);

            if (chosenAccountName != null) {
                sp.edit().remove(ACCOUNT_NAME).apply();
            }
            return true;
        case R.id.action_search:
            item.expandActionView();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 18
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}