添加主窗口封面刷新机制和剪裁图片调试日志
- 添加剪裁图片保存时的调试日志输出 - 添加广播机制通知主窗口刷新封面图片 - 优化剪裁画布的显示和缩放功能 - 添加缩放按钮和ZoomContainerView支持 - 添加新的图标资源(ic_done、ic_zoom_in、ic_zoom_out)
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
package cc.winboll.studio.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class ZoomContainerView extends FrameLayout {
|
||||
private float scaleFactor = 1.0f;
|
||||
private float minScale = 0.5f;
|
||||
private float maxScale = 5.0f;
|
||||
private static final float ZOOM_STEP = 0.25f;
|
||||
|
||||
private ScaleGestureDetector scaleGestureDetector;
|
||||
private GestureDetector gestureDetector;
|
||||
private Paint borderPaint;
|
||||
|
||||
public ZoomContainerView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomContainerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public ZoomContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setWillNotDraw(false);
|
||||
|
||||
borderPaint = new Paint();
|
||||
borderPaint.setColor(Color.parseColor("#333333"));
|
||||
borderPaint.setStyle(Paint.Style.STROKE);
|
||||
borderPaint.setStrokeWidth(2);
|
||||
|
||||
scaleGestureDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||
@Override
|
||||
public boolean onScale(ScaleGestureDetector detector) {
|
||||
scaleFactor *= detector.getScaleFactor();
|
||||
scaleFactor = Math.max(minScale, Math.min(scaleFactor, maxScale));
|
||||
invalidate();
|
||||
requestLayout();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
if (scaleFactor > 1.5f) {
|
||||
scaleFactor = 1.0f;
|
||||
} else {
|
||||
scaleFactor = 2.0f;
|
||||
}
|
||||
invalidate();
|
||||
requestLayout();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void zoomIn() {
|
||||
scaleFactor = Math.min(maxScale, scaleFactor + ZOOM_STEP);
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public void zoomOut() {
|
||||
scaleFactor = Math.max(minScale, scaleFactor - ZOOM_STEP);
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public float getScaleFactor() {
|
||||
return scaleFactor;
|
||||
}
|
||||
|
||||
public void resetZoom() {
|
||||
scaleFactor = 1.0f;
|
||||
invalidate();
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int childCount = getChildCount();
|
||||
if (childCount > 0) {
|
||||
View child = getChildAt(0);
|
||||
measureChild(child, widthMeasureSpec, heightMeasureSpec);
|
||||
int childW = (int) (child.getMeasuredWidth() * scaleFactor);
|
||||
int childH = (int) (child.getMeasuredHeight() * scaleFactor);
|
||||
setMeasuredDimension(
|
||||
MeasureSpec.getSize(widthMeasureSpec),
|
||||
MeasureSpec.getSize(heightMeasureSpec)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
boolean handled = scaleGestureDetector.onTouchEvent(event);
|
||||
if (!scaleGestureDetector.isInProgress()) {
|
||||
handled = gestureDetector.onTouchEvent(event) || handled;
|
||||
}
|
||||
return handled || super.onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user