]> Pileus Git - ~andy/freeotp/commitdiff
Resurrect refresh icon / circle progress bar
authorNathaniel McCallum <npmccallum@redhat.com>
Mon, 2 Dec 2013 23:18:10 +0000 (18:18 -0500)
committerNathaniel McCallum <npmccallum@redhat.com>
Mon, 2 Dec 2013 23:18:10 +0000 (18:18 -0500)
res/drawable-hdpi/generate.png [new file with mode: 0755]
res/drawable-mdpi/generate.png [new file with mode: 0755]
res/drawable-xhdpi/generate.png [new file with mode: 0755]
res/layout/token.xml
src/org/fedorahosted/freeotp/CircleProgressBar.java [new file with mode: 0644]
src/org/fedorahosted/freeotp/Token.java
src/org/fedorahosted/freeotp/UrgencyProgressBar.java [deleted file]
src/org/fedorahosted/freeotp/adapters/TokenAdapter.java

diff --git a/res/drawable-hdpi/generate.png b/res/drawable-hdpi/generate.png
new file mode 100755 (executable)
index 0000000..0f3ceec
Binary files /dev/null and b/res/drawable-hdpi/generate.png differ
diff --git a/res/drawable-mdpi/generate.png b/res/drawable-mdpi/generate.png
new file mode 100755 (executable)
index 0000000..ca28ba3
Binary files /dev/null and b/res/drawable-mdpi/generate.png differ
diff --git a/res/drawable-xhdpi/generate.png b/res/drawable-xhdpi/generate.png
new file mode 100755 (executable)
index 0000000..a80b9ab
Binary files /dev/null and b/res/drawable-xhdpi/generate.png differ
index 9f5cd3d9ac537ee9d34a821a16cf1af3d507b654..d6ad3efb847b9c8e503471ee8edfbd5b180e8f81 100644 (file)
    - limitations under the License.
    -->
 
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_marginTop="4dp"
     android:layout_marginBottom="4dp"
     android:layout_marginLeft="8dp"
     android:layout_marginRight="8dp"
-    android:background="@drawable/token"
-    android:orientation="vertical" >
-    <TextView
-        android:id="@+id/code"
-        android:layout_width="match_parent"
-        android:layout_height="60dp"
-        android:gravity="center"
-        android:paddingTop="4dp"
-        android:text="01234567"
-        android:textSize="48sp"
-        android:textStyle="bold"
-        android:typeface="monospace" />
-
-    <org.fedorahosted.freeotp.UrgencyProgressBar
-        android:id="@+id/progress"
-        style="?android:attr/progressBarStyleHorizontal"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:max="1000"
-        android:progress="500" />
+    android:background="@drawable/token" >
 
     <LinearLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_margin="4dp"
-        android:orientation="horizontal" >
+        android:layout_height="96dp"
+        android:orientation="vertical" >
+
+        <TextView
+            android:id="@+id/code"
+            android:layout_width="match_parent"
+            android:layout_height="48dp"
+            android:gravity="center|left"
+            android:text="01234567"
+            android:textSize="38sp"
+            android:textStyle="bold"
+            android:typeface="monospace" />
 
         <LinearLayout
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
+            android:layout_width="match_parent"
+            android:layout_height="48dp"
+            android:paddingTop="4dp"
+            android:paddingBottom="4dp"
             android:orientation="vertical" >
-
             <TextView
                 android:id="@+id/issuer"
                 android:layout_width="match_parent"
-                android:layout_height="24dp"
+                android:layout_height="0dp"
+                android:layout_weight="3"
+                android:layout_marginRight="48dp"
                 android:ellipsize="end"
-                android:gravity="center_vertical"
+                android:gravity="left|center"
                 android:singleLine="true"
                 android:text="example@example.com"
                 android:textColor="@android:color/primary_text_light"
             <TextView
                 android:id="@+id/label"
                 android:layout_width="match_parent"
-                android:layout_height="16dp"
+                android:layout_height="0dp"
+                android:layout_weight="2"
+                android:layout_marginRight="48dp"
                 android:ellipsize="end"
-                android:gravity="center_vertical"
+                android:gravity="left|center"
                 android:singleLine="true"
                 android:text="1FMAS0M43MF98ASMDMF10MF0M"
                 android:textColor="@android:color/secondary_text_light"
                 android:textSize="12sp"
                 android:textStyle="normal" />
         </LinearLayout>
