summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Huang <ath@google.com>2013-07-08 13:06:01 -0700
committerAndy Huang <ath@google.com>2013-07-08 13:36:45 -0700
commit6dc34603a4b2afd8e0be92798dffd2bf46f73511 (patch)
tree5a18df12a70852497b6c92730f10d90e532119eb
parentdfbc6985e44c05e37fd8addce65a063ff57a3dc1 (diff)
downloadandroid_packages_apps_UnifiedEmail-6dc34603a4b2afd8e0be92798dffd2bf46f73511.tar.gz
android_packages_apps_UnifiedEmail-6dc34603a4b2afd8e0be92798dffd2bf46f73511.tar.bz2
android_packages_apps_UnifiedEmail-6dc34603a4b2afd8e0be92798dffd2bf46f73511.zip
smoother progress bar
Remove hard-coded assets for the swipe-refresh progress bar and use a new procedurally drawn progress bar that runs at 60fps and reduces memory footprint and GC significantly. Some colors and sizes are now configurable now, to boot. Bug: 9737423 Change-Id: I46d34d4c6c49b9c57fb80ff4cb03bdc99cfe13f4
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo1.pngbin705 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo2.pngbin829 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo3.pngbin862 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo4.pngbin925 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo5.pngbin853 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo6.pngbin954 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo7.pngbin768 -> 0 bytes
-rw-r--r--res/drawable-hdpi/progressbar_indeterminate_holo8.pngbin824 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo1.pngbin510 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo2.pngbin597 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo3.pngbin644 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo4.pngbin641 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo5.pngbin633 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo6.pngbin667 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo7.pngbin617 -> 0 bytes
-rw-r--r--res/drawable-mdpi/progressbar_indeterminate_holo8.pngbin617 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo1.pngbin735 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo2.pngbin919 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo3.pngbin1039 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo4.pngbin1028 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo5.pngbin995 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo6.pngbin1067 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo7.pngbin962 -> 0 bytes
-rw-r--r--res/drawable-xhdpi/progressbar_indeterminate_holo8.pngbin950 -> 0 bytes
-rw-r--r--res/drawable/progress_indeterminate_horizontal_holo.xml30
-rw-r--r--res/layout/conversation_list_progress.xml15
-rw-r--r--res/values/attrs.xml5
-rw-r--r--src/com/android/mail/ui/ButteryProgressBar.java143
-rw-r--r--src/com/android/mail/ui/ConversationListView.java18
29 files changed, 159 insertions, 52 deletions
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo1.png b/res/drawable-hdpi/progressbar_indeterminate_holo1.png
deleted file mode 100644
index 971ece765..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo2.png b/res/drawable-hdpi/progressbar_indeterminate_holo2.png
deleted file mode 100644
index 2089de30c..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo3.png b/res/drawable-hdpi/progressbar_indeterminate_holo3.png
deleted file mode 100644
index b6d0fc26d..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo4.png b/res/drawable-hdpi/progressbar_indeterminate_holo4.png
deleted file mode 100644
index 1e06e05e0..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo5.png b/res/drawable-hdpi/progressbar_indeterminate_holo5.png
deleted file mode 100644
index 306d40011..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo5.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo6.png b/res/drawable-hdpi/progressbar_indeterminate_holo6.png
deleted file mode 100644
index f7d0cc338..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo6.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo7.png b/res/drawable-hdpi/progressbar_indeterminate_holo7.png
deleted file mode 100644
index d30a676fc..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo7.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/progressbar_indeterminate_holo8.png b/res/drawable-hdpi/progressbar_indeterminate_holo8.png
deleted file mode 100644
index 8fe443c39..000000000
--- a/res/drawable-hdpi/progressbar_indeterminate_holo8.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo1.png b/res/drawable-mdpi/progressbar_indeterminate_holo1.png
deleted file mode 100644
index 460ecd1a9..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo2.png b/res/drawable-mdpi/progressbar_indeterminate_holo2.png
deleted file mode 100644
index 05d19a774..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo3.png b/res/drawable-mdpi/progressbar_indeterminate_holo3.png
deleted file mode 100644
index 5a0bb00af..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo4.png b/res/drawable-mdpi/progressbar_indeterminate_holo4.png
deleted file mode 100644
index 3f99453f6..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo5.png b/res/drawable-mdpi/progressbar_indeterminate_holo5.png
deleted file mode 100644
index 4a72b49e0..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo5.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo6.png b/res/drawable-mdpi/progressbar_indeterminate_holo6.png
deleted file mode 100644
index aa54f41df..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo6.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo7.png b/res/drawable-mdpi/progressbar_indeterminate_holo7.png
deleted file mode 100644
index 5a39510f2..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo7.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/progressbar_indeterminate_holo8.png b/res/drawable-mdpi/progressbar_indeterminate_holo8.png
deleted file mode 100644
index ac0a8e251..000000000
--- a/res/drawable-mdpi/progressbar_indeterminate_holo8.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo1.png b/res/drawable-xhdpi/progressbar_indeterminate_holo1.png
deleted file mode 100644
index a28ee7917..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo1.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo2.png b/res/drawable-xhdpi/progressbar_indeterminate_holo2.png
deleted file mode 100644
index 887ffffb7..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo2.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo3.png b/res/drawable-xhdpi/progressbar_indeterminate_holo3.png
deleted file mode 100644
index 1666d8e7b..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo3.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo4.png b/res/drawable-xhdpi/progressbar_indeterminate_holo4.png
deleted file mode 100644
index 26bb2d2e0..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo4.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo5.png b/res/drawable-xhdpi/progressbar_indeterminate_holo5.png
deleted file mode 100644
index 6966e0099..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo5.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo6.png b/res/drawable-xhdpi/progressbar_indeterminate_holo6.png
deleted file mode 100644
index c4f6b3df8..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo6.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo7.png b/res/drawable-xhdpi/progressbar_indeterminate_holo7.png
deleted file mode 100644
index a57c7012d..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo7.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/progressbar_indeterminate_holo8.png b/res/drawable-xhdpi/progressbar_indeterminate_holo8.png
deleted file mode 100644
index 1bcae42b9..000000000
--- a/res/drawable-xhdpi/progressbar_indeterminate_holo8.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable/progress_indeterminate_horizontal_holo.xml b/res/drawable/progress_indeterminate_horizontal_holo.xml
deleted file mode 100644
index e99c35bc7..000000000
--- a/res/drawable/progress_indeterminate_horizontal_holo.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2011, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-<animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <item android:drawable="@drawable/progressbar_indeterminate_holo1" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo2" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo3" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo4" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo5" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo6" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo7" android:duration="50" />
- <item android:drawable="@drawable/progressbar_indeterminate_holo8" android:duration="50" />
-</animation-list>
diff --git a/res/layout/conversation_list_progress.xml b/res/layout/conversation_list_progress.xml
index 3259b98ff..c8218cada 100644
--- a/res/layout/conversation_list_progress.xml
+++ b/res/layout/conversation_list_progress.xml
@@ -15,7 +15,9 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
+<merge
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:butterbar="http://schemas.android.com/apk/res-auto">
<ProgressBar
android:id="@+id/sync_trigger"
@@ -28,13 +30,14 @@
android:progress="100"
android:progressDrawable="@drawable/progressbar_solid_holo" />
- <ProgressBar
+ <com.android.mail.ui.ButteryProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
- android:layout_height="5dp"
+ android:layout_height="30dp"
android:layout_gravity="top"
- android:visibility="gone"
- android:indeterminateDrawable="@drawable/progress_indeterminate_horizontal_holo"
- android:indeterminate="true" />
+ butterbar:barColor="@android:color/holo_blue_dark"
+ butterbar:barHeight="2.5dp"
+ butterbar:detentWidth="4dp"
+ android:visibility="gone" />
</merge>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 0a2d7678f..60fbc86bd 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -30,4 +30,9 @@
<declare-styleable name="FolderItemViewDrawableState">
<attr name="state_drag_mode" format="boolean" />
</declare-styleable>
+ <declare-styleable name="ButteryProgressBar">
+ <attr name="barColor" format="color" />
+ <attr name="barHeight" format="dimension" />
+ <attr name="detentWidth" format="dimension" />
+ </declare-styleable>
</resources>
diff --git a/src/com/android/mail/ui/ButteryProgressBar.java b/src/com/android/mail/ui/ButteryProgressBar.java
new file mode 100644
index 000000000..e0421415f
--- /dev/null
+++ b/src/com/android/mail/ui/ButteryProgressBar.java
@@ -0,0 +1,143 @@
+package com.android.mail.ui;
+
+import android.animation.ValueAnimator;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.drawable.GradientDrawable;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.animation.Interpolator;
+
+import com.android.mail.R;
+
+/**
+ * Procedurally-drawn version of a horizontal indeterminate progress bar. Draws faster and more
+ * frequently (by making use of the animation timer), requires minimal memory overhead, and allows
+ * some configuration via attributes:
+ * <ul>
+ * <li>barColor (color attribute for the bar's solid color)
+ * <li>barHeight (dimension attribute for the height of the solid progress bar)
+ * <li>detentWidth (dimension attribute for the width of each transparent detent in the bar)
+ * </ul>
+ * <p>
+ * This progress bar has no intrinsic height, so you must declare it with one explicitly. (It will
+ * use the given height as the bar's shadow height.)
+ */
+public class ButteryProgressBar extends View {
+
+ private final GradientDrawable mShadow;
+ private final ValueAnimator mAnimator;
+
+ private final Paint mPaint = new Paint();
+
+ final int mBarColor;
+ final int mSolidBarHeight;
+ final int mSolidBarDetentWidth;
+
+ private static final int SEGMENT_COUNT = 3;
+
+ public ButteryProgressBar(Context c) {
+ this(c, null);
+ }
+
+ public ButteryProgressBar(Context c, AttributeSet attrs) {
+ super(c, attrs);
+
+ final TypedArray ta = c.obtainStyledAttributes(attrs, R.styleable.ButteryProgressBar);
+ try {
+ mBarColor = ta.getColor(R.styleable.ButteryProgressBar_barColor, 0);
+ mSolidBarHeight = ta.getDimensionPixelSize(
+ R.styleable.ButteryProgressBar_barHeight, 0);
+ mSolidBarDetentWidth = ta.getDimensionPixelSize(
+ R.styleable.ButteryProgressBar_detentWidth, 0);
+ } finally {
+ ta.recycle();
+ }
+
+ mAnimator = new ValueAnimator();
+ mAnimator.setFloatValues(1.0f, 2.0f);
+ mAnimator.setDuration(300);
+ mAnimator.setRepeatCount(ValueAnimator.INFINITE);
+ mAnimator.setInterpolator(new ExponentialInterpolator());
+ mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ invalidate();
+ }
+
+ });
+
+ mPaint.setColor(mBarColor);
+
+ mShadow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
+ new int[]{(mBarColor & 0x00ffffff) | 0x22000000, 0});
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ if (changed) {
+ mShadow.setBounds(0, mSolidBarHeight, getWidth(), getHeight() - mSolidBarHeight);
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (!mAnimator.isStarted()) {
+ return;
+ }
+
+ mShadow.draw(canvas);
+
+ final float val = (Float) mAnimator.getAnimatedValue();
+
+ final int totalW = getWidth();
+ int w = totalW;
+ float l = val * w;
+ // segments are spaced at half-width, quarter, eighth (powers-of-two). to maintain a smooth
+ // transition between segments, we used a power-of-two interpolator.
+ for (int i = 0; i < SEGMENT_COUNT; i++) {
+ w = totalW >> (i + 1);
+ l = val * w;
+ canvas.drawRect(l + mSolidBarDetentWidth, 0, l * 2, mSolidBarHeight, mPaint);
+ }
+ canvas.drawRect(0, 0, l, mSolidBarHeight, mPaint);
+ }
+
+ @Override
+ protected void onVisibilityChanged(View changedView, int visibility) {
+ super.onVisibilityChanged(changedView, visibility);
+
+ if (visibility == VISIBLE) {
+ start();
+ } else {
+ stop();
+ }
+ }
+
+ private void start() {
+ if (mAnimator == null) {
+ return;
+ }
+ mAnimator.start();
+ }
+
+ private void stop() {
+ if (mAnimator == null) {
+ return;
+ }
+ mAnimator.cancel();
+ }
+
+ private static class ExponentialInterpolator implements Interpolator {
+
+ @Override
+ public float getInterpolation(float input) {
+ return (float) Math.pow(2.0, input) - 1;
+ }
+
+ }
+
+}
diff --git a/src/com/android/mail/ui/ConversationListView.java b/src/com/android/mail/ui/ConversationListView.java
index c8140fc82..fcfce47ed 100644
--- a/src/com/android/mail/ui/ConversationListView.java
+++ b/src/com/android/mail/ui/ConversationListView.java
@@ -78,14 +78,6 @@ public class ConversationListView extends FrameLayout implements SwipeableListVi
private ConversationListContext mConvListContext;
- private final Runnable mOnSyncDismiss = new Runnable() {
- @Override
- public void run() {
- mSyncProgressBar.setVisibility(GONE);
- mSyncTriggerBar.setVisibility(GONE);
- }
- };
-
// Instantiated through view inflation
@SuppressWarnings("unused")
public ConversationListView(Context context) {
@@ -105,14 +97,8 @@ public class ConversationListView extends FrameLayout implements SwipeableListVi
mSyncDismissListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator arg0) {
- // Even though alpha is set to 0, still need to set visiblity to
- // GONE, otherwise the progressbar animation continues to get drawn
- // even though it's not visible.
- //
- // For some reason, setting this visibility to GONE immediately upon animation end
- // occasionally does not terminate the periodic drawing of the progress bar.
- // Posting it seems to alleviate this...
- post(mOnSyncDismiss);
+ mSyncProgressBar.setVisibility(GONE);
+ mSyncTriggerBar.setVisibility(GONE);
}
};
}