Search in sources :

Example 6 with ChatWallpaper

use of org.thoughtcrime.securesms.wallpaper.ChatWallpaper in project Signal-Android by signalapp.

the class WallpaperCropRepository method setWallPaper.

@WorkerThread
@NonNull
ChatWallpaper setWallPaper(byte[] bytes) throws IOException {
    try (InputStream inputStream = new ByteArrayInputStream(bytes)) {
        ChatWallpaper wallpaper = WallpaperStorage.save(context, inputStream, "webp");
        if (recipientId != null) {
            Log.i(TAG, "Setting image wallpaper for " + recipientId);
            SignalDatabase.recipients().setWallpaper(recipientId, wallpaper);
        } else {
            Log.i(TAG, "Setting image wallpaper for default");
            SignalStore.wallpaper().setWallpaper(context, wallpaper);
        }
        return wallpaper;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 7 with ChatWallpaper

use of org.thoughtcrime.securesms.wallpaper.ChatWallpaper in project Signal-Android by WhisperSystems.

the class WallpaperCropViewModel method render.

void render(@NonNull Context context, @NonNull EditorModel model, @NonNull Point size, @NonNull AsynchronousCallback.WorkerThread<ChatWallpaper, Error> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        Bitmap bitmap = model.render(context, size);
        try {
            ChatWallpaper chatWallpaper = repository.setWallPaper(BitmapUtil.toWebPByteArray(bitmap));
            callback.onComplete(chatWallpaper);
        } catch (IOException e) {
            Log.w(TAG, e);
            callback.onError(Error.SAVING);
        } finally {
            bitmap.recycle();
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) IOException(java.io.IOException)

Example 8 with ChatWallpaper

use of org.thoughtcrime.securesms.wallpaper.ChatWallpaper in project Signal-Android by signalapp.

the class WallpaperCropViewModel method render.

void render(@NonNull Context context, @NonNull EditorModel model, @NonNull Point size, @NonNull AsynchronousCallback.WorkerThread<ChatWallpaper, Error> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        Bitmap bitmap = model.render(context, size);
        try {
            ChatWallpaper chatWallpaper = repository.setWallPaper(BitmapUtil.toWebPByteArray(bitmap));
            callback.onComplete(chatWallpaper);
        } catch (IOException e) {
            Log.w(TAG, e);
            callback.onError(Error.SAVING);
        } finally {
            bitmap.recycle();
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) IOException(java.io.IOException)

Aggregations

ChatWallpaper (org.thoughtcrime.securesms.wallpaper.ChatWallpaper)8 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 EditorModel (org.signal.imageeditor.core.model.EditorModel)2 Wallpaper (org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper)2