Search in sources :

Example 1 with ChatWallpaper

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

the class WallpaperValues method setWallpaper.

public void setWallpaper(@NonNull Context context, @Nullable ChatWallpaper wallpaper) {
    Wallpaper currentWallpaper = getCurrentWallpaper();
    Uri currentUri = null;
    if (currentWallpaper != null && currentWallpaper.hasFile()) {
        currentUri = Uri.parse(currentWallpaper.getFile().getUri());
    }
    if (wallpaper != null) {
        putBlob(KEY_WALLPAPER, wallpaper.serialize().toByteArray());
    } else {
        getStore().beginWrite().remove(KEY_WALLPAPER).apply();
    }
    if (currentUri != null) {
        WallpaperStorage.onWallpaperDeselected(context, currentUri);
    }
}
Also used : Wallpaper(org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) Uri(android.net.Uri)

Example 2 with ChatWallpaper

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

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 3 with ChatWallpaper

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

the class WallpaperCropActivity method setWallpaper.

private void setWallpaper() {
    EditorModel model = imageEditor.getModel();
    Point size = new Point(imageEditor.getWidth(), imageEditor.getHeight());
    AlertDialog dialog = SimpleProgressDialog.show(this);
    viewModel.render(this, model, size, new AsynchronousCallback.MainThread<ChatWallpaper, WallpaperCropViewModel.Error>() {

        @Override
        public void onComplete(@Nullable ChatWallpaper result) {
            dialog.dismiss();
            setResult(RESULT_OK, new Intent().putExtra(ChatWallpaperPreviewActivity.EXTRA_CHAT_WALLPAPER, result));
            finish();
        }

        @Override
        public void onError(@Nullable WallpaperCropViewModel.Error error) {
            dialog.dismiss();
            Toast.makeText(WallpaperCropActivity.this, R.string.WallpaperCropActivity__error_setting_wallpaper, Toast.LENGTH_SHORT).show();
        }
    }.toWorkerCallback());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditorModel(org.signal.imageeditor.core.model.EditorModel) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) Intent(android.content.Intent) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Example 4 with ChatWallpaper

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

the class WallpaperValues method setWallpaper.

public void setWallpaper(@NonNull Context context, @Nullable ChatWallpaper wallpaper) {
    Wallpaper currentWallpaper = getCurrentWallpaper();
    Uri currentUri = null;
    if (currentWallpaper != null && currentWallpaper.hasFile()) {
        currentUri = Uri.parse(currentWallpaper.getFile().getUri());
    }
    if (wallpaper != null) {
        putBlob(KEY_WALLPAPER, wallpaper.serialize().toByteArray());
    } else {
        getStore().beginWrite().remove(KEY_WALLPAPER).apply();
    }
    if (currentUri != null) {
        WallpaperStorage.onWallpaperDeselected(context, currentUri);
    }
}
Also used : Wallpaper(org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) Uri(android.net.Uri)

Example 5 with ChatWallpaper

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

the class WallpaperCropActivity method setWallpaper.

private void setWallpaper() {
    EditorModel model = imageEditor.getModel();
    Point size = new Point(imageEditor.getWidth(), imageEditor.getHeight());
    AlertDialog dialog = SimpleProgressDialog.show(this);
    viewModel.render(this, model, size, new AsynchronousCallback.MainThread<ChatWallpaper, WallpaperCropViewModel.Error>() {

        @Override
        public void onComplete(@Nullable ChatWallpaper result) {
            dialog.dismiss();
            setResult(RESULT_OK, new Intent().putExtra(ChatWallpaperPreviewActivity.EXTRA_CHAT_WALLPAPER, result));
            finish();
        }

        @Override
        public void onError(@Nullable WallpaperCropViewModel.Error error) {
            dialog.dismiss();
            Toast.makeText(WallpaperCropActivity.this, R.string.WallpaperCropActivity__error_setting_wallpaper, Toast.LENGTH_SHORT).show();
        }
    }.toWorkerCallback());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditorModel(org.signal.imageeditor.core.model.EditorModel) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) Intent(android.content.Intent) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

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