From a0ae42dbb93f008b11f21ff21e0c691627449866 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Thu, 21 Jul 2016 23:29:33 -0400 Subject: [PATCH] Switch to progress bar library --- .gitmodules | 3 + AnimatedProgressBar | 1 + app/build.gradle | 2 + .../lightning/activity/BrowserActivity.java | 2 +- .../lightning/view/AnimatedProgressBar.java | 223 ------------------ app/src/main/res/layout/toolbar.xml | 6 +- app/src/main/res/values/attr.xml | 6 - settings.gradle | 2 + 8 files changed, 12 insertions(+), 233 deletions(-) create mode 160000 AnimatedProgressBar delete mode 100644 app/src/main/java/acr/browser/lightning/view/AnimatedProgressBar.java diff --git a/.gitmodules b/.gitmodules index 645e902..e0f1651 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ [submodule "Bonsai"] path = Bonsai url = https://github.com/anthonycr/Bonsai.git +[submodule "AnimatedProgressBar"] + path = AnimatedProgressBar + url = git@github.com:anthonycr/AnimatedProgressBar.git diff --git a/AnimatedProgressBar b/AnimatedProgressBar new file mode 160000 index 0000000..2d7f756 --- /dev/null +++ b/AnimatedProgressBar @@ -0,0 +1 @@ +Subproject commit 2d7f756be8f562b2cedca46de7d2ff24f9383040 diff --git a/app/build.gradle b/app/build.gradle index 15361c0..ff3f662 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -103,6 +103,8 @@ dependencies { compile project(':bonsai') + compile project(':animated-progress-bar') + // memory leak analysis debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 09f4c23..3fee11e 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -84,6 +84,7 @@ import android.widget.TextView.OnEditorActionListener; import android.widget.VideoView; import com.anthonycr.grant.PermissionsManager; +import com.anthonycr.progress.AnimatedProgressBar; import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; @@ -126,7 +127,6 @@ import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.WebUtils; -import acr.browser.lightning.view.AnimatedProgressBar; import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.SearchView; import butterknife.Bind; diff --git a/app/src/main/java/acr/browser/lightning/view/AnimatedProgressBar.java b/app/src/main/java/acr/browser/lightning/view/AnimatedProgressBar.java deleted file mode 100644 index de145f1..0000000 --- a/app/src/main/java/acr/browser/lightning/view/AnimatedProgressBar.java +++ /dev/null @@ -1,223 +0,0 @@ -package acr.browser.lightning.view; - -import android.animation.ObjectAnimator; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.os.Bundle; -import android.os.Parcelable; -import android.support.annotation.NonNull; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.animation.Animation; -import android.view.animation.DecelerateInterpolator; -import android.view.animation.Transformation; -import android.widget.LinearLayout; - -import acr.browser.lightning.R; - -/** - * Copyright 11/4/2014 Anthony Restaino - *

