Added a scroll indicator for scrolling news details by swipe or volume buttons.

This commit is contained in:
Christine Emrich 2015-04-01 14:45:41 +02:00
parent 8c382c2fd5
commit 1df0b736c5
3 changed files with 157 additions and 0 deletions

View file

@ -43,6 +43,7 @@ import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ProgressBar;
import butterknife.ButterKnife;
import butterknife.InjectView;
@ -70,6 +71,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity {
*/
SectionsPagerAdapter mSectionsPagerAdapter;
@InjectView(R.id.toolbar) Toolbar toolbar;
@InjectView(R.id.progressIndicator) ProgressBar progressIndicator;
/**
* The {@link ViewPager} that will host the section contents.
@ -151,6 +153,8 @@ public class NewsDetailActivity extends PodcastFragmentActivity {
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
progressIndicator.setMax(mSectionsPagerAdapter.getCount());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
@ -244,6 +248,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity {
StopVideoOnCurrentPage();
currentPosition = position;
ResumeVideoPlayersOnCurrentPage();
progressIndicator.setProgress(position + 1);
if(!rssItems.get(position).getRead_temp())
{

View file

@ -0,0 +1,145 @@
package de.luhmer.owncloudnewsreader.view;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.ProgressBar;
/**
* Like a standard android progress bar but with an animated progress
* on Honeycomb and above. Use it like a normal progress bar.
*/
public class AnimatingProgressBar extends ProgressBar {
/**
* easing of the bar animation
*/
private static final Interpolator DEFAULT_INTERPOLATOR = new DecelerateInterpolator();
/**
* animation dureation in milliseconds
*/
private static final int ANIMATION_DURATION = 350;
/**
* Factor by which the progress bar resolution will be increased. E.g. the max
* value is set to 5 and the resolution to 100: the bar can animate internally
* between the values 0 and 500.
*/
private static final int RESOLUTION = 100;
private ValueAnimator animator;
private ValueAnimator animatorSecondary;
private boolean animate = true;
public AnimatingProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public AnimatingProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AnimatingProgressBar(Context context) {
super(context);
}
public boolean isAnimate() {
return animate;
}
public void setAnimate(boolean animate) {
this.animate = animate;
}
@Override
public synchronized void setMax(int max) {
super.setMax(max * RESOLUTION);
}
@Override
public synchronized int getMax() {
return super.getMax() / RESOLUTION;
}
@Override
public synchronized int getProgress() {
return super.getProgress() / RESOLUTION;
}
@Override
public synchronized int getSecondaryProgress() {
return super.getSecondaryProgress() / RESOLUTION;
}
@TargetApi(11)
@Override
public synchronized void setProgress(int progress) {
if (!animate || android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
super.setProgress(progress);
return;
}
if (animator == null) {
animator = ValueAnimator.ofInt(getProgress() * RESOLUTION, progress * RESOLUTION);
animator.setInterpolator(DEFAULT_INTERPOLATOR);
animator.setDuration(ANIMATION_DURATION);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
AnimatingProgressBar.super.setProgress((Integer) animation.getAnimatedValue());
}
});
}
animator.cancel();
animator.setIntValues(getProgress() * RESOLUTION, progress * RESOLUTION);
animator.start();
}
@TargetApi(11)
@Override
public synchronized void setSecondaryProgress(int secondaryProgress) {
if (!animate || android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
super.setSecondaryProgress(secondaryProgress);
return;
}
if (animatorSecondary == null) {
animatorSecondary = ValueAnimator.ofInt(getSecondaryProgress() * RESOLUTION, secondaryProgress * RESOLUTION);
animatorSecondary.setInterpolator(DEFAULT_INTERPOLATOR);
animatorSecondary.setDuration(ANIMATION_DURATION);
animatorSecondary.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
AnimatingProgressBar.super.setSecondaryProgress((Integer) animation.getAnimatedValue());
}
});
}
animatorSecondary.cancel();
animatorSecondary.setIntValues(getSecondaryProgress() * RESOLUTION, secondaryProgress * RESOLUTION);
animatorSecondary.start();
}
@TargetApi(11)
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (animator != null) {
animator.cancel();
}
if (animatorSecondary != null) {
animatorSecondary.cancel();
}
}
}
}

View file

@ -71,6 +71,13 @@
</de.luhmer.owncloudnewsreader.view.ZoomableRelativeLayout>
<de.luhmer.owncloudnewsreader.view.AnimatingProgressBar
android:id="@+id/progressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="-7dp"
style="?android:attr/progressBarStyleHorizontal" />
</FrameLayout>
</RelativeLayout>