From 1da8fb39499e8f5a962f7307fefdfd2ab6b79224 Mon Sep 17 00:00:00 2001 From: Jae Seo Date: Tue, 21 Apr 2015 10:50:59 -0700 Subject: [PATCH] TIF: Cache the stream volume on TvView Also added explanation of the default value. Bug: 18939663 Change-Id: Idffd45738b0299779c245a11022faadc12004060 --- .../java/android/media/tv/TvInputService.java | 10 ++++-- media/java/android/media/tv/TvView.java | 31 +++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java index 343ffcb8bf114..9bdeb2540e4e2 100644 --- a/media/java/android/media/tv/TvInputService.java +++ b/media/java/android/media/tv/TvInputService.java @@ -736,10 +736,14 @@ public abstract class TvInputService extends Service { } /** - * Sets the relative stream volume of the current TV input session to handle the change of - * audio focus by setting. + * Sets the relative stream volume of the current TV input session. * - * @param volume Volume scale from 0.0 to 1.0. + *

The implementation should honor this request in order to handle audio focus changes or + * mute the current session when multiple sessions, possibly from different inputs are + * active. If the method has not yet been called, the implementation should assume the + * default value of {@code 1.0f}. + * + * @param volume A volume value between {@code 0.0f} to {@code 1.0f}. */ public abstract void onSetStreamVolume(float volume); diff --git a/media/java/android/media/tv/TvView.java b/media/java/android/media/tv/TvView.java index 024ffd19b0da4..9451f69aa49ca 100644 --- a/media/java/android/media/tv/TvView.java +++ b/media/java/android/media/tv/TvView.java @@ -66,10 +66,6 @@ public class TvView extends ViewGroup { private static final int ZORDER_MEDIA_OVERLAY = 1; private static final int ZORDER_ON_TOP = 2; - private static final int CAPTION_DEFAULT = 0; - private static final int CAPTION_ENABLED = 1; - private static final int CAPTION_DISABLED = 2; - private static final WeakReference NULL_TV_VIEW = new WeakReference<>(null); private static final Object sMainTvViewLock = new Object(); @@ -85,9 +81,8 @@ public class TvView extends ViewGroup { private MySessionCallback mSessionCallback; private TvInputCallback mCallback; private OnUnhandledInputEventListener mOnUnhandledInputEventListener; - private boolean mHasStreamVolume; - private float mStreamVolume; - private int mCaptionEnabled; + private Float mStreamVolume; + private Boolean mCaptionEnabled; private String mAppPrivateCommandAction; private Bundle mAppPrivateCommandData; @@ -253,13 +248,16 @@ public class TvView extends ViewGroup { } /** - * Sets the relative stream volume of this session to handle a change of audio focus. + * Sets the relative stream volume of this TvView. * - * @param volume A volume value between 0.0f to 1.0f. + *

This method is primarily used to handle audio focus changes or mute a specific TvView when + * multiple views are displayed. If the method has not yet been called, the TvView assumes the + * default value of {@code 1.0f}. + * + * @param volume A volume value between {@code 0.0f} to {@code 1.0f}. */ public void setStreamVolume(float volume) { if (DEBUG) Log.d(TAG, "setStreamVolume(" + volume + ")"); - mHasStreamVolume = true; mStreamVolume = volume; if (mSession == null) { // Volume will be set once the connection has been made. @@ -367,7 +365,8 @@ public class TvView extends ViewGroup { * @param enabled {@code true} to enable, {@code false} to disable. */ public void setCaptionEnabled(boolean enabled) { - mCaptionEnabled = enabled ? CAPTION_ENABLED : CAPTION_DISABLED; + if (DEBUG) Log.d(TAG, "setCaptionEnabled(" + enabled + ")"); + mCaptionEnabled = enabled; if (mSession != null) { mSession.setCaptionEnabled(enabled); } @@ -1018,13 +1017,13 @@ public class TvView extends ViewGroup { } } createSessionOverlayView(); - if (mCaptionEnabled != CAPTION_DEFAULT) { - mSession.setCaptionEnabled(mCaptionEnabled == CAPTION_ENABLED); - } - mSession.tune(mChannelUri, mTuneParams); - if (mHasStreamVolume) { + if (mStreamVolume != null) { mSession.setStreamVolume(mStreamVolume); } + if (mCaptionEnabled != null) { + mSession.setCaptionEnabled(mCaptionEnabled); + } + mSession.tune(mChannelUri, mTuneParams); if (mAppPrivateCommandAction != null) { mSession.sendAppPrivateCommand( mAppPrivateCommandAction, mAppPrivateCommandData);