Java Code Examples for android.support.v7.app.AlertDialog#setTitle()

The following examples show how to use android.support.v7.app.AlertDialog#setTitle() . 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: AddTodoItem.java    From Minitask with Apache License 2.0 6 votes vote down vote up
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    // if the date is in the past tell user to choose again
    if (dateTimeUtils.checkInvalidDate(year, monthOfYear, dayOfMonth)){
        AlertDialog alertDialog = new AlertDialog.Builder(AddTodoItem.this).create();
        alertDialog.setTitle("Date not valid!");
        alertDialog.setIcon(R.drawable.ic_warning_black_24dp);
        alertDialog.setMessage("You are selecting a time a point of time in the past!");
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alertDialog.show();
        return;
    }

    // set date value to the value user selected and change the text
    date = dateTimeUtils.dateToString(year, monthOfYear, dayOfMonth);
    reminderText.setText(getString(R.string.reminder_set_at) + " " + date + " " + time);
}
 
Example 2
Source File: AddTodoItem.java    From Minitask with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
    // if date is not chosen first but time is chosen -> make today the default date.
    // also check for valid time, must be today but not the past hour or minutes.
    if (date.equals(dateTimeUtils.fillDateIfEmpty("")) && dateTimeUtils.checkInvalidTime(hourOfDay, minute)) {
        AlertDialog alertDialog = new AlertDialog.Builder(AddTodoItem.this).create();
        alertDialog.setTitle("Time not valid!");
        alertDialog.setMessage("You are selecting a point of time in the past!");
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alertDialog.show();
        return;
    }

    // set time value and update text
    time = dateTimeUtils.timeToString(hourOfDay, minute);
    reminderText.setText(getString(R.string.reminder_set_at) + " " + date + " " + time);
}
 
Example 3
Source File: MainActivity.java    From LecteurOPUS with GNU General Public License v3.0 6 votes vote down vote up
private void enableReaderMode() {
    Log.i(TAG, "Enabling reader mode");
    Activity activity = this;
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (!nfc.isEnabled()) {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle(getString(R.string.disable_title));
        alertDialog.setMessage(getString(R.string.nfc_disable));
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

                    }
                });
        alertDialog.show();
    }
    else if (nfc != null) {
        nfc.enableReaderMode(activity, mCardReader, FLAG_MIFARE | FLAG_OPUS, null);
    }
}
 
Example 4
Source File: ArticlesFragment.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void showAutoLoginFail() {
    final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
    alertDialog.setTitle(R.string.warning_title);
    alertDialog.setMessage(getString(R.string.tip));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.sure), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            MainActivity main = (MainActivity) getActivity();
            main.navigateToLogin();
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}
 
Example 5
Source File: CompassActivity.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * Check AccelerometerSensor in device
 **/
private void getAccelerometerSensor() {
    PackageManager mManager = getPackageManager();
    boolean hasAccelerometer = mManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
    boolean hasMagneticSensor = mManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
    if (!hasAccelerometer || !hasMagneticSensor) {
        AlertDialog alertDialog = new AlertDialog.Builder(CompassActivity.this).create();
        alertDialog.setTitle(getResources().getString(R.string.compass_dialog_header));
        alertDialog.setMessage(getResources().getString(R.string.compass_dialog_description));
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.compass_dialog_confirm),
                (dialog, which) -> dialog.dismiss());
        alertDialog.show();
    }
}
 
Example 6
Source File: AboutFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows a dialog with given data.
 *
 * @param title dialog title.
 * @param body  dialog text.
 */
private void showDialog(String title, String body) {
    AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(AndroidUtils.fromHtml(body));
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.close_btn),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
}
 
Example 7
Source File: GameFragment.java    From block-this with GNU General Public License v3.0 5 votes vote down vote up
public void displayDialog(){
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
    alertDialog.setTitle("Thank you!");
    alertDialog.setMessage("By installing any of these games, you support this app's existence and further development." +
            " Without your help, all of this would not be possible. Thank you!");
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Okay, I understand",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putBoolean("seen_games_dialog", true).apply();
                    dialog.dismiss();
                }
            });
    alertDialog.show();
}
 
Example 8
Source File: TimingActivity.java    From Lamp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void sendTime() {
    if (switchOpen) {

        final AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle(getResources().getString(R.string.remind));
        dialog.setMessage(getResources().getString(R.string.wait));
        dialog.show();

        Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int min = c.get(Calendar.MINUTE);

        String hourStr = hour + "";
        String minStr = min + "";

        if (hour < 10) {
            hourStr = "0" + hour + "";
        }

        if (min < 10) {
            minStr = "0" + min + "";
        }

        ControlLight.sendTime(CommandUtils.TIMING_CURRENT, hourStr, minStr);
        startAPM.postDelayed(new Runnable() {
            @Override
            public void run() {
                ControlLight.sendTime(CommandUtils.TIMING_ON_1, time[0], time[1]);

                startAPM.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ControlLight.sendTime(CommandUtils.TIMING_ON_2, time[2], time[3]);
                        dialog.cancel();
                        finishThis();
                    }
                }, 1000);

            }
        }, 1000);


    } else {
        ControlLight.sendOrder(CommandUtils.TIMING_OFF);

        finishThis();
    }

}
 
Example 9
Source File: UpdateAgent.java    From update with Apache License 2.0 4 votes vote down vote up
@Override
public void prompt(IUpdateAgent agent) {
    if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
        return;
    }
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}
 
Example 10
Source File: ZooFragment.java    From android-galaxyzoo with GNU General Public License v3.0 4 votes vote down vote up
private void showAbout() {
    final Activity activity = getActivity();
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    // Get the layout inflater
    final LayoutInflater inflater = activity.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View view = inflater.inflate(R.layout.about, null);
    builder.setView(view);


    final TextView textView = (TextView) view.findViewById(R.id.textViewAbout);
    if (textView == null) {
        Log.error("showAbout: textView was null.");
        return;
    }

    //This voodoo makes the textviews' HTML links clickable:
    //See http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable/20647011#20647011
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    final String versionText =
            String.format(getString(R.string.about_version_text_format), BuildConfig.VERSION_NAME);

    //The about dialog's text is split into multiple strings to make translation easier,
    //so we need to concatenate them here.
    //Note that we use getText(), not getString(),
    //so we don't lose the <a href=""> links.
    //Likewise, we use SpannableStringBuilder instead of StringBuilder,
    //because we lose the links when using StringBuilder.
    final SpannableStringBuilder strBuilder = new SpannableStringBuilder();
    final String PARAGRAPH_BREAK = "\n\n";
    strBuilder.append(versionText);
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text1));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text2));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text3));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text3b));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text4));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text5));
    strBuilder.append(PARAGRAPH_BREAK);
    strBuilder.append(getText(R.string.about_text6));

    textView.setText(strBuilder);

    /* We used to put the version text into a separate TextView,
       but when the about text in textView is too long,
       the scroll never reaches this far.
       It does work when we add it to first regular textView.
     */
    /*
    final TextView textViewVersion = (TextView) view.findViewById(R.id.textViewVersion);
    if (textViewVersion != null) {
        textViewVersion.setText(versionText);
    }
    */

    final AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.app_name);
    dialog.setIcon(R.mipmap.ic_launcher);

    dialog.show();
}