Class SmartRefreshLayout

  • All Implemented Interfaces:
    ai.nexconn.chatui.widget.pullrefresh.api.RefreshLayout , android.graphics.drawable.Drawable.Callback , android.view.KeyEvent.Callback , android.view.ViewManager , android.view.ViewParent , android.view.accessibility.AccessibilityEventSource , androidx.core.view.NestedScrollingParent

    
    public class SmartRefreshLayout
    extends ViewGroup implements RefreshLayout, NestedScrollingParent
                        
    • Constructor Detail

      • SmartRefreshLayout

        SmartRefreshLayout(Context context)
      • SmartRefreshLayout

        SmartRefreshLayout(Context context, AttributeSet attrs)
    • Method Detail

      • onFinishInflate

         void onFinishInflate()

        Override onFinishInflate for smart-specific features: 1. Auto-detect Content, Header, Footer defined in XML.

      • onAttachedToWindow

         void onAttachedToWindow()

        Override onAttachedToWindow for smart-specific features: 1. Add default or globally configured Header and Footer (only when absent). 2. Show a TextView hint when Content is empty. 3. Smart-enable NestedScrollingEnabled. 4. Initialize theme colors and adjust Header/Footer/Content display order.

      • onMeasure

         void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

        Measure Header, Footer, and Content. 1. The measurement code appears complex because Header/Footer have four spinner styles SpinnerStyle, each with its own measurement method. 2. Provides preview measurement for XML editing (isInEditMode). 3. Resets the horizontal touch position cache mLastTouchX to the screen center.

        Parameters:
        widthMeasureSpec - Horizontal measure spec
        heightMeasureSpec - Vertical measure spec
      • onLayout

         void onLayout(boolean changed, int l, int t, int r, int b)

        Layout Header, Footer, and Content. The layout code is relatively simple because complex calculations have already been done during measurement; layout just follows the results.

        Parameters:
        changed - Whether the layout has changed
        l - Left
        t - Top
        r - Right
        b - Bottom
      • onDetachedFromWindow

         void onDetachedFromWindow()

        Override onDetachedFromWindow for smart-specific features: 1. Restore original state. 2. Clear animation data (prevent memory leaks).

      • drawChild

         boolean drawChild(Canvas canvas, View child, long drawingTime)

        Override drawChild for smart-specific features: 1. Draw background for Header and Footer (only when background is set). 2. Clip Header/Footer in FixedBehind style (when mEnableClipHeaderWhenFixedBehind=true).

        Parameters:
        canvas - Drawing canvas
        child - Child view to draw
        drawingTime - Drawing time
      • computeScroll

         void computeScroll()

        Override computeScroll for smart-specific features: 1. Over-scroll bounce. 2. Boundary collision.

      • dispatchTouchEvent

         boolean dispatchTouchEvent(MotionEvent e)

        Event dispatch (gesture core): 1. Multi-touch support. 2. Seamless content scrolling.

        Parameters:
        e - Touch event
      • requestDisallowInterceptTouchEvent

         void requestDisallowInterceptTouchEvent(boolean disallowIntercept)

        This code is from Google's official SwipeRefreshLayout, mainly to let older ListView scroll down smoothly by selectively blocking requestDisallowInterceptTouchEvent. Most third-party refresh libraries retain this code

      • startFlingIfNeed

         boolean startFlingIfNeed(float flingVelocity)

        Start fling mode when necessary.

        Parameters:
        flingVelocity - Velocity
        Returns:

        true if nested scrolling fling can be intercepted

      • interceptAnimatorByAction

         boolean interceptAnimatorByAction(int action)

        When animation is playing, touch the screen to interrupt animation and switch to drag state.

        Parameters:
        action - MotionEvent
        Returns:

        Whether the animation was successfully interrupted

      • setStateDirectLoading

         void setStateDirectLoading(boolean triggerLoadMoreEvent)

        Directly set state to Loading.

        Parameters:
        triggerLoadMoreEvent - Whether to trigger the load more callback
      • setStateLoading

         void setStateLoading(boolean notify)

        Set state to Loading.

        Parameters:
        notify - Whether to trigger notification event
      • setStateRefreshing

         void setStateRefreshing(boolean notify)

        Set state to Refreshing.

        Parameters:
        notify - Whether to trigger notification event
      • isEnableTranslationContent

         boolean isEnableTranslationContent(boolean enable, @Nullable() RefreshComponent internal)

        Determine whether content should be translated when pulling down

        Parameters:
        enable - mEnableHeaderTranslationContent or mEnableFooterTranslationContent
        internal - mRefreshHeader or mRefreshFooter
        Returns:

        enable

      • isEnableRefreshOrLoadMore

         boolean isEnableRefreshOrLoadMore(boolean enable)

        Whether the layout can actually refresh or load (distinct from over-scroll drag / pure scroll mode). Directly affects Header/Footer visibility.

        Parameters:
        enable - mEnableRefresh or mEnableLoadMore
        Returns:

        enable

      • animSpinner

         ValueAnimator animSpinner(int endSpinner, int startDelay, Interpolator interpolator, int duration)

        Execute rebound animation.

        Parameters:
        endSpinner - Target value
        startDelay - Start delay
        interpolator - Interpolator
        duration - Duration
        Returns:

        ValueAnimator or null

      • animSpinnerBounce

         void animSpinnerBounce(float velocity)

        Over-scroll bounce animation.

        Parameters:
        velocity - Velocity
      • overSpinner

         void overSpinner()

        Gesture drag ended, start executing rebound animation.

      • moveSpinnerInfinitely

         void moveSpinnerInfinitely(float spinner)

        Viscous (sticky) spinner translation.

        Parameters:
        spinner - Offset
      • onStartNestedScroll

         boolean onStartNestedScroll(@NonNull() View child, @NonNull() View target, int nestedScrollAxes)
      • onNestedScrollAccepted

         void onNestedScrollAccepted(@NonNull() View child, @NonNull() View target, int axes)
      • onNestedPreScroll

         void onNestedPreScroll(@NonNull() View target, int dx, int dy, @NonNull() Array<int> consumed)
      • onNestedScroll

         void onNestedScroll(@NonNull() View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
      • onNestedPreFling

         boolean onNestedPreFling(@NonNull() View target, float velocityX, float velocityY)
      • onNestedFling

         boolean onNestedFling(@NonNull() View target, float velocityX, float velocityY, boolean consumed)
      • setHeaderHeight

         RefreshLayout setHeaderHeight(float heightDp)

        Set the Header's height.

        Parameters:
        heightDp - Density-independent Pixels Density-independent pixels (use px2dp for pixel conversion)
        Returns:

        RefreshLayout

      • setFooterHeight

         RefreshLayout setFooterHeight(float heightDp)

        Set the Footer's height.

        Parameters:
        heightDp - Density-independent Pixels Density-independent pixels (use px2dp for pixel conversion)
        Returns:

        RefreshLayout

      • setHeaderInsetStart

         RefreshLayout setHeaderInsetStart(float insetDp)

        Set the Header's start offset (see srlHeaderInsetStart in the RepastPracticeActivity XML in demo-app for the practical application).

        Parameters:
        insetDp - Density-independent Pixels Density-independent pixels (use px2dp for pixel conversion)
        Returns:

        RefreshLayout

      • setHeaderInsetStartPx

         RefreshLayout setHeaderInsetStartPx(int insetPx)

        Set the Header's start offset (see srlHeaderInsetStart in the RepastPracticeActivity XML in demo-app for the practical application).

        Parameters:
        insetPx - Pixels
        Returns:

        RefreshLayout

      • setFooterInsetStart

         RefreshLayout setFooterInsetStart(float insetDp)

        Set the Footer's start offset.

        Parameters:
        insetDp - Density-independent Pixels Density-independent pixels (use px2dp for pixel conversion)
        Returns:

        RefreshLayout

      • setDragRate

         RefreshLayout setDragRate(float rate)

        Set the damping effect. Ratio of displayed drag height to actual drag height (default 0.5).

        Parameters:
        rate - ratio = (The drag height of the view)/(The actual drag height of the finger) Ratio = view drag height / finger drag height
        Returns:

        RefreshLayout

      • setHeaderMaxDragRate

         RefreshLayout setHeaderMaxDragRate(float rate)

        Set the ratio of the maximum height to drag header.

        Parameters:
        rate - ratio = (the maximum height to drag header)/(the height of header) Ratio = max pull-down height / Header height
        Returns:

        RefreshLayout

      • setFooterMaxDragRate

         RefreshLayout setFooterMaxDragRate(float rate)

        Set the ratio of the maximum height to drag footer.

        Parameters:
        rate - ratio = (the maximum height to drag footer)/(the height of footer) Ratio = max pull-up height / Footer height
        Returns:

        RefreshLayout

      • setHeaderTriggerRate

         RefreshLayout setHeaderTriggerRate(float rate)

        Set the ratio at which the refresh is triggered.

        Parameters:
        rate - Ratio of trigger refresh distance to HeaderHeight
        Returns:

        RefreshLayout

      • setFooterTriggerRate

         RefreshLayout setFooterTriggerRate(float rate)

        Set the ratio at which the load more is triggered.

        Parameters:
        rate - Ratio of trigger load distance to FooterHeight
        Returns:

        RefreshLayout

      • setReboundInterpolator

         RefreshLayout setReboundInterpolator(@NonNull() Interpolator interpolator)

        Set the rebound interpolator.

        Parameters:
        interpolator - Animation interpolator
        Returns:

        RefreshLayout

      • setReboundDuration

         RefreshLayout setReboundDuration(int duration)

        Set the duration of the rebound animation.

        Parameters:
        duration - Duration
        Returns:

        RefreshLayout

      • setEnableLoadMore

         RefreshLayout setEnableLoadMore(boolean enabled)

        Set whether to enable pull-up loading more (enabled by default).

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableRefresh

         RefreshLayout setEnableRefresh(boolean enabled)

        Whether to enable pull-down refresh (enabled by default).

        Parameters:
        enabled - Whether to enable
        Returns:

        SmartRefreshLayout

      • setEnableAutoLoadMore

         RefreshLayout setEnableAutoLoadMore(boolean enabled)

        Sets whether to listen for the list to trigger a load event when scrolling to the bottom (default true).

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableOverScrollBounce

         RefreshLayout setEnableOverScrollBounce(boolean enabled)

        Set whether to enable the over-scroll bounce function.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnablePureScrollMode

         RefreshLayout setEnablePureScrollMode(boolean enabled)

        Set whether to enable pure scroll mode.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableScrollContentWhenLoaded

         RefreshLayout setEnableScrollContentWhenLoaded(boolean enabled)

        Set whether to scroll the content to display new data after loading more complete. Whether to scroll content to show new data after load more.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableScrollContentWhenRefreshed

         RefreshLayout setEnableScrollContentWhenRefreshed(boolean enabled)

        Set whether to scroll the content to display new data after the refresh is complete. Whether to scroll content to show new data after refresh

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableLoadMoreWhenContentNotFull

         RefreshLayout setEnableLoadMoreWhenContentNotFull(boolean enabled)

        Set whether to pull up and load more when the content is not full of one page. Whether to allow pull-up load more when content is less than one page.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableOverScrollDrag

         RefreshLayout setEnableOverScrollDrag(boolean enabled)

        Set whether to enable over-scroll drag (imitation iPhone effect).

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableClipHeaderWhenFixedBehind

         RefreshLayout setEnableClipHeaderWhenFixedBehind(boolean enabled)

        Set whether to clip header when the Header is in the FixedBehind state.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableClipFooterWhenFixedBehind

         RefreshLayout setEnableClipFooterWhenFixedBehind(boolean enabled)

        Set whether to clip footer when the Footer is in the FixedBehind state.

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setEnableNestedScroll

         RefreshLayout setEnableNestedScroll(boolean enabled)

        Setting whether nesting scrolling is enabled (default off + smart on). Set whether to enable nested scrolling (default off, smart auto-enable).

        Parameters:
        enabled - Whether to enable
        Returns:

        RefreshLayout

      • setFixedHeaderViewId

         RefreshLayout setFixedHeaderViewId(int id)

        Set the View ID fixed below the Header, which stays stationary when Footer scrolls.

        Parameters:
        id - View ID fixed at header
        Returns:

        RefreshLayout

      • setFixedFooterViewId

         RefreshLayout setFixedFooterViewId(int id)

        Set the View ID fixed above the Footer, which stays stationary when Header scrolls.

        Parameters:
        id - View ID fixed at footer
        Returns:

        RefreshLayout

      • setHeaderTranslationViewId

         RefreshLayout setHeaderTranslationViewId(int id)

        Set the View ID that should scroll along with the Header. Defaults to the entire Content view.

        Parameters:
        id - View ID fixed at header
        Returns:

        RefreshLayout

      • setFooterTranslationViewId

         RefreshLayout setFooterTranslationViewId(int id)

        Set the View ID that should scroll along with the Footer. Defaults to the entire Content view.

        Parameters:
        id - View ID fixed at header
        Returns:

        RefreshLayout

      • setDisableContentWhenRefresh

         RefreshLayout setDisableContentWhenRefresh(boolean disable)

        Set whether to disable content interaction during refresh.

        Parameters:
        disable - Whether to disable
        Returns:

        RefreshLayout

      • setDisableContentWhenLoading

         RefreshLayout setDisableContentWhenLoading(boolean disable)

        Set whether to disable content interaction during loading.

        Parameters:
        disable - Whether to disable
        Returns:

        RefreshLayout

      • setRefreshHeader

         RefreshLayout setRefreshHeader(@NonNull() RefreshHeader header, int width, int height)

        Set the header of RefreshLayout.

        Parameters:
        header - RefreshHeader refresh header
        width - the width in px, can use MATCH_PARENT and WRAP_CONTENT.
        height - the height in px, can use MATCH_PARENT and WRAP_CONTENT.
        Returns:

        RefreshLayout

      • setRefreshFooter

         RefreshLayout setRefreshFooter(@NonNull() RefreshFooter footer, int width, int height)

        Set the footer of RefreshLayout.

        Parameters:
        footer - RefreshFooter refresh footer
        width - the width in px, can use MATCH_PARENT and WRAP_CONTENT.
        height - the height in px, can use MATCH_PARENT and WRAP_CONTENT.
        Returns:

        RefreshLayout

      • setRefreshContent

         RefreshLayout setRefreshContent(@NonNull() View content)

        Set the content of RefreshLayout (Suitable for non-XML pages, not suitable for replacing empty layouts).

        Parameters:
        content - View content view
        Returns:

        RefreshLayout

      • setRefreshContent

         RefreshLayout setRefreshContent(@NonNull() View content, int width, int height)

        Set the content of RefreshLayout (Suitable for non-XML pages, not suitable for replacing empty layouts).

        Parameters:
        content - View content view
        width - the width in px, can use MATCH_PARENT and WRAP_CONTENT.
        height - the height in px, can use MATCH_PARENT and WRAP_CONTENT.
        Returns:

        RefreshLayout

      • getState

        @NonNull() RefreshState getState()

        Get the current state of RefreshLayout.

        Returns:

        RefreshLayout

      • getLayout

        @NonNull() ViewGroup getLayout()

        Get the ViewGroup of RefreshLayout.

        Returns:

        ViewGroup

      • setPrimaryColors

         RefreshLayout setPrimaryColors(@ColorInt() Array<int> primaryColors)

        Set theme color int (primaryColor and accentColor).

        Parameters:
        primaryColors - ColorInt theme colors
        Returns:

        RefreshLayout

      • setPrimaryColorsId

         RefreshLayout setPrimaryColorsId(@ColorRes() Array<int> primaryColorId)

        Set theme color id (primaryColor and accentColor).

        Parameters:
        primaryColorId - ColorRes theme color resource IDs
        Returns:

        RefreshLayout

      • setNoMoreData

         RefreshLayout setNoMoreData(boolean noMoreData)

        Restore the original state after finishLoadMoreWithNoMoreData.

        Parameters:
        noMoreData - Whether there is more data
        Returns:

        RefreshLayout

      • finishRefresh

         RefreshLayout finishRefresh(int delayed)

        Finish refresh.

        Parameters:
        delayed - Start delay
        Returns:

        RefreshLayout

      • finishRefresh

         RefreshLayout finishRefresh(boolean success)

        Finish refresh.

        Parameters:
        success - Whether data was refreshed successfully (affects last update time)
        Returns:

        RefreshLayout

      • finishRefresh

         RefreshLayout finishRefresh(int delayed, boolean success, Boolean noMoreData)

        Finish refresh.

        Parameters:
        delayed - Start delay
        success - Whether data was refreshed successfully (affects last update time)
        Returns:

        RefreshLayout

      • finishLoadMore

         RefreshLayout finishLoadMore(boolean success)

        Finish load more.

        Parameters:
        success - Whether data was successful
        Returns:

        RefreshLayout

      • finishLoadMore

         RefreshLayout finishLoadMore(int delayed, boolean success, boolean noMoreData)

        Finish load more.

        Parameters:
        delayed - Start delay
        success - Whether data was successful
        noMoreData - Whether there is more data
        Returns:

        RefreshLayout

      • closeHeaderOrFooter

         RefreshLayout closeHeaderOrFooter()

        Close the Header or Footer. Note: this cannot replace finishRefresh and finishLoadMore. 1. closeHeaderOrFooter can close header/footer at any time in any state. 2. finishRefresh and finishLoadMore can only close during refresh or load respectively.

        Returns:

        RefreshLayout

      • autoRefresh

         boolean autoRefresh()

        Display refresh animation and trigger refresh event.

        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoRefresh

         boolean autoRefresh(int delayed)

        Display refresh animation and trigger refresh event with delayed start.

        Parameters:
        delayed - Start delay
        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoRefreshAnimationOnly

         boolean autoRefreshAnimationOnly()

        Display refresh animation without triggering events.

        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoRefresh

         boolean autoRefresh(int delayed, int duration, float dragRate, boolean animationOnly)

        Display refresh animation with multifunction options.

        Parameters:
        delayed - Start delay
        duration - Drag animation duration
        dragRate - Drag height ratio
        animationOnly - Animation only
        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoLoadMore

         boolean autoLoadMore()

        Display load more animation and trigger load more event.

        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoLoadMore

         boolean autoLoadMore(int delayed)

        Display load more animation and trigger load more event with delayed start.

        Parameters:
        delayed - Start delay
        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoLoadMoreAnimationOnly

         boolean autoLoadMoreAnimationOnly()

        Display load more animation without triggering events.

        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • autoLoadMore

         boolean autoLoadMore(int delayed, int duration, float dragRate, boolean animationOnly)

        Display load more animation with multifunction options.

        Parameters:
        delayed - Start delay
        duration - Drag animation duration
        dragRate - Drag height ratio
        Returns:

        true or false, Status non-compliance will fail. true if successful (fails if state is non-compliant)

      • isRefreshing

         boolean isRefreshing()

        Whether currently refreshing

        Returns:

        Whether currently refreshing

      • isLoading

         boolean isLoading()

        Whether currently loading

        Returns:

        Whether currently loading