<gallery>优化裁剪功能:更新颜色拾取逻辑、同步工具栏图标、调整布局文件
This commit is contained in:
@@ -3,6 +3,7 @@ package cc.winboll.studio.gallery;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.content.DialogInterface;
|
||||
@@ -115,10 +116,11 @@ public class CropActivity extends AppCompatActivity {
|
||||
cropCanvasView = findViewById(R.id.crop_canvas_view);
|
||||
|
||||
final View colorView = findViewById(R.id.color_view);
|
||||
final GradientDrawable colorDrawable = (GradientDrawable) colorView.getBackground();
|
||||
cropCanvasView.setOnBackgroundColorChangedListener(new CropCanvasView.OnBackgroundColorChangedListener() {
|
||||
@Override
|
||||
public void onBackgroundColorChanged(int color) {
|
||||
colorView.setBackgroundColor(color);
|
||||
colorDrawable.setColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -127,7 +129,7 @@ public class CropActivity extends AppCompatActivity {
|
||||
public void onColorPicked(int color) {
|
||||
int pickX = cropCanvasView.getLastPickImageX();
|
||||
int pickY = cropCanvasView.getLastPickImageY();
|
||||
colorView.setBackgroundColor(color);
|
||||
colorDrawable.setColor(color);
|
||||
Toast.makeText(CropActivity.this,
|
||||
"颜色已拾取: #" + String.format("%06X", color & 0xFFFFFF) +
|
||||
" (" + pickX + "," + pickY + ")",
|
||||
@@ -143,7 +145,7 @@ public class CropActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
colorView.setBackgroundColor(cropCanvasView.getBackgroundColor());
|
||||
colorDrawable.setColor(cropCanvasView.getBackgroundColor());
|
||||
|
||||
loadImage();
|
||||
}
|
||||
|
||||
@@ -518,7 +518,15 @@ public class CropCanvasView extends View {
|
||||
if (colorPickMode) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (originalBitmap != null && !originalBitmap.isRecycled()) {
|
||||
previewColor = getImageColorAt(x, y);
|
||||
float imgX = screenToImageX(x);
|
||||
float imgY = screenToImageY(y);
|
||||
if (imageBounds.contains(imgX, imgY)) {
|
||||
previewColor = getImageColorAt(x, y);
|
||||
} else if (canvasBounds.contains(x, y)) {
|
||||
previewColor = backgroundColor;
|
||||
} else {
|
||||
previewColor = Color.TRANSPARENT;
|
||||
}
|
||||
lastPickX = x;
|
||||
lastPickY = y;
|
||||
if (backgroundColorChangedListener != null) {
|
||||
|
||||
Reference in New Issue
Block a user