- * 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. - */ -public class AnimatedProgressBar extends LinearLayout { - - private int mProgress = 0; - private boolean mBidirectionalAnimate = true; - private int mDrawWidth = 0; - private int mProgressColor; - - public AnimatedProgressBar(@NonNull Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs); - } - - public AnimatedProgressBar(@NonNull Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context, attrs); - } - - /** - * Initialize the AnimatedProgressBar - * - * @param context is the context passed by the constructor - * @param attrs is the attribute set passed by the constructor - */ - private void init(@NonNull final Context context, AttributeSet attrs) { - TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AnimatedProgressBar, 0, 0); - int backgroundColor; - try { // Retrieve the style of the progress bar that the user hopefully set - int DEFAULT_BACKGROUND_COLOR = 0x424242; - int DEFAULT_PROGRESS_COLOR = 0x2196f3; - - backgroundColor = array.getColor(R.styleable.AnimatedProgressBar_backgroundColor, DEFAULT_BACKGROUND_COLOR); - mProgressColor = array.getColor(R.styleable.AnimatedProgressBar_progressColor, DEFAULT_PROGRESS_COLOR); - mBidirectionalAnimate = array.getBoolean(R.styleable.AnimatedProgressBar_bidirectionalAnimate, false); - } finally { - array.recycle(); - } - - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.animated_progress_bar, this, true); - - - this.setBackgroundColor(backgroundColor); // set the background color for this view - - } - - /** - * Returns the current progress value between 0 and 100 - * - * @return progress of the view - */ - public int getProgress() { - return mProgress; - } - - private final Paint mPaint = new Paint(); - private final Rect mRect = new Rect(); - - @Override - protected void onDraw(@NonNull Canvas canvas) { - mPaint.setColor(mProgressColor); - mPaint.setStrokeWidth(10); - mRect.right = mRect.left + mDrawWidth; - canvas.drawRect(mRect, mPaint); - } - - /** - * sets the progress as an integer value between 0 and 100. - * Values above or below that interval will be adjusted to their - * nearest value within the interval, i.e. setting a value of 150 will have - * the effect of setting the progress to 100. You cannot trick us. - * - * @param progress an integer between 0 and 100 - */ - public void setProgress(int progress) { - - if (progress > 100) { // progress cannot be greater than 100 - progress = 100; - } else if (progress < 0) { // progress cannot be less than 0 - progress = 0; - } - - if (this.getAlpha() < 1.0f) { - fadeIn(); - } - - int mWidth = this.getMeasuredWidth(); - // Set the drawing bounds for the ProgressBar - mRect.left = 0; - mRect.top = 0; - mRect.bottom = this.getBottom() - this.getTop(); - if (progress < mProgress && !mBidirectionalAnimate) { // if the we only animate the view in one direction - // then reset the view width if it is less than the - // previous progress - mDrawWidth = 0; - } else if (progress == mProgress) { // we don't need to go any farther if the progress is unchanged - if (progress == 100) { - fadeOut(); - } - return; - } - - mProgress = progress; // save the progress - - final int deltaWidth = (mWidth * mProgress / 100) - mDrawWidth; // calculate amount the width has to change - - animateView(mDrawWidth, mWidth, deltaWidth); // animate the width change - } - - /** - * private method used to create and run the animation used to change the progress - * - * @param initialWidth is the width at which the progress starts at - * @param maxWidth is the maximum width (total width of the view) - * @param deltaWidth is the amount by which the width of the progress view will change - */ - private void animateView(final int initialWidth, final int maxWidth, final int deltaWidth) { - Animation fill = new Animation() { - - @Override - protected void applyTransformation(float interpolatedTime, Transformation t) { - int width = initialWidth + (int) (deltaWidth * interpolatedTime); - if (width <= maxWidth) { - mDrawWidth = width; - invalidate(); - } - if ((1.0f - interpolatedTime) < 0.0005) { - if (mProgress >= 100) { - fadeOut(); - } - } - } - - @Override - public boolean willChangeBounds() { - return false; - } - }; - - fill.setDuration(500); - fill.setInterpolator(new DecelerateInterpolator()); - this.startAnimation(fill); - } - - /** - * fades in the progress bar - */ - private void fadeIn() { - ObjectAnimator fadeIn = ObjectAnimator.ofFloat(this, "alpha", 1.0f); - fadeIn.setDuration(200); - fadeIn.setInterpolator(new DecelerateInterpolator()); - fadeIn.start(); - } - - /** - * fades out the progress bar - */ - private void fadeOut() { - ObjectAnimator fadeOut = ObjectAnimator.ofFloat(this, "alpha", 0.0f); - fadeOut.setDuration(200); - fadeOut.setInterpolator(new DecelerateInterpolator()); - fadeOut.start(); - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - - if (state instanceof Bundle) { - Bundle bundle = (Bundle) state; - this.mProgress = bundle.getInt("progressState"); - state = bundle.getParcelable("instanceState"); - - - } - - super.onRestoreInstanceState(state); - } - - @NonNull - @Override - protected Parcelable onSaveInstanceState() { - - Bundle bundle = new Bundle(); - bundle.putParcelable("instanceState", super.onSaveInstanceState()); - bundle.putInt("progressState", mProgress); - return bundle; - } - -} diff --git a/app/src/main/res/layout/toolbar.xml b/app/src/main/res/layout/toolbar.xml index 51f755d..4634b31 100644 --- a/app/src/main/res/layout/toolbar.xml +++ b/app/src/main/res/layout/toolbar.xml @@ -5,9 +5,9 @@ xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" - android:fitsSystemWindows="true" android:background="?attr/colorPrimary" android:elevation="2dp" + android:fitsSystemWindows="true" android:orientation="vertical"> - diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index a359d3b..ec87a06 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -12,10 +12,4 @@ - - - - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index cc1b61c..463d0c1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,8 @@ include ':app' include ':libnetcipher' include ':bonsai' +include ':animated-progress-bar' project(':libnetcipher').projectDir = new File(rootProject.projectDir, 'external/netcipher/libnetcipher') project(':bonsai').projectDir = new File(rootProject.projectDir, 'Bonsai/library') +project(':animated-progress-bar').projectDir = new File(rootProject.projectDir, 'AnimatedProgressBar/library') \ No newline at end of file