Example usage for android.media.tv TvInputInfo isPassthroughInput

List of usage examples for android.media.tv TvInputInfo isPassthroughInput

Introduction

In this page you can find the example usage for android.media.tv TvInputInfo isPassthroughInput.

Prototype

public boolean isPassthroughInput() 

Source Link

Document

Returns true if this TV input is pass-though which does not have any real channels in TvProvider.

Usage

From source file:com.android.tv.TvApplication.java

/**
 * Handles the global key KEYCODE_TV_INPUT.
 *//*from   ww  w.java  2  s  .  c om*/
public void handleTvInputKey() {
    TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    List<TvInputInfo> tvInputs = tvInputManager.getTvInputList();
    int inputCount = 0;
    boolean hasTunerInput = false;
    for (TvInputInfo input : tvInputs) {
        if (input.isPassthroughInput()) {
            if (!input.isHidden(this)) {
                ++inputCount;
            }
        } else if (!hasTunerInput) {
            hasTunerInput = true;
            ++inputCount;
        }
    }
    if (inputCount < 2) {
        return;
    }
    Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity()
            : mSelectInputActivity;
    if (activityToHandle != null) {
        // If startActivity is called, MainActivity.onPause is unnecessarily called. To
        // prevent it, MainActivity.dispatchKeyEvent is directly called.
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT));
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT));
    } else if (mMainActivityWrapper.isStarted()) {
        Bundle extras = new Bundle();
        extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT);
        startMainActivity(extras);
    } else {
        startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
}

From source file:com.android.tv.settings.MainFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    mAuthenticatorHelper = new AuthenticatorHelper(getContext(), new UserHandle(UserHandle.myUserId()),
            new AuthenticatorHelper.OnAccountsUpdateListener() {
                @Override/*from www  .  j a  v a 2 s . com*/
                public void onAccountsUpdate(UserHandle userHandle) {
                    updateAccounts();
                }
            });
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    mConnectivityListener = new ConnectivityListener(getContext(), new ConnectivityListener.Listener() {
        @Override
        public void onConnectivityChange() {
            updateWifi();
        }
    });

    final TvInputManager manager = (TvInputManager) getContext().getSystemService(Context.TV_INPUT_SERVICE);
    if (manager != null) {
        for (final TvInputInfo input : manager.getTvInputList()) {
            if (input.isPassthroughInput()) {
                mInputSettingNeeded = true;
            }
        }
    }
    super.onCreate(savedInstanceState);
}

From source file:com.android.tv.MainActivity.java

