Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Runnable mUpdate = new Runnable() {
- public void run() {
- boolean firstRun = true;
- while (true) {
- SharedPreferences settings = getSharedPreferences(WindowActivity.PREFS_NAME, 0);
- Calendar newCal = Calendar.getInstance();
- int minutes = newCal.get(Calendar.MINUTE);
- int seconds = newCal.get(Calendar.SECOND);
- int hours = 0;
- if (!settings.getBoolean(h_mode, false)) {
- hours = newCal.get(Calendar.HOUR_OF_DAY);
- timeString = String.format("%02d", hours) + ":" + String.format("%02d", minutes);
- } else {
- hours = newCal.get(Calendar.HOUR);
- switch (newCal.get(Calendar.AM_PM)) {
- case 0:
- timeString = String.format("%02d", hours) + ":" + String.format("%02d", minutes) + "am";
- case 1:
- timeString = String.format("%02d", hours) + ":" + String.format("%02d", minutes) + "pm";
- }
- ;
- }
- if (firstRun || seconds == 58 || seconds == 59 || seconds == 00) {
- firstRun = false;
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- timeText.setText(timeString);
- }
- });
- } else {
- synchronized (this) {
- try {
- Thread.sleep(58000 - seconds * 1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement