Added progressbars to keys

This commit is contained in:
Michael Schättgen 2016-09-29 12:32:03 +02:00
parent 9112c16235
commit 1b12dfc3e0
4 changed files with 53 additions and 5 deletions

View file

@ -1,11 +1,14 @@
package me.impy.aegis; package me.impy.aegis;
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.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.TextDrawable;
@ -53,12 +56,17 @@ public class KeyProfileAdapter extends RecyclerView.Adapter<KeyProfileAdapter.Ke
TextView profileCode; TextView profileCode;
ImageView profileDrawable; ImageView profileDrawable;
KeyProfile keyProfile; KeyProfile keyProfile;
ProgressBar progressBar;
CountDownTimer mCountDownTimer;
int i = 0;
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);
profileCode = (TextView) itemView.findViewById(R.id.profile_code); profileCode = (TextView) itemView.findViewById(R.id.profile_code);
profileDrawable = (ImageView) itemView.findViewById(R.id.ivTextDrawable); profileDrawable = (ImageView) itemView.findViewById(R.id.ivTextDrawable);
progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
} }
public void setData(KeyProfile profile) { public void setData(KeyProfile profile) {
@ -81,6 +89,30 @@ 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((float)keyProfile.Info.getMillisTillNextRotation() / (float)((keyProfile.Info.getPeriod() * 1000)) * 100);
if(i == 100)
{
i = 0;
}
progressBar.setProgress(i);
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 = 0;
progressBar.setProgress(i);
}
};
mCountDownTimer.start();
} }
private TextDrawable generateTextDrawable(KeyProfile profile) private TextDrawable generateTextDrawable(KeyProfile profile)

View file

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:background="@color/background"
android:layout_height="match_parent"> android:layout_height="match_parent">
<RelativeLayout <RelativeLayout
@ -68,4 +69,19 @@
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:padding="0dp"
android:layout_margin="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:id="@+id/progressBar"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -6,7 +6,7 @@
<color name="colorPrimaryLight">#B3E5FC</color> <color name="colorPrimaryLight">#B3E5FC</color>
<color name="colorAccent">#FF5252</color> <color name="colorAccent">#FF5252</color>
<color name="primary_text">#212121</color> <color name="primary_text">#212121</color>
<color name="secondary_text">#434343</color> <color name="secondary_text">#FF5252</color>
<color name="primary_text_inverted">#ffffff</color> <color name="primary_text_inverted">#ffffff</color>
<color name="secondary_text_inverted">#efefef</color> <color name="secondary_text_inverted">#efefef</color>
<color name="icons">#FFFFFF</color> <color name="icons">#FFFFFF</color>

View file

@ -27,9 +27,9 @@
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
</style> </style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="EditTextTintTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <style name="EditTextTintTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--<item name="colorAccent">@color/</item>--> <!--<item name="colorAccent">@color/</item>-->