Merge pull request #1493 from dethstar/time_left

Player: Toggle "time left" and "total time" #1456
This commit is contained in:
Tom Hennen 2015-12-28 12:26:12 -05:00
commit 14fec88e5b
1 changed files with 47 additions and 1 deletions

View File

@ -1,8 +1,10 @@
package de.danoeh.antennapod.activity; package de.danoeh.antennapod.activity;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
@ -43,6 +45,8 @@ import de.danoeh.antennapod.dialog.SleepTimerDialog;
public abstract class MediaplayerActivity extends ActionBarActivity public abstract class MediaplayerActivity extends ActionBarActivity
implements OnSeekBarChangeListener { implements OnSeekBarChangeListener {
private static final String TAG = "MediaplayerActivity"; private static final String TAG = "MediaplayerActivity";
private static final String PREFS = "MediaPlayerActivityPreferences";
private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft";
protected PlaybackController controller; protected PlaybackController controller;
@ -51,6 +55,7 @@ public abstract class MediaplayerActivity extends ActionBarActivity
protected SeekBar sbPosition; protected SeekBar sbPosition;
protected ImageButton butPlay; protected ImageButton butPlay;
protected ImageButton butRev; protected ImageButton butRev;
protected boolean showTimeLeft = false;
protected TextView txtvRev; protected TextView txtvRev;
protected ImageButton butFF; protected ImageButton butFF;
protected TextView txtvFF; protected TextView txtvFF;
@ -413,7 +418,14 @@ public abstract class MediaplayerActivity extends ActionBarActivity
&& controller.getMedia() != null) { && controller.getMedia() != null) {
txtvPosition.setText(Converter txtvPosition.setText(Converter
.getDurationStringLong(currentPosition)); .getDurationStringLong(currentPosition));
txtvLength.setText(Converter.getDurationStringLong(duration)); if(showTimeLeft) {
txtvLength.setText("-"+Converter
.getDurationStringLong(duration - currentPosition));
}
else {
txtvLength.setText(Converter
.getDurationStringLong(duration));
}
updateProgressbarPosition(currentPosition, duration); updateProgressbarPosition(currentPosition, duration);
} else { } else {
Log.w(TAG, "Could not react to position observer update because of invalid time"); Log.w(TAG, "Could not react to position observer update because of invalid time");
@ -436,6 +448,8 @@ public abstract class MediaplayerActivity extends ActionBarActivity
protected boolean loadMediaInfo() { protected boolean loadMediaInfo() {
Log.d(TAG, "loadMediaInfo()"); Log.d(TAG, "loadMediaInfo()");
Playable media = controller.getMedia(); Playable media = controller.getMedia();
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT,false);
if (media != null) { if (media != null) {
txtvPosition.setText(Converter.getDurationStringLong((media txtvPosition.setText(Converter.getDurationStringLong((media
.getPosition()))); .getPosition())));
@ -446,6 +460,10 @@ public abstract class MediaplayerActivity extends ActionBarActivity
float progress = ((float) media.getPosition()) float progress = ((float) media.getPosition())
/ media.getDuration(); / media.getDuration();
sbPosition.setProgress((int) (progress * sbPosition.getMax())); sbPosition.setProgress((int) (progress * sbPosition.getMax()));
if(showTimeLeft) {
txtvLength.setText("-"+Converter.getDurationStringLong((media
.getDuration()-media.getPosition())));
}
} }
return true; return true;
} else { } else {
@ -457,7 +475,30 @@ public abstract class MediaplayerActivity extends ActionBarActivity
setContentView(getContentViewResourceId()); setContentView(getContentViewResourceId());
sbPosition = (SeekBar) findViewById(R.id.sbPosition); sbPosition = (SeekBar) findViewById(R.id.sbPosition);
txtvPosition = (TextView) findViewById(R.id.txtvPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition);
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT,false);
Log.d("timeleft",showTimeLeft? "true":"false");
txtvLength = (TextView) findViewById(R.id.txtvLength); txtvLength = (TextView) findViewById(R.id.txtvLength);
txtvLength.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showTimeLeft = !showTimeLeft;
Playable media = controller.getMedia();
if(showTimeLeft) {
txtvLength.setText("-"+Converter.getDurationStringLong((media
.getDuration()-media.getPosition())));
}else{
txtvLength.setText("-"+Converter.getDurationStringLong((media.getDuration())));
}
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PREF_SHOW_TIME_LEFT,showTimeLeft);
editor.commit();
Log.d("timeleft on click",showTimeLeft? "true":"false");
}
});
butPlay = (ImageButton) findViewById(R.id.butPlay); butPlay = (ImageButton) findViewById(R.id.butPlay);
butRev = (ImageButton) findViewById(R.id.butRev); butRev = (ImageButton) findViewById(R.id.butRev);
txtvRev = (TextView) findViewById(R.id.txtvRev); txtvRev = (TextView) findViewById(R.id.txtvRev);
@ -598,6 +639,11 @@ public abstract class MediaplayerActivity extends ActionBarActivity
if (controller != null) { if (controller != null) {
prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser,
txtvPosition); txtvPosition);
if(showTimeLeft && prog!=0) {
int duration = controller.getDuration();
txtvLength.setText("-"+Converter
.getDurationStringLong(duration - (int) (prog * duration)));
}
} }
} }