Skip to content

Commit cec8a62

Browse files
committed
make field/method open/protected
1 parent ce634cd commit cec8a62

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

lib/src/main/java/com/yy/mobile/widget/SlidableLayout.kt

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
6969
const val HORIZONTAL = 0
7070
const val VERTICAL = 1
7171

72-
private const val DEBUG = false
72+
protected const val DEBUG = false
7373

74-
private const val MIN_FLING_VELOCITY = 400 // dips
74+
const val MIN_FLING_VELOCITY = 400 // dips
7575

7676
const val MAX_DURATION = 600 //最大滑行时间ms
7777

@@ -98,12 +98,12 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
9898
field = value
9999
}
100100

101-
private val mMinFlingSpeed: Float //定义滑动速度足够快的标准
101+
protected val mMinFlingSpeed: Float //定义滑动速度足够快的标准
102102

103-
private val childHelper = NestedScrollingChildHelper(this)
104-
private val parentHelper = NestedScrollingParentHelper(this)
103+
protected val childHelper = NestedScrollingChildHelper(this)
104+
protected val parentHelper = NestedScrollingParentHelper(this)
105105

106-
private val mTouchSlop: Int
106+
protected val mTouchSlop: Int
107107

108108
private val mDataObservable = SlidableDataObservable()
109109
private val mDataObserver = Observer()
@@ -118,15 +118,15 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
118118
isNestedScrollingEnabled = true
119119
}
120120

