Created
October 15, 2012 18:43
Revisions
-
derekstavis revised this gist
Oct 15, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public DigitalClock(Context context) { private void update() { seconds++; if (seconds >= 60) { seconds = 0; if (minutes < 59) { minutes++; -
derekstavis revised this gist
Oct 15, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ private void update() { if (seconds > 60) { seconds = 0; if (minutes < 59) { minutes++; } else if (hours < 23) { minutes = 0; -
derekstavis revised this gist
Oct 15, 2012 . No changes.There are no files selected for viewing
-
derekstavis revised this gist
Oct 15, 2012 . 1 changed file with 4 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ public class DigitalClock extends TextView { private Timer clockTimer; private final TimerTask clockTask = new TimerTask() { @Override public void run() { mHandler.post(mUpdateResults); @@ -16,11 +15,10 @@ public void run() { final Handler mHandler = new Handler(); final Runnable mUpdateResults = new Runnable() { public void run() { update(); } }; public DigitalClock(Context context) { super(context); -
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,73 @@ package com.derekstavis; public class DigitalClock extends TextView { private int hours; private int minutes; private int seconds; private Timer clockTimer; private final TimerTask clockTask = new TimerTask() { @Override public void run() { mHandler.post(mUpdateResults); } }; final Handler mHandler = new Handler(); final Runnable mUpdateResults = new Runnable() { public void run() { update(); } }; public DigitalClock(Context context) { super(context); init(); } private void update() { seconds++; if (seconds > 60) { seconds = 0; if (minutes < 60) { minutes++; } else if (hours < 23) { minutes = 0; hours++; } else { minutes = 0; hours = 0; } } if (seconds % 2 == 0) { setText(String.format("%02d:%02d", hours, minutes)); } else { setText(String.format("%02d %02d", hours, minutes)); } } private void init() { clockTimer = new Timer(); Calendar mCalendar = Calendar.getInstance(); hours = mCalendar.get(Calendar.HOUR_OF_DAY); minutes = mCalendar.get(Calendar.MINUTE); seconds = mCalendar.get(Calendar.SECOND); clockTimer.scheduleAtFixedRate(clockTask, 0, 1000); } public DigitalClock(Context context, AttributeSet attrs) { super(context, attrs); init(); } public DigitalClock(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ <com.derekstavis.DigitalClock android:id="@+id/digitalClock" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="120dp"/>