- 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>
--- /dev/null
+/*
+ * 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);
+ }
+}
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() {
+++ /dev/null
-/*
- * 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);
- }
- }
-
-
-}
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
+import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
TextView label;
TextView issuer;
ProgressBar progress;
+ ImageView image;
}
private static class Ticker extends Handler {
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();
}
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);
}
}
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
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();