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
|
<ListView
|
||||||
android:id="@+id/listview"
|
android:id="@+id/listview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" >
|
android:layout_height="wrap_content" />
|
||||||
</ListView>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@id/android:empty"
|
android:id="@id/android:empty"
|
||||||
|
@ -27,36 +26,59 @@
|
||||||
android:id="@+id/controls"
|
android:id="@+id/controls"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:background="@android:color/white" >
|
android:background="@android:color/white" >
|
||||||
|
|
||||||
<SeekBar
|
<SeekBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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
|
<ImageButton
|
||||||
android:id="@+id/previous"
|
android:id="@+id/previous"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/previous" />
|
android:contentDescription="@string/previous"
|
||||||
|
android:layout_toLeftOf="@+id/playpause" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/playpause"
|
android:id="@+id/playpause"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/play" />
|
android:contentDescription="@string/play"
|
||||||
|
android:layout_centerHorizontal="true"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/next"
|
android:id="@+id/next"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:contentDescription="@string/next" />
|
android:contentDescription="@string/next"
|
||||||
|
android:layout_toRightOf="@id/playpause" />
|
||||||
|
|
||||||
|
<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"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,8 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.github.nutomic.controldlna.R;
|
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.
|
* Receives information from MediaRouterPlayService about playback status.
|
||||||
|
* TODO: doc
|
||||||
*/
|
*/
|
||||||
public void receivePlaybackStatus(MediaItemStatus status) {
|
public void receivePlaybackStatus(MediaItemStatus status) {
|
||||||
mProgressBar.setProgress((int) status.getContentPosition() / 1000);
|
int currentTime = (int) status.getContentPosition() / 1000;
|
||||||
mProgressBar.setMax((int) status.getContentDuration() / 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 ||
|
if (status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_PLAYING ||
|
||||||
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_BUFFERING ||
|
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_BUFFERING ||
|
||||||
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_PENDING) {
|
status.getPlaybackState() == MediaItemStatus.PLAYBACK_STATE_PENDING) {
|
||||||
|
|
Reference in a new issue