Commit d7e5749a authored by 王韦's avatar 王韦

[new] 完善功能

parent ccd1e473
...@@ -34,4 +34,5 @@ dependencies { ...@@ -34,4 +34,5 @@ dependencies {
implementation project(path: ':widgetlib') implementation project(path: ':widgetlib')
// implementation 'com.qmai.android.sdk:widgetlib:1.1.2-SNAPSHOT' // implementation 'com.qmai.android.sdk:widgetlib:1.1.2-SNAPSHOT'
implementation project(path: ':tools') implementation project(path: ':tools')
implementation 'androidx.recyclerview:recyclerview:1.0.0'
} }
...@@ -3,16 +3,30 @@ package com.qimai.android.widget ...@@ -3,16 +3,30 @@ package com.qimai.android.widget
import android.os.Bundle import android.os.Bundle
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.qimai.android.widgetlib.popup.QmToolTip import com.qimai.android.widgetlib.popup.QmToolTip
import com.qimai.android.widgetlib.topbar.QmTopBar
class TipActivity : AppCompatActivity() { class TipActivity : AppCompatActivity() {
lateinit var mPop: QmToolTip
lateinit var topbar: QmTopBar
var items = mutableListOf("堂食", "外卖")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_tip) setContentView(R.layout.activity_tip)
topbar = findViewById(R.id.topBar)
customTopBar()
findViewById<Button>(R.id.top).setOnClickListener { findViewById<Button>(R.id.top).setOnClickListener {
val view = LayoutInflater.from(TipActivity@ this).inflate(R.layout.tip, null) val view = LayoutInflater.from(TipActivity@ this).inflate(R.layout.tip, null)
...@@ -36,5 +50,96 @@ class TipActivity : AppCompatActivity() { ...@@ -36,5 +50,96 @@ class TipActivity : AppCompatActivity() {
.build().show() .build().show()
} }
findViewById<Button>(R.id.topnorrow).setOnClickListener {
val view = LayoutInflater.from(TipActivity@ this).inflate(R.layout.tip, null)
QmToolTip.Builder()
.withAttachedView(findViewById(R.id.topnorrow))
.withContentView(view)
.withArrowShow(false)
.withGravity(Gravity.TOP)
.build().show()
}
findViewById<Button>(R.id.bottomnoArrow).setOnClickListener {
val view = LayoutInflater.from(TipActivity@ this).inflate(R.layout.tip, null)
QmToolTip.Builder()
.withAttachedView(findViewById<Button>(R.id.bottomnoArrow))
.withContentView(view)
.withArrowShow(false)
.withGravity(Gravity.BOTTOM)
.build().show()
}
}
private class PopListAdapter(
var datas: MutableList<String>,
var itemClick: (position: Int) -> Unit
) : RecyclerView.Adapter<PopListAdapter.PopListHolder>() {
private var currentChoosePositon = 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PopListHolder {
return PopListHolder(
LayoutInflater.from(parent.context).inflate(
R.layout.goodmanager_pop_item,
parent,
false
)
)
}
override fun getItemCount(): Int = datas.size
override fun onBindViewHolder(holder: PopListHolder, position: Int) {
holder.content.text = datas[position]
holder.container.setOnClickListener {
currentChoosePositon = position
itemClick.invoke(position)
}
holder.container.isSelected = position == currentChoosePositon
}
class PopListHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var content: TextView = itemView.findViewById(R.id.content)
var container: LinearLayout = itemView.findViewById(R.id.container)
}
}
private fun customTopBar() {
val topRight =
layoutInflater.inflate(R.layout.goodmanager_rightview_titlebar, topbar, false)
val rightText = topRight.findViewById<TextView>(R.id.rightText)
rightText.text = "堂食"
topbar.customRightView(topRight, null)
val recyclerView = RecyclerView(this)
recyclerView.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = PopListAdapter(items) {
mPop.dismiss()
}
topRight.setOnClickListener {
if (!GoodsManagerActivity@ this::mPop.isInitialized) {
GoodsManagerActivity@ this.mPop = QmToolTip.Builder()
.withGravity(Gravity.BOTTOM)
.withAttachedView(topRight)
.withDefaultOverlayStyle(R.style.tangshi)
.withContentView(recyclerView)
.withArrowShow(true)
.withArrowWeight(0.5f)
.build()
}
mPop.show()
}
} }
} }
package com.qimai.android.widget package com.qimai.android.widget
import android.graphics.Color import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.qimai.android.widgetlib.topbar.QmTopBar import com.qimai.android.widgetlib.topbar.QmTopBar
...@@ -15,6 +15,7 @@ class TopBarActivity : AppCompatActivity() { ...@@ -15,6 +15,7 @@ class TopBarActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_top_bar) setContentView(R.layout.activity_top_bar)
val toolbar = findViewById<QmTopBar>(R.id.toolbar) val toolbar = findViewById<QmTopBar>(R.id.toolbar)
val topbar2 = findViewById<QmTopBar>(R.id.topbar2)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowCustomEnabled(false) supportActionBar?.setDisplayShowCustomEnabled(false)
toolbar.registerViewClickListener { toolbar.registerViewClickListener {
...@@ -42,15 +43,22 @@ class TopBarActivity : AppCompatActivity() { ...@@ -42,15 +43,22 @@ class TopBarActivity : AppCompatActivity() {
findViewById<Button>(R.id.leftTextview).setOnClickListener { findViewById<Button>(R.id.leftTextview).setOnClickListener {
toolbar.rightTextProperty = toolbar.rightTextProperty.apply { toolbar.rightTextProperty = toolbar.rightTextProperty.apply {
text = "确定" text = "确定"
textColor = ContextCompat.getColor(this@TopBarActivity, R.color.abc_btn_colored_borderless_text_material) textColor = ContextCompat.getColor(
textBackground = ContextCompat.getDrawable(this@TopBarActivity, R.drawable.btn_shape) this@TopBarActivity,
R.color.abc_btn_colored_borderless_text_material
)
textBackground =
ContextCompat.getDrawable(this@TopBarActivity, R.drawable.btn_shape)
} }
} }
findViewById<Button>(R.id.center).setOnClickListener { findViewById<Button>(R.id.center).setOnClickListener {
toolbar.centerTextProperty = toolbar.centerTextProperty.apply { toolbar.centerTextProperty = toolbar.centerTextProperty.apply {
text = "修改" text = "修改"
textColor = ContextCompat.getColor(this@TopBarActivity, R.color.abc_btn_colored_borderless_text_material) textColor = ContextCompat.getColor(
this@TopBarActivity,
R.color.abc_btn_colored_borderless_text_material
)
} }
} }
...@@ -74,5 +82,14 @@ class TopBarActivity : AppCompatActivity() { ...@@ -74,5 +82,14 @@ class TopBarActivity : AppCompatActivity() {
toolbar.customRightView(text, null) toolbar.customRightView(text, null)
} }
val rightView =
layoutInflater.inflate(R.layout.goodmanager_rightview_titlebar, topbar2, false)
val rightText = rightView.findViewById<TextView>(R.id.rightText)
rightText.text = "堂食"
topbar2.customRightView(rightView, null)
} }
} }
...@@ -3,10 +3,18 @@ ...@@ -3,10 +3,18 @@
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"
android:background="#E9DFE0"
tools:context=".TipActivity"> tools:context=".TipActivity">
<com.qimai.android.widgetlib.topbar.QmTopBar
android:id="@+id/topBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="match_parent"
app:title_text="提示"
android:layout_height="45dp" />
<Button <Button
android:id="@+id/top" android:id="@+id/top"
android:layout_width="90dp" android:layout_width="90dp"
...@@ -31,14 +39,28 @@ ...@@ -31,14 +39,28 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <Button
android:layout_width="wrap_content" android:id="@+id/bottomnoArrow"
android:layout_height="wrap_content" android:layout_width="150dp"
android:text="测试测试测试\n 测试测试测试" android:layout_height="50dp"
android:textColor="#C02F14"
android:textSize="10sp" android:layout_marginTop="160dp"
app:layout_constraintBottom_toBottomOf="parent" android:text="bottomnoArrow"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintTop_toBottomOf="@+id/top" />
<Button
android:id="@+id/topnorrow"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="172dp"
android:layout_marginEnd="60dp"
android:text="topnorrow"
app:layout_constraintEnd_toStartOf="@+id/bottomnoArrow"
app:layout_constraintHorizontal_bias="0.725"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bottom" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -62,5 +62,9 @@ ...@@ -62,5 +62,9 @@
</LinearLayout> </LinearLayout>
<com.qimai.android.widgetlib.topbar.QmTopBar
android:id="@+id/topbar2"
android:layout_width="match_parent"
app:title_text="定义"
android:layout_height="45dp"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="35dp"
android:id="@+id/container"
android:layout_gravity="center"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content">
<TextView
android:id="@+id/content"
android:layout_width="match_parent"
tools:text="堂食"
android:gravity="center"
android:textColor="#000000"
android:textSize="16sp"
android:layout_height="wrap_content" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="45dp"
android:layout_height="45dp"
android:background="#776F6F"
android:orientation="horizontal">
<TextView
android:id="@+id/rightText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginEnd="4dp"
android:textColor="#e63939"
android:textSize="17sp"
tools:text="堂食" />
</LinearLayout>
\ No newline at end of file
...@@ -7,5 +7,11 @@ ...@@ -7,5 +7,11 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
</style> </style>
<style name="tangshi">
<item name="overlay_radius">5dp</item>
<item name="overlay_bgColor">#FFFFFF</item>
<item name="overlay_borderColor">#C54545</item>
<item name="overlay_borderWidth">1dp</item>
</style>
</resources> </resources>
...@@ -42,8 +42,8 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() { ...@@ -42,8 +42,8 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
val theme = context.theme.obtainStyledAttributes( val theme = context.theme.obtainStyledAttributes(
null, null,
R.styleable.QmToolTipOverlay, R.styleable.QmToolTipOverlay,
builder.defaultOverlayStyle, 0,
0 builder.defaultOverlayStyle
) )
this.radius = this.radius =
theme.getDimensionPixelSize( theme.getDimensionPixelSize(
...@@ -61,18 +61,18 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() { ...@@ -61,18 +61,18 @@ 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,
0 ContextCompat.getColor(context, R.color.QmTopBar_color_FFFFFFF)
) )
theme.recycle() theme.recycle()
this.showArrow = builder.showArrow this.showArrow = builder.showArrow
this.rectF = RectF() this.rectF = RectF()
bgPaint = Paint(Paint.ANTI_ALIAS_FLAG) bgPaint = Paint(Paint.ANTI_ALIAS_FLAG)
bgPaint.color = bgColor bgPaint.color =bgColor
bgPaint.style = Paint.Style.FILL bgPaint.style = Paint.Style.FILL
if (borderColor != 0) { if (borderColor != 0) {
borderPaint = Paint(Paint.ANTI_ALIAS_FLAG) borderPaint = Paint(Paint.ANTI_ALIAS_FLAG)
bgPaint.color = borderColor borderPaint.color = borderColor
borderPaint.style = Paint.Style.STROKE borderPaint.style = Paint.Style.STROKE
borderPaint.strokeJoin = Paint.Join.ROUND borderPaint.strokeJoin = Paint.Join.ROUND
borderPaint.strokeWidth = borderWidth.toFloat() borderPaint.strokeWidth = borderWidth.toFloat()
...@@ -85,7 +85,10 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() { ...@@ -85,7 +85,10 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
} }
override fun draw(canvas: Canvas) { override fun draw(canvas: Canvas) {
path.op(arrowPath, Path.Op.XOR) if (showArrow) {
path.op(arrowPath, Path.Op.UNION)
}
bgPaint?.let { bgPaint?.let {
canvas.drawPath(path, it) canvas.drawPath(path, it)
} }
...@@ -141,7 +144,12 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() { ...@@ -141,7 +144,12 @@ internal class QmTipOverlayDrawable(builder: QmToolTip.Builder) : Drawable() {
bottom = bottom bottom = bottom
) )
} else { } else {
rectF.set(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat()) rectF.set(
left.toFloat() + borderWidth,
top.toFloat() + borderWidth,
right.toFloat() - borderWidth,
bottom.toFloat() - borderWidth
)
path.addRoundRect(rectF, radius, radius, Path.Direction.CW) path.addRoundRect(rectF, radius, radius, Path.Direction.CW)
} }
} }
......
...@@ -45,6 +45,7 @@ class QmToolTip private constructor( ...@@ -45,6 +45,7 @@ class QmToolTip private constructor(
private val containerPaddingSmall = 10 private val containerPaddingSmall = 10
private var containerMeasureWidth = 0 private var containerMeasureWidth = 0
private var containerMeasureHeight = 0 private var containerMeasureHeight = 0
private var arrowWeight = 0f
private constructor(builder: Builder) : this( private constructor(builder: Builder) : this(
builder.attachedView, builder.attachedView,
...@@ -52,6 +53,7 @@ class QmToolTip private constructor( ...@@ -52,6 +53,7 @@ class QmToolTip private constructor(
builder.gravity builder.gravity
) { ) {
checkMustParams(builder) checkMustParams(builder)
arrowWeight = builder.arrowWeight
mWindow.width = ViewGroup.LayoutParams.WRAP_CONTENT mWindow.width = ViewGroup.LayoutParams.WRAP_CONTENT
mWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT mWindow.height = ViewGroup.LayoutParams.WRAP_CONTENT
...@@ -60,23 +62,32 @@ class QmToolTip private constructor( ...@@ -60,23 +62,32 @@ class QmToolTip private constructor(
mWindow.isOutsideTouchable = true mWindow.isOutsideTouchable = true
gravity = builder.gravity gravity = builder.gravity
val container = FrameLayout(builder.contentView!!.context) val container = FrameLayout(builder.contentView!!.context)
when (builder.gravity) { if (builder.showArrow) {
Gravity.TOP -> { when (builder.gravity) {
container.setPadding( Gravity.TOP -> {
containerPaddingSmall, container.setPadding(
containerPaddingSmall, containerPaddingSmall,
containerPaddingSmall, containerPaddingSmall,
containerPaddingBig containerPaddingSmall,
) containerPaddingBig
} )
Gravity.BOTTOM -> { }
container.setPadding( Gravity.BOTTOM -> {
containerPaddingSmall, container.setPadding(
containerPaddingBig, containerPaddingSmall,
containerPaddingSmall, containerPaddingBig,
containerPaddingSmall containerPaddingSmall,
) containerPaddingSmall
)
}
} }
} else {
container.setPadding(
containerPaddingSmall,
containerPaddingSmall,
containerPaddingSmall,
containerPaddingSmall
)
} }
container.addView( container.addView(
builder.contentView, builder.contentView,
...@@ -113,7 +124,6 @@ class QmToolTip private constructor( ...@@ -113,7 +124,6 @@ class QmToolTip private constructor(
if (containerMeasureHeight > remainOffset) { if (containerMeasureHeight > remainOffset) {
// view的下边放不下了 // view的下边放不下了
val containerParams = container.layoutParams val containerParams = container.layoutParams
if (containerParams == null) { if (containerParams == null) {
container.layoutParams = ViewGroup.LayoutParams( container.layoutParams = ViewGroup.LayoutParams(
...@@ -224,7 +234,10 @@ class QmToolTip private constructor( ...@@ -224,7 +234,10 @@ class QmToolTip private constructor(
private fun calculateBottomOffset(anchorView: View): Point { private fun calculateBottomOffset(anchorView: View): Point {
val point = Point() val point = Point()
point.x = attachedViewLocation[0] + containerMeasureWidth / 2
point.x =
(attachedViewLocation[0] + anchorView.measuredWidth / 2 - containerMeasureWidth * arrowWeight).toInt()
point.y = attachedViewLocation[1] + anchorView.measuredHeight point.y = attachedViewLocation[1] + anchorView.measuredHeight
return point return point
} }
......
...@@ -215,7 +215,7 @@ class QmTopBar : Toolbar { ...@@ -215,7 +215,7 @@ class QmTopBar : Toolbar {
if (params == null) { if (params == null) {
rightParams = RelativeLayout.LayoutParams( rightParams = RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT RelativeLayout.LayoutParams.MATCH_PARENT
) )
rightParams.addRule(RelativeLayout.CENTER_VERTICAL) rightParams.addRule(RelativeLayout.CENTER_VERTICAL)
rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT) rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
<resources> <resources>
<style name="QmToolTipOverlayDefault"> <style name="QmToolTipOverlayDefault">
<item name="overlay_radius">19dp</item> <item name="overlay_radius">5dp</item>
<item name="overlay_bgColor">@color/QmTopBar_color_FFFFFFF</item> <item name="overlay_bgColor">#ffffff</item>
<item name="overlay_borderColor">@color/color_777777</item> <item name="overlay_borderColor">#FFFFFF</item>
<item name="overlay_borderWidth">0.5dp</item> <item name="overlay_borderWidth">1dp</item>
</style> </style>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment