mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
New loading-progress animation for story lists. (#582)
This commit is contained in:
parent
184d0375a3
commit
d2b16b2897
3 changed files with 83 additions and 2 deletions
|
@ -10,6 +10,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_alignParentTop="true" />
|
||||
|
||||
<com.newsblur.view.ProgressThrobber
|
||||
android:id="@+id/itemlist_topthrob"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_alignParentTop="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/itemlist_sync_status"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.newsblur.util.ReadFilterChangedListener;
|
|||
import com.newsblur.util.StateFilter;
|
||||
import com.newsblur.util.StoryOrder;
|
||||
import com.newsblur.util.StoryOrderChangedListener;
|
||||
import com.newsblur.view.ProgressThrobber;
|
||||
import com.newsblur.view.StateToggleButton.StateChangedListener;
|
||||
|
||||
public abstract class ItemsList extends NbActivity implements StateChangedListener, StoryOrderChangedListener, ReadFilterChangedListener, DefaultFeedViewChangedListener {
|
||||
|
@ -38,6 +39,7 @@ public abstract class ItemsList extends NbActivity implements StateChangedListen
|
|||
public static final String BUNDLE_FEED_IDS = "feedIds";
|
||||
|
||||
protected ItemListFragment itemListFragment;
|
||||
protected ProgressThrobber progressView;
|
||||
protected FragmentManager fragmentManager;
|
||||
private TextView overlayStatusText;
|
||||
protected StateFilter currentState;
|
||||
|
@ -55,7 +57,6 @@ public abstract class ItemsList extends NbActivity implements StateChangedListen
|
|||
this.fs = createFeedSet();
|
||||
|
||||
requestWindowFeature(Window.FEATURE_PROGRESS);
|
||||
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
||||
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
setContentView(R.layout.activity_itemslist);
|
||||
|
@ -64,6 +65,7 @@ public abstract class ItemsList extends NbActivity implements StateChangedListen
|
|||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
this.overlayStatusText = (TextView) findViewById(R.id.itemlist_sync_status);
|
||||
this.progressView = (ProgressThrobber) findViewById(R.id.itemlist_topthrob);
|
||||
}
|
||||
|
||||
protected abstract FeedSet createFeedSet();
|
||||
|
@ -139,7 +141,13 @@ public abstract class ItemsList extends NbActivity implements StateChangedListen
|
|||
|
||||
private void updateStatusIndicators() {
|
||||
boolean isLoading = NBSyncService.isFeedSetSyncing(this.fs, this);
|
||||
setProgressBarIndeterminateVisibility(isLoading);
|
||||
if (progressView != null ) {
|
||||
if (isLoading) {
|
||||
progressView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
progressView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (overlayStatusText != null) {
|
||||
String syncStatus = NBSyncService.getSyncStatusMessage(this);
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package com.newsblur.view;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.newsblur.R;
|
||||
|
||||
/**
|
||||
* A indeterminate loading indicator that pulses between two colours.
|
||||
*/
|
||||
public class ProgressThrobber extends View {
|
||||
|
||||
ObjectAnimator animator;
|
||||
int color = Color.BLUE;
|
||||
float saturation = 1f;
|
||||
|
||||
public ProgressThrobber(Context context) {
|
||||
super(context);
|
||||
setupAnimator();
|
||||
}
|
||||
|
||||
public ProgressThrobber(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setupAnimator();
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
private void setupAnimator() {
|
||||
animator = ObjectAnimator.ofFloat(this, "saturation", 0f, 1f);
|
||||
animator.setRepeatCount(ValueAnimator.INFINITE);
|
||||
animator.setRepeatMode(ValueAnimator.REVERSE);
|
||||
animator.setDuration(1500L);
|
||||
animator.start();
|
||||
}
|
||||
|
||||
public void setSaturation(float sat) {
|
||||
this.saturation = sat;
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
protected void onDraw(Canvas canvas) {
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[1] = saturation;
|
||||
canvas.drawColor(Color.HSVToColor(hsv));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibility(int visibility) {
|
||||
super.setVisibility(visibility);
|
||||
if (visibility == View.VISIBLE) {
|
||||
animator.start();
|
||||
} else {
|
||||
animator.end();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue