Java Code Examples for org.telegram.messenger.FileLoader#getDirectory()
The following examples show how to use
org.telegram.messenger.FileLoader#getDirectory() .
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: WallpaperUpdater.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) { try { if (!photos.isEmpty()) { SendMessagesHelper.SendingMediaInfo info = photos.get(0); if (info.path != null) { currentWallpaperPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.random.nextInt() + ".jpg"); Point screenSize = AndroidUtilities.getRealScreenSize(); Bitmap bitmap = ImageLoader.loadBitmap(info.path, null, screenSize.x, screenSize.y, true); FileOutputStream stream = new FileOutputStream(currentWallpaperPath); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); delegate.didSelectWallpaper(currentWallpaperPath, bitmap, true); } } } catch (Throwable e) { FileLog.e(e); } }
Example 2
Source File: WallpaperUpdater.java From Telegram with GNU General Public License v2.0 | 6 votes |
private void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos) { try { if (!photos.isEmpty()) { SendMessagesHelper.SendingMediaInfo info = photos.get(0); if (info.path != null) { currentWallpaperPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.random.nextInt() + ".jpg"); Point screenSize = AndroidUtilities.getRealScreenSize(); Bitmap bitmap = ImageLoader.loadBitmap(info.path, null, screenSize.x, screenSize.y, true); FileOutputStream stream = new FileOutputStream(currentWallpaperPath); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); delegate.didSelectWallpaper(currentWallpaperPath, bitmap, true); } } } catch (Throwable e) { FileLog.e(e); } }
Example 3
Source File: ImageUpdater.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void processBitmap(Bitmap bitmap) { if (bitmap == null) { return; } if (encryptedDocument) { bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 2048, 2048, 89, false, 320, 320); if (delegate != null) { TLRPC.TL_secureFile secureFile = new TLRPC.TL_secureFile(); secureFile.dc_id = (int) bigPhoto.location.volume_id; secureFile.id = bigPhoto.location.local_id; secureFile.date = (int) (System.currentTimeMillis() / 1000); delegate.didUploadedPhoto(null, null, null, secureFile); } SharedConfig.saveConfig(); } else { smallPhoto = ImageLoader.scaleAndSaveImage(bitmap, 100, 100, 80, false); bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 800, 800, 80, false, 320, 320); bitmap.recycle(); if (bigPhoto != null && smallPhoto != null) { if (returnOnly) { if (delegate != null) { delegate.didUploadedPhoto(null, smallPhoto, bigPhoto, null); } } else { UserConfig.getInstance(currentAccount).saveConfig(false); uploadingImage = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg"; NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidUpload); NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidFailUpload); FileLoader.getInstance(currentAccount).uploadFile(uploadingImage, false, true, ConnectionsManager.FileTypePhoto); } } } }
Example 4
Source File: ImageUpdater.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void processBitmap(Bitmap bitmap) { if (bitmap == null) { return; } if (encryptedDocument) { bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 2048, 2048, 89, false, 320, 320); if (delegate != null) { TLRPC.TL_secureFile secureFile = new TLRPC.TL_secureFile(); secureFile.dc_id = (int) bigPhoto.location.volume_id; secureFile.id = bigPhoto.location.local_id; secureFile.date = (int) (System.currentTimeMillis() / 1000); delegate.didUploadedPhoto(null, null, null, secureFile); } SharedConfig.saveConfig(); } else { smallPhoto = ImageLoader.scaleAndSaveImage(bitmap, 100, 100, 80, false); bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 800, 800, 80, false, 320, 320); bitmap.recycle(); if (bigPhoto != null && smallPhoto != null) { if (returnOnly) { if (delegate != null) { delegate.didUploadedPhoto(null, smallPhoto, bigPhoto, null); } } else { UserConfig.getInstance(currentAccount).saveConfig(false); uploadingImage = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg"; NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidUpload); NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidFailUpload); FileLoader.getInstance(currentAccount).uploadFile(uploadingImage, false, true, ConnectionsManager.FileTypePhoto); } } } }
Example 5
Source File: ImageUpdater.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void processBitmap(Bitmap bitmap) { if (bitmap == null) { return; } bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 800, 800, 80, false, 320, 320); smallPhoto = ImageLoader.scaleAndSaveImage(bitmap, 150, 150, 80, false, 150, 150); if (smallPhoto != null) { try { Bitmap b = BitmapFactory.decodeFile(FileLoader.getPathToAttach(smallPhoto, true).getAbsolutePath()); String key = smallPhoto.location.volume_id + "_" + smallPhoto.location.local_id + "@50_50"; ImageLoader.getInstance().putImageToCache(new BitmapDrawable(b), key); } catch (Throwable ignore) { } } bitmap.recycle(); if (bigPhoto != null) { UserConfig.getInstance(currentAccount).saveConfig(false); uploadingImage = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg"; if (uploadAfterSelect) { NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidUpload); NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidFailUpload); FileLoader.getInstance(currentAccount).uploadFile(uploadingImage, false, true, ConnectionsManager.FileTypePhoto); } if (delegate != null) { delegate.didUploadPhoto(null, bigPhoto, smallPhoto); } } }
Example 6
Source File: ImageUpdater.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void processBitmap(Bitmap bitmap) { if (bitmap == null) { return; } bigPhoto = ImageLoader.scaleAndSaveImage(bitmap, 800, 800, 80, false, 320, 320); smallPhoto = ImageLoader.scaleAndSaveImage(bitmap, 150, 150, 80, false, 150, 150); if (smallPhoto != null) { try { Bitmap b = BitmapFactory.decodeFile(FileLoader.getPathToAttach(smallPhoto, true).getAbsolutePath()); String key = smallPhoto.location.volume_id + "_" + smallPhoto.location.local_id + "@50_50"; ImageLoader.getInstance().putImageToCache(new BitmapDrawable(b), key); } catch (Throwable ignore) { } } bitmap.recycle(); if (bigPhoto != null) { UserConfig.getInstance(currentAccount).saveConfig(false); uploadingImage = FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg"; if (uploadAfterSelect) { NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidUpload); NotificationCenter.getInstance(currentAccount).addObserver(ImageUpdater.this, NotificationCenter.FileDidFailUpload); FileLoader.getInstance(currentAccount).uploadFile(uploadingImage, false, true, ConnectionsManager.FileTypePhoto); } if (delegate != null) { delegate.didUploadPhoto(null, bigPhoto, smallPhoto); } } }
Example 7
Source File: WallpaperUpdater.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public WallpaperUpdater(Activity activity, WallpaperUpdaterDelegate wallpaperUpdaterDelegate) { parentActivity = activity; delegate = wallpaperUpdaterDelegate; currentWallpaperPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.random.nextInt() + ".jpg"); }
Example 8
Source File: WallpaperUpdater.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
public WallpaperUpdater(Activity activity, WallpaperUpdaterDelegate wallpaperUpdaterDelegate) { parentActivity = activity; delegate = wallpaperUpdaterDelegate; currentWallpaperPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.random.nextInt() + ".jpg"); }
Example 9
Source File: CropView.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
public Bitmap getResult(MediaController.MediaEditState editState) { if (state == null || !state.hasChanges() && state.getBaseRotation() < EPSILON && freeform) { return bitmap; } RectF cropRect = new RectF(); areaView.getCropRect(cropRect); RectF sizeRect = new RectF(0, 0, RESULT_SIDE, RESULT_SIDE); float w = scaleWidthToMaxSize(cropRect, sizeRect); int width = (int) Math.ceil(w); int height = (int) (Math.ceil(width / areaView.getAspectRatio())); float scale = width / areaView.getCropWidth(); Bitmap resultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Matrix matrix = new Matrix(); matrix.postTranslate(-state.getWidth() / 2, -state.getHeight() / 2); matrix.postRotate(state.getOrientation()); state.getConcatMatrix(matrix); matrix.postScale(scale, scale); matrix.postTranslate(width / 2, height / 2); Canvas canvas = new Canvas(resultBitmap); if (editState.paintPath != null) { editBitmap(editState.paintPath, null, canvas, resultBitmap, Bitmap.CompressFormat.PNG, scale, null, false); if (!editState.paintPath.equals(editState.fullPaintPath)) { editBitmap(editState.fullPaintPath, null, canvas, resultBitmap, Bitmap.CompressFormat.PNG, scale, editState.mediaEntities, true); } } if (editState.filterPath != null) { if (editState.croppedPath == null) { File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg"); editState.croppedPath = f.getAbsolutePath(); } Bitmap b = ImageLoader.loadBitmap(editState.getPath(), null, bitmap.getWidth(), bitmap.getHeight(), true); editBitmap(editState.croppedPath, b, canvas, resultBitmap, Bitmap.CompressFormat.JPEG, scale, null, false); } canvas.drawBitmap(bitmap, matrix, new Paint(FILTER_BITMAP_FLAG)); return resultBitmap; }
Example 10
Source File: CropView.java From Telegram with GNU General Public License v2.0 | 4 votes |
public Bitmap getResult(MediaController.MediaEditState editState) { if (state == null || !state.hasChanges() && state.getBaseRotation() < EPSILON && freeform) { return bitmap; } RectF cropRect = new RectF(); areaView.getCropRect(cropRect); RectF sizeRect = new RectF(0, 0, RESULT_SIDE, RESULT_SIDE); float w = scaleWidthToMaxSize(cropRect, sizeRect); int width = (int) Math.ceil(w); int height = (int) (Math.ceil(width / areaView.getAspectRatio())); float scale = width / areaView.getCropWidth(); Bitmap resultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Matrix matrix = new Matrix(); matrix.postTranslate(-state.getWidth() / 2, -state.getHeight() / 2); matrix.postRotate(state.getOrientation()); state.getConcatMatrix(matrix); matrix.postScale(scale, scale); matrix.postTranslate(width / 2, height / 2); Canvas canvas = new Canvas(resultBitmap); if (editState.paintPath != null) { editBitmap(editState.paintPath, null, canvas, resultBitmap, Bitmap.CompressFormat.PNG, scale, null, false); if (!editState.paintPath.equals(editState.fullPaintPath)) { editBitmap(editState.fullPaintPath, null, canvas, resultBitmap, Bitmap.CompressFormat.PNG, scale, editState.mediaEntities, true); } } if (editState.filterPath != null) { if (editState.croppedPath == null) { File f = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), SharedConfig.getLastLocalId() + "_temp.jpg"); editState.croppedPath = f.getAbsolutePath(); } Bitmap b = ImageLoader.loadBitmap(editState.getPath(), null, bitmap.getWidth(), bitmap.getHeight(), true); editBitmap(editState.croppedPath, b, canvas, resultBitmap, Bitmap.CompressFormat.JPEG, scale, null, false); } canvas.drawBitmap(bitmap, matrix, new Paint(FILTER_BITMAP_FLAG)); return resultBitmap; }