Added playback time texts to control view, slight layout changes.
This commit is contained in:
parent
a5ab978bba
commit
cad94167ef
2 changed files with 64 additions and 13 deletions
|
@ -7,8 +7,7 @@
|
|||
<ListView
|
||||
android:id="@+id/listview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
</ListView>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@id/android:empty"
|
||||
|
@ -33,30 +32,53 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center" >
|
||||
android:gravity="center"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingRight="10dip" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/current_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="right"
|
||||
android:minEms="2" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/previous"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/previous" />
|
||||
android:contentDescription="@string/previous"
|
||||
android:layout_toLeftOf="@+id/playpause" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/playpause"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/play" />
|
||||
android:contentDescription="@string/play"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/next"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/next" />
|
||||
android:contentDescription="@string/next"
|
||||
android:layout_toRightOf="@id/playpause" />
|
||||
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/total_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:gravity="right"
|
||||
android:minEms="2"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.nutomic.controldlna.R;
|
||||
|
@ -428,12 +428,41 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a time string in the format mm:ss from a time value in seconds.
|
||||
*
|
||||
* @param time Time value in seconds (non-negative).
|
||||
* @return Formatted time string.
|
||||
*/
|
||||
private String generateTimeString(int time) {
|
||||
assert(time >= 0);
|
||||
int seconds = (int) time % 60;
|
||||
int minutes = (int) time / 60;
|
||||
if (minutes > 99)
|
||||
return "99:99";
|
||||
else
|
||||
return Integer.toString(minutes) + ":" +
|
||||
((seconds > 9)
|
||||
? seconds
|
||||
: "0" + Integer.toString(seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives information from MediaRouterPlayService about playback status.
|
||||
* TODO: doc
|
||||
*/
|
||||
public void receivePlaybackStatus(MediaItemStatus status) {
|
||||
mProgressBar.setProgress((int) status.getContentPosition() / 1000);
|
||||
mProgressBar.setMax((int) status.getContentDuration() / 1000);
|
||||
int currentTime = (int) status.getContentPosition() / 1000;
|
||||
int totalTime = (int) status.getContentDuration() / 1000;
|
||||
|
||||
TextView currentTimeView = (TextView) getView().findViewById(R.id.current_time);
|
||||
currentTimeView.setText(generateTimeString(currentTime));
|
||||
TextView totalTimeView = (TextView) getView().findViewById(R.id.total_time);
|
||||
totalTimeView.setText(generateTimeString(totalTime));
|
||||
|
||||
mProgressBar.setProgress(currentTime);
|
||||
mProgressBar.setMax(totalTime);
|
||||
|
||||
if (status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_PLAYING ||
|
||||
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_BUFFERING ||
|
||||
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_PENDING) {
|
||||
|
|
Reference in a new issue