Skip to content

Commit

Permalink
新增AppBarScaleHeaderBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
junixapp committed Nov 25, 2022
1 parent dd910cb commit 8fe18c0
Show file tree
Hide file tree
Showing 18 changed files with 845 additions and 212 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<!-- <meta-data android:name="android.support.PARENT_ACTIVITY"-->
<!-- android:value=".MainActivity" />-->
</activity>
<activity android:name=".blibli.BlibliVideoActivity" android:configChanges="orientation|screenSize|screenLayout"/>

<!-- <service android:name=".notification.NotificationClickService"/>-->
<!-- <service android:name=".notification.NotificationClickService"/>-->
</application>

</manifest>
4 changes: 3 additions & 1 deletion app/src/main/java/com/lxj/androidktxdemo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.lxj.share.Share
import com.lxj.androidktxdemo.databinding.ActivityMainBinding
import com.lxj.androidktxdemo.entity.PageInfo
import com.lxj.androidktxdemo.fragment.*
import com.lxj.androidktxdemo.popup.TestPopup
import com.lxj.androidktxdemo.vm.TestVM
import com.lxj.xpopup.XPopup
import kotlinx.android.synthetic.main.activity_main.*
import kotlin.random.Random

Expand Down Expand Up @@ -59,7 +61,7 @@ class MainActivity : BaseActivity() {
""".trimIndent().toBean<HashMap<String,Any>>()
LogUtils.e("ut: ${ut.toJson()}")

runOnUiThread { }
// XPopup.Builder(this).asCustom(TestPopup(this)).show()
}

override fun initData() {
Expand Down
198 changes: 0 additions & 198 deletions app/src/main/java/com/lxj/androidktxdemo/ShadowLayout.java

This file was deleted.

22 changes: 22 additions & 0 deletions app/src/main/java/com/lxj/androidktxdemo/blibli/BlibliFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lxj.androidktxdemo.blibli

import android.widget.TextView
import androidx.core.graphics.ColorUtils
import com.lxj.androidktx.core.bindData
import com.lxj.androidktx.core.vertical
import com.lxj.androidktxdemo.R
import com.lxj.androidktxdemo.fragment.BaseFragment
import kotlinx.android.synthetic.main.fragment_blibli.*

class BlibliFragment: BaseFragment() {
override fun getLayoutId() = R.layout.fragment_blibli

override fun initView() {
super.initView()
rvBliBli.vertical()
.bindData(listOf(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), R.layout.adapter_blibli, bindFn = {holder, t, position ->
(holder.itemView as TextView).setText("评论内容-${position}")
(holder.itemView as TextView).setBackgroundColor(com.blankj.utilcode.util.ColorUtils.getRandomColor())
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.lxj.androidktxdemo.blibli

import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.viewpager.widget.ViewPager
import com.blankj.utilcode.util.ScreenUtils
import com.lxj.androidktx.base.BaseActivity
import com.lxj.androidktx.core.*
import com.lxj.androidktx.widget.behavior.AppBarScaleHeaderBehavior
import com.lxj.androidktxdemo.R
import kotlinx.android.synthetic.main.activity_blibli_video.*

class BlibliVideoActivity: BaseActivity() {

override fun getLayoutId() = R.layout.activity_blibli_video
val behavior = AppBarScaleHeaderBehavior()
override fun initView() {
viewPager.bindFragment(
fm = supportFragmentManager, fragments = listOf(BlibliFragment(), BlibliFragment()),
pageTitles = listOf("评论", "相关产品"),
)
tabLayout.setupWithViewPager(viewPager)
viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {}
override fun onPageSelected(position: Int) {
appBar.setExpanded(false, true)
}
override fun onPageScrollStateChanged(state: Int) {}
})

tvScale.click {
if (behavior.isFullscreenHeader){
ScreenUtils.setPortrait(this)
behavior.fullscreenHeader(false)
toast("恢复正常播放")
}else{
ScreenUtils.setLandscape(this)
behavior.fullscreenHeader(true) //禁用padding更新
toast("模拟视频全屏播放")
}
}
tvEnableDrag.click {
behavior.enableAppBarDrag(!behavior.enableAppBarDrag)
toast("AppBar区域${if(behavior.enableAppBarDrag) "可以" else "禁用"}拖拽")
}
(appBar.layoutParams as CoordinatorLayout.LayoutParams).behavior = behavior
tvHideTab.click {
tabLayout.visible(!tabLayout.isVisible)
}
}

override fun initData() {}

override fun onBackPressed() {
if(behavior.isFullscreenHeader){
tvScale.performClick()
return
}
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.lxj.androidktxdemo.blibli

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.coordinatorlayout.widget.CoordinatorLayout

class CustomCoordinatorLayout @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0)
: CoordinatorLayout(context, attributeSet, defStyleAttr){


override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return isEnabled && super.onInterceptTouchEvent(ev)
}

override fun onTouchEvent(ev: MotionEvent?): Boolean {
return isEnabled && super.onTouchEvent(ev)
}

fun resetTouchBehaviors() {
// val childCount = childCount
// for (i in 0 until childCount) {
// val child = getChildAt(i)
// val lp = child.layoutParams as LayoutParams
// val b = lp.behavior
// if (b != null) {
// val now = SystemClock.uptimeMillis()
// val cancelEvent = MotionEvent.obtain(
// now, now,
// MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0
// )
// b.onInterceptTouchEvent(this, child, cancelEvent)
//// if (notifyOnInterceptTouchEvent) {
//// } else {
// b.onTouchEvent(this, child, cancelEvent)
//// }
// cancelEvent.recycle()
// }
// }
// for (i in 0 until childCount) {
// val child = getChildAt(i)
// val lp = child.layoutParams as LayoutParams
// lp.resetTouchBehaviorTracking()
// }
// mBehaviorTouchView = null
// mDisallowInterceptReset = false
}

}
Loading

0 comments on commit 8fe18c0

Please sign in to comment.