121-
private fun initAttr(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
121+
protected open fun initAttr(context: Context, attrs: AttributeSet?, defStyleAttr: Int) {
122122
val a = context.obtainStyledAttributes(
123123
attrs, R.styleable.SlidableLayout, defStyleAttr, 0)
124124
orientation = a.getInt(R.styleable.SlidableLayout_android_orientation, VERTICAL)
125125
a.recycle()
126126
}
127127

128128
@Suppress("unused")
129-
private enum class State(val flag: Int) {
129+
protected enum class State(val flag: Int) {
130130
/**
131131
* IDLE
132132
* 静止状态
@@ -175,7 +175,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
175175
}
176176
}
177177

178-
private object Mask {
178+
protected object Mask {
179179
const val IDLE = 0b000001
180180
const val NEXT = 0b000010
181181
const val PREV = 0b000100
@@ -184,40 +184,40 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
184184
const val REJECT = 0b100000
185185
}
186186

187-
private var mState = State.of(Mask.IDLE)
187+
protected var mState = State.of(Mask.IDLE)
188188

189189
private val mInflater by lazy(NONE) { LayoutInflater.from(context) }
190190

191-
private val mScroller = Scroller(context, sInterpolator)
192-
private var mAnimator: ValueAnimator? = null
191+
protected val mScroller = Scroller(context, sInterpolator)
192+
protected var mAnimator: ValueAnimator? = null
193193

194-
private var mViewHolderDelegate: ViewHolderDelegate<out SlideViewHolder>? = null
194+
protected var mViewHolderDelegate: ViewHolderDelegate<out SlideViewHolder>? = null
195195

196-
private inline val mCurrentView: View?
196+
protected inline val mCurrentView: View?
197197
get() = mViewHolderDelegate?.currentViewHolder?.view
198198

199-
private inline val mBackupView: View?
199+
protected inline val mBackupView: View?
200200
get() = mViewHolderDelegate?.backupViewHolder?.view
201201

202-
private var downY = 0f
203-
private var downX = 0f
202+
protected var downY = 0f
203+
protected var downX = 0f
204204

205-
private var mScrollConsumed: IntArray = IntArray(2)
206-
private var mScrollOffset: IntArray = IntArray(2)
205+
protected var mScrollConsumed: IntArray = IntArray(2)
206+
protected var mScrollOffset: IntArray = IntArray(2)
207207

208-
private val mGestureCallback = GestureCallback()
209-
private val mHorizontalGesture = HorizontalMode()
210-
private val mVerticalGesture = VerticalMode()
211-
private inline val mGesture
208+
protected val mGestureCallback = GestureCallback()
209+
protected val mHorizontalGesture = HorizontalMode()
210+
protected val mVerticalGesture = VerticalMode()
211+
protected inline val mGesture
212212
get() = if (orientation == HORIZONTAL) mHorizontalGesture else mVerticalGesture
213213

214-
private inline val mScrollAxis
214+
protected inline val mScrollAxis
215215
get() = if (orientation == HORIZONTAL) ViewCompat.SCROLL_AXIS_HORIZONTAL else ViewCompat.SCROLL_AXIS_VERTICAL
216216

217-
private val gestureDetector = GestureDetector(context, mGestureCallback)
217+
protected val gestureDetector = GestureDetector(context, mGestureCallback)
218218

219-
private var shouldDetermineIfStartNestedScroll = false
220-
private var nestedScrolling = false
219+
protected var shouldDetermineIfStartNestedScroll = false
220+
protected var nestedScrolling = false
221221

222222
@SuppressLint("ClickableViewAccessibility")
223223
override fun onTouchEvent(event: MotionEvent): Boolean {
@@ -239,7 +239,11 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
239239
}
240240

241241
// just like ViewPager
242-
private fun calculateDuration(velocity: Float, maxDistance: Int, currentDistance: Int): Int {
242+
protected open fun calculateDuration(
243+
velocity: Float,
244+
maxDistance: Int,
245+
currentDistance: Int
246+
): Int {
243247

244248
// We want the duration of the page snap animation to be influenced by the distance that
245249
// the screen has to travel, however, we don't want this duration to be effected in a
@@ -464,7 +468,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
464468
}
465469

466470
@Suppress("ConstantConditionIf")
467-
private fun log(str: String) {
471+
protected fun log(str: String) {
468472
if (DEBUG) Log.i("SlidableLayout", str)
469473
}
470474

@@ -474,7 +478,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
474478
* @see SlideViewAdapter
475479
* @see SlideFragmentAdapter
476480
*/
477-
fun setAdapter(adapter: SlideAdapter<out SlideViewHolder>?) {
481+
open fun setAdapter(adapter: SlideAdapter<out SlideViewHolder>?) {
478482
if (mViewHolderDelegate != null) {
479483
removeAllViews()
480484
unregisterDataSetObserver(mDataObserver)
@@ -501,7 +505,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
501505
*
502506
* @return true if successfully sliding.
503507
*/
504-
fun slideTo(direction: SlideDirection): Boolean {
508+
open fun slideTo(direction: SlideDirection): Boolean {
505509
if (direction != SlideDirection.Origin &&
506510
mState satisfy Mask.IDLE) {
507511

@@ -569,7 +573,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
569573
mDataObservable.notifyDataSetChanged()
570574
}
571575

572-
private inner class ViewHolderDelegate<ViewHolder : SlideViewHolder>(
576+
protected inner class ViewHolderDelegate<ViewHolder : SlideViewHolder>(
573577
val adapter: SlideAdapter<ViewHolder>
574578
) {
575579

@@ -642,7 +646,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
642646
}
643647
}
644648

645-
private inner class GestureCallback : GestureDetector.SimpleOnGestureListener() {
649+
protected inner class GestureCallback : GestureDetector.SimpleOnGestureListener() {
646650

647651
override fun onScroll(
648652
e1: MotionEvent?, e2: MotionEvent,
@@ -855,7 +859,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
855859
}
856860
}
857861

858-
private interface OrientationGestureCallback {
862+
protected interface OrientationGestureCallback {
859863

860864
fun interceptTouchEvent(dxFromDownX: Float, dyFromDownY: Float): Boolean
861865

@@ -892,7 +896,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
892896
fun dontConsumeTouchEvent(dx: Float, dy: Float)
893897
}
894898

895-
private inner class HorizontalMode : OrientationGestureCallback {
899+
protected open inner class HorizontalMode : OrientationGestureCallback {
896900

897901
override fun interceptTouchEvent(dxFromDownX: Float, dyFromDownY: Float): Boolean {
898902
return dxFromDownX > mTouchSlop && dxFromDownX > 2 * dyFromDownY
@@ -982,7 +986,7 @@ open class SlidableLayout : FrameLayout, NestedScrollingChild2, NestedScrollingP
982986
}
983987
}
984988

985-
private inner class VerticalMode : OrientationGestureCallback {
989+
protected open inner class VerticalMode : OrientationGestureCallback {
986990

987991
override fun interceptTouchEvent(dxFromDownX: Float, dyFromDownY: Float): Boolean {
988992
return dyFromDownY > mTouchSlop && dyFromDownY > 2 * dxFromDownX

0 commit comments

Comments
 (0)