List of usage examples for android.app Activity getString
@NonNull public final String getString(@StringRes int resId)
From source file:org.wahtod.wififixer.utility.LogUtil.java
public static void sendLog(final Activity activity) { /*//from w w w .j a v a 2s . c o m * Gets appropriate dir and filename on sdcard across API versions. */ //File file = VersionedFile.getFile(context, LOGFILE); final File file = new File(activity.getFilesDir(), LOGFILE); dumpLog(activity, file); /* * Get the issue report, then start send log dialog */ AlertDialog.Builder issueDialog = new AlertDialog.Builder(activity); issueDialog.setTitle(activity.getString(R.string.issue_report_header)); issueDialog.setMessage(activity.getString(R.string.issue_prompt)); // Set an EditText view to get user input final EditText input = new EditText(activity); input.setLines(3); issueDialog.setView(input); issueDialog.setPositiveButton(activity.getString(R.string.ok_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (input.getText().length() > 1) sendIssueReport(activity, input.getText().toString(), file); else NotifUtil.showToast(activity, R.string.issue_report_nag); } }); issueDialog.setNegativeButton(activity.getString(R.string.cancel_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); issueDialog.show(); }
From source file:de.baumann.hhsmoodle.helper.helper_main.java
public static void openAtt(Activity activity, View view, String fileString) { File file = new File(fileString); final String fileExtension = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); String text = activity.getString(R.string.toast_extension) + ": " + fileExtension; switch (fileExtension) { case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".jpeg": helper_main.openFile(activity, file, "image/*", view); break;/* ww w . ja v a 2 s. c o m*/ case ".m3u8": case ".mp3": case ".wma": case ".midi": case ".wav": case ".aac": case ".aif": case ".amp3": case ".weba": helper_main.openFile(activity, file, "audio/*", view); break; case ".mpeg": case ".mp4": case ".ogg": case ".webm": case ".qt": case ".3gp": case ".3g2": case ".avi": case ".f4v": case ".flv": case ".h261": case ".h263": case ".h264": case ".asf": case ".wmv": helper_main.openFile(activity, file, "video/*", view); break; case ".rtx": case ".csv": case ".txt": case ".vcs": case ".vcf": case ".css": case ".ics": case ".conf": case ".config": case ".java": helper_main.openFile(activity, file, "text/*", view); break; case ".html": helper_main.openFile(activity, file, "text/html", view); break; case ".apk": helper_main.openFile(activity, file, "application/vnd.android.package-archive", view); break; case ".pdf": helper_main.openFile(activity, file, "application/pdf", view); break; case ".doc": helper_main.openFile(activity, file, "application/msword", view); break; case ".xls": helper_main.openFile(activity, file, "application/vnd.ms-excel", view); break; case ".ppt": helper_main.openFile(activity, file, "application/vnd.ms-powerpoint", view); break; case ".docx": helper_main.openFile(activity, file, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", view); break; case ".pptx": helper_main.openFile(activity, file, "application/vnd.openxmlformats-officedocument.presentationml.presentation", view); break; case ".xlsx": helper_main.openFile(activity, file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", view); break; case ".odt": helper_main.openFile(activity, file, "application/vnd.oasis.opendocument.text", view); break; case ".ods": helper_main.openFile(activity, file, "application/vnd.oasis.opendocument.spreadsheet", view); break; case ".odp": helper_main.openFile(activity, file, "application/vnd.oasis.opendocument.presentation", view); break; case ".zip": helper_main.openFile(activity, file, "application/zip", view); break; case ".rar": helper_main.openFile(activity, file, "application/x-rar-compressed", view); break; case ".epub": helper_main.openFile(activity, file, "application/epub+zip", view); break; case ".cbz": helper_main.openFile(activity, file, "application/x-cbz", view); break; case ".cbr": helper_main.openFile(activity, file, "application/x-cbr", view); break; case ".fb2": helper_main.openFile(activity, file, "application/x-fb2", view); break; case ".rtf": helper_main.openFile(activity, file, "application/rtf", view); break; case ".opml": helper_main.openFile(activity, file, "application/opml", view); break; default: Snackbar snackbar = Snackbar.make(view, text, Snackbar.LENGTH_LONG); snackbar.show(); break; } }
From source file:com.pyamsoft.dontsuckmp.main.MainActivity.java
public static void overlapToolbar(@NonNull Activity activity, boolean overlap) { if (activity instanceof MainActivity) { final MainActivity mainActivity = (MainActivity) activity; final ActionBar actionBar = mainActivity.getSupportActionBar(); final float elevation = overlap ? AppUtil.convertToDP(activity, 4) : 0; ViewCompat.setElevation(mainActivity.binding.toolbar, elevation); if (actionBar != null) { final Drawable background = overlap ? new ColorDrawable(ContextCompat.getColor(activity, R.color.orange500)) : null;//from w w w . j a v a 2 s . c om final String title = overlap ? activity.getString(R.string.app_name) : null; actionBar.setBackgroundDrawable(background); actionBar.setTitle(title); } } else { throw new IllegalStateException("Activity is not MainActivity"); } }
From source file:eu.trentorise.smartcampus.portfolio.PMHelper.java
private static void callshare(Portfolio exp, Activity ctx) { Entity obj = new Entity(); obj.setEntityId(exp.entityId);/* w w w .j a v a 2 s .c o m*/ obj.setTitle(exp.name); obj.setEntityType(ENTITY_TYPE_PORTFOLIO); Intent intent = new Intent(); intent.setAction(ctx.getString(eu.trentorise.smartcampus.android.common.R.string.share_intent_action)); intent.putExtra(ctx.getString(eu.trentorise.smartcampus.android.common.R.string.share_entity_arg_entity), obj); AppHelper.startActivityForApp(intent, ctx); }
From source file:com.medlog.medlogmobile.NewMessageNotification.java
public static AlertDialog.Builder eulaAlert(final Activity mActivity) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity).setTitle(" End-User License Agreement") .setMessage(EULATEEXT).setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { @Override// w w w. j av a 2s. c o m public void onClick(DialogInterface dialogInterface, int i) { // Mark this version as read. SharedPreferences sp = mActivity.getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean(mActivity.getString(R.string.PREF_EULA), true); editor.commit(); dialogInterface.dismiss(); } }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Close the activity as they have declined the EULA mActivity.finishAffinity(); System.exit(0); } }); return builder; }
From source file:com.google.android.gm.ay.java
public static void a(final Activity activity, final Account account, final String s) { final Uri build = Uri .parse(c.a(activity.getContentResolver(), "gmail_context_sensitive_help_url", "http://support.google.com/mail")) .buildUpon().appendPath("topic").appendPath(activity.getString(2131297018)).build(); final Locale default1 = Locale.getDefault(); final Uri build2 = build.buildUpon() .appendQueryParameter("hl", default1.getLanguage() + "_" + default1.getCountry().toLowerCase()) .build();/*w w w. j a v a2 s . com*/ final GoogleHelp a = GoogleHelp.gi(s).L(build2).h(GoogleHelp.j(activity)).z(g((Context) activity, account)) .a(2131558417, activity.getString(2131296702), h((Context) activity, build2)) .a(2131558418, activity.getString(2131297062), h((Context) activity, Uri.parse(c.a(activity.getContentResolver(), "gmail_privacy_policy_url", "https://www.google.com/policies/privacy/")))) .a(2131558419, activity.getString(2131297061), new Intent((Context) activity, (Class) LicenseActivity.class)) .a(2131558420, activity.getString(2131297063), h((Context) activity, Uri.parse(c.a(activity.getContentResolver(), "gmail_terms_of_service_url", "https://www.google.com/policies/terms/")))); if (account != null) { a.d(account.uf()); } new a(activity).e(a.QA()); }
From source file:com.felkertech.n.ActivityUtils.java
public static void writeDriveData(final Activity context, GoogleApiClient gapi) { //Ask here for permission to storage PermissionUtils.requestPermissionIfDisabled(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, context.getString(R.string.permission_storage_rationale)); if (PermissionUtils.isDisabled(context, android.Manifest.permission_group.STORAGE)) { new MaterialDialog.Builder(context).title(R.string.permission_not_allowed_error) .content(R.string.permission_not_allowed_text).positiveText(R.string.permission_action_settings) .negativeText(R.string.ok).callback(new MaterialDialog.ButtonCallback() { @Override//w w w.j ava2 s. c o m public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", context.getPackageName(), null); intent.setData(uri); } }).build(); } else actuallyWriteData(context, gapi); }
From source file:com.felkertech.n.ActivityUtils.java
public static void createDriveData(Activity activity, GoogleApiClient gapi, final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback) { PermissionUtils.requestPermissionIfDisabled(activity, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, activity.getString(R.string.permission_storage_rationale)); if (gapi == null) gapi = GoogleDrive.gapi;/* w ww . j a va 2 s. com*/ try { final GoogleApiClient finalGapi = gapi; new MaterialDialog.Builder(activity).title(R.string.create_sync_file_title) .content(R.string.create_sync_file_description).positiveText(R.string.ok) .negativeText(R.string.no).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); Drive.DriveApi.newDriveContents(finalGapi).setResultCallback(driveContentsCallback); } }).show(); } catch (Exception ignored) { } }
From source file:eu.janmuller.android.simplecropimage.CropImage.java
public static void showStorageToast(Activity activity, int remaining) { String noStorageText = null;//www .j a v a 2 s . c om if (remaining == NO_STORAGE_ERROR) { String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_CHECKING)) { noStorageText = activity.getString(R.string.preparing_card); } else { noStorageText = activity.getString(R.string.no_storage_card); } } else if (remaining < 1) { noStorageText = activity.getString(R.string.not_enough_space); } if (noStorageText != null) { Toast.makeText(activity, noStorageText, Toast.LENGTH_LONG).show(); } }
From source file:com.android.stockbrowser.DownloadHandler.java
private static void onDownloadNoStreamImpl(Activity activity, String url, String userAgent, String contentDisposition, String mimetype, String referer, boolean privateBrowsing) { String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); // Check to see if we have an SDCard String status = Environment.getExternalStorageState(); if (!status.equals(Environment.MEDIA_MOUNTED)) { int title; String msg;//from w ww. jav a 2 s .co m // Check to see if the SDCard is busy, same as the music app if (status.equals(Environment.MEDIA_SHARED)) { msg = activity.getString(R.string.download_sdcard_busy_dlg_msg); title = R.string.download_sdcard_busy_dlg_title; } else { msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename); title = R.string.download_no_sdcard_dlg_title; } new AlertDialog.Builder(activity).setTitle(title).setIconAttribute(android.R.attr.alertDialogIcon) .setMessage(msg).setPositiveButton(R.string.ok, null).show(); return; } // java.net.URI is a lot stricter than KURL so we have to encode some // extra characters. Fix for b 2538060 and b 1634719 WebAddress webAddress; try { webAddress = new WebAddress(url); webAddress.setPath(encodePath(webAddress.getPath())); } catch (Exception e) { // This only happens for very bad urls, we want to chatch the // exception here Log.e(LOGTAG, "Exception trying to parse url:" + url); return; } String addressString = webAddress.toString(); Uri uri = Uri.parse(addressString); final DownloadManager.Request request; try { request = new DownloadManager.Request(uri); } catch (IllegalArgumentException e) { Toast.makeText(activity, R.string.cannot_download, Toast.LENGTH_SHORT).show(); return; } request.setMimeType(mimetype); // set downloaded file destination to /sdcard/Download. // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype? try { request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); } catch (IllegalStateException ex) { // This only happens when directory Downloads can't be created or it isn't a directory // this is most commonly due to temporary problems with sdcard so show appropriate string Log.w(LOGTAG, "Exception trying to create Download dir:", ex); Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, Toast.LENGTH_SHORT).show(); return; } // let this downloaded file be scanned by MediaScanner - so that it can // show up in Gallery app, for example. request.allowScanningByMediaScanner(); request.setDescription(webAddress.getHost()); // XXX: Have to use the old url since the cookies were stored using the // old percent-encoded url. String cookies = "";//CookieManager.getInstance().getCookie(url, privateBrowsing); request.addRequestHeader("cookie", cookies); request.addRequestHeader("User-Agent", userAgent); if (!TextUtils.isEmpty(referer)) { request.addRequestHeader("Referer", referer); } request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); if (mimetype == null) { if (TextUtils.isEmpty(addressString)) { return; } // We must have long pressed on a link or image to download it. We // are not sure of the mimetype in this case, so do a head request new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start(); } else { final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE); new Thread("StockBrowser download") { public void run() { manager.enqueue(request); } }.start(); } Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT).show(); }