-
-        <CheckBox
-            android:id="@+id/checkBox"
-            android:layout_width="40dp"
-            android:layout_height="40dp"
-            android:background="?android:attr/selectableItemBackground" />
     </LinearLayout>
-</LinearLayout>
+
+    <ImageView
+        android:id="@+id/image"
+        android:layout_width="48dp"
+        android:layout_height="48dp"
+        android:layout_gravity="top|right"
+        android:padding="4dp"
+        android:src="@drawable/generate" />
+
+    <org.fedorahosted.freeotp.CircleProgressBar
+        android:id="@+id/progress"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="48dp"
+        android:layout_height="48dp"
+        android:layout_gravity="top|right"
+        android:max="1000"
+        android:padding="8dp"
+        android:progress="750" />
+
+    <CheckBox
+        android:id="@+id/checkBox"
+        android:layout_width="40dp"
+        android:layout_height="48dp"
+        android:layout_gravity="bottom|right"
+        android:background="?android:attr/selectableItemBackground"
+        android:gravity="center_vertical" />
+</FrameLayout>
diff --git a/src/org/fedorahosted/freeotp/CircleProgressBar.java b/src/org/fedorahosted/freeotp/CircleProgressBar.java
new file mode 100644 (file)
index 0000000..b1c26cc
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * FreeOTP
+ *
+ * Authors: Nathaniel McCallum <npmccallum@redhat.com>
+ *
+ * Copyright (C) 2013  Nathaniel McCallum, Red Hat
+ *
+ * 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.
+ */
+
+package org.fedorahosted.freeotp;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Paint.Style;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.widget.ProgressBar;
+
+public class CircleProgressBar extends ProgressBar {
+       private Paint paint;
+       private RectF rectf;
+       private Rect rect;
+
+       public CircleProgressBar(Context context, AttributeSet attrs, int defStyle) {
+               super(context, attrs, defStyle);
+               setup();
+       }
+
+       public CircleProgressBar(Context context, AttributeSet attrs) {
+               super(context, attrs);
+               setup();
+       }
+
+       public CircleProgressBar(Context context) {
+               super(context);
+               setup();
+       }
+
+       private void setup() {
+               paint = new Paint();
+        rectf = new RectF();
+        rect = new Rect();
+
+        paint.setARGB(0x99, 0x33, 0x33, 0x33);
+        paint.setAntiAlias(true);
+        paint.setStyle(Style.FILL_AND_STROKE);
+       }
+
+       @Override
+       public synchronized void setProgress(int progress) {
+               super.setProgress(progress);
+               if (paint != null) {
+                       int percent = progress * 100 / getMax();
+                       if (percent > 25 || progress == 0)
+                               paint.setARGB(0x99, 0x33, 0x33, 0x33);
+                       else
+                               paint.setARGB(0x99, 0xff, 0xe0 * percent / 25, 0x00);
+               }
+       }
+
+       @Override
+       protected synchronized void onDraw(Canvas canvas) {
+               getDrawingRect(rect);
+               rect.left += getPaddingLeft() + 2;
+               rect.top += getPaddingTop() + 2;
+               rect.right -= getPaddingRight() + 2;
+               rect.bottom -= getPaddingBottom() + 2;
+
+               rectf.set(rect);
+               canvas.drawArc(rectf, -90, getProgress() * 360 / getMax(), true, paint);
+       }
+}
index f087297a8971dc17a9ce3fc202bb666e219a3c9b..9acecb4e8a86b2b6c09fb211051db76c218efbf9 100644 (file)
@@ -228,10 +228,10 @@ public class Token {
                long time = System.currentTimeMillis();
 
                if (mType == TokenType.TOTP)
-                       return (int) (time % (mPeriod * 1000) / mPeriod);
+                       return 1000 - (int) (time % (mPeriod * 1000) / mPeriod);
 
                long state = (time - mLastCode) / 60;
-               return (int) (state > 1000 ? 1000 : state);
+               return 1000 - (int) (state > 1000 ? 1000 : state);
        }
 
        public Uri toUri() {
diff --git a/src/org/fedorahosted/freeotp/UrgencyProgressBar.java b/src/org/fedorahosted/freeotp/UrgencyProgressBar.java
deleted file mode 100644 (file)
index d9fe2f0..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * FreeOTP
- *
- * Authors: Nathaniel McCallum <npmccallum@redhat.com>
- *
- * Copyright (C) 2013  Nathaniel McCallum, Red Hat
- *
- * 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.
- */
-
-package org.fedorahosted.freeotp;
-
-import android.content.Context;
-import android.graphics.Color;
-import android.graphics.PorterDuff.Mode;
-import android.util.AttributeSet;
-import android.widget.ProgressBar;
-
-public class UrgencyProgressBar extends ProgressBar {
-       public UrgencyProgressBar(Context context, AttributeSet attrs, int defStyle) {
-               super(context, attrs, defStyle);
-       }
-
-       public UrgencyProgressBar(Context context, AttributeSet attrs) {
-               super(context, attrs);
-       }
-
-       public UrgencyProgressBar(Context context) {
-               super(context);
-       }
-
-       @Override
-       public synchronized void setProgress(int progress) {
-               super.setProgress(progress);
-
-               int percent = progress * 100 / getMax();
-               if (percent > 33 || progress == 0)
-                       getProgressDrawable().clearColorFilter();
-               else {
-                       int green = 0xe0 * percent / 33;
-                       getProgressDrawable().setColorFilter(Color.RED | (green << 8), Mode.SRC_IN);
-               }
-       }
-
-
-}
index 4824e2092da3de014d6b30424ecb3ae41fe5086f..8126aca9fb619b3d99f1474101a4870acef206a6 100644 (file)
@@ -33,6 +33,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.CompoundButton;
+import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
@@ -44,6 +45,7 @@ public class TokenAdapter extends TokenPersistenceBaseAdapter {
                TextView label;
                TextView issuer;
                ProgressBar progress;
+               ImageView image;
        }
 
        private static class Ticker extends Handler {
@@ -60,11 +62,18 @@ public class TokenAdapter extends TokenPersistenceBaseAdapter {
                                return;
 
                        ViewHolder holder = (ViewHolder) view.getTag();
-                       int progress = 1000 - holder.token.getProgress();
                        holder.code.setText(holder.token.getCode());
+
+                       int progress = holder.token.getProgress();
                        holder.progress.setProgress(progress);
                        if (progress > 0 && progress < 950)
                                view.setEnabled(true);
+
+                       if (holder.token.getType() == TokenType.HOTP && progress == 0) {
+                               holder.progress.setVisibility(View.GONE);
+                               holder.image.setVisibility(View.VISIBLE);
+                       }
+
                        start();
                }
 
@@ -107,6 +116,8 @@ public class TokenAdapter extends TokenPersistenceBaseAdapter {
                                        ViewHolder holder = (ViewHolder) v.getTag();
                                        holder.token.increment();
                                        holder.code.setText(holder.token.getCode());
+                                       holder.progress.setVisibility(View.VISIBLE);
+                                       holder.image.setVisibility(View.GONE);
                                        save(holder.token);
                                        v.setEnabled(false);
                                }
@@ -114,10 +125,15 @@ public class TokenAdapter extends TokenPersistenceBaseAdapter {
                }
                view.setOnClickListener(ocl);
 
-               if (holder.token.getType() == TokenType.TOTP)
+               if (holder.token.getType() == TokenType.TOTP) {
                        view.setBackgroundResource(R.drawable.token_normal);
-               else
+                       holder.progress.setVisibility(View.VISIBLE);
+                       holder.image.setVisibility(View.GONE);
+               } else {
                        view.setBackgroundResource(R.drawable.token);
+                       holder.progress.setVisibility(View.GONE);
+                       holder.image.setVisibility(View.VISIBLE);
+               }
        }
 
        @Override
@@ -129,6 +145,7 @@ public class TokenAdapter extends TokenPersistenceBaseAdapter {
                holder.label = (TextView) view.findViewById(R.id.label);
                holder.issuer = (TextView) view.findViewById(R.id.issuer);
                holder.progress = (ProgressBar) view.findViewById(R.id.progress);
+               holder.image = (ImageView) view.findViewById(R.id.image);
                view.setTag(holder);
 
                new Ticker(view).start();