List of usage examples for android.app Activity getString
@NonNull public final String getString(@StringRes int resId)
From source file:com.rks.musicx.misc.utils.Sleeptimer.java
public static void showTimerInfo(Activity c) { final String Continue = c.getString(R.string.Continue); final String cancelTimer = c.getString(R.string.cancel_timer); if (mTask.getDelay(TimeUnit.MILLISECONDS) < 0) { Stop();/*w w w. j a v a 2 s.c o m*/ return; } View view = LayoutInflater.from(c).inflate(R.layout.timer_info, null); final TextView timeLeft = ((TextView) view.findViewById(R.id.time_left)); if (PreferenceManager.getDefaultSharedPreferences(c).getBoolean("dark_theme", false)) { timeLeft.setTextColor(Color.WHITE); } else { timeLeft.setTextColor(Color.BLACK); } final String stopTimer = c.getString(R.string.stop_timer); MaterialDialog.Builder sleepdialog = new MaterialDialog.Builder(c); sleepdialog.title("SleepTimer"); sleepdialog.positiveText(Continue); sleepdialog.onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { sleepdialog.autoDismiss(true); } }); sleepdialog.negativeText(cancelTimer); sleepdialog.onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { Stop(); Toast.makeText(c, stopTimer, Toast.LENGTH_LONG).show(); } }); sleepdialog.customView(view, false); new CountDownTimer(mTask.getDelay(TimeUnit.MILLISECONDS), 1000) { @SuppressLint("StringFormatInvalid") @Override public void onTick(long seconds) { long miliseconds = seconds; miliseconds = miliseconds / 1000; timeLeft.setText(String.format(c.getString(R.string.timer_info), ((miliseconds % 3600) / 60), ((miliseconds % 3600) % 60))); } @Override public void onFinish() { sleepdialog.autoDismiss(true); } }.start(); sleepdialog.show(); }
From source file:org.wahtod.wififixer.utility.LogUtil.java
public static void sendIssueReport(Activity activity, String report, File file) { Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType(activity.getString(R.string.log_mimetype)); sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { activity.getString(R.string.email) }); sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.subject)); Uri uri = FileProvider.getUriForFile(activity, "org.wahtod.wififixer.files", file); sendIntent.putExtra(Intent.EXTRA_STREAM, uri); List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(sendIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); }//from www . ja v a2s.c o m sendIntent.putExtra(Intent.EXTRA_TEXT, LogUtil.getBuildInfo() + "\n\n" + report); activity.startActivityForResult(Intent.createChooser(sendIntent, activity.getString(R.string.emailintent)), 1); }
From source file:io.hypertrack.sendeta.util.PermissionUtils.java
public static AlertDialog showRationaleMessageAsDialog(@NonNull final Activity activity, @NonNull final String permission, @NonNull final String message) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setMessage(message);// ww w.j a va 2 s. c om builder.setPositiveButton(activity.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PermissionUtils.requestPermission(activity, permission); } }); return builder.show(); }
From source file:com.cloverstudio.spika.utils.Utils.java
public static String checkPasswordForGroup(Activity activity, String password) { if (password == null || password.length() == 0) return activity.getString(R.string.password_ok); if (password.length() < 6) { return activity.getString(R.string.password_error_number_of_characters); } else if (!isAlphaNumeric(password)) { return activity.getString(R.string.password_error_invalid_characters); }// ww w . java2s . c om return activity.getString(R.string.password_ok); }
From source file:com.cloverstudio.spika.utils.Utils.java
public static String checkName(Activity activity, String name) { if (name != null && !name.equals("") && name.length() > 1) { return activity.getString(R.string.name_ok); } else {//from www .j a v a 2 s . co m return activity.getString(R.string.name_error); } }
From source file:io.github.mkjung.ivi.util.Permissions.java
private static Dialog createDialogCompat(final Activity activity, boolean exit) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.allow_storage_access_title)) .setMessage(activity.getString(R.string.allow_storage_access_description)) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton( activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); if (!settings.getBoolean("user_declined_storage_access", false)) requestStoragePermission(activity); else { Intent i = new Intent(); i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri .parse("package:" + VLCApplication.getAppContext().getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { activity.startActivity(i); } catch (Exception ex) { }// w w w . j ava2s . c o m } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_storage_access", true); Util.commitPreferences(editor); } }); if (exit) { dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.finish(); } }).setCancelable(false); } return dialogBuilder.show(); }
From source file:io.hypertrack.sendeta.util.PermissionUtils.java
/** * @param activity Context where the Snackbar will be shown * @param permission Permission for which Snackbar has to be shown, * helps in deciding the message string for Snackbar * @return snackbar snackbar instance which can be useful to set callbacks,if needed *//* w w w. ja v a 2 s . c o m*/ public static AlertDialog.Builder showPermissionDeclineDialog(@NonNull final Activity activity, @NonNull final String permission, @NonNull final String message) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setMessage(message); builder.setPositiveButton(activity.getString(R.string.action_settings), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { openSettings(activity); } }); builder.setNegativeButton(activity.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); return builder; }
From source file:org.videolan.vlc.util.Permissions.java
private static Dialog createDialogCompat(final Activity activity, boolean exit) { AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.allow_storage_access_title)) .setMessage(activity.getString(R.string.allow_storage_access_description)) .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton( activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(activity); if (!settings.getBoolean("user_declined_storage_access", false)) requestStoragePermission(activity); else { Intent i = new Intent(); i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS"); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri .parse("package:" + VLCApplication.getAppContext().getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { activity.startActivity(i); } catch (Exception ex) { }/*from w ww .j a va2s .co m*/ } SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("user_declined_storage_access", true); editor.apply(); } }); if (exit) { dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { activity.finish(); } }).setCancelable(false); } return dialogBuilder.show(); }
From source file:it.feio.android.omninotes.helpers.PermissionsHelper.java
private static void requestPermissionExecute(Activity activity, String permission, OnPermissionRequestedListener onPermissionRequestedListener, View messageView) { RxPermissions.getInstance(activity).request(permission).subscribe(granted -> { if (granted) { onPermissionRequestedListener.onPermissionGranted(); } else {//ww w. ja v a2s . c o m String msg = activity.getString(R.string.permission_not_granted) + ": " + permission; Snackbar.make(messageView, msg, Snackbar.LENGTH_LONG).show(); } }); }
From source file:com.dycody.android.idealnote.helpers.PermissionsHelper.java
private static void requestPermissionExecute(Activity activity, String permission, OnPermissionRequestedListener onPermissionRequestedListener, View messageView) { RxPermissions.getInstance(activity).request(permission).subscribe(granted -> { if (granted) { onPermissionRequestedListener.onPermissionGranted(); } else {/*from w ww. j a va 2 s . c o m*/ String msg = activity.getString(com.dycody.android.idealnote.R.string.permission_not_granted) + ": " + permission; Snackbar.make(messageView, msg, Snackbar.LENGTH_LONG).show(); } }); }