method public boolean onKeyUp(int, android.view.KeyEvent);
method public abstract void onRelease();
method public boolean onSelectTrack(android.media.tv.TvTrackInfo);
+ method public abstract void onSetCaptionEnabled(boolean);
method public abstract void onSetStreamVolume(float);
method public abstract boolean onSetSurface(android.view.Surface);
method public boolean onTouchEvent(android.view.MotionEvent);
method public boolean onUnhandledInputEvent(android.view.InputEvent);
method public void reset();
method public void selectTrack(android.media.tv.TvTrackInfo);
+ method public void setCaptionEnabled(boolean);
method public void setOnUnhandledInputEventListener(android.media.tv.TvView.OnUnhandledInputEventListener);
method public void setStreamVolume(float);
method public void setTvInputListener(android.media.tv.TvView.TvInputListener);
void setSurface(in IBinder sessionToken, in Surface surface, int userId);
void setVolume(in IBinder sessionToken, float volume, int userId);
void tune(in IBinder sessionToken, in Uri channelUri, int userId);
+ void setCaptionEnabled(in IBinder sessionToken, boolean enabled, int userId);
void selectTrack(in IBinder sessionToken, in TvTrackInfo track, int userId);
void unselectTrack(in IBinder sessionToken, in TvTrackInfo track, int userId);
// is to introduce some new concepts that will solve a number of problems in audio policy today.
void setVolume(float volume);
void tune(in Uri channelUri);
+ void setCaptionEnabled(boolean enabled);
void selectTrack(in TvTrackInfo track);
void unselectTrack(in TvTrackInfo track);
private static final int DO_SET_SURFACE = 2;
private static final int DO_SET_VOLUME = 3;
private static final int DO_TUNE = 4;
- private static final int DO_SELECT_TRACK = 5;
- private static final int DO_UNSELECT_TRACK = 6;
- private static final int DO_CREATE_OVERLAY_VIEW = 7;
- private static final int DO_RELAYOUT_OVERLAY_VIEW = 8;
- private static final int DO_REMOVE_OVERLAY_VIEW = 9;
+ private static final int DO_SET_CAPTION_ENABLED = 5;
+ private static final int DO_SELECT_TRACK = 6;
+ private static final int DO_UNSELECT_TRACK = 7;
+ private static final int DO_CREATE_OVERLAY_VIEW = 8;
+ private static final int DO_RELAYOUT_OVERLAY_VIEW = 9;
+ private static final int DO_REMOVE_OVERLAY_VIEW = 10;
private final HandlerCaller mCaller;
mTvInputSessionImpl.tune((Uri) msg.obj);
return;
}
+ case DO_SET_CAPTION_ENABLED: {
+ mTvInputSessionImpl.setCaptionEnabled((Boolean) msg.obj);
+ return;
+ }
case DO_SELECT_TRACK: {
mTvInputSessionImpl.selectTrack((TvTrackInfo) msg.obj);
return;
}
@Override
+ public void setCaptionEnabled(boolean enabled) {
+ mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_CAPTION_ENABLED, enabled));
+ }
+
+ @Override
public void selectTrack(TvTrackInfo track) {
mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SELECT_TRACK, track));
}
import android.view.View;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
}
/**
+ * Enables or disables the caption for this session.
+ *
+ * @param enabled {@code true} to enable, {@code false} to disable.
+ */
+ public void setCaptionEnabled(boolean enabled) {
+ if (mToken == null) {
+ Log.w(TAG, "The session has been already released");
+ return;
+ }
+ try {
+ mService.setCaptionEnabled(mToken, enabled, mUserId);
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* Select a track.
*
* @param track the track to be selected.
package android.media.tv;
+import android.annotation.SuppressLint;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
+import android.view.accessibility.CaptioningManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
public abstract boolean onTune(Uri channelUri);
/**
+ * Enables or disables the caption.
+ * <p>
+ * The locale for the user's preferred captioning language can be obtained by calling
+ * {@link CaptioningManager#getLocale CaptioningManager.getLocale()}.
+ *
+ * @param enabled {@code true} to enable, {@code false} to disable.
+ * @see CaptioningManager
+ */
+ public abstract void onSetCaptionEnabled(boolean enabled);
+
+ /**
* Selects a given track.
* <p>
* If it is called multiple times on the same type of track (ie. Video, Audio, Text), the
* Also, if the select operation was successful, the implementation should call
* {@link #dispatchTrackInfoChanged(List)} to report the updated track information.
* </p>
+ *
* @param track The track to be selected.
* @return {@code true} if the select operation was successful, {@code false} otherwise.
- * @see #dispatchTrackInfoChanged(TvTrackInfo[])
+ * @see #dispatchTrackInfoChanged
* @see TvTrackInfo#KEY_IS_SELECTED
*/
public boolean onSelectTrack(TvTrackInfo track) {
* If the unselect operation was successful, the implementation should call
* {@link #dispatchTrackInfoChanged(List)} to report the updated track information.
* </p>
+ *
* @param track The track to be unselected.
* @return {@code true} if the unselect operation was successful, {@code false} otherwise.
- * @see #dispatchTrackInfoChanged(TvTrackInfo[])
+ * @see #dispatchTrackInfoChanged
* @see TvTrackInfo#KEY_IS_SELECTED
*/
public boolean onUnselectTrack(TvTrackInfo track) {
}
/**
+ * Calls {@link #onSetCaptionEnabled}.
+ */
+ void setCaptionEnabled(boolean enabled) {
+ onSetCaptionEnabled(enabled);
+ }
+
+ /**
* Calls {@link #onSelectTrack}.
*/
void selectTrack(TvTrackInfo track) {
return false;
}
+ @SuppressLint("HandlerLeak")
private final class ServiceHandler extends Handler {
private static final int DO_CREATE_SESSION = 1;
private static final int DO_BROADCAST_AVAILABILITY_CHANGE = 2;
import android.content.Context;
import android.graphics.Rect;
-import android.media.MediaPlayer.TrackInfo;
import android.media.tv.TvInputManager.Session;
import android.media.tv.TvInputManager.Session.FinishedInputEventCallback;
import android.media.tv.TvInputManager.SessionCallback;
}
/**
+ * Enables or disables the caption in this TvView.
+ * <p>
+ * Note that this method does not take any effect unless the current TvView is tuned.
+ *
+ * @param enabled {@code true} to enable, {@code false} to disable.
+ */
+ public void setCaptionEnabled(boolean enabled) {
+ if (mSession != null) {
+ mSession.setCaptionEnabled(enabled);
+ }
+ }
+
+ /**
* Select a track.
* <p>
* If it is called multiple times on the same type of track (ie. Video, Audio, Text), the track
- * selected in previous will be unselected.
+ * selected in previous will be unselected. Note that this method does not take any effect
+ * unless the current TvView is tuned.
* </p>
+ *
* @param track the track to be selected.
* @see #getTracks()
*/
/**
* Unselect a track.
+ * <p>
+ * Note that this method does not take any effect unless the current TvView is tuned.
*
* @param track the track to be unselected.
* @see #getTracks()
}
@Override
+ public void setCaptionEnabled(IBinder sessionToken, boolean enabled, int userId) {
+ final int callingUid = Binder.getCallingUid();
+ final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
+ userId, "setCaptionEnabled");
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ synchronized (mLock) {
+ try {
+ getSessionLocked(sessionToken, callingUid, resolvedUserId)
+ .setCaptionEnabled(enabled);
+ } catch (RemoteException e) {
+ Slog.e(TAG, "error in setCaptionEnabled", e);
+ }
+ }
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
+ @Override
public void selectTrack(IBinder sessionToken, TvTrackInfo track, int userId) {
final int callingUid = Binder.getCallingUid();
final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,