Skip to content

Commit

Permalink
Add timer
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Dec 26, 2019
1 parent 3289338 commit 1335446
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,21 @@ public enum State {
private String lastScanCode;
private State state = State.SCANNING;
private Handler timeoutHandler;
private Handler timerHandler;
private long timerStart;
private MediaPlayer mediaPlayer;
private TicketCheckProvider checkProvider;
private AppConfig config;
private DataWedgeHelper dataWedgeHelper;
private AlertDialog dialog;

Runnable timerUpdate = new Runnable() {
@Override
public void run() {
updateTimer(true);
}
};

private JSONObject options;
private String last_secret;

Expand Down Expand Up @@ -102,6 +111,7 @@ public void onCreate(Bundle savedInstanceState) {
mediaPlayer = buildMediaPlayer(this);

timeoutHandler = new Handler();
timerHandler = new Handler();

resetView();

Expand All @@ -123,6 +133,7 @@ public void onCreate(Bundle savedInstanceState) {
}
}
}
timerHandler.postDelayed(timerUpdate, 100);
}


Expand Down Expand Up @@ -248,6 +259,7 @@ private void handleTicketScanned(String s) {
options = new JSONObject();
state = State.LOADING;
findViewById(R.id.tvScanResult).setVisibility(View.GONE);
findViewById(R.id.tvTimer).setVisibility(View.GONE);
findViewById(R.id.pbScan).setVisibility(View.VISIBLE);
new CheckTask().execute(s);
}
Expand All @@ -256,6 +268,7 @@ private void resetView() {
TextView tvScanResult = (TextView) findViewById(R.id.tvScanResult);
timeoutHandler.removeCallbacksAndMessages(null);
tvScanResult.setVisibility(View.VISIBLE);
findViewById(R.id.tvTimer).setVisibility(View.GONE);
((TextView) findViewById(R.id.tvScanResult)).setText("");
findViewById(R.id.rlScanStatus).setBackgroundColor(
ContextCompat.getColor(this, R.color.scan_result_unknown));
Expand Down Expand Up @@ -290,9 +303,19 @@ protected void onPostExecute(TicketCheckProvider.CheckResult checkResult) {
}
}

private void updateTimer(boolean repeat) {
((TextView) findViewById(R.id.tvTimer)).setText(String.valueOf(Math.round((System.currentTimeMillis() - timerStart) / 1000)));
if (repeat) {
timerHandler.postDelayed(timerUpdate, 500);
}
}

private void displayScanResult(TicketCheckProvider.CheckResult checkResult) {
TextView tvScanResult = findViewById(R.id.tvScanResult);
timerStart = System.currentTimeMillis();
updateTimer(false);
findViewById(R.id.tvTimer).setVisibility(View.VISIBLE);

TextView tvScanResult = (TextView) findViewById(R.id.tvScanResult);

state = State.RESULT;
findViewById(R.id.pbScan).setVisibility(View.INVISIBLE);
Expand Down
14 changes: 12 additions & 2 deletions postixdroid/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RelativeLayout
android:id="@+id/rlScanStatus"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_height="180dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
Expand All @@ -29,11 +29,21 @@
android:id="@+id/tvScanResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/tvTimer"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="invisible" />

<TextView
android:id="@+id/tvTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="invisible" />
</RelativeLayout>

<de.ccc.events.postixdroid.ui.CustomizedScannerView
Expand Down

0 comments on commit 1335446

Please sign in to comment.