Java Code Examples for android.app.AlertDialog.Builder#show()

The following examples show how to use android.app.AlertDialog.Builder#show() . 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: LogsFragment.java    From callmeter with GNU General Public License v3.0 8 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    final Builder b = new Builder(getActivity());
    b.setCancelable(true);
    b.setItems(R.array.dialog_delete, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            LogsFragment.this
                    .getActivity()
                    .getContentResolver()
                    .delete(ContentUris.withAppendedId(DataProvider.Logs.CONTENT_URI, id),
                            null, null);
            LogsFragment.this.setAdapter(true);
            LogRunnerService.update(LogsFragment.this.getActivity(), null);
        }
    });
    b.setNegativeButton(android.R.string.cancel, null);
    b.show();
    return true;
}
 
Example 2
Source File: AccountActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_ACCOUNT_REQUEST_CODE && resultCode == RESULT_OK) {
        refresh();
        if (data == null) {
            return;
        }
        String expires_time = data.getExtras().getString("expires_in");
        long expiresDays = TimeUnit.SECONDS.toDays(Long.valueOf(expires_time));

        String content = String.format(getString(R.string.token_expires_in_time), String.valueOf(expiresDays));
        DevLog.printLog("AccountActivity: ", content);
        if (false) {
            Builder builder = new Builder(this).setMessage(content).setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });

            builder.show();
        }

    }
}
 
Example 3
Source File: WipeActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private void doWipe() {
	if (mOnlyTesting) {
		Builder alert = new AlertDialog.Builder(this)
				.setTitle(R.string.app_name)
				.setPositiveButton(android.R.string.ok,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								dialog.dismiss();
								WipeActivity.this.finish();
							}
						}).setMessage(R.string.panic_test_successful);
		alert.show();
	} else {
		this.setResult(Activity.RESULT_OK);
		WipeActivity.this.finish();
	}
}
 
Example 4
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
Example 5
Source File: BaseHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void showDialog(Activity context, String strTitle, String strText, int icon) {
    if (context != null && !context.isFinishing() && !context.isRestricted()) {
        Builder tDialog = new Builder(context);
        tDialog.setIcon(icon);
        tDialog.setTitle(strTitle);
        tDialog.setMessage(strText);
        tDialog.setPositiveButton(R.string.Ensure, null);
        try {
            tDialog.show();
        } catch (Exception e) {
        }
    }
}
 
Example 6
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
Example 7
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
Example 8
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item_add:
            showNumberDialog(-1);
            return true;
        case R.id.item_delete:
            Builder b = new Builder(this);
            b.setTitle(R.string.delete_group_);
            b.setMessage(R.string.delete_group_hint);
            b.setNegativeButton(android.R.string.no, null);
            b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    NumberGroupEdit.this.getContentResolver().delete(
                            ContentUris.withAppendedId(DataProvider.NumbersGroup.CONTENT_URI,
                                    NumberGroupEdit.this.gid), null, null);
                    Preferences.setDefaultPlan(NumberGroupEdit.this, false);
                    RuleMatcher.unmatch(NumberGroupEdit.this);
                    NumberGroupEdit.this.finish();
                }
            });
            b.show();
            return true;
        case R.id.item_rename:
            showNameDialog();
            return true;
        case R.id.item_help:
            showHelp(R.string.numbergroup_help);
            return true;
        default:
            return false;
    }
}
 
Example 9
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show help text.
 *
 * @param res resource
 */
private void showHelp(final int res) {
    final Builder b = new Builder(this);
    b.setMessage(res);
    b.setPositiveButton(android.R.string.ok, null);
    b.show();
}
 
Example 10
Source File: Notification.java    From reacteu-app with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
Example 11
Source File: BillModeListPreference.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    final String ov = getValue();
    super.onDialogClosed(positiveResult);
    if (positiveResult) {
        String v = getValue();
        if (v == null || !v.contains("/")) { // custom bill mode
            Builder b = new Builder(getContext());
            final EditText et = new EditText(getContext());
            et.setText(ov);
            b.setView(et);
            b.setCancelable(false);
            b.setTitle(getTitle());
            b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface paramDialogInterface,
                        final int paramInt) {
                    BillModeListPreference.this.setValue(ov);
                }
            });
            b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    String nv = et.getText().toString().trim();
                    final String[] t = nv.toString().split("/");
                    if (t.length != 2 || !TextUtils.isDigitsOnly(t[0])
                            || !TextUtils.isDigitsOnly(t[1])) {
                        Toast.makeText(BillModeListPreference.this.ctx, R.string.missing_slash,
                                Toast.LENGTH_LONG).show();
                        BillModeListPreference.this.setValue(ov);
                    } else {
                        BillModeListPreference.this.setValue(nv);
                    }
                }
            });
            b.show();
        }
    }
}
 