private boolean handleIntent(Intent intent) {
    // Reset the closed caption settings when the activity is 1)created or 2) restarted.
    // And do not reset while TvView is playing.
    if (!mTvView.isPlaying()) {
        mCaptionSettings = new CaptionSettings(this);
    }/*from w w w.j a v  a  2 s. c  om*/

    // Handle the passed key press, if any. Note that only the key codes that are currently
    // handled in the TV app will be handled via Intent.
    // TODO: Consider defining a separate intent filter as passing data of mime type
    // vnd.android.cursor.item/channel isn't really necessary here.
    int keyCode = intent.getIntExtra(Utils.EXTRA_KEY_KEYCODE, KeyEvent.KEYCODE_UNKNOWN);
    if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
        if (DEBUG)
            Log.d(TAG, "Got an intent with keycode: " + keyCode);
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, keyCode);
        onKeyUp(keyCode, event);
        return true;
    }
    mShouldTuneToTunerChannel = intent.getBooleanExtra(Utils.EXTRA_KEY_FROM_LAUNCHER, false);
    mInitChannelUri = null;

    String extraAction = intent.getStringExtra(Utils.EXTRA_KEY_ACTION);
    if (!TextUtils.isEmpty(extraAction)) {
        if (DEBUG)
            Log.d(TAG, "Got an extra action: " + extraAction);
        if (Utils.EXTRA_ACTION_SHOW_TV_INPUT.equals(extraAction)) {
            String lastWatchedChannelUri = Utils.getLastWatchedChannelUri(this);
            if (lastWatchedChannelUri != null) {
                mInitChannelUri = Uri.parse(lastWatchedChannelUri);
            }
            mShowSelectInputView = true;
        }
    }

    if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
        mRecordingUri = intent.getParcelableExtra(Utils.EXTRA_KEY_RECORDING_URI);
        if (mRecordingUri != null) {
            return true;
        }
    }

    // TODO: remove the checkState once N API is finalized.
    SoftPreconditions
            .checkState(TvInputManager.ACTION_SETUP_INPUTS.equals("android.media.tv.action.SETUP_INPUTS"));
    if (TvInputManager.ACTION_SETUP_INPUTS.equals(intent.getAction())) {
        runAfterAttachedToWindow(new Runnable() {
            @Override
            public void run() {
                mOverlayManager.showSetupFragment();
            }
        });
    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        try {
            mSource = uri.getQueryParameter(Utils.PARAM_SOURCE);
        } catch (UnsupportedOperationException e) {
            // ignore this exception.
        }
        // When the URI points to the programs (directory, not an individual item), go to the
        // program guide. The intention here is to respond to
        // "content://android.media.tv/program", not "content://android.media.tv/program/XXX".
        // Later, we might want to add handling of individual programs too.
        if (Utils.isProgramsUri(uri)) {
            // The given data is a programs URI. Open the Program Guide.
            mShowProgramGuide = true;
            return true;
        }
        // In case the channel is given explicitly, use it.
        mInitChannelUri = uri;
        if (DEBUG)
            Log.d(TAG, "ACTION_VIEW with " + mInitChannelUri);
        if (Channels.CONTENT_URI.equals(mInitChannelUri)) {
            // Tune to default channel.
            mInitChannelUri = null;
            mShouldTuneToTunerChannel = true;
            return true;
        }
        if ((!Utils.isChannelUriForOneChannel(mInitChannelUri)
                && !Utils.isChannelUriForInput(mInitChannelUri))) {
            Log.w(TAG, "Malformed channel uri " + mInitChannelUri + " tuning to default instead");
            mInitChannelUri = null;
            return true;
        }
        mTuneParams = intent.getExtras();
        if (mTuneParams == null) {
            mTuneParams = new Bundle();
        }
        if (Utils.isChannelUriForTunerInput(mInitChannelUri)) {
            long channelId = ContentUris.parseId(mInitChannelUri);
            mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId);
        } else if (TvContract.isChannelUriForPassthroughInput(mInitChannelUri)) {
            // If mInitChannelUri is for a passthrough TV input.
            String inputId = mInitChannelUri.getPathSegments().get(1);
            TvInputInfo input = mTvInputManagerHelper.getTvInputInfo(inputId);
            if (input == null) {
                mInitChannelUri = null;
                Toast.makeText(this, R.string.msg_no_specific_input, Toast.LENGTH_SHORT).show();
                return false;
            } else if (!input.isPassthroughInput()) {
                mInitChannelUri = null;
                Toast.makeText(this, R.string.msg_not_passthrough_input, Toast.LENGTH_SHORT).show();
                return false;
            }
        } else if (mInitChannelUri != null) {
            // Handle the URI built by TvContract.buildChannelsUriForInput().
            // TODO: Change hard-coded "input" to TvContract.PARAM_INPUT.
            String inputId = mInitChannelUri.getQueryParameter("input");
            long channelId = Utils.getLastWatchedChannelIdForInput(this, inputId);
            if (channelId == Channel.INVALID_ID) {
                String[] projection = { Channels._ID };
                try (Cursor cursor = getContentResolver().query(uri, projection, null, null, null)) {
                    if (cursor != null && cursor.moveToNext()) {
                        channelId = cursor.getLong(0);
                    }
                }
            }
            if (channelId == Channel.INVALID_ID) {
                // Couldn't find any channel probably because the input hasn't been set up.
                // Try to set it up.
                mInitChannelUri = null;
                mInputToSetUp = mTvInputManagerHelper.getTvInputInfo(inputId);
            } else {
                mInitChannelUri = TvContract.buildChannelUri(channelId);
                mTuneParams.putLong(KEY_INIT_CHANNEL_ID, channelId);
            }
        }
    }
    return true;
}