Add Toasts that appear on volume change
This commit is contained in:
parent
c7f481d5ba
commit
c14e3d077c
5 changed files with 34 additions and 3 deletions
|
@ -504,12 +504,29 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
|||
enableTrackHighlight();
|
||||
}
|
||||
|
||||
private Toast mVolumeToast;
|
||||
|
||||
private void updateVolumeToast(String text)
|
||||
{
|
||||
// The local provider doesn't report correct values so don't use our toast
|
||||
// (local provider can use the SHOW_UI option on setVolume itself which
|
||||
// does show correct values)
|
||||
if (mMediaRouterPlayService.isLocal())
|
||||
return;
|
||||
if (mVolumeToast != null)
|
||||
mVolumeToast.cancel();
|
||||
mVolumeToast=Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
|
||||
mVolumeToast.show();
|
||||
}
|
||||
|
||||
public void increaseVolume() {
|
||||
mMediaRouterPlayService.increaseVolume();
|
||||
updateVolumeToast(mMediaRouterPlayService.getVolumeText());
|
||||
}
|
||||
|
||||
public void decreaseVolume() {
|
||||
mMediaRouterPlayService.decreaseVolume();
|
||||
updateVolumeToast(mMediaRouterPlayService.getVolumeText());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,13 +92,13 @@ public class Controller extends MediaRouteProvider.RouteController implements
|
|||
|
||||
@Override
|
||||
public void onSetVolume(int volume) {
|
||||
mAudio.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
|
||||
mAudio.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateVolume(int delta) {
|
||||
int currentVolume = mAudio.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
mAudio.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume + delta, 0);
|
||||
mAudio.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume + delta, AudioManager.FLAG_SHOW_UI);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -91,7 +91,8 @@ final class Provider extends MediaRouteProvider {
|
|||
.addControlFilters(CONTROL_FILTERS)
|
||||
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
|
||||
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE)
|
||||
.setVolume(mAudio.getStreamMaxVolume(AudioManager.STREAM_MUSIC))
|
||||
.setVolume(mAudio.getStreamVolume(AudioManager.STREAM_MUSIC))
|
||||
.setVolumeMax(mAudio.getStreamMaxVolume(AudioManager.STREAM_MUSIC))
|
||||
.build();
|
||||
|
||||
|
||||
|
|
|
@ -496,6 +496,13 @@ public class MediaRouterPlayService extends Service {
|
|||
mMediaRouter.getSelectedRoute().requestUpdateVolume(-1);
|
||||
}
|
||||
|
||||
public String getVolumeText()
|
||||
{
|
||||
return String.format(getResources().getString(R.string.volume_text),
|
||||
mMediaRouter.getSelectedRoute().getVolume(),
|
||||
mMediaRouter.getSelectedRoute().getVolumeMax());
|
||||
}
|
||||
|
||||
public List<Item> getPlaylist() {
|
||||
return mPlaylist;
|
||||
}
|
||||
|
@ -525,4 +532,9 @@ public class MediaRouterPlayService extends Service {
|
|||
return mCurrentRoute;
|
||||
}
|
||||
|
||||
public boolean isLocal()
|
||||
{
|
||||
return mCurrentRoute.getName().startsWith(getResources().getString(R.string.local_device));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<string name="select_route">Please select a route</string>
|
||||
<string name="enable_wifi_dialog">Wifi needs to be connected for playback.
|
||||
Do you want to enable it now?</string>
|
||||
<string name="volume_text">Volume: %1$d/%2$d</string>
|
||||
|
||||
<!-- Description for local playback device -->
|
||||
<string name="local_device">Local Device</string>
|
||||
|
|
Reference in a new issue