private void exportToHastebin() { String xml = mRepo.mergeDefaultTemplate(mSelectedLocale); final ShareUtil shu = new ShareUtil(this); shu.pasteOnHastebin(xml, (ok, url) -> { if (ok) { shu.setClipboard(url); } Toast.makeText(TranslateActivity.this, ok ? R.string.exported_to_hastebin : R.string.export_unsuccessful, Toast.LENGTH_SHORT).show(); }); }
/** * Share the given file as stream with given mime-type * * @param file The file to share * @param mimeType The files mime type */ public void shareStream(File file, String mimeType) { Uri fileUri = FileProvider.getUriForFile(_context, getFileProviderAuthority(), file); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath()); intent.setType(mimeType); showChooser(intent, null); }
/** * See {@link #print(WebView, String) print method} */ @RequiresApi(api = Build.VERSION_CODES.KITKAT) @SuppressWarnings("deprecation") public PrintJob createPdf(WebView webview, String jobName) { return print(webview, jobName); }
private void exportToCopy() { String filename = mSelectedLocaleResources.getFilename(); String xml = mRepo.mergeDefaultTemplate(mSelectedLocale); new ShareUtil(this).setClipboard(xml); Toast.makeText(this, getString(R.string.xml_copied_to_clipboard, filename), Toast.LENGTH_SHORT).show(); }
private void exportToEmail() { String xml = mRepo.mergeDefaultTemplate(mSelectedLocale); String subject = mRepo.getProjectName() + " - " + getString(R.string.updated_x_translation, mSelectedLocale, LocaleString.getEnglishDisplay(mSelectedLocale)); new ShareUtil(this).draftEmail(subject, xml, mRepo.settings.getProjectMail()); }
/** * Share text with given mime-type * * @param text The text to share * @param mimeType MimeType or null (uses text/plain) */ public void shareText(String text, @Nullable String mimeType) { Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, text); intent.setType(mimeType != null ? mimeType : MIME_TEXT_PLAIN); showChooser(intent, null); }
/** * Share the given bitmap with given format * * @param bitmap Image * @param format A {@link Bitmap.CompressFormat}, supporting JPEG,PNG,WEBP * @return if success, true */ public boolean shareImage(Bitmap bitmap, Bitmap.CompressFormat format) { return shareImage(bitmap, format, 95, "SharedImage"); }
/** * Convert a {@link File} to an {@link Uri} * * @param file the file * @return Uri for this file */ public Uri getUriByFileProviderAuthority(File file) { return FileProvider.getUriForFile(_context, getFileProviderAuthority(), file); }
/** * Share the given bitmap with given format * * @param bitmap Image * @param format A {@link Bitmap.CompressFormat}, supporting JPEG,PNG,WEBP * @param imageName Filename without extension * @param quality Quality of the exported image [0-100] * @return if success, true */ public boolean shareImage(Bitmap bitmap, Bitmap.CompressFormat format, int quality, String imageName) { try { String ext = format.name().toLowerCase(); File file = File.createTempFile(imageName, "." + ext.replace("jpeg", "jpg"), _context.getExternalCacheDir()); if (bitmap != null && new ContextUtils(_context).writeImageToFile(file, bitmap, format, quality)) { shareStream(file, "image/" + ext); return true; } } catch (IOException e) { e.printStackTrace(); } return false; }
/** * Draft an email with given data. Unknown data can be supplied as null. * This will open a chooser with installed mail clients where the mail can be sent from * * @param subject Subject (top/title) text to be prefilled in the mail * @param body Body (content) text to be prefilled in the mail * @param to recipients to be prefilled in the mail */ public void draftEmail(String subject, String body, String... to) { Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); if (subject != null) { intent.putExtra(Intent.EXTRA_SUBJECT, subject); } if (body != null) { intent.putExtra(Intent.EXTRA_TEXT, body); } if (to != null && to.length > 0 && to[0] != null) { intent.putExtra(Intent.EXTRA_EMAIL, to); } showChooser(intent, null); }
/** * Open a View intent for given file * * @param file The file to share */ public void viewFileInOtherApp(File file, @Nullable String type) { Uri fileUri = FileProvider.getUriForFile(_context, getFileProviderAuthority(), file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.putExtra(Intent.EXTRA_STREAM, fileUri); intent.setData(fileUri); intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath()); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setDataAndType(fileUri, type); showChooser(intent, null); }