mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Made the progressbar animation somewhat smoother
This commit is contained in:
parent
016cbd9ebc
commit
2128b5bf59
2 changed files with 9 additions and 27 deletions
|
@ -1,12 +1,12 @@
|
||||||
package me.impy.aegis;
|
package me.impy.aegis;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.os.CountDownTimer;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.LinearInterpolator;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -58,9 +58,6 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
KeyProfile keyProfile;
|
KeyProfile keyProfile;
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
|
|
||||||
CountDownTimer mCountDownTimer;
|
|
||||||
int i = 100;
|
|
||||||
|
|
||||||
KeyProfileHolder(final View itemView) {
|
KeyProfileHolder(final View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
profileName = (TextView) itemView.findViewById(R.id.profile_name);
|
||||||
|
@ -90,29 +87,13 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
|
||||||
this.keyProfile.Code = otp;
|
this.keyProfile.Code = otp;
|
||||||
profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
profileCode.setText(otp.substring(0, 3) + " " + otp.substring(3));
|
||||||
|
|
||||||
i = Math.round(100 - ((float)keyProfile.Info.getMillisTillNextRotation() / (float)((keyProfile.Info.getPeriod() * 1000)) * 100));
|
long millisTillRotation = keyProfile.Info.getMillisTillNextRotation();
|
||||||
if(i == 0)
|
long period = keyProfile.Info.getPeriod() * 1000;
|
||||||
{
|
int currentProgress = (int)((((double)period - millisTillRotation) / period) * 1000);
|
||||||
i = 100;
|
ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", currentProgress, 1000);
|
||||||
}
|
animation.setDuration(millisTillRotation);
|
||||||
progressBar.setProgress(i);
|
animation.setInterpolator(new LinearInterpolator());
|
||||||
|
animation.start();
|
||||||
mCountDownTimer = new CountDownTimer(keyProfile.Info.getMillisTillNextRotation(), (keyProfile.Info.getPeriod() * 1000 / 100)) {
|
|
||||||
@Override
|
|
||||||
public void onTick(long millisUntilFinished) {
|
|
||||||
i--;
|
|
||||||
progressBar.setProgress(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFinish() {
|
|
||||||
//Do what you want
|
|
||||||
i = 100;
|
|
||||||
progressBar.setProgress(i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mCountDownTimer.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextDrawable generateTextDrawable(KeyProfile profile)
|
private TextDrawable generateTextDrawable(KeyProfile profile)
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="4dp"
|
android:layout_height="4dp"
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
|
android:max="1000"
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue