Example usage for android.media.tv TvInputManager getTvInputList

List of usage examples for android.media.tv TvInputManager getTvInputList

Introduction

In this page you can find the example usage for android.media.tv TvInputManager getTvInputList.

Prototype

public List<TvInputInfo> getTvInputList() 

Source Link

Document

Returns the complete list of TV inputs on the system.

Usage

From source file:Main.java

public static String getServiceNameFromInputId(Context context, String inputId) {
    TvInputManager tim = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
    for (TvInputInfo info : tim.getTvInputList()) {
        if (info.getId().equals(inputId)) {
            return info.getServiceInfo().name;
        }/*from w  w  w  .  j av  a2 s  . c  om*/
    }
    return null;
}

From source file:com.android.tv.dvr.DvrSessionManager.java

@VisibleForTesting
DvrSessionManager(Context context, TvInputManager tvInputManager, Handler handler) {
    SoftPreconditions.checkFeatureEnabled(context, CommonFeatures.DVR, TAG);
    mTvInputManager = tvInputManager;/*  www  .j  a va 2  s .  co m*/
    mContext = context.getApplicationContext();
    for (TvInputInfo info : tvInputManager.getTvInputList()) {
        if (DEBUG) {
            Log.d(TAG, info + " canRecord=" + info.canRecord() + " tunerCount=" + info.getTunerCount());
        }
        if (info.canRecord()) {
            mRecordingTvInputs.put(info.getId(), info);
        }
    }
    tvInputManager.registerCallback(this, handler);

}

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

/**
 * Handles the global key KEYCODE_TV_INPUT.
 *///www .  jav  a2  s. c o  m
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 .ja  v a  2 s  .  c o  m
                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.TvApplication.java

/**
 * Checks the input counts and enable/disable TvActivity. Also updates the input list in
 * {@link SetupUtils}./*from   w w  w .j  av a 2 s.  co  m*/
 *
 * @param calledByTunerServiceChanged true if it is called when UsbTunerTvInputService
 *        is enabled or disabled.
 * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true.
 * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts
 *        by default. But, if dontKillApp is true, the app won't restart.
 */
public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled,
        boolean dontKillApp) {
    TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled)
            || Features.UNHIDE.isEnabled(TvApplication.this);
    if (!enable) {
        List<TvInputInfo> inputs = inputManager.getTvInputList();
        boolean skipTunerInputCheck = false;
        // Enable the TvActivity only if there is at least one tuner type input.
        if (!skipTunerInputCheck) {
            for (TvInputInfo input : inputs) {
                if (calledByTunerServiceChanged && !tunerServiceEnabled
                        && UsbTunerTvInputService.getInputId(this).equals(input.getId())) {
                    continue;
                }
                if (input.getType() == TvInputInfo.TYPE_TUNER) {
                    enable = true;
                    break;
                }
            }
        }
        if (DEBUG)
            Log.d(TAG, "Enable MainActivity: " + enable);
    }
    PackageManager packageManager = getPackageManager();
    ComponentName name = new ComponentName(this, TvActivity.class);
    int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (packageManager.getComponentEnabledSetting(name) != newState) {
        packageManager.setComponentEnabledSetting(name, newState,
                dontKillApp ? PackageManager.DONT_KILL_APP : 0);
    }
    SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager);
}