package ***.edit;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import ***.uitls.Utils;
import ***.view.CustomsEditText;
import ***.view.dialog.manager.ScreenUtil;
import ***.***.R;
import ***.***.model.bean.BubbleInfo;
import ***.***.model.bean.EditFrameInfo;
import ***.***.util.LogUtil;
import static com.blankj.utilcode.util.SizeUtils.dp2px;
import static com.blankj.utilcode.util.SizeUtils.px2dp;
import static com.blankj.utilcode.util.SizeUtils.px2sp;
public class MoveLayout extends RelativeLayout implements View.OnTouchListener {
private boolean isBorder = true;
private int dragDirection = 0;
private static final int TOP = 0x15;
private static final int LEFT = 0x16;
private static final int BOTTOM = 0x17;
private static final int RIGHT = 0x18;
private static final int LEFT_TOP = 0x11;
private static final int RIGHT_TOP = 0x12;
private static final int LEFT_BOTTOM = 0x13;
private static final int RIGHT_BOTTOM = 0x14;
private static final int CENTER = 0x19;
private int lastX;
private int lastY;
private float lastTrueX;
private float lastTrueY;
private int oriX,oriY;
private int screenWidth;
private int screenHeight;
private int oriLeft;
private int oriRight;
private int oriTop;
private int oriBottom;
private int oriWidth, oriHeight;
private int initWidth, initHeight;
/**
* 标示此类的每个实例的id
*/
private int identity = 0;
/**
* 保存此布局所显示的Image的本地路径
*/
private String imgLocalPath;
/**
* 保存此布局所显示的Image的服务器地址
*/
private String imgUrlPath;
/**
* 保存此布局锁展示的图标id
*/
private int imgLocalId;//没用上
private String imgLogcalBitmap;
/**
* 图片类型(图片或图标)
*/
private int imgType;
/**
* 保存气泡内边距 及背景图片本地路径
*/
private BubbleInfo bubbleInfo;
private String editBg;
/**
* 触控区域设定
*/
private int touchAreaLength = 60;
private int minWidth = 180;
private int minHeight = 120;
private final int minDragWidth = 180;
private final int minDragHeight = 90;
private static final String TAG = MoveLayout.class.getSimpleName();
private float ratio = DEFAULT_RATIO;
public final static float DEFAULT_RATIO = 1f;
private boolean isBubble = false;
private CustomsEditText customsEditText;
private int locationX;
private int locationY;
private Context mContext;
private int childViewType;
private int lastWidth = 0;
private int totalDw = 0;//累积宽度差
//存储四个角的宽高
private int currentCornerWidth = 0;
private int currentCornerHeight = 0;
private boolean hasInitTouchEvent = false;//四个角的触摸监听是否设置
private int singleLineMinWidth = 0;//单行最小宽度
private boolean noMove = false;
//四个角的序号
public static final int DELETE = 1;
public static final int COPY = 2;
public static final int ROTATION_SCALE = 3;
public static final int SIZE_CHANGE = 4;
private float lastSpacing,currentSpacing;
private float MIN_SCALE = 0.2f;//最小缩放比例
private float MAX_SCALE = 5.0f;//最大缩放比例
public MoveLayout(Context context, float ratio) {
super(context);
this.ratio = ratio;
init(context);
}
public MoveLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MoveLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
mContext = context;
screenHeight = 500;//getResources().getDisplayMetrics().heightPixels - 40;
screenWidth = 500;// getResources().getDisplayMetrics().widthPixels;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if(oldw == 0 && w != 0){
MIN_SCALE = (float) minHeight/h;
}
}
public void setViewWidthHeight(int width, int height) {
screenWidth = width;
screenHeight = height;
}
public void setMinHeight(int height) {
minHeight = height;
if (minHeight < touchAreaLength * 2) {
minHeight = touchAreaLength * 2;
}
}
public void setMinWidth(int width) {
minWidth = width;
if (minWidth < touchAreaLength * 3) {
minWidth = touchAreaLength * 3;
}
}
public String getImgUrlPath() {
return imgUrlPath;
}
public void setImgUrlPath(String imgUrlPath) {
this.imgUrlPath = imgUrlPath;
}
public BubbleInfo getBubbleInfo() {
return bubbleInfo;
}
public void setBubbleInfo(BubbleInfo bubbleInfo) {
this.bubbleInfo = bubbleInfo;
}
public String getEditBg() {
return editBg;
}
public void setEditBg(String editBg) {
this.editBg = editBg;
}
public boolean isBorder() {
return isBorder;
}
public void setBorder(boolean border) {
isBorder = border;
}
private int mDeleteHeight = 0;
private int mDeleteWidth = 0;
private boolean isInDeleteArea = false;
public void setDeleteWidthHeight(int width, int height) {
mDeleteWidth = screenWidth - width;
mDeleteHeight = height;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!hasInitTouchEvent) {
RelativeLayout rlt = (RelativeLayout) getChildAt(0);
View view = ((LinearLayout) rlt.getChildAt(0)).getChildAt(0);
rlt.getChildAt(DELETE).setOnTouchListener(this);
rlt.getChildAt(COPY).setOnTouchListener(this);
rlt.getChildAt(ROTATION_SCALE).setOnTouchListener(this);
rlt.getChildAt(SIZE_CHANGE).setOnTouchListener(this);
if (view instanceof ImageView) {
rlt.getChildAt(ROTATION_SCALE).setBackgroundResource(R.drawable.ic_copy_element);
rlt.getChildAt(COPY).setVisibility(GONE);
} else if (view instanceof CustomsEditText) {
rlt.getChildAt(SIZE_CHANGE).setBackgroundResource(R.drawable.ic_size_change_horizontal);
}
hasInitTouchEvent = true;
}
}
// 属性变量
private float translationX; // 移动X
private float translationY; // 移动Y
private float scale = 1; // 伸缩比例
private float rotation; // 旋转角度
// 移动过程中临时变量
private float actionX;
private float actionY;
private float spacing;
private float degree;
private int moveType; // 0=未选择,1=拖动,2=缩放
private boolean isImage = false;
private boolean isCustomEdit = false;
private boolean isDrag = false;
private float textRotationDegree = 0;//文本框旋转角度
@Override