Commit d028688a88068e2e4b8f128b6e21906475fd3edc
1 parent
90224e26a4
Exists in
master
框选功能优化
Showing
1 changed file
with
59 additions
and
59 deletions
Show diff stats
libs/common/src/main/java/com/prws/common/widget/MarkSizeView.java
| ... | ... | @@ -158,6 +158,7 @@ public class MarkSizeView extends View { |
| 158 | 158 | markPaint.setStyle(Paint.Style.STROKE);//不填充 |
| 159 | 159 | markPaint.setColor(strokeColor); |
| 160 | 160 | canvas.drawRect(markedArea, markPaint); |
| 161 | + setTranslationZ(8); | |
| 161 | 162 | } |
| 162 | 163 | if (!isEnabled()) { |
| 163 | 164 | return; |
| ... | ... | @@ -172,10 +173,8 @@ public class MarkSizeView extends View { |
| 172 | 173 | |
| 173 | 174 | //draw button |
| 174 | 175 | if (isValid && isUp) { |
| 175 | - if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { | |
| 176 | - canvas.drawBitmap(confirmBitmap, null, confirmArea, mBitPaint); | |
| 177 | - canvas.drawBitmap(cancelBitmap, null, cancelArea, mBitPaint); | |
| 178 | - } | |
| 176 | + canvas.drawBitmap(confirmBitmap, null, confirmArea, mBitPaint); | |
| 177 | + canvas.drawBitmap(cancelBitmap, null, cancelArea, mBitPaint); | |
| 179 | 178 | } |
| 180 | 179 | super.onDraw(canvas); |
| 181 | 180 | } |
| ... | ... | @@ -216,6 +215,7 @@ public class MarkSizeView extends View { |
| 216 | 215 | if (mOnClickListener != null) { |
| 217 | 216 | mOnClickListener.onConfirm(markedArea); |
| 218 | 217 | } |
| 218 | + setTranslationZ(0); | |
| 219 | 219 | } else if (isAreaContainPoint(cancelArea, x, y)) { |
| 220 | 220 | isButtonClicked = true; |
| 221 | 221 | isValid = true; |
| ... | ... | @@ -225,6 +225,7 @@ public class MarkSizeView extends View { |
| 225 | 225 | startX = startY = endX = endY = 0; |
| 226 | 226 | adjustMark(0, 0); |
| 227 | 227 | } |
| 228 | + setTranslationZ(0); | |
| 228 | 229 | } else if (isAreaContainPoint(ltVer, x, y)) { |
| 229 | 230 | isAdjustMode = true; |
| 230 | 231 | adjustNum = 1; |
| ... | ... | @@ -255,64 +256,63 @@ public class MarkSizeView extends View { |
| 255 | 256 | break; |
| 256 | 257 | case MotionEvent.ACTION_UP: |
| 257 | 258 | isUp = true; |
| 258 | - if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { | |
| 259 | - if (isButtonClicked) { | |
| 260 | - break; | |
| 261 | - } | |
| 262 | - adjustMark(x, y); | |
| 263 | - startX = markedArea.left; | |
| 264 | - startY = markedArea.top; | |
| 265 | - endX = markedArea.right; | |
| 266 | - endY = markedArea.bottom; | |
| 267 | - | |
| 268 | - if (markedArea.width() > confirmBitmap.getWidth() * 3 + mActionGap * 3 && markedArea.height() > confirmBitmap.getHeight() * 5) { | |
| 269 | - //显示在选区的内底部 | |
| 270 | - confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 271 | - endY - confirmBitmap.getHeight() - mActionGap, | |
| 272 | - endX - mActionGap, | |
| 273 | - endY - mActionGap); | |
| 274 | - | |
| 275 | - cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 276 | - endY - confirmBitmap.getHeight() - mActionGap, | |
| 277 | - endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 278 | - endY - mActionGap); | |
| 279 | - } else if (endY > getHeight() - confirmBitmap.getHeight() * 3) { | |
| 280 | - //显示在选区的上面 | |
| 281 | - confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 282 | - startY - confirmBitmap.getHeight() - mActionGap, | |
| 283 | - endX - mActionGap, | |
| 284 | - startY - mActionGap); | |
| 285 | - | |
| 286 | - cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 287 | - startY - confirmBitmap.getHeight() - mActionGap, | |
| 288 | - endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 289 | - startY - mActionGap); | |
| 290 | - } else { | |
| 291 | - //显示在选区的下面 | |
| 292 | - confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 293 | - endY + mActionGap, | |
| 294 | - endX - mActionGap, | |
| 295 | - endY + confirmBitmap.getHeight() + mActionGap); | |
| 296 | - | |
| 297 | - cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 298 | - endY + mActionGap, | |
| 299 | - endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 300 | - endY + confirmBitmap.getHeight() + mActionGap); | |
| 301 | - } | |
| 259 | + if (isButtonClicked) { | |
| 260 | + break; | |
| 261 | + } | |
| 262 | + adjustMark(x, y); | |
| 263 | + startX = markedArea.left; | |
| 264 | + startY = markedArea.top; | |
| 265 | + endX = markedArea.right; | |
| 266 | + endY = markedArea.bottom; | |
| 267 | + | |
| 268 | + if (markedArea.width() > confirmBitmap.getWidth() * 3 + mActionGap * 3 && markedArea.height() > confirmBitmap.getHeight() * 5) { | |
| 269 | + //显示在选区的内底部 | |
| 270 | + confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 271 | + endY - confirmBitmap.getHeight() - mActionGap, | |
| 272 | + endX - mActionGap, | |
| 273 | + endY - mActionGap); | |
| 274 | + | |
| 275 | + cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 276 | + endY - confirmBitmap.getHeight() - mActionGap, | |
| 277 | + endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 278 | + endY - mActionGap); | |
| 279 | + } else if (endY > getHeight() - confirmBitmap.getHeight() * 3) { | |
| 280 | + //显示在选区的上面 | |
| 281 | + confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 282 | + startY - confirmBitmap.getHeight() - mActionGap, | |
| 283 | + endX - mActionGap, | |
| 284 | + startY - mActionGap); | |
| 285 | + | |
| 286 | + cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 287 | + startY - confirmBitmap.getHeight() - mActionGap, | |
| 288 | + endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 289 | + startY - mActionGap); | |
| 290 | + } else { | |
| 291 | + //显示在选区的下面 | |
| 292 | + confirmArea.set(endX - confirmBitmap.getWidth() - mActionGap, | |
| 293 | + endY + mActionGap, | |
| 294 | + endX - mActionGap, | |
| 295 | + endY + confirmBitmap.getHeight() + mActionGap); | |
| 296 | + | |
| 297 | + cancelArea.set(endX - 2 * confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 298 | + endY + mActionGap, | |
| 299 | + endX - confirmBitmap.getWidth() - mActionGap * 2 - CommonUtil.dpToPx(context, 15), | |
| 300 | + endY + confirmBitmap.getHeight() + mActionGap); | |
| 301 | + } | |
| 302 | 302 | |
| 303 | - if (cancelArea.left < 0) { | |
| 304 | - int cancelAreaLeftMargin = Math.abs(cancelArea.left) + mActionGap; | |
| 305 | - cancelArea.left = cancelArea.left + cancelAreaLeftMargin; | |
| 306 | - cancelArea.right = cancelArea.right + cancelAreaLeftMargin; | |
| 307 | - confirmArea.left = confirmArea.left + cancelAreaLeftMargin; | |
| 308 | - confirmArea.right = confirmArea.right + cancelAreaLeftMargin; | |
| 309 | - } | |
| 303 | + if (cancelArea.left < 0) { | |
| 304 | + int cancelAreaLeftMargin = Math.abs(cancelArea.left) + mActionGap; | |
| 305 | + cancelArea.left = cancelArea.left + cancelAreaLeftMargin; | |
| 306 | + cancelArea.right = cancelArea.right + cancelAreaLeftMargin; | |
| 307 | + confirmArea.left = confirmArea.left + cancelAreaLeftMargin; | |
| 308 | + confirmArea.right = confirmArea.right + cancelAreaLeftMargin; | |
| 309 | + } | |
| 310 | 310 | |
| 311 | - if (!isValid) { | |
| 312 | - if (mOnClickListener != null) { | |
| 313 | - mOnClickListener.onCancel(); | |
| 314 | - } | |
| 311 | + if (!isValid) { | |
| 312 | + if (mOnClickListener != null) { | |
| 313 | + mOnClickListener.onCancel(); | |
| 315 | 314 | } |
| 315 | + setTranslationZ(0); | |
| 316 | 316 | } |
| 317 | 317 | break; |
| 318 | 318 | case MotionEvent.ACTION_CANCEL: | ... | ... |