Compare commits
8 Commits
gallery-v1
...
gallery-v1
| Author | SHA1 | Date | |
|---|---|---|---|
| 5decb2f8d9 | |||
| 29e7cfe985 | |||
| 6d521fefdb | |||
| f7932c134f | |||
| 93c59b0424 | |||
| fe248349df | |||
| 4790238343 | |||
| f144d91bb6 |
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Fri May 01 04:09:20 HKT 2026
|
||||
stageCount=12
|
||||
#Fri May 01 10:29:10 HKT 2026
|
||||
stageCount=15
|
||||
libraryProject=
|
||||
baseVersion=15.0
|
||||
publishVersion=15.0.11
|
||||
publishVersion=15.0.14
|
||||
buildCount=0
|
||||
baseBetaVersion=15.0.12
|
||||
baseBetaVersion=15.0.15
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package cc.winboll.studio.gallery;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
public class BgSelectorDialog extends Dialog {
|
||||
|
||||
public interface OnBgSelectedListener {
|
||||
void onBgSelected(int bgType);
|
||||
}
|
||||
|
||||
private int currentBgType;
|
||||
private OnBgSelectedListener listener;
|
||||
|
||||
public BgSelectorDialog(Context context, int currentBgType) {
|
||||
super(context);
|
||||
this.currentBgType = currentBgType;
|
||||
setContentView(R.layout.dialog_bg_selector);
|
||||
initViews();
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
RadioGroup radioGroup = findViewById(R.id.radio_group_bg);
|
||||
RadioButton radioCheckerboard = findViewById(R.id.radio_checkerboard);
|
||||
RadioButton radioWhite = findViewById(R.id.radio_white);
|
||||
RadioButton radioBlack = findViewById(R.id.radio_black);
|
||||
|
||||
switch (currentBgType) {
|
||||
case 0:
|
||||
radioCheckerboard.setChecked(true);
|
||||
break;
|
||||
case 1:
|
||||
radioWhite.setChecked(true);
|
||||
break;
|
||||
case 2:
|
||||
radioBlack.setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
int which = 0;
|
||||
if (checkedId == R.id.radio_white) {
|
||||
which = 1;
|
||||
} else if (checkedId == R.id.radio_black) {
|
||||
which = 2;
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onBgSelected(which);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnBgSelectedListener(OnBgSelectedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class CropActivity extends AppCompatActivity {
|
||||
private int cropWidth = 240;
|
||||
private int cropHeight = 120;
|
||||
private float cropRatio = 2.0f;
|
||||
private Preferences prefs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -54,7 +55,8 @@ public class CropActivity extends AppCompatActivity {
|
||||
cropWidth = getIntent().getIntExtra(EXTRA_CROP_WIDTH, 240);
|
||||
cropHeight = getIntent().getIntExtra(EXTRA_CROP_HEIGHT, 120);
|
||||
|
||||
Preferences prefs = new Preferences(this);
|
||||
prefs = new Preferences(this);
|
||||
int bgType = prefs.getBgType();
|
||||
if (cropWidth > 0 && cropHeight > 0) {
|
||||
cropRatio = (float) cropWidth / cropHeight;
|
||||
} else {
|
||||
@@ -70,13 +72,12 @@ public class CropActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
final ImageView btnColorPick = findViewById(R.id.btn_color_pick);
|
||||
btnColorPick.setOnClickListener(new View.OnClickListener() {
|
||||
final ImageView btnBg = findViewById(R.id.btn_color_pick);
|
||||
btnBg.setImageResource(R.drawable.ic_bg);
|
||||
btnBg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean pickMode = !cropCanvasView.isColorPickMode();
|
||||
cropCanvasView.setColorPickMode(pickMode);
|
||||
btnColorPick.setAlpha(pickMode ? 0.5f : 1.0f);
|
||||
showBgDialog();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -117,39 +118,51 @@ public class CropActivity extends AppCompatActivity {
|
||||
|
||||
final View colorView = findViewById(R.id.color_view);
|
||||
final GradientDrawable colorDrawable = (GradientDrawable) colorView.getBackground();
|
||||
|
||||
cropCanvasView.setBackgroundType(bgType);
|
||||
updateColorView(colorDrawable, bgType);
|
||||
|
||||
cropCanvasView.setOnBackgroundColorChangedListener(new CropCanvasView.OnBackgroundColorChangedListener() {
|
||||
@Override
|
||||
public void onBackgroundColorChanged(int color) {
|
||||
colorDrawable.setColor(color);
|
||||
}
|
||||
});
|
||||
|
||||
cropCanvasView.setOnColorPickedListener(new CropCanvasView.OnColorPickedListener() {
|
||||
@Override
|
||||
public void onColorPicked(int color) {
|
||||
int pickX = cropCanvasView.getLastPickImageX();
|
||||
int pickY = cropCanvasView.getLastPickImageY();
|
||||
colorDrawable.setColor(color);
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
colorDrawable.setColor(cropCanvasView.getBackgroundColor());
|
||||
|
||||
loadImage();
|
||||
}
|
||||
|
||||
private void updateColorView(GradientDrawable drawable, int bgType) {
|
||||
switch (bgType) {
|
||||
case 0:
|
||||
drawable.setColor(0xFF808080);
|
||||
break;
|
||||
case 1:
|
||||
drawable.setColor(0xFFFFFFFF);
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
drawable.setColor(0xFF000000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void showBgDialog() {
|
||||
final View colorView = findViewById(R.id.color_view);
|
||||
final GradientDrawable colorDrawable = (GradientDrawable) colorView.getBackground();
|
||||
final int currentBgType = cropCanvasView.getBackgroundType();
|
||||
|
||||
BgSelectorDialog dialog = new BgSelectorDialog(this, currentBgType);
|
||||
dialog.setOnBgSelectedListener(new BgSelectorDialog.OnBgSelectedListener() {
|
||||
@Override
|
||||
public void onBgSelected(int which) {
|
||||
cropCanvasView.setBackgroundType(which);
|
||||
prefs.setBgType(which);
|
||||
updateColorView(colorDrawable, which);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void loadImage() {
|
||||
try {
|
||||
if (imagePath != null && new File(imagePath).exists()) {
|
||||
@@ -261,7 +274,9 @@ public class CropActivity extends AppCompatActivity {
|
||||
info.append("画布宽度: ").append(cropCanvasView.getCanvasWidth()).append("px\n");
|
||||
info.append("画布高度: ").append(cropCanvasView.getCanvasHeight()).append("px\n");
|
||||
|
||||
info.append("\n=== 拾取颜色 ===\n");
|
||||
info.append("\n=== 背景类型 ===\n");
|
||||
String[] bgNames = {"灰白相间", "全白", "全黑"};
|
||||
info.append("背景: ").append(bgNames[cropCanvasView.getBackgroundType()]).append("\n");
|
||||
int bgColor = cropCanvasView.getBackgroundColor();
|
||||
info.append("背景颜色: #").append(String.format("%06X", bgColor & 0xFFFFFF)).append("\n");
|
||||
info.append("拾取坐标: ").append(cropCanvasView.getLastPickImageX()).append(",")
|
||||
|
||||
@@ -2,11 +2,14 @@ package cc.winboll.studio.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
@@ -71,6 +74,10 @@ public class CropCanvasView extends View {
|
||||
private Bitmap displayBitmap;
|
||||
private RectF initialSpanRect;
|
||||
private float initialSpan;
|
||||
private int bgType = 2;
|
||||
private Bitmap tileBitmap;
|
||||
private BitmapShader tileShader;
|
||||
private Paint bgPaint;
|
||||
private int backgroundColor = Color.BLUE;
|
||||
private boolean colorPickMode = false;
|
||||
private int previewColor = 0;
|
||||
@@ -111,6 +118,60 @@ public class CropCanvasView extends View {
|
||||
cornerPaint = new Paint();
|
||||
cornerPaint.setColor(Color.WHITE);
|
||||
cornerPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
bgType = 2;
|
||||
bgPaint = new Paint();
|
||||
initTileBitmap();
|
||||
}
|
||||
|
||||
private void initTileBitmap() {
|
||||
if (tileBitmap != null && !tileBitmap.isRecycled()) {
|
||||
tileBitmap.recycle();
|
||||
tileBitmap = null;
|
||||
}
|
||||
tileShader = null;
|
||||
|
||||
if (bgType == 0) {
|
||||
Drawable drawable = getContext().getDrawable(R.drawable.bg_checkerboard);
|
||||
if (drawable != null) {
|
||||
int w = drawable.getIntrinsicWidth();
|
||||
int h = drawable.getIntrinsicHeight();
|
||||
if (w <= 0) w = 10;
|
||||
if (h <= 0) h = 10;
|
||||
tileBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(tileBitmap);
|
||||
drawable.setBounds(0, 0, w, h);
|
||||
drawable.draw(c);
|
||||
tileShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackgroundType(int type) {
|
||||
if (bgType != type) {
|
||||
bgType = type;
|
||||
initTileBitmap();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public int getBackgroundType() {
|
||||
return bgType;
|
||||
}
|
||||
|
||||
private void drawBackground(Canvas canvas) {
|
||||
if (bgType == 0 && tileShader != null) {
|
||||
bgPaint.setShader(tileShader);
|
||||
canvas.drawRect(canvasBounds, bgPaint);
|
||||
} else if (bgType == 1) {
|
||||
bgPaint.setShader(null);
|
||||
bgPaint.setColor(Color.WHITE);
|
||||
canvas.drawRect(canvasBounds, bgPaint);
|
||||
} else {
|
||||
bgPaint.setShader(null);
|
||||
bgPaint.setColor(Color.BLACK);
|
||||
canvas.drawRect(canvasBounds, bgPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageBitmap(Bitmap bitmap) {
|
||||
@@ -175,7 +236,7 @@ public class CropCanvasView extends View {
|
||||
}
|
||||
Bitmap canvasBmp = Bitmap.createBitmap(canvasWidth, canvasHeight, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(canvasBmp);
|
||||
canvas.drawColor(backgroundColor);
|
||||
drawBackground(canvas);
|
||||
if (displayBitmap != null && !displayBitmap.isRecycled()) {
|
||||
if (displayBitmap == originalBitmap) {
|
||||
canvas.drawBitmap(displayBitmap, imageBounds.left, imageBounds.top, imagePaint);
|
||||
@@ -409,7 +470,7 @@ public class CropCanvasView extends View {
|
||||
getDisplayMatrix(matrix);
|
||||
canvas.concat(matrix);
|
||||
|
||||
canvas.drawColor(backgroundColor);
|
||||
drawBackground(canvas);
|
||||
|
||||
if (displayBitmap == originalBitmap) {
|
||||
canvas.drawBitmap(displayBitmap, imageBounds.left, imageBounds.top, imagePaint);
|
||||
@@ -523,7 +584,7 @@ public class CropCanvasView extends View {
|
||||
if (imageBounds.contains(imgX, imgY)) {
|
||||
previewColor = getImageColorAt(x, y);
|
||||
} else if (canvasBounds.contains(x, y)) {
|
||||
previewColor = backgroundColor;
|
||||
previewColor = (bgType == 1) ? Color.WHITE : Color.BLACK;
|
||||
} else {
|
||||
previewColor = Color.TRANSPARENT;
|
||||
}
|
||||
@@ -545,7 +606,7 @@ public class CropCanvasView extends View {
|
||||
pickedColor = colorAtPoint;
|
||||
backgroundColor = colorAtPoint;
|
||||
} else {
|
||||
pickedColor = backgroundColor;
|
||||
pickedColor = (bgType == 1) ? Color.WHITE : Color.BLACK;
|
||||
}
|
||||
if (colorPickedListener != null) {
|
||||
colorPickedListener.onColorPicked(pickedColor);
|
||||
|
||||
@@ -169,28 +169,24 @@ public class ImageViewerActivity extends Activity implements ViewPager.OnPageCha
|
||||
}
|
||||
|
||||
private void switchBg() {
|
||||
final String[] bgNames = {"灰白相间", "全白", "全黑"};
|
||||
final int[] bgResources = {R.drawable.bg_checkerboard, R.drawable.bg_white, R.drawable.bg_black};
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("选择背景")
|
||||
.setSingleChoiceItems(bgNames, bgType, new android.content.DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(android.content.DialogInterface dialog, int which) {
|
||||
bgType = which;
|
||||
prefs.setBgType(which);
|
||||
int currentItem = viewPager.getCurrentItem();
|
||||
View container = findViewById(R.id.container);
|
||||
if (container != null) {
|
||||
container.setBackgroundResource(bgResources[which]);
|
||||
}
|
||||
viewPager.setAdapter(new ImagePagerAdapter(imageUrls, bgType));
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
dialog.dismiss();
|
||||
BgSelectorDialog dialog = new BgSelectorDialog(this, bgType);
|
||||
dialog.setOnBgSelectedListener(new BgSelectorDialog.OnBgSelectedListener() {
|
||||
@Override
|
||||
public void onBgSelected(int which) {
|
||||
bgType = which;
|
||||
prefs.setBgType(which);
|
||||
int currentItem = viewPager.getCurrentItem();
|
||||
View container = findViewById(R.id.container);
|
||||
if (container != null) {
|
||||
container.setBackgroundResource(bgResources[which]);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消", null)
|
||||
.show();
|
||||
viewPager.setAdapter(new ImagePagerAdapter(imageUrls, bgType));
|
||||
viewPager.setCurrentItem(currentItem);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showDeleteDialog() {
|
||||
|
||||
11
gallery/src/main/res/drawable/ic_view_gallery_outline.xml
Normal file
11
gallery/src/main/res/drawable/ic_view_gallery_outline.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M1,3V21H23V3H1M21,5V14H3V5H21M11,16V19H8V16H11M3,16H6V19H3V16M13,19V16H16V19H13M18,19V16H21V19H18Z"/>
|
||||
|
||||
</vector>
|
||||
@@ -41,7 +41,7 @@
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_cover"
|
||||
android:src="@drawable/ic_view_gallery_outline"
|
||||
android:contentDescription="Gallery"/>
|
||||
|
||||
<ImageButton
|
||||
|
||||
45
gallery/src/main/res/layout/dialog_bg_selector.xml
Normal file
45
gallery/src/main/res/layout/dialog_bg_selector.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="选择背景"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="16dp" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radio_group_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_checkerboard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="灰白相间"
|
||||
android:padding="12dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_white"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="全白"
|
||||
android:padding="12dp" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radio_black"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="全黑"
|
||||
android:padding="12dp" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user