Compare commits
4 Commits
gallery-v1
...
gallery-v1
| Author | SHA1 | Date | |
|---|---|---|---|
| 139083c22f | |||
| c49e68d7f1 | |||
| b035d461aa | |||
| 474ddcbb3b |
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue Apr 28 10:57:44 HKT 2026
|
||||
stageCount=8
|
||||
#Tue Apr 28 13:58:55 HKT 2026
|
||||
stageCount=9
|
||||
libraryProject=
|
||||
baseVersion=15.0
|
||||
publishVersion=15.0.7
|
||||
publishVersion=15.0.8
|
||||
buildCount=0
|
||||
baseBetaVersion=15.0.8
|
||||
baseBetaVersion=15.0.9
|
||||
|
||||
@@ -5,13 +5,21 @@ import android.graphics.BitmapFactory;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import java.io.File;
|
||||
@@ -78,6 +86,13 @@ public class CropActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btn_info).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showCropInfoDialog();
|
||||
}
|
||||
});
|
||||
|
||||
zoomContainer = findViewById(R.id.zoom_container);
|
||||
|
||||
SeekBar seekBarZoom = findViewById(R.id.seekbar_zoom);
|
||||
@@ -98,6 +113,37 @@ public class CropActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
cropCanvasView = findViewById(R.id.crop_canvas_view);
|
||||
|
||||
final View colorView = findViewById(R.id.color_view);
|
||||
cropCanvasView.setOnBackgroundColorChangedListener(new CropCanvasView.OnBackgroundColorChangedListener() {
|
||||
@Override
|
||||
public void onBackgroundColorChanged(int color) {
|
||||
colorView.setBackgroundColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
cropCanvasView.setOnColorPickedListener(new CropCanvasView.OnColorPickedListener() {
|
||||
@Override
|
||||
public void onColorPicked(int color) {
|
||||
int pickX = cropCanvasView.getLastPickImageX();
|
||||
int pickY = cropCanvasView.getLastPickImageY();
|
||||
Toast.makeText(CropActivity.this,
|
||||
"颜色已拾取: #" + String.format("%06X", color & 0xFFFFFF) +
|
||||
" (" + pickX + "," + pickY + ")",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
cropCanvasView.setOnColorPickEndListener(new CropCanvasView.OnColorPickEndListener() {
|
||||
@Override
|
||||
public void onColorPickEnd() {
|
||||
cropCanvasView.setColorPickMode(false);
|
||||
btnColorPick.setAlpha(1.0f);
|
||||
}
|
||||
});
|
||||
|
||||
colorView.setBackgroundColor(cropCanvasView.getBackgroundColor());
|
||||
|
||||
loadImage();
|
||||
}
|
||||
|
||||
@@ -206,6 +252,67 @@ public class CropActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void showCropInfoDialog() {
|
||||
StringBuilder info = new StringBuilder();
|
||||
info.append("=== 画布信息 ===\n");
|
||||
info.append("画布宽度: ").append(cropCanvasView.getCanvasWidth()).append("px\n");
|
||||
info.append("画布高度: ").append(cropCanvasView.getCanvasHeight()).append("px\n");
|
||||
|
||||
info.append("\n=== 拾取颜色 ===\n");
|
||||
int bgColor = cropCanvasView.getBackgroundColor();
|
||||
info.append("背景颜色: #").append(String.format("%06X", bgColor & 0xFFFFFF)).append("\n");
|
||||
info.append("拾取坐标: ").append(cropCanvasView.getLastPickImageX()).append(",")
|
||||
.append(cropCanvasView.getLastPickImageY()).append("\n");
|
||||
|
||||
info.append("\n=== 裁剪结果 ===\n");
|
||||
RectF cropRect = cropCanvasView.getCropRect();
|
||||
if (cropRect != null) {
|
||||
info.append("裁剪区域: ").append((int)cropRect.left).append(",")
|
||||
.append((int)cropRect.top).append(",")
|
||||
.append((int)cropRect.right).append(",")
|
||||
.append((int)cropRect.bottom).append("\n");
|
||||
info.append("裁剪宽度: ").append((int)cropRect.width()).append("px\n");
|
||||
info.append("裁剪高度: ").append((int)cropRect.height()).append("px\n");
|
||||
}
|
||||
|
||||
Bitmap canvasBitmap = cropCanvasView.getCanvasBitmap();
|
||||
final Bitmap[] previewHolder = new Bitmap[1];
|
||||
if (canvasBitmap != null && !canvasBitmap.isRecycled() && cropRect != null) {
|
||||
int bmpX = Math.max(0, (int) cropRect.left);
|
||||
int bmpY = Math.max(0, (int) cropRect.top);
|
||||
int bmpW = Math.min((int) cropRect.width(), canvasBitmap.getWidth() - bmpX);
|
||||
int bmpH = Math.min((int) cropRect.height(), canvasBitmap.getHeight() - bmpY);
|
||||
if (bmpW > 0 && bmpH > 0) {
|
||||
previewHolder[0] = Bitmap.createBitmap(canvasBitmap, bmpX, bmpY, bmpW, bmpH);
|
||||
}
|
||||
}
|
||||
|
||||
final Bitmap previewBitmap = previewHolder[0];
|
||||
|
||||
View dialogView = getLayoutInflater().inflate(R.layout.dialog_crop_info, null);
|
||||
TextView infoText = dialogView.findViewById(R.id.info_text);
|
||||
ImageView previewImage = dialogView.findViewById(R.id.preview_image);
|
||||
infoText.setText(info.toString());
|
||||
if (previewBitmap != null) {
|
||||
previewImage.setImageBitmap(previewBitmap);
|
||||
}
|
||||
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setTitle("裁剪信息")
|
||||
.setView(dialogView)
|
||||
.setPositiveButton("确定", null)
|
||||
.create();
|
||||
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (previewBitmap != null && !previewBitmap.isRecycled()) {
|
||||
previewBitmap.recycle();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -12,6 +12,33 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class CropCanvasView extends View {
|
||||
public interface OnBackgroundColorChangedListener {
|
||||
void onBackgroundColorChanged(int color);
|
||||
}
|
||||
|
||||
public interface OnColorPickedListener {
|
||||
void onColorPicked(int color);
|
||||
}
|
||||
|
||||
public interface OnColorPickEndListener {
|
||||
void onColorPickEnd();
|
||||
}
|
||||
|
||||
private OnBackgroundColorChangedListener backgroundColorChangedListener;
|
||||
private OnColorPickedListener colorPickedListener;
|
||||
private OnColorPickEndListener colorPickEndListener;
|
||||
|
||||
public void setOnBackgroundColorChangedListener(OnBackgroundColorChangedListener listener) {
|
||||
this.backgroundColorChangedListener = listener;
|
||||
}
|
||||
|
||||
public void setOnColorPickedListener(OnColorPickedListener listener) {
|
||||
this.colorPickedListener = listener;
|
||||
}
|
||||
|
||||
public void setOnColorPickEndListener(OnColorPickEndListener listener) {
|
||||
this.colorPickEndListener = listener;
|
||||
}
|
||||
private Paint imagePaint;
|
||||
private Paint borderPaint;
|
||||
private Paint cornerPaint;
|
||||
@@ -39,11 +66,16 @@ public class CropCanvasView extends View {
|
||||
private RectF imageBounds = new RectF();
|
||||
private RectF canvasBounds = new RectF();
|
||||
private Bitmap originalBitmap;
|
||||
private Bitmap canvasBitmap;
|
||||
private float bitmapScale = 1.0f;
|
||||
private Bitmap displayBitmap;
|
||||
private RectF initialSpanRect;
|
||||
private float initialSpan;
|
||||
private int backgroundColor = Color.BLUE;
|
||||
private boolean colorPickMode = false;
|
||||
private int previewColor = 0;
|
||||
private float lastPickX = 0;
|
||||
private float lastPickY = 0;
|
||||
private float pickX, pickY;
|
||||
|
||||
private float displayScale = 1.0f;
|
||||
@@ -239,6 +271,9 @@ public class CropCanvasView extends View {
|
||||
|
||||
public void setBackgroundColor(int color) {
|
||||
this.backgroundColor = color;
|
||||
if (backgroundColorChangedListener != null) {
|
||||
backgroundColorChangedListener.onBackgroundColorChanged(color);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@@ -246,6 +281,40 @@ public class CropCanvasView extends View {
|
||||
return backgroundColor;
|
||||
}
|
||||
|
||||
public int getPreviewColor() {
|
||||
return previewColor;
|
||||
}
|
||||
|
||||
public float getLastPickX() {
|
||||
return lastPickX;
|
||||
}
|
||||
|
||||
public float getLastPickY() {
|
||||
return lastPickY;
|
||||
}
|
||||
|
||||
public int getLastPickImageX() {
|
||||
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||
return 0;
|
||||
}
|
||||
float imgX = screenToImageX(lastPickX);
|
||||
float imgY = screenToImageY(lastPickY);
|
||||
int bmpX = (int) ((imgX - imageBounds.left) * displayBitmapScale);
|
||||
int bmpY = (int) ((imgY - imageBounds.top) * displayBitmapScale);
|
||||
return Math.max(0, Math.min(bmpX, originalBitmap.getWidth() - 1));
|
||||
}
|
||||
|
||||
public int getLastPickImageY() {
|
||||
if (originalBitmap == null || originalBitmap.isRecycled()) {
|
||||
return 0;
|
||||
}
|
||||
float imgX = screenToImageX(lastPickX);
|
||||
float imgY = screenToImageY(lastPickY);
|
||||
int bmpX = (int) ((imgX - imageBounds.left) * displayBitmapScale);
|
||||
int bmpY = (int) ((imgY - imageBounds.top) * displayBitmapScale);
|
||||
return Math.max(0, Math.min(bmpY, originalBitmap.getHeight() - 1));
|
||||
}
|
||||
|
||||
public void setColorPickMode(boolean enable) {
|
||||
this.colorPickMode = enable;
|
||||
if (enable) {
|
||||
@@ -447,11 +516,29 @@ public class CropCanvasView extends View {
|
||||
}
|
||||
|
||||
if (colorPickMode) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
pickX = x;
|
||||
pickY = y;
|
||||
int color = getColorAt(x, y);
|
||||
setBackgroundColor(color);
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (originalBitmap != null && !originalBitmap.isRecycled()) {
|
||||
previewColor = getImageColorAt(x, y);
|
||||
lastPickX = x;
|
||||
lastPickY = y;
|
||||
if (backgroundColorChangedListener != null) {
|
||||
backgroundColorChangedListener.onBackgroundColorChanged(previewColor);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (previewColor != 0 && previewColor != Color.TRANSPARENT) {
|
||||
backgroundColor = previewColor;
|
||||
if (colorPickedListener != null) {
|
||||
colorPickedListener.onColorPicked(backgroundColor);
|
||||
}
|
||||
}
|
||||
if (colorPickEndListener != null) {
|
||||
colorPickEndListener.onColorPickEnd();
|
||||
}
|
||||
previewColor = 0;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
6
gallery/src/main/res/drawable/bg_color_circle.xml
Normal file
6
gallery/src/main/res/drawable/bg_color_circle.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@android:color/holo_green_dark"/>
|
||||
<size android:width="32dp" android:height="32dp"/>
|
||||
</shape>
|
||||
6
gallery/src/main/res/drawable/bg_color_circle_border.xml
Normal file
6
gallery/src/main/res/drawable/bg_color_circle_border.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<stroke android:width="2dp" android:color="@android:color/white"/>
|
||||
<size android:width="36dp" android:height="36dp"/>
|
||||
</shape>
|
||||
6
gallery/src/main/res/drawable/bg_dialog.xml
Normal file
6
gallery/src/main/res/drawable/bg_dialog.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@android:color/black"/>
|
||||
<stroke android:width="2dp" android:color="@android:color/white"/>
|
||||
</shape>
|
||||
@@ -21,6 +21,27 @@
|
||||
android:src="@drawable/ic_close"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/color_icon_container"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_marginStart="8dp">
|
||||
|
||||
<View
|
||||
android:id="@+id/color_view"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/bg_color_circle"/>
|
||||
|
||||
<View
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/bg_color_circle_border"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_color_pick"
|
||||
android:layout_width="48dp"
|
||||
@@ -34,6 +55,14 @@
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_info"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_info"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_done"
|
||||
android:layout_width="48dp"
|
||||
|
||||
26
gallery/src/main/res/layout/dialog_crop_info.xml
Normal file
26
gallery/src/main/res/layout/dialog_crop_info.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp"
|
||||
android:background="@drawable/bg_dialog">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="monospace"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/preview_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:background="@android:color/black"/>
|
||||
|
||||
</LinearLayout>
|
||||
20
gallery/src/main/res/layout/item_color_icon.xml
Normal file
20
gallery/src/main/res/layout/item_color_icon.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp">
|
||||
|
||||
<View
|
||||
android:id="@+id/color_view"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/bg_color_circle"/>
|
||||
|
||||
<View
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="@drawable/bg_color_circle_border"/>
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user