@Override public void onCreate() { super.onCreate(); mHandlerThread = new HandlerThread(getClass().getSimpleName()); mHandlerThread.start(); mDbHandler = new Handler(mHandlerThread.getLooper()); mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE); setTheme(android.R.style.Theme_Holo_Light_NoActionBar); mSessions = new ArrayList<>(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(TvInputManager.ACTION_BLOCKED_RATINGS_CHANGED); intentFilter.addAction(TvInputManager.ACTION_PARENTAL_CONTROLS_ENABLED_CHANGED); registerReceiver(mParentalControlsBroadcastReceiver, intentFilter); }
public CaptionWindowLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // Add a subtitle view to the layout. mSubtitleView = new SubtitleView(context); LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); addView(mSubtitleView, params); // Set the system wide cc preferences to the subtitle view. CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); mFontScale = captioningManager.getFontScale(); mCaptionStyleCompat = CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); mSubtitleView.setStyle(mCaptionStyleCompat); mSubtitleView.setText(""); captioningManager.addCaptioningChangeListener(new SystemWideCaptioningChangeListener()); updateWidestChar(); }
/** * Creates a {@link CaptionStyleCompat} equivalent to a provided {@link CaptionStyle}. * * @param captionStyle A {@link CaptionStyle}. * @return The equivalent {@link CaptionStyleCompat}. */ @TargetApi(19) public static CaptionStyleCompat createFromCaptionStyle( CaptioningManager.CaptionStyle captionStyle) { if (Util.SDK_INT >= 21) { return createFromCaptionStyleV21(captionStyle); } else { // Note - Any caller must be on at least API level 19 or greater (because CaptionStyle did // not exist in earlier API levels). return createFromCaptionStyleV19(captionStyle); } }
@TargetApi(19) private static CaptionStyleCompat createFromCaptionStyleV19( CaptioningManager.CaptionStyle captionStyle) { return new CaptionStyleCompat( captionStyle.foregroundColor, captionStyle.backgroundColor, Color.TRANSPARENT, captionStyle.edgeType, captionStyle.edgeColor, captionStyle.getTypeface()); }
@TargetApi(21) private static CaptionStyleCompat createFromCaptionStyleV21( CaptioningManager.CaptionStyle captionStyle) { return new CaptionStyleCompat( captionStyle.hasForegroundColor() ? captionStyle.foregroundColor : DEFAULT.foregroundColor, captionStyle.hasBackgroundColor() ? captionStyle.backgroundColor : DEFAULT.backgroundColor, captionStyle.hasWindowColor() ? captionStyle.windowColor : DEFAULT.windowColor, captionStyle.hasEdgeType() ? captionStyle.edgeType : DEFAULT.edgeType, captionStyle.hasEdgeColor() ? captionStyle.edgeColor : DEFAULT.edgeColor, captionStyle.getTypeface()); }
@SuppressLint("NewApi") private void registerCaptionListener(final Context context) { if (Utils.IS_KITKAT_OR_ABOVE) { CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); captioningManager.addCaptioningChangeListener( new CaptioningManager.CaptioningChangeListener() { @Override public void onEnabledChanged(boolean enabled) { onTextTrackEnabledChanged(enabled); } @Override public void onUserStyleChanged( @NonNull CaptioningManager.CaptionStyle userStyle) { onTextTrackStyleChanged(mTrackManager.getTextTrackStyle()); } @Override public void onFontScaleChanged(float fontScale) { onTextTrackStyleChanged(mTrackManager.getTextTrackStyle()); } @Override public void onLocaleChanged(Locale locale) { onTextTrackLocaleChanged(locale); } } ); } }
@SuppressLint("NewApi") public boolean isCaptionEnabled() { if (Utils.IS_KITKAT_OR_ABOVE) { CaptioningManager captioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE); return captioningManager.isEnabled(); } else { return mPreferenceAccessor.getBooleanFromPreference( mContext.getString(R.string.ccl_key_caption_enabled), false); } }
@TargetApi(19) @SuppressWarnings("ResourceType") private static CaptionStyleCompat createFromCaptionStyleV19( CaptioningManager.CaptionStyle captionStyle) { return new CaptionStyleCompat( captionStyle.foregroundColor, captionStyle.backgroundColor, Color.TRANSPARENT, captionStyle.edgeType, captionStyle.edgeColor, captionStyle.getTypeface()); }
@TargetApi(21) @SuppressWarnings("ResourceType") private static CaptionStyleCompat createFromCaptionStyleV21( CaptioningManager.CaptionStyle captionStyle) { return new CaptionStyleCompat( captionStyle.hasForegroundColor() ? captionStyle.foregroundColor : DEFAULT.foregroundColor, captionStyle.hasBackgroundColor() ? captionStyle.backgroundColor : DEFAULT.backgroundColor, captionStyle.hasWindowColor() ? captionStyle.windowColor : DEFAULT.windowColor, captionStyle.hasEdgeType() ? captionStyle.edgeType : DEFAULT.edgeType, captionStyle.hasEdgeColor() ? captionStyle.edgeColor : DEFAULT.edgeColor, captionStyle.getTypeface()); }
public TunerSessionWorker(Context context, ChannelDataManager channelDataManager, BufferManager bufferManager, TunerSession tunerSession) { if (DEBUG) Log.d(TAG, "TunerSessionWorker created"); mContext = context; // HandlerThread should be set up before it is registered as a listener in the all other // components. HandlerThread handlerThread = new HandlerThread(TAG); handlerThread.start(); mHandler = new Handler(handlerThread.getLooper(), this); mSession = tunerSession; mChannelDataManager = channelDataManager; mChannelDataManager.setListener(this); mChannelDataManager.checkDataVersion(mContext); mSourceManager = TsDataSourceManager.createSourceManager(false); mTvInputManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE); mTvTracks = new ArrayList<>(); mAudioTrackMap = new SparseArray<>(); mCaptionTrackMap = new SparseArray<>(); CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); mCaptionEnabled = captioningManager.isEnabled(); mPlaybackParams.setSpeed(1.0f); mBufferManager = bufferManager; mPreparingStartTimeMs = INVALID_TIME; mBufferingStartTimeMs = INVALID_TIME; mReadyStartTimeMs = INVALID_TIME; }
@SuppressLint("NewApi") private void registerCaptionListener(final Context context) { if (Utils.IS_KITKAT_OR_ABOVE) { CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE); captioningManager.addCaptioningChangeListener( new CaptioningManager.CaptioningChangeListener() { @Override public void onEnabledChanged(boolean enabled) { onTextTrackEnabledChanged(enabled); } @Override public void onUserStyleChanged( CaptioningManager.CaptionStyle userStyle) { onTextTrackStyleChanged(mTrackManager.getTextTrackStyle()); } @Override public void onFontScaleChanged(float fontScale) { onTextTrackStyleChanged(mTrackManager.getTextTrackStyle()); } @Override public void onLocaleChanged(Locale locale) { onTextTrackLocaleChanged(locale); } } ); } }
@SuppressLint("NewApi") public boolean isCaptionEnabled() { if (Utils.IS_KITKAT_OR_ABOVE) { CaptioningManager captioningManager = (CaptioningManager) mContext.getSystemService(Context.CAPTIONING_SERVICE); return captioningManager.isEnabled(); } else { return Utils.getBooleanFromPreference(mContext, mContext.getString(R.string.ccl_key_caption_enabled), false); } }
/** * Constructor * * @param sessionListener Listener through which reporting when session onRelease() is called. */ public TvSession(Context context, ITvSession sessionListener, String inputID) { super(context); mLog.d("[TvSession][Started!]"); mTvManager = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE); mInputID = inputID; mSessionListener = sessionListener; mContext = context; mIsSubtitleEnabled = ((CaptioningManager) mContext .getSystemService(Context.CAPTIONING_SERVICE)).isEnabled(); mDtvManager = DtvManager.getInstance(); mChannelManager = mDtvManager.getChannelManager(); mSubtitleManager = mDtvManager.getSubtitleManager(); mAudioManager = mDtvManager.getAudioManager(); }
/** * Construct a new KitKat+ captioning bridge * * @param context the Context to associate with this bridge. */ private KitKatCaptioningBridge(Context context) { mCaptioningChangeDelegate = new CaptioningChangeDelegate(); mCaptioningManager = (CaptioningManager) context.getApplicationContext().getSystemService( Context.CAPTIONING_SERVICE); }
@TargetApi(21) private static CaptionStyleCompat createFromCaptionStyleV21( CaptioningManager.CaptionStyle captionStyle) { return null; /*CaptionStyleCompat( captionStyle.hasForegroundColor() ? captionStyle.foregroundColor : DEFAULT.foregroundColor, captionStyle.hasBackgroundColor() ? captionStyle.backgroundColor : DEFAULT.backgroundColor, captionStyle.hasWindowColor() ? captionStyle.windowColor : DEFAULT.windowColor, captionStyle.hasEdgeType() ? captionStyle.edgeType : DEFAULT.edgeType, captionStyle.hasEdgeColor() ? captionStyle.edgeColor : DEFAULT.edgeColor, captionStyle.getTypeface());*/ }