com.handmark.pulltorefresh.library.internal.ViewCompat Java Examples

The following examples show how to use com.handmark.pulltorefresh.library.internal.ViewCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: h.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void run()
{
    if (h == -1L)
    {
        h = System.currentTimeMillis();
    } else
    {
        long l = Math.max(Math.min((1000L * (System.currentTimeMillis() - h)) / e, 1000L), 0L);
        int j = Math.round((float)(d - c) * b.getInterpolation((float)l / 1000F));
        i = d - j;
        a.setHeaderScroll(i);
    }
    if (g && c != i)
    {
        ViewCompat.postOnAnimation(a, this);
    } else
    if (f != null)
    {
        f.a();
        return;
    }
}
 
Example #2
Source File: PullToRefreshBase.java    From PullToRefresh-PinnedSection-ListView with MIT License 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #3
Source File: PullToRefreshBase.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #4
Source File: PullToRefreshBase.java    From ONE-Unofficial with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #5
Source File: PullToRefreshBase.java    From bmob-android-demo-paging with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #6
Source File: PullToRefreshBase.java    From bmob-android-demo-paging with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #7
Source File: PullToRefreshBase.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #8
Source File: PullToRefreshBase.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #9
Source File: PullToRefreshBase.java    From PullToRefresh-PinnedSection-ListView with MIT License 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #10
Source File: PullToRefreshBase.java    From SweetMusicPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #11
Source File: PullToRefreshBase.java    From handmarkPulltorefreshLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime))
				/ mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator
						.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #12
Source File: PullToRefreshBase.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #13
Source File: PullToRefreshBase.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #14
Source File: PullToRefreshBase.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #15
Source File: PullToRefreshBase.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #16
Source File: PullToRefreshBase.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #17
Source File: PullToRefreshBase.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #18
Source File: PullToRefreshBase.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #19
Source File: PullToRefreshBase.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #20
Source File: PullToRefreshBase.java    From sctalk with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #21
Source File: PullToRefreshBase.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #22
Source File: PullToRefreshBase.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 *
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
    if (DEBUG) {
        Log.d(LOG_TAG, "setHeaderScroll: " + value);
    }

    // Clamp value to with pull scroll range
    final int maximumPullScroll = getMaximumPullScroll();
    value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

    if (mLayoutVisibilityChangesEnabled) {
        if (value < 0) {
            mHeaderLayout.setVisibility(View.VISIBLE);
        } else if (value > 0) {
            mFooterLayout.setVisibility(View.VISIBLE);
        } else {
            mHeaderLayout.setVisibility(View.INVISIBLE);
            mFooterLayout.setVisibility(View.INVISIBLE);
        }
    }

    if (USE_HW_LAYERS) {
        /**
         * Use a Hardware Layer on the Refreshable View if we've scrolled at
         * all. We don't use them on the Header/Footer Views as they change
         * often, which would negate any HW layer performance boost.
         */
        ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
                : View.LAYER_TYPE_NONE);
    }

    switch (getPullToRefreshScrollDirection()) {
        case VERTICAL:
            scrollTo(0, value);
            break;
        case HORIZONTAL:
            scrollTo(value, 0);
            break;
    }
}
 
Example #23
Source File: PullToRefreshBase.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

    /**
     * Only set mStartTime if this is the first time we're starting,
     * else actually calculate the Y delta
     */
    if (mStartTime == -1) {
        mStartTime = System.currentTimeMillis();
    } else {

        /**
         * We do do all calculations in long to reduce software float
         * calculations. We use 1000 as it gives us good accuracy and
         * small rounding errors
         */
        long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
        normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

        final int deltaY = Math.round((mScrollFromY - mScrollToY)
                * mInterpolator.getInterpolation(normalizedTime / 1000f));
        mCurrentY = mScrollFromY - deltaY;
        setHeaderScroll(mCurrentY);
    }

    // If we're not at the target Y, keep going...
    if (mContinueRunning && mScrollToY != mCurrentY) {
        ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
    } else {
        if (null != mListener) {
            mListener.onSmoothScrollFinished();
        }
    }
}
 
Example #24
Source File: PullToRefreshBase.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

    /**
     * Only set mStartTime if this is the first time we're starting,
     * else actually calculate the Y delta
     */
    if (mStartTime == -1) {
        mStartTime = System.currentTimeMillis();
    } else {

        /**
         * We do do all calculations in long to reduce software float
         * calculations. We use 1000 as it gives us good accuracy and
         * small rounding errors
         */
        long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime))
                / mDuration;
        normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

        final int deltaY = Math.round((mScrollFromY - mScrollToY)
                * mInterpolator
                .getInterpolation(normalizedTime / 1000f));
        mCurrentY = mScrollFromY - deltaY;
        setHeaderScroll(mCurrentY);
    }

    // If we're not at the target Y, keep going...
    if (mContinueRunning && mScrollToY != mCurrentY) {
        ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
    } else {
        if (null != mListener) {
            mListener.onSmoothScrollFinished();
        }
    }
}
 
Example #25
Source File: PullToRefreshBase.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #26
Source File: PullToRefreshBase.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #27
Source File: PullToRefreshBase.java    From LbaizxfPulltoRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #28
Source File: PullToRefreshBase.java    From LbaizxfPulltoRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}
 
Example #29
Source File: PullToRefreshBase.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 * 
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}

	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example #30
Source File: PullToRefreshBase.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

	/**
	 * Only set mStartTime if this is the first time we're starting,
	 * else actually calculate the Y delta
	 */
	if (mStartTime == -1) {
		mStartTime = System.currentTimeMillis();
	} else {

		/**
		 * We do do all calculations in long to reduce software float
		 * calculations. We use 1000 as it gives us good accuracy and
		 * small rounding errors
		 */
		long normalizedTime = (1000 * (System.currentTimeMillis() - mStartTime)) / mDuration;
		normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

		final int deltaY = Math.round((mScrollFromY - mScrollToY)
				* mInterpolator.getInterpolation(normalizedTime / 1000f));
		mCurrentY = mScrollFromY - deltaY;
		setHeaderScroll(mCurrentY);
	}

	// If we're not at the target Y, keep going...
	if (mContinueRunning && mScrollToY != mCurrentY) {
		ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
	} else {
		if (null != mListener) {
			mListener.onSmoothScrollFinished();
		}
	}
}