mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Material 3 media gallery refresh.
This commit is contained in:
committed by
Cody Henthorne
parent
b78633f9a7
commit
359a39ddaf
@@ -119,7 +119,7 @@ public final class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static EditorModel initialModel() {
|
||||
|
||||
EditorModel model = EditorModel.create();
|
||||
EditorModel model = EditorModel.create(0xFF000000);
|
||||
|
||||
EditorElement image = new EditorElement(new UrlRenderer("https://cdn.aarp.net/content/dam/aarp/home-and-family/your-home/2018/06/1140-house-inheriting.imgcache.rev68c065601779c5d76b913cf9ec3a977e.jpg"));
|
||||
image.getFlags().setSelectable(false).persist();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.signal.imageeditor.core;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
@@ -15,8 +16,11 @@ import android.widget.FrameLayout;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.core.view.GestureDetectorCompat;
|
||||
|
||||
import org.signal.imageeditor.R;
|
||||
import org.signal.imageeditor.core.model.EditorElement;
|
||||
import org.signal.imageeditor.core.model.EditorModel;
|
||||
import org.signal.imageeditor.core.model.ThumbRenderer;
|
||||
@@ -45,6 +49,8 @@ import java.util.List;
|
||||
*/
|
||||
public final class ImageEditorView extends FrameLayout {
|
||||
|
||||
private static final int DEFAULT_BLACKOUT_COLOR = 0xFF000000;
|
||||
|
||||
private HiddenEditText editText;
|
||||
|
||||
@NonNull
|
||||
@@ -91,22 +97,32 @@ public final class ImageEditorView extends FrameLayout {
|
||||
|
||||
public ImageEditorView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
init(null);
|
||||
}
|
||||
|
||||
public ImageEditorView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
public ImageEditorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
init(attrs);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
private void init(@Nullable AttributeSet attributeSet) {
|
||||
setWillNotDraw(false);
|
||||
setModel(EditorModel.create());
|
||||
|
||||
final int blackoutColor;
|
||||
if (attributeSet != null) {
|
||||
TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ImageEditorView);
|
||||
blackoutColor = typedArray.getColor(R.styleable.ImageEditorView_imageEditorView_blackoutColor, DEFAULT_BLACKOUT_COLOR);
|
||||
typedArray.recycle();
|
||||
} else {
|
||||
blackoutColor = DEFAULT_BLACKOUT_COLOR;
|
||||
}
|
||||
|
||||
setModel(EditorModel.create(blackoutColor));
|
||||
|
||||
editText = createAHiddenTextEntryField();
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import org.signal.imageeditor.core.Bounds;
|
||||
import org.signal.imageeditor.R;
|
||||
@@ -53,16 +55,16 @@ import org.signal.imageeditor.core.renderers.TrashRenderer;
|
||||
*/
|
||||
final class EditorElementHierarchy {
|
||||
|
||||
static @NonNull EditorElementHierarchy create() {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.RECTANGLE));
|
||||
static @NonNull EditorElementHierarchy create(@ColorInt int blackoutColor) {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.RECTANGLE, blackoutColor));
|
||||
}
|
||||
|
||||
static @NonNull EditorElementHierarchy createForCircleEditing() {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.CIRCLE));
|
||||
static @NonNull EditorElementHierarchy createForCircleEditing(@ColorInt int blackoutColor) {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.CIRCLE, blackoutColor));
|
||||
}
|
||||
|
||||
static @NonNull EditorElementHierarchy createForPinchAndPanCropping() {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.PINCH_AND_PAN));
|
||||
static @NonNull EditorElementHierarchy createForPinchAndPanCropping(@ColorInt int blackoutColor) {
|
||||
return new EditorElementHierarchy(createRoot(CropStyle.PINCH_AND_PAN, blackoutColor));
|
||||
}
|
||||
|
||||
static @NonNull EditorElementHierarchy create(@NonNull EditorElement root) {
|
||||
@@ -116,7 +118,7 @@ final class EditorElementHierarchy {
|
||||
PINCH_AND_PAN
|
||||
}
|
||||
|
||||
private static @NonNull EditorElement createRoot(@NonNull CropStyle cropStyle) {
|
||||
private static @NonNull EditorElement createRoot(@NonNull CropStyle cropStyle, @ColorInt int blackoutColor) {
|
||||
EditorElement root = new EditorElement(null);
|
||||
|
||||
EditorElement imageRoot = new EditorElement(null);
|
||||
@@ -138,7 +140,7 @@ final class EditorElementHierarchy {
|
||||
overlay.addElement(selection);
|
||||
|
||||
boolean renderCenterThumbs = cropStyle == CropStyle.RECTANGLE;
|
||||
EditorElement cropEditorElement = new EditorElement(new CropAreaRenderer(R.color.crop_area_renderer_outer_color, renderCenterThumbs));
|
||||
EditorElement cropEditorElement = new EditorElement(new CropAreaRenderer(ColorUtils.setAlphaComponent(blackoutColor, 0x7F), renderCenterThumbs));
|
||||
|
||||
cropEditorElement.getFlags()
|
||||
.setRotateLocked(true)
|
||||
@@ -149,7 +151,8 @@ final class EditorElementHierarchy {
|
||||
|
||||
imageCrop.addElement(cropEditorElement);
|
||||
|
||||
EditorElement fade = new EditorElement(new FillRenderer(0x66000000), EditorModel.Z_FADE);
|
||||
|
||||
EditorElement fade = new EditorElement(new FillRenderer(ColorUtils.setAlphaComponent(blackoutColor, 0x66)), EditorModel.Z_FADE);
|
||||
fade.getFlags()
|
||||
.setSelectable(false)
|
||||
.setEditable(false)
|
||||
@@ -165,7 +168,7 @@ final class EditorElementHierarchy {
|
||||
.persist();
|
||||
cropEditorElement.addElement(trash);
|
||||
|
||||
EditorElement blackout = new EditorElement(new InverseFillRenderer(0xff000000));
|
||||
EditorElement blackout = new EditorElement(new InverseFillRenderer(ColorUtils.setAlphaComponent(blackoutColor, 0xFF)));
|
||||
|
||||
blackout.getFlags()
|
||||
.setSelectable(false)
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.graphics.RectF;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
@@ -116,26 +117,26 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
|
||||
this.cropUndoRedoStacks = new UndoRedoStacks(50);
|
||||
}
|
||||
|
||||
public static EditorModel create() {
|
||||
EditorModel model = new EditorModel(EditingPurpose.IMAGE, 0, EditorElementHierarchy.create());
|
||||
public static EditorModel create(@ColorInt int blackoutColor) {
|
||||
EditorModel model = new EditorModel(EditingPurpose.IMAGE, 0, EditorElementHierarchy.create(blackoutColor));
|
||||
model.setCropAspectLock(false);
|
||||
return model;
|
||||
}
|
||||
|
||||
public static EditorModel createForAvatarCapture() {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.AVATAR_CAPTURE, 1, EditorElementHierarchy.createForCircleEditing());
|
||||
public static EditorModel createForAvatarCapture(@ColorInt int blackoutColor) {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.AVATAR_CAPTURE, 1, EditorElementHierarchy.createForCircleEditing(blackoutColor));
|
||||
editorModel.setCropAspectLock(true);
|
||||
return editorModel;
|
||||
}
|
||||
|
||||
public static EditorModel createForAvatarEdit() {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.AVATAR_EDIT, 1, EditorElementHierarchy.createForCircleEditing());
|
||||
public static EditorModel createForAvatarEdit(@ColorInt int blackoutColor) {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.AVATAR_EDIT, 1, EditorElementHierarchy.createForCircleEditing(blackoutColor));
|
||||
editorModel.setCropAspectLock(true);
|
||||
return editorModel;
|
||||
}
|
||||
|
||||
public static EditorModel createForWallpaperEditing(float fixedRatio) {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.WALLPAPER, fixedRatio, EditorElementHierarchy.createForPinchAndPanCropping());
|
||||
public static EditorModel createForWallpaperEditing(float fixedRatio, @ColorInt int blackoutColor) {
|
||||
EditorModel editorModel = new EditorModel(EditingPurpose.WALLPAPER, fixedRatio, EditorElementHierarchy.createForPinchAndPanCropping(blackoutColor));
|
||||
editorModel.setCropAspectLock(true);
|
||||
return editorModel;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.signal.imageeditor.core.RendererContext;
|
||||
*/
|
||||
public final class CropAreaRenderer implements Renderer {
|
||||
|
||||
@ColorRes
|
||||
@ColorInt
|
||||
private final int color;
|
||||
private final boolean renderCenterThumbs;
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class CropAreaRenderer implements Renderer {
|
||||
Resources resources = rendererContext.context.getResources();
|
||||
|
||||
canvas.clipPath(cropClipPath);
|
||||
canvas.drawColor(ResourcesCompat.getColor(resources, color, null));
|
||||
canvas.drawColor(color);
|
||||
|
||||
rendererContext.mapRect(dst, Bounds.FULL_BOUNDS);
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class CropAreaRenderer implements Renderer {
|
||||
rendererContext.restore();
|
||||
}
|
||||
|
||||
public CropAreaRenderer(@ColorRes int color, boolean renderCenterThumbs) {
|
||||
public CropAreaRenderer(@ColorInt int color, boolean renderCenterThumbs) {
|
||||
this.color = color;
|
||||
this.renderCenterThumbs = renderCenterThumbs;
|
||||
|
||||
|
||||
6
image-editor/lib/src/main/res/values/styles.xml
Normal file
6
image-editor/lib/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<declare-styleable name="ImageEditorView">
|
||||
<attr name="imageEditorView_blackoutColor" format="color" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user