Commit 2a68cfa2 authored by Edward Wang's avatar Edward Wang Committed by Jean-Baptiste Kempf

Add show remaining time feature

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 95a0f827
......@@ -69,7 +69,9 @@
android:textSize="18dip"
android:text="@string/time_0"
android:textColor="#ffffff"
android:id="@+id/time" />
android:id="@+id/time"
android:clickable="true"
android:onClick="onTimeLabelClick" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
......
......@@ -69,7 +69,9 @@
android:textSize="18dip"
android:text="@string/time_0"
android:textColor="#ffffff"
android:id="@+id/time" />
android:id="@+id/time"
android:clickable="true"
android:onClick="onTimeLabelClick" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
......
......@@ -32,6 +32,7 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
private AudioServiceController mAudioController;
private boolean mIsTracking = false;
private boolean mShowRemainingTime = false;
private String lastTitle;
@Override
......@@ -100,7 +101,7 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
mAlbum.setText(mAudioController.getAlbum());
int time = (int) mAudioController.getTime();
int length = (int) mAudioController.getLength();
mTime.setText(Util.millisToString(time));
mTime.setText(Util.millisToString(mShowRemainingTime ? time-length : time));
mLength.setText(Util.millisToString(length));
mTimeline.setMax(length);
if (!mIsTracking)
......@@ -149,12 +150,16 @@ public class AudioPlayerActivity extends Activity implements AudioPlayer {
public void onProgressChanged(SeekBar sb, int prog, boolean fromUser) {
if (fromUser) {
mAudioController.setTime(prog);
mTime.setText(Util.millisToString(prog))
mTime.setText(Util.millisToString(mShowRemainingTime ? prog-mAudioController.getLength() : prog))
;
}
}
};
public void onTimeLabelClick(View view) {
mShowRemainingTime = !mShowRemainingTime;
}
public void onPlayPauseClick(View view) {
if (mAudioController.isPlaying()) {
mAudioController.pause();
......
......@@ -37,6 +37,9 @@ public class Util {
* @return formated string (hh:)mm:ss
*/
public static String millisToString(long millis) {
boolean negative = millis < 0;
millis = java.lang.Math.abs(millis);
millis /= 1000;
int sec = (int) (millis % 60);
millis /= 60;
......@@ -47,9 +50,9 @@ public class Util {
String time;
DecimalFormat format = new DecimalFormat("00");
if (millis > 0) {
time = hours + ":" + format.format(min) + ":" + format.format(sec);
time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec);
} else {
time = min + ":" + format.format(sec);
time = (negative ? "-" : "") + min + ":" + format.format(sec);
}
return time;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment