Skip to content

Commit

Permalink
日常修改:2024-01-23.
Browse files Browse the repository at this point in the history
  • Loading branch information
walgr committed Jan 23, 2024
1 parent 015613c commit 836e364
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ import kotlin.math.abs
*/
open class QuickItemGroup<T : ViewGroup> @JvmOverloads constructor(
mContext: Context,
attributeSet: AttributeSet? = null,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
override val addToParent: Boolean = true,
override var addToParent: Boolean = true,
@LayoutRes private var layoutId: Int = 0,
open var viewType: Int = 0,
) : QuickViewGroup<T>(mContext, attributeSet, defStyleAttr, addToParent = addToParent), Bind {
) : QuickViewGroup<T>(mContext, attrs, defStyleAttr, addToParent = addToParent), Bind {

private var mView: View? = null
var position: Int = -1

override fun init() {
if (attrSet == null) {
attrs?.let {
attrSet = QuickViewGroupAttrSet(context, it)
}
}
initView()
initViewType()
super.init()
Expand All @@ -48,7 +43,7 @@ open class QuickItemGroup<T : ViewGroup> @JvmOverloads constructor(
}

private fun initLayoutIdByXml() {
layoutId = attrSet?.layoutRes ?: layoutId
layoutId = attrSet.layoutRes
}

open fun onCreateViewHolder() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.wpf.app.quickwidget.quickview

import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.RadioGroup
Expand All @@ -12,6 +15,7 @@ import androidx.annotation.CallSuper
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.tabs.TabLayout
import com.wpf.app.quickutil.helper.attribute.AutoGetAttribute
import com.wpf.app.quickutil.helper.attribute.AutoGetAttributeHelper
import com.wpf.app.quickutil.other.GenericEx
import com.wpf.app.quickutil.other.asTo
import com.wpf.app.quickutil.view.matchLayoutParams
Expand All @@ -23,16 +27,17 @@ import com.wpf.app.quickwidget.R
*/
//@InternalCoroutinesApi
open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(
mContext: Context,
open val attrs: AttributeSet? = null,
context: Context,
private val attrs: AttributeSet? = null,
open val defStyleAttr: Int = 0,
open val addToParent: Boolean = true,
open var addToParent: Boolean = true,
open val childView: Array<View>? = null
) : ViewGroup(mContext, attrs, defStyleAttr) {
) : ViewGroup(context, attrs, defStyleAttr) {

protected var attrSet: QuickViewGroupAttrSet? = null
protected val attrSet: QuickViewGroupAttrSet

init {
attrSet = AutoGetAttributeHelper.init(context, attrs, R.styleable.QuickViewGroup)
init()
}

Expand All @@ -41,16 +46,14 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(

@CallSuper
open fun init() {
if (attrSet == null) {
attrs?.let {
attrSet = QuickViewGroupAttrSet(context, it)
}
attrSet.addToParent?.let {
addToParent = it
}
initViewGroupByXml()
initViewGroupByT()
addChildToT()
if (!addToParent || isInEditMode) {
addTToThis()
addT()
}
}

Expand All @@ -68,34 +71,33 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(

private fun initViewGroupByXml() {
if (this.shadowView != null) return
attrSet?.let {
when (it.groupType) {
GroupType.TabLayout.type -> {
this.shadowView = TabLayout(context, attrs, defStyleAttr) as T
}
GroupType.LinearLayout.type -> {
this.shadowView = LinearLayout(context, attrs, defStyleAttr) as T
}
when (attrSet.groupType) {
GroupType.TabLayout.type -> {
this.shadowView = TabLayout(context, attrs, defStyleAttr) as T
}

GroupType.RelativeLayout.type -> {
this.shadowView = RelativeLayout(context, attrs, defStyleAttr) as T
}
GroupType.LinearLayout.type -> {
this.shadowView = LinearLayout(context, attrs, defStyleAttr) as T
}

GroupType.FrameLayout.type -> {
this.shadowView = FrameLayout(context, attrs, defStyleAttr) as T
}
GroupType.RelativeLayout.type -> {
this.shadowView = RelativeLayout(context, attrs, defStyleAttr) as T
}

GroupType.ConstraintLayout.type -> {
this.shadowView = ConstraintLayout(context, attrs, defStyleAttr) as T
}
GroupType.FrameLayout.type -> {
this.shadowView = FrameLayout(context, attrs, defStyleAttr) as T
}

GroupType.RadioGroup.type -> {
this.shadowView = RadioGroup(context, attrs) as T
}
GroupType.ConstraintLayout.type -> {
this.shadowView = ConstraintLayout(context, attrs, defStyleAttr) as T
}

else -> {
this.shadowView = LinearLayout(context, attrs, defStyleAttr) as T
}
GroupType.RadioGroup.type -> {
this.shadowView = RadioGroup(context, attrs) as T
}

else -> {
this.shadowView = LinearLayout(context, attrs, defStyleAttr) as T
}
}
}
Expand Down Expand Up @@ -144,7 +146,7 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(
MeasureSpec.makeMeasureSpec(viewMeasureHeight, specModeHeight)
)
if (addToParent && !isInEditMode) {
addTToParent()
addT()
}
} ?: let {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
Expand All @@ -157,10 +159,6 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(
}
}

// override fun onDraw(canvas: Canvas) {
// shadowView?.draw(canvas) ?: super.onDraw(canvas)
// }

fun getChildAtInShadow(index: Int): View? {
if (shadowView is TabLayout) {
return shadowView.asTo<TabLayout>()?.getTabAt(index)?.view
Expand Down Expand Up @@ -221,9 +219,45 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(
return shadowView?.childCount ?: 0
}

override fun setClipChildren(clipChildren: Boolean) {
super.setClipChildren(clipChildren)
shadowView?.clipChildren = clipChildren
}

override fun setAlpha(alpha: Float) {
super.setAlpha(alpha)
shadowView?.alpha = alpha
}

override fun setActivated(activated: Boolean) {
super.setActivated(activated)
shadowView?.isActivated = activated
}

override fun setAnimation(animation: Animation?) {
super.setAnimation(animation)
shadowView?.animation = animation
}

override fun setBackground(background: Drawable?) {
super.setBackground(background)
shadowView?.background = background
}

override fun setBackgroundColor(color: Int) {
super.setBackgroundColor(color)
shadowView?.setBackgroundColor(color)
}

override fun setBackgroundResource(resid: Int) {
super.setBackgroundResource(resid)
shadowView?.setBackgroundResource(resid)
}

override fun generateDefaultLayoutParams(): LayoutParams {
return generateLayoutParams(attrs)
}

override fun generateLayoutParams(attrs: AttributeSet?): LayoutParams {
return when (shadowView) {
is TabLayout -> {
Expand Down Expand Up @@ -279,15 +313,11 @@ open class QuickViewGroup<T : ViewGroup> @JvmOverloads constructor(
}
}

class QuickViewGroupAttrSet(
mContext: Context,
attributeSet: AttributeSet,
) : AutoGetAttribute(mContext, attributeSet, R.styleable.QuickViewGroup) {

val groupType: Int? = null

val layoutRes: Int? = null
}
class QuickViewGroupAttrSet @JvmOverloads constructor(
val addToParent: Boolean? = null,
val groupType: Int = 0,
val layoutRes: Int = 0,
)

enum class GroupType(val type: Int) {
LinearLayout(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open class QuickBindGroup<T : ViewGroup> @JvmOverloads constructor(
mContext: Context,
attributeSet: AttributeSet? = null,
defStyleAttr: Int = 0,
override val addToParent: Boolean = true,
override var addToParent: Boolean = true,
@LayoutRes private val layoutId: Int = 0,
private var dealBind: Boolean = true
) : QuickItemGroup<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open class QuickSelectGroup<T : ViewGroup> @JvmOverloads constructor(
mContext: Context,
attributeSet: AttributeSet? = null,
defStyleAttr: Int = 0,
override val addToParent: Boolean = true,
override var addToParent: Boolean = true,
open val id: String? = null,
open val isSelect: Boolean = false,
@LayoutRes val layoutId: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wpf.app.quickwidget.tab

import android.animation.Animator
import android.app.Activity
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
Expand All @@ -17,7 +18,9 @@ import android.widget.LinearLayout
import androidx.annotation.IdRes
import androidx.core.view.children
import androidx.core.view.drawToBitmap
import androidx.core.view.get
import androidx.viewpager.widget.ViewPager
import com.wpf.app.quickutil.activity.contentView
import com.wpf.app.quickutil.helper.anim
import com.wpf.app.quickutil.helper.attribute.AutoGetAttributeHelper
import com.wpf.app.quickutil.other.asTo
Expand Down Expand Up @@ -51,8 +54,10 @@ open class BottomTabLayout @JvmOverloads constructor(
}
}
viewList.add(it)
viewBitmap.getOrPut(it) {
it.drawToBitmap()
if (it.measuredWidth != 0) {
viewBitmap.getOrPut(it) {
it.drawToBitmap()
}
}
}
}
Expand Down Expand Up @@ -342,7 +347,13 @@ open class BottomTabLayout @JvmOverloads constructor(
}

private fun dealParentClipChild() {
parent?.asTo<ViewGroup>()?.clipChildren = false
if (context is Activity) {
(context as Activity).contentView()?.asTo<ViewGroup>()?.get(0)?.let {
it.asTo<ViewGroup>()?.clipChildren = false
}
} else {
parent?.asTo<ViewGroup>()?.clipChildren = false
}
}

init {
Expand Down
Loading

0 comments on commit 836e364

Please sign in to comment.