Example 12
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void openDialogMessage(int title,int message,boolean isCancelable,boolean killAllActivity){
		final Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setCancelable(isCancelable);
		builder.setPositiveButton(R.string.confirm_btn, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				builder.create().dismiss();
				if(isExit){
//					application.exit();
				}
			}
		});
		builder.show();
	}
 
Example 13
Source File: PlansFragment.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    final Builder builder = new Builder(getActivity());
    builder.setItems(R.array.dialog_edit_plan,
            new android.content.DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    switch (which) {
                        case 0:
                            Intent intent = new Intent(PlansFragment.this.getActivity(),
                                    PlanEdit.class);
                            intent.setData(ContentUris.withAppendedId(
                                    DataProvider.Plans.CONTENT_URI, id));
                            PlansFragment.this.getActivity().startActivity(intent);
                            break;
                        case 1:
                            ((Plans) PlansFragment.this.getActivity()).showLogsFragment(id);
                            break;
                        default:
                            break;
                    }
                }
            });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
    return true;
}
 
Example 14
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    String k = preference.getKey();
    if (k != null && k.startsWith("item_")) {
        final long id = Long.parseLong(k.substring("item_".length()));

        final Builder builder = new Builder(this);
        builder.setItems(R.array.dialog_edit_delete,
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        switch (which) {
                            case WHICH_EDIT:
                                NumberGroupEdit.this.showNumberDialog(id);
                                break;
                            case WHICH_DELETE:
                                NumberGroupEdit.this.getContentResolver().delete(
                                        ContentUris.withAppendedId(
                                                DataProvider.Numbers.CONTENT_URI, id), null,
                                        null);
                                NumberGroupEdit.this.reload();
                                RuleMatcher.unmatch(NumberGroupEdit.this);
                                break;
                            default:
                                break;
                        }
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.show();
    }

    return false;
}
 
Example 15
Source File: ActivityDlgActionInput.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
public void onClick(View v) {
  Builder help = new AlertDialog.Builder(v.getContext());
  help.setIcon(android.R.drawable.ic_menu_help);
  help.setTitle(R.string.help);
  help.setMessage(Html.fromHtml(getString(R.string.help_dlgactioninput)));
  help.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    }
  });
  help.show();
}
 
Example 16
Source File: ActivityDlgFilterInput.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
public void onClick(View v) {
  Builder help = new AlertDialog.Builder(v.getContext());
  help.setIcon(android.R.drawable.ic_menu_help);
  help.setTitle(R.string.help);
  help.setMessage(Html.fromHtml(getString(R.string.help_dlgfilterinput)));
  help.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
    }
  });
  help.show();
}
 
Example 17
Source File: HourGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item_add:
            showHourDialog(-1);
            return true;
        case R.id.item_delete:
            Builder b = new Builder(this);
            b.setTitle(R.string.delete_group_);
            b.setMessage(R.string.delete_group_hint);
            b.setNegativeButton(android.R.string.no, null);
            b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    HourGroupEdit.this.getContentResolver().delete(
                            ContentUris.withAppendedId(DataProvider.HoursGroup.CONTENT_URI,
                                    HourGroupEdit.this.gid), null, null);
                    Preferences.setDefaultPlan(HourGroupEdit.this, false);
                    RuleMatcher.unmatch(HourGroupEdit.this);
                    HourGroupEdit.this.finish();
                }
            });
            b.show();
            return true;
        case R.id.item_rename:
            showNameDialog();
            return true;
        case R.id.item_help:
            showHelp(R.string.hourgroup_help);
            return true;
        default:
            return false;
    }
}
 
Example 18
Source File: ActivityMain.java    From LibreTasks with Apache License 2.0 5 votes vote down vote up
/**
 * Display our about dialog.
 */
private void showAbout() {
  // Get package information
  String version;
  try {
    PackageInfo pkgInfo;
    pkgInfo = getPackageManager().getPackageInfo(this.getPackageName(), 0);
    version = pkgInfo.versionName;
  } catch (NameNotFoundException e) {
    version = getString(R.string.unknown);
  }

  StringBuilder message = new StringBuilder();
  message.append(getString(R.string.about_desc)).append("<br /><br />");
  message.append(getString(R.string.copyright)).append("<br /><br />");
  message.append(getString(R.string.about_version)).append(" ").append(version);
  message.append("<br /><br />");
  message.append(getString(R.string.about_license)).append("<br /><br />");
  message.append(getString(R.string.about_website));

  Builder about = new AlertDialog.Builder(this);
  about.setTitle(R.string.about_title);
  about.setIcon(R.drawable.icon);
  about.setMessage(Html.fromHtml(message.toString()));
  about.setPositiveButton(R.string.ok, null);
  about.show();
}
 
Example 19
Source File: CVBillModePreference.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    final String ov = getValue();
    super.onDialogClosed(positiveResult);
    if (positiveResult) {
        String v = getValue();
        if (v == null || !v.contains("/")) { // custom bill mode
            Builder b = new Builder(getContext());
            final EditText et = new EditText(getContext());
            et.setText(ov);
            b.setView(et);
            b.setCancelable(false);
            b.setTitle(getTitle());
            b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface paramDialogInterface,
                        final int paramInt) {
                    CVBillModePreference.this.setValue(ov);
                }
            });
            b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    String nv = et.getText().toString().trim();
                    final String[] t = nv.toString().split("/");
                    if (t.length != 2 || !TextUtils.isDigitsOnly(t[0])
                            || !TextUtils.isDigitsOnly(t[1])) {
                        Toast.makeText(CVBillModePreference.this.ctx, R.string.missing_slash,
                                Toast.LENGTH_LONG).show();
                        CVBillModePreference.this.setValue(ov);
                    } else {
                        CVBillModePreference.this.setValue(nv);
                        CVBillModePreference.this.cv
                                .put(CVBillModePreference.this.getKey(), nv);
                        if (CVBillModePreference.this.ul != null) {
                            CVBillModePreference.this.ul
                                    .onUpdateValue(CVBillModePreference.this);
                        }
                    }
                }
            });
            b.show();
        } else {
            cv.put(getKey(), v);
            if (ul != null) {
                ul.onUpdateValue(this);
            }
        }
    }
}
 
Example 20
Source File: MainActivity.java    From droitatedDB with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
	if (R.id.dump_db == item.getItemId()) {
		File sd = Environment.getExternalStorageDirectory();
		File data = Environment.getDataDirectory();
		FileChannel source = null;
		FileChannel destination = null;
		String currentDBPath = "/data/com.arconsis.android.datarobot.performance/databases/performance.db";
		File currentDB = new File(data, currentDBPath);
		File backupDB = new File(sd, "performance.db");
		try {
			source = new FileInputStream(currentDB).getChannel();
			destination = new FileOutputStream(backupDB).getChannel();
			destination.transferFrom(source, 0, source.size());
			source.close();
			destination.close();
			Toast.makeText(this, R.string.db_exported, Toast.LENGTH_LONG).show();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return true;
	} else if (R.id.delete_all == item.getItemId()) {
		getContentResolver().delete(BaseContentProvider.uri(Operation.class.getSimpleName()), null, null);

		operationsAdapter.clear();
		operationsAdapter.notifyDataSetChanged();
		return true;
	} else if (R.id.bulk_creation == item.getItemId()) {
		Builder builder = new AlertDialog.Builder(this);

		builder.setTitle("Choose batch");
		builder.setSingleChoiceItems(new String[]{"Simple (Single)", "Note (Single)", "Simple (Bulk)", "Note (Bulk)"}, 0, new OnClickListener() {
			@Override
			public void onClick(final DialogInterface dialog, final int which) {
				if (which == 0) {
					new SimpleCreationTask(MainActivity.this, new SavePerformance("Simple (Single)")).executeOnExecutor(executor);
				} else if (which == 1) {
					new NoteCreationTask(MainActivity.this, new SavePerformance("Note (Single)")).executeOnExecutor(executor);
				} else if (which == 2) {
					new BulkSimpleCreationTask(MainActivity.this, new SavePerformance("Simple (Bulk)")).executeOnExecutor(executor);
				} else if (which == 3) {
					new BulkNoteCreation(MainActivity.this, new SavePerformance("Note (Bulk)")).executeOnExecutor(executor);
				}
				dialog.dismiss();
			}
		});
		builder.show();
	}
	return super.onOptionsItemSelected(item);
}