Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Widget
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Android Widget
Widget
Commits
630ed17f
Commit
630ed17f
authored
Sep 01, 2019
by
王韦
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[new] 去除部分无效代码
parent
a60ca88a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
119 deletions
+65
-119
activity_tip.xml
app/src/main/res/layout/activity_tip.xml
+1
-0
QmTipOverlayDrawable.kt
...com/qimai/android/widgetlib/popup/QmTipOverlayDrawable.kt
+38
-105
QmToolTip.kt
.../main/java/com/qimai/android/widgetlib/popup/QmToolTip.kt
+26
-14
No files found.
app/src/main/res/layout/activity_tip.xml
View file @
630ed17f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:background=
"#E9DFE0"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".TipActivity"
>
tools:context=
".TipActivity"
>
...
...
widgetlib/src/main/java/com/qimai/android/widgetlib/popup/QmTipOverlayDrawable.kt
View file @
630ed17f
...
@@ -4,6 +4,7 @@ import android.graphics.*
...
@@ -4,6 +4,7 @@ import android.graphics.*
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
android.os.Build
import
android.os.Build
import
android.view.Gravity
import
android.view.Gravity
import
androidx.core.content.ContextCompat
import
com.qimai.android.tools.dpTopx
import
com.qimai.android.tools.dpTopx
import
com.qimai.android.widgetlib.R
import
com.qimai.android.widgetlib.R
...
@@ -12,6 +13,7 @@ import com.qimai.android.widgetlib.R
...
@@ -12,6 +13,7 @@ import com.qimai.android.widgetlib.R
* @version 1.1.1
* @version 1.1.1
* @Description
* @Description
**/
**/
@Suppress
(
"unused"
)
internal
class
QmTipOverlayDrawable
(
builder
:
QmToolTip
.
Builder
)
:
Drawable
()
{
internal
class
QmTipOverlayDrawable
(
builder
:
QmToolTip
.
Builder
)
:
Drawable
()
{
private
val
outlineRect
=
Rect
()
private
val
outlineRect
=
Rect
()
...
@@ -26,8 +28,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -26,8 +28,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
private
var
padding
=
0
private
var
padding
=
0
private
var
gravity
=
builder
.
gravity
private
var
gravity
=
builder
.
gravity
private
val
rectF
:
RectF
private
val
rectF
:
RectF
private
val
arrowHeight
=
15f
private
val
arrowHeight
=
20f
/**
/**
...
@@ -50,7 +51,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -50,7 +51,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
).
toFloat
()
).
toFloat
()
this
.
bgColor
=
theme
.
getColor
(
this
.
bgColor
=
theme
.
getColor
(
R
.
styleable
.
QmToolTipOverlay_overlay_bgColor
,
R
.
styleable
.
QmToolTipOverlay_overlay_bgColor
,
context
.
resources
.
getColor
(
R
.
color
.
QmTopBar_color_FFFFFFF
)
ContextCompat
.
getColor
(
context
,
R
.
color
.
QmTopBar_color_FFFFFFF
)
)
)
this
.
borderWidth
=
this
.
borderWidth
=
theme
.
getDimensionPixelOffset
(
theme
.
getDimensionPixelOffset
(
...
@@ -59,7 +60,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -59,7 +60,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
)
)
this
.
borderColor
=
theme
.
getColor
(
this
.
borderColor
=
theme
.
getColor
(
R
.
styleable
.
QmToolTipOverlay_overlay_borderColor
,
R
.
styleable
.
QmToolTipOverlay_overlay_borderColor
,
context
.
resources
.
getColor
(
R
.
color
.
QmTopBar_color_FFFFFFF
)
ContextCompat
.
getColor
(
context
,
R
.
color
.
QmTopBar_color_FFFFFFF
)
)
)
theme
.
recycle
()
theme
.
recycle
()
...
@@ -84,16 +85,13 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -84,16 +85,13 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
override
fun
draw
(
canvas
:
Canvas
)
{
override
fun
draw
(
canvas
:
Canvas
)
{
path
.
op
(
arrowPath
,
Path
.
Op
.
XOR
)
path
.
op
(
arrowPath
,
Path
.
Op
.
XOR
)
bgPaint
?.
let
{
canvas
.
drawPath
(
path
,
it
)
}
borderPaint
?.
let
{
borderPaint
?.
let
{
canvas
.
drawPath
(
path
,
it
)
canvas
.
drawPath
(
path
,
it
)
}
}
// borderPaint?.let {
// canvas.drawPath(arrowPath,it)
// }
// borderPaint?.let {
// canvas.drawPath(path, it)
// }
}
}
override
fun
setAlpha
(
alpha
:
Int
)
{
override
fun
setAlpha
(
alpha
:
Int
)
{
...
@@ -118,7 +116,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -118,7 +116,7 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
}
else
{
}
else
{
// 5.0以下
// 5.0以下
// todo nothing
}
}
}
}
...
@@ -135,85 +133,85 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -135,85 +133,85 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
val
right
=
outBounds
.
right
-
padding
val
right
=
outBounds
.
right
-
padding
val
bottom
=
outBounds
.
bottom
-
padding
val
bottom
=
outBounds
.
bottom
-
padding
val
maxY
=
bottom
-
radius
val
maxX
=
right
-
radius
val
minY
=
top
+
radius
val
minX
=
left
+
radius
if
(
gravity
!=
Gravity
.
NO_GRAVITY
)
{
if
(
gravity
!=
Gravity
.
NO_GRAVITY
)
{
calculatePathWithGravity
(
calculatePathWithGravity
(
outBounds
=
outBounds
,
left
=
left
,
left
=
left
,
top
=
top
,
top
=
top
,
right
=
right
,
right
=
right
,
bottom
=
bottom
,
bottom
=
bottom
maxY
=
maxY
,
maxX
=
maxX
,
minY
=
minY
,
minX
=
minX
)
)
}
else
{
}
else
{
rectF
.
set
(
left
.
toFloat
(),
top
.
toFloat
(),
right
.
toFloat
(),
bottom
.
toFloat
())
rectF
.
set
(
left
.
toFloat
(),
top
.
toFloat
(),
right
.
toFloat
(),
bottom
.
toFloat
())
path
.
addRoundRect
(
rectF
,
radius
,
radius
,
Path
.
Direction
.
CW
)
path
.
addRoundRect
(
rectF
,
radius
,
radius
,
Path
.
Direction
.
CW
)
}
}
}
}
}
}
private
fun
calculatePathWithGravity
(
private
fun
calculatePathWithGravity
(
outBounds
:
Rect
,
left
:
Int
,
left
:
Int
,
top
:
Int
,
top
:
Int
,
right
:
Int
,
right
:
Int
,
bottom
:
Int
,
bottom
:
Int
maxY
:
Float
,
maxX
:
Float
,
minY
:
Float
,
minX
:
Float
)
{
)
{
when
(
gravity
)
{
when
(
gravity
)
{
Gravity
.
TOP
->
{
Gravity
.
TOP
->
{
drawArrow
Top
WithRect
(
left
,
top
,
right
,
bottom
)
drawArrow
Bottom
WithRect
(
left
,
top
,
right
,
bottom
)
}
}
Gravity
.
BOTTOM
->
{
Gravity
.
BOTTOM
->
{
drawArrow
Bottom
WithRect
(
left
,
top
,
right
,
bottom
)
drawArrow
Top
WithRect
(
left
,
top
,
right
,
bottom
)
}
}
}
}
}
}
/**
/**
* 箭头朝上
* 箭头朝下
*
* * --------------
* * | |
* * | |
* * |-----\/-----|
*/
*/
private
fun
drawArrowTopWithRect
(
private
fun
drawArrowBottomWithRect
(
left
:
Int
,
left
:
Int
,
top
:
Int
,
top
:
Int
,
right
:
Int
,
right
:
Int
,
bottom
:
Int
bottom
:
Int
)
{
)
{
val
radioHeight
=
(
right
-
left
)
*
arrowWeight
rectF
.
set
(
rectF
.
set
(
left
.
toFloat
()
+
borderWidth
,
left
.
toFloat
()
+
borderWidth
,
top
.
toFloat
()
+
borderWidth
,
top
.
toFloat
()
+
borderWidth
,
right
.
toFloat
()
-
borderWidth
,
right
.
toFloat
()
-
borderWidth
,
bottom
.
toFloat
()
-
arrowHeight
-
borderWidth
bottom
.
toFloat
()
-
arrowHeight
-
borderWidth
)
)
path
.
addRoundRect
(
rectF
,
radius
,
radius
,
Path
.
Direction
.
CW
)
path
.
addRoundRect
(
rectF
,
radius
,
radius
,
Path
.
Direction
.
CW
)
val
radioHeight
=
(
right
-
left
)
*
arrowWeight
arrowPath
.
moveTo
(
arrowPath
.
moveTo
(
left
+
radioHeight
+
borderWidth
-
arrowHeight
,
bottom
-
arrowHeight
-
borderWidth
)
left
+
radioHeight
+
borderWidth
-
arrowHeight
,
bottom
-
arrowHeight
-
borderWidth
)
arrowPath
.
lineTo
(
arrowPath
.
lineTo
(
left
.
toFloat
()
+
radioHeight
+
borderWidth
,
left
.
toFloat
()
+
radioHeight
+
borderWidth
,
(
bottom
-
borderWidth
).
toFloat
()
(
bottom
-
borderWidth
).
toFloat
()
)
)
arrowPath
.
lineTo
(
left
+
radioHeight
+
arrowHeight
+
borderWidth
,
bottom
-
arrowHeight
-
borderWidth
)
arrowPath
.
lineTo
(
left
+
radioHeight
+
arrowHeight
+
borderWidth
,
bottom
-
arrowHeight
-
borderWidth
)
arrowPath
.
close
()
arrowPath
.
close
()
}
}
private
fun
drawArrowBottomWithRect
(
/**
* 箭头朝上
*/
private
fun
drawArrowTopWithRect
(
left
:
Int
,
left
:
Int
,
top
:
Int
,
top
:
Int
,
right
:
Int
,
right
:
Int
,
...
@@ -237,70 +235,5 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
...
@@ -237,70 +235,5 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
top
+
arrowHeight
+
borderWidth
top
+
arrowHeight
+
borderWidth
)
)
arrowPath
.
close
()
arrowPath
.
close
()
}
}
private
fun
drawLeftArrayWithRect
(
left
:
Int
,
top
:
Int
,
right
:
Int
,
bottom
:
Int
)
{
rectF
.
set
(
left
.
toFloat
()
+
arrowHeight
+
borderWidth
,
top
.
toFloat
()
+
borderWidth
,
right
.
toFloat
()
-
borderWidth
,
bottom
.
toFloat
()
-
borderWidth
)
path
.
addRoundRect
(
rectF
,
radius
,
radius
,
Path
.
Direction
.
CW
)
val
radioHeight
=
(
bottom
-
top
)
*
arrowWeight
arrowPath
.
moveTo
(
left
+
arrowHeight
+
borderWidth
,
top
+
radioHeight
+
arrowHeight
)
arrowPath
.
lineTo
(
left
.
toFloat
()
+
borderWidth
,
top
+
radioHeight
)
arrowPath
.
lineTo
(
left
+
arrowHeight
+
borderWidth
,
top
+
radioHeight
-
arrowHeight
)
arrowPath
.
close
()
// path.moveTo(left + arrowHeight, bottom - radius)
// val radioHeight = (bottom - top) * arrowWeight
// path.lineTo(left + arrowHeight, top + radioHeight + arrowHeight)
// path.lineTo(left.toFloat(), top + radioHeight)
// path.lineTo(left + arrowHeight, top + radioHeight - arrowHeight)
// path.lineTo(left + arrowHeight, top + radius)
//// // 话 左上的 圆弧
// path.addArc(
// RectF(
// left + arrowHeight,
// top.toFloat(),
// left + arrowHeight + 2 * radius,
// top + 2 * radius
// ),
// 180F,
// 90f
// )
// path.lineTo(right - radius, top.toFloat())
// path.addArc(
// RectF(right - 2 * radius, top.toFloat(), right.toFloat(), top + 2 * radius),
// 270F,
// 90f)
// path.lineTo(right.toFloat(), bottom - radius)
// path.addArc(
// RectF(
// right - 2 * radius,
// bottom - 2 * radius,
// right.toFloat(),
// bottom.toFloat()
// ), 0f, 90f
// )
// path.lineTo(left + arrowHeight + radius, bottom.toFloat())
// path.addArc(
// RectF(
// left + arrowHeight,
// bottom - radius,
// left + arrowHeight + 2 * radius,
// bottom.toFloat()
// ), 90f, 90f
// )
// path.close()
}
}
}
\ No newline at end of file
widgetlib/src/main/java/com/qimai/android/widgetlib/popup/QmToolTip.kt
View file @
630ed17f
...
@@ -19,6 +19,7 @@ import com.qimai.android.widgetlib.R
...
@@ -19,6 +19,7 @@ import com.qimai.android.widgetlib.R
* @version 1.1.1
* @version 1.1.1
* @Description
* @Description
**/
**/
@Suppress
(
"unused"
)
class
QmToolTip
private
constructor
(
class
QmToolTip
private
constructor
(
var
attachedView
:
View
?,
var
attachedView
:
View
?,
var
defaultOverlayStyle
:
Int
,
var
defaultOverlayStyle
:
Int
,
...
@@ -41,8 +42,8 @@ class QmToolTip private constructor(
...
@@ -41,8 +42,8 @@ class QmToolTip private constructor(
private
val
containerPaddingBig
=
30
private
val
containerPaddingBig
=
30
private
val
containerPaddingSmall
=
10
private
val
containerPaddingSmall
=
10
var
containerMeasureWidth
=
0
private
var
containerMeasureWidth
=
0
var
containerMeasureHeight
=
0
private
var
containerMeasureHeight
=
0
private
constructor
(
builder
:
Builder
)
:
this
(
private
constructor
(
builder
:
Builder
)
:
this
(
builder
.
attachedView
,
builder
.
attachedView
,
...
@@ -126,10 +127,9 @@ class QmToolTip private constructor(
...
@@ -126,10 +127,9 @@ class QmToolTip private constructor(
})
})
mWindow
.
setOnDismissListener
{
mWindow
.
setOnDismissListener
{
// this@QMBasePopup.onDismiss()
if
(
builder
.
dismissListener
!=
null
)
{
// if (mDismissListener != null) {
builder
.
dismissListener
?.
invoke
(
mWindow
)
// mDismissListener!!.onDismiss()
}
// }
}
}
builder
.
attachedView
?.
addOnAttachStateChangeListener
(
object
:
builder
.
attachedView
?.
addOnAttachStateChangeListener
(
object
:
...
@@ -145,6 +145,10 @@ class QmToolTip private constructor(
...
@@ -145,6 +145,10 @@ class QmToolTip private constructor(
}
}
})
})
if
(
builder
.
animationStyle
!=
-
1
)
{
mWindow
.
animationStyle
=
builder
.
animationStyle
}
}
}
fun
hasShowing
():
Boolean
{
fun
hasShowing
():
Boolean
{
...
@@ -177,7 +181,7 @@ class QmToolTip private constructor(
...
@@ -177,7 +181,7 @@ class QmToolTip private constructor(
}
}
private
fun
calculateLocation
(
anchorView
:
View
):
Point
{
private
fun
calculateLocation
(
anchorView
:
View
):
Point
{
anchorView
?
.
getLocationOnScreen
(
attachedViewLocation
)
anchorView
.
getLocationOnScreen
(
attachedViewLocation
)
var
point
=
Point
()
var
point
=
Point
()
when
(
gravity
)
{
when
(
gravity
)
{
...
@@ -189,7 +193,6 @@ class QmToolTip private constructor(
...
@@ -189,7 +193,6 @@ class QmToolTip private constructor(
}
}
}
}
return
point
return
point
}
}
private
fun
calculateTopOffset
(
anchorView
:
View
):
Point
{
private
fun
calculateTopOffset
(
anchorView
:
View
):
Point
{
...
@@ -197,7 +200,7 @@ class QmToolTip private constructor(
...
@@ -197,7 +200,7 @@ class QmToolTip private constructor(
val
point
=
Point
()
val
point
=
Point
()
point
.
x
=
point
.
x
=
(
attachedViewLocation
[
0
]
+
anchorView
.
measuredWidth
/
2
)
-
containerMeasureWidth
/
2
(
attachedViewLocation
[
0
]
+
anchorView
.
measuredWidth
/
2
)
-
containerMeasureWidth
/
2
point
.
y
=
attachedViewLocation
[
1
]
-
a
rrowOffsetOfAnchor
-
anchorView
.
measuredHeight
/
2
point
.
y
=
attachedViewLocation
[
1
]
-
a
nchorView
.
measuredHeight
return
point
return
point
}
}
...
@@ -206,21 +209,18 @@ class QmToolTip private constructor(
...
@@ -206,21 +209,18 @@ class QmToolTip private constructor(
private
fun
calculateBottomOffset
(
anchorView
:
View
):
Point
{
private
fun
calculateBottomOffset
(
anchorView
:
View
):
Point
{
val
point
=
Point
()
val
point
=
Point
()
val
anchorViewHeight
=
anchorView
.
measuredWidth
point
.
x
=
attachedViewLocation
[
0
]
+
containerMeasureWidth
/
2
point
.
x
=
attachedViewLocation
[
0
]
+
containerMeasureWidth
/
2
point
.
y
=
attachedViewLocation
[
1
]
+
anchorView
.
measuredHeight
point
.
y
=
attachedViewLocation
[
1
]
+
anchorView
.
measuredHeight
return
point
return
point
}
}
class
Builder
{
class
Builder
{
@IntDef
(
Gravity
.
TOP
,
Gravity
.
BOTTOM
,
Gravity
.
NO_GRAVITY
)
@IntDef
(
Gravity
.
TOP
,
Gravity
.
BOTTOM
,
Gravity
.
NO_GRAVITY
)
@Retention
(
AnnotationRetention
.
SOURCE
)
@Retention
(
AnnotationRetention
.
SOURCE
)
internal
annotation
class
GravityRange
internal
annotation
class
GravityRange
internal
var
attachedView
:
View
?
=
null
internal
var
attachedView
:
View
?
=
null
internal
var
defaultOverlayStyle
:
Int
=
R
.
style
.
QmToolTipOverlayDefault
internal
var
defaultOverlayStyle
:
Int
=
R
.
style
.
QmToolTipOverlayDefault
...
@@ -229,17 +229,29 @@ class QmToolTip private constructor(
...
@@ -229,17 +229,29 @@ class QmToolTip private constructor(
internal
var
contentView
:
View
?
=
null
internal
var
contentView
:
View
?
=
null
internal
var
animationStyle
:
Int
=
-
1
internal
var
dismissListener
:
((
window
:
PopupWindow
)
->
Unit
)?
=
null
fun
withAttachedView
(
attachedView
:
View
?)
=
apply
{
fun
withAttachedView
(
attachedView
:
View
?)
=
apply
{
this
.
attachedView
=
attachedView
this
.
attachedView
=
attachedView
}
}
fun
withDismissListener
(
listener
:
(
window
:
PopupWindow
)
->
Unit
)
=
apply
{
this
.
dismissListener
=
listener
}
fun
withGravity
(
@GravityRange
gravity
:
Int
)
=
apply
{
fun
withGravity
(
@GravityRange
gravity
:
Int
)
=
apply
{
this
.
gravity
=
gravity
this
.
gravity
=
gravity
}
}
fun
withAnimationStyle
(
animationStyle
:
Int
)
=
apply
{
this
.
animationStyle
=
animationStyle
}
fun
withDefaultOverlayStyle
(
defaultOverlayStyle
:
Int
)
=
apply
{
fun
withDefaultOverlayStyle
(
defaultOverlayStyle
:
Int
)
=
apply
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment