From 9224095dbaa037a9d0c99d1b58e4a541628ec36e Mon Sep 17 00:00:00 2001 From: Christopher Eby Date: Wed, 24 Aug 2011 16:37:55 -0500 Subject: [PATCH] More detailed time display in IdlePreference --- res/values/strings.xml | 14 ++++++++---- src/org/kreed/vanilla/IdlePreference.java | 28 ++++++++++++++--------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 90cf3b18..12ac74c2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,6 @@ + + 01 second + %02d seconds + - 1 minute - %d minutes + 01 minute + %02d minutes - 1 hour - %d hours + 01 hour + %02d hours Audio Output diff --git a/src/org/kreed/vanilla/IdlePreference.java b/src/org/kreed/vanilla/IdlePreference.java index 9aac8d3d..83df5f29 100644 --- a/src/org/kreed/vanilla/IdlePreference.java +++ b/src/org/kreed/vanilla/IdlePreference.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Christopher Eby + * Copyright (C) 2010, 2011 Christopher Eby * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -95,15 +95,21 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa { Resources res = getContext().getResources(); int value = mValue; - String text; - if (value >= 3570) { - int hours = (int)Math.round(value / 3600f); - text = res.getQuantityString(R.plurals.hours, hours, hours); + StringBuilder text = new StringBuilder(); + if (value >= 3600) { + int hours = value / 3600; + text.append(res.getQuantityString(R.plurals.hours, hours, hours)); + text.append(", "); + int minutes = value / 60 - hours * 60; + text.append(res.getQuantityString(R.plurals.minutes, minutes, minutes)); } else { - int minutes = (int)Math.round(value / 60f); - text = res.getQuantityString(R.plurals.minutes, minutes, minutes); + int minutes = value / 60; + text.append(res.getQuantityString(R.plurals.minutes, minutes, minutes)); + text.append(", "); + int seconds = value - minutes * 60; + text.append(res.getQuantityString(R.plurals.seconds, seconds, seconds)); } - mValueText.setText(text); + mValueText.setText(text.toString()); } @Override @@ -115,7 +121,7 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - // Approximate an exponential curve with x^4. Produces a value from 60-10860. + // Approximate an exponential curve with x^4. Produces a value from MIN-MAX. if (fromUser) { float value = seekBar.getProgress() / 1000.0f; value *= value; @@ -126,10 +132,10 @@ public class IdlePreference extends DialogPreference implements SeekBar.OnSeekBa } public void onStartTrackingTouch(SeekBar seekBar) - { + { } public void onStopTrackingTouch(SeekBar seekBar) { } -} \ No newline at end of file +}