mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 00:29:11 +01:00
Use the image editor for avatars.
This commit is contained in:
@@ -47,7 +47,8 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
|
||||
private static final String TAG = Log.tag(ImageEditorFragment.class);
|
||||
|
||||
private static final String KEY_IMAGE_URI = "image_uri";
|
||||
private static final String KEY_IMAGE_URI = "image_uri";
|
||||
private static final String KEY_IS_AVATAR_MODE = "avatar_mode";
|
||||
|
||||
private static final int SELECT_OLD_STICKER_REQUEST_CODE = 123;
|
||||
private static final int SELECT_NEW_STICKER_REQUEST_CODE = 124;
|
||||
@@ -89,6 +90,12 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
private ImageEditorHud imageEditorHud;
|
||||
private ImageEditorView imageEditorView;
|
||||
|
||||
public static ImageEditorFragment newInstanceForAvatar(@NonNull Uri imageUri) {
|
||||
ImageEditorFragment fragment = newInstance(imageUri);
|
||||
fragment.requireArguments().putBoolean(KEY_IS_AVATAR_MODE, true);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public static ImageEditorFragment newInstance(@NonNull Uri imageUri) {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(KEY_IMAGE_URI, imageUri);
|
||||
@@ -133,6 +140,8 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
boolean isAvatarMode = requireArguments().getBoolean(KEY_IS_AVATAR_MODE, false);
|
||||
|
||||
imageEditorHud = view.findViewById(R.id.scribble_hud);
|
||||
imageEditorView = view.findViewById(R.id.image_editor_view);
|
||||
|
||||
@@ -150,12 +159,17 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
}
|
||||
|
||||
if (editorModel == null) {
|
||||
editorModel = new EditorModel();
|
||||
editorModel = isAvatarMode ? EditorModel.createForCircleEditing() : EditorModel.create();
|
||||
EditorElement image = new EditorElement(new UriGlideRenderer(imageUri, true, imageMaxWidth, imageMaxHeight));
|
||||
image.getFlags().setSelectable(false).persist();
|
||||
editorModel.addElement(image);
|
||||
}
|
||||
|
||||
if (isAvatarMode) {
|
||||
imageEditorHud.setUpForAvatarEditing();
|
||||
imageEditorHud.enterMode(ImageEditorHud.Mode.CROP);
|
||||
}
|
||||
|
||||
imageEditorView.setModel(editorModel);
|
||||
|
||||
refreshUniqueColors();
|
||||
@@ -381,6 +395,11 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
controller.onRequestFullScreen(fullScreen, hideKeyboard);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone() {
|
||||
controller.onDoneEditing();
|
||||
}
|
||||
|
||||
private void refreshUniqueColors() {
|
||||
imageEditorHud.setColorPalette(imageEditorView.getModel().getUniqueColorsIgnoringAlpha());
|
||||
}
|
||||
@@ -439,5 +458,7 @@ public final class ImageEditorFragment extends Fragment implements ImageEditorHu
|
||||
void onTouchEventsNeeded(boolean needed);
|
||||
|
||||
void onRequestFullScreen(boolean fullScreen, boolean hideKeyboard);
|
||||
|
||||
void onDoneEditing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -41,6 +40,7 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
private View saveButton;
|
||||
private View deleteButton;
|
||||
private View confirmButton;
|
||||
private View doneButton;
|
||||
private VerticalSlideColorPicker colorPicker;
|
||||
private RecyclerView colorPalette;
|
||||
|
||||
@@ -88,6 +88,7 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
deleteButton = findViewById(R.id.scribble_delete_button);
|
||||
confirmButton = findViewById(R.id.scribble_confirm_button);
|
||||
colorPicker = findViewById(R.id.scribble_color_picker);
|
||||
doneButton = findViewById(R.id.scribble_done_button);
|
||||
|
||||
cropAspectLock.setOnClickListener(v -> {
|
||||
eventListener.onCropAspectLock(!eventListener.isCropAspectLocked());
|
||||
@@ -123,6 +124,7 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
}
|
||||
|
||||
allViews.add(stickerButton);
|
||||
allViews.add(doneButton);
|
||||
}
|
||||
|
||||
private void setVisibleViewsWhenInMode(Mode mode, View... views) {
|
||||
@@ -154,6 +156,20 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
textButton.setOnClickListener(v -> setMode(Mode.TEXT));
|
||||
stickerButton.setOnClickListener(v -> setMode(Mode.INSERT_STICKER));
|
||||
saveButton.setOnClickListener(v -> eventListener.onSave());
|
||||
doneButton.setOnClickListener(v -> eventListener.onDone());
|
||||
}
|
||||
|
||||
public void setUpForAvatarEditing() {
|
||||
visibilityModeMap.get(Mode.NONE).add(doneButton);
|
||||
visibilityModeMap.get(Mode.NONE).remove(saveButton);
|
||||
visibilityModeMap.get(Mode.CROP).remove(cropAspectLock);
|
||||
|
||||
if (currentMode == Mode.NONE) {
|
||||
doneButton.setVisibility(View.VISIBLE);
|
||||
saveButton.setVisibility(View.GONE);
|
||||
} else if (currentMode == Mode.CROP) {
|
||||
cropAspectLock.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setColorPalette(@NonNull Set<Integer> colors) {
|
||||
@@ -266,6 +282,7 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
void onCropAspectLock(boolean locked);
|
||||
boolean isCropAspectLocked();
|
||||
void onRequestFullScreen(boolean fullScreen, boolean hideKeyboard);
|
||||
void onDone();
|
||||
}
|
||||
|
||||
private static final EventListener NULL_EVENT_LISTENER = new EventListener() {
|
||||
@@ -310,5 +327,9 @@ public final class ImageEditorHud extends LinearLayout {
|
||||
@Override
|
||||
public void onRequestFullScreen(boolean fullScreen, boolean hideKeyboard) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone() {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user