Search in sources :

Example 1 with BaseCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project Shuttle by timusus.

the class BaseCastManager method onConnected.

/*
     * (non-Javadoc)
     * @see com.google.android.gms.GoogleApiClient.ConnectionCallbacks#onConnected
     * (android.os.Bundle)
     */
@Override
public final void onConnected(Bundle hint) {
    LOGD(TAG, "onConnected() reached with prior suspension: " + mConnectionSuspended);
    if (mConnectionSuspended) {
        mConnectionSuspended = false;
        if (hint != null && hint.getBoolean(Cast.EXTRA_APP_NO_LONGER_RUNNING)) {
            // the same app is not running any more
            LOGD(TAG, "onConnected(): App no longer running, so disconnecting");
            disconnect();
        } else {
            onConnectivityRecovered();
        }
        return;
    }
    if (!isConnected()) {
        if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
            setReconnectionStatus(RECONNECTION_STATUS_INACTIVE);
        }
        return;
    }
    try {
        if (isFeatureEnabled(CastConfiguration.FEATURE_WIFI_RECONNECT)) {
            String ssid = Utils.getWifiSsid(mContext);
            mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SSID, ssid);
        }
        Cast.CastApi.requestStatus(mApiClient);
        if (!mCastConfiguration.isDisableLaunchOnConnect()) {
            launchApp();
        }
        for (BaseCastConsumer consumer : mBaseCastConsumers) {
            consumer.onConnected();
        }
    } catch (IOException | IllegalStateException e) {
        LOGE(TAG, "requestStatus()", e);
    }
}
Also used : IOException(java.io.IOException) BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Example 2 with BaseCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project Shuttle by timusus.

the class BaseCastManager method onConnectionFailed.

/*
     * (non-Javadoc)
     * @see com.google.android.gms.GoogleApiClient.OnConnectionFailedListener#
     * onConnectionFailed(com.google.android.gms.common.ConnectionResult)
     */
@Override
public void onConnectionFailed(ConnectionResult result) {
    LOGD(TAG, "onConnectionFailed() reached, error code: " + result.getErrorCode() + ", reason: " + result.toString());
    disconnectDevice(mDestroyOnDisconnect, false, /* clearPersistentConnectionData */
    false);
    mConnectionSuspended = false;
    if (mMediaRouter != null) {
        mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
    }
    for (BaseCastConsumer consumer : mBaseCastConsumers) {
        consumer.onConnectionFailed(result);
    }
    PendingIntent pendingIntent = result.getResolution();
    if (pendingIntent != null) {
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            LOGE(TAG, "Failed to show recovery from the recoverable error", e);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Example 3 with BaseCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project zype-android by zype.

the class BaseCastManager method onUiVisibilityChanged.

/**
 * This is called when UI visibility of the client has changed
 *
 * @param visible The updated visibility status
 */
protected void onUiVisibilityChanged(boolean visible) {
    if (visible) {
        if (mMediaRouter != null && mMediaRouterCallback != null) {
            LOGD(TAG, "onUiVisibilityChanged() addCallback called");
            startCastDiscovery();
        }
    } else {
        if (mMediaRouter != null) {
            LOGD(TAG, "onUiVisibilityChanged() removeCallback called");
            stopCastDiscovery();
        }
    }
    for (BaseCastConsumer consumer : mBaseCastConsumers) {
        consumer.onUiVisibilityChanged(visible);
    }
}
Also used : BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Example 4 with BaseCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project zype-android by zype.

the class BaseCastManager method onConnected.

/*
     * (non-Javadoc)
     * @see com.google.android.gms.GoogleApiClient.ConnectionCallbacks#onConnected
     * (android.os.Bundle)
     */
@Override
public final void onConnected(Bundle hint) {
    LOGD(TAG, "onConnected() reached with prior suspension: " + mConnectionSuspended);
    if (mConnectionSuspended) {
        mConnectionSuspended = false;
        if (hint != null && hint.getBoolean(Cast.EXTRA_APP_NO_LONGER_RUNNING)) {
            // the same app is not running any more
            LOGD(TAG, "onConnected(): App no longer running, so disconnecting");
            disconnect();
        } else {
            onConnectivityRecovered();
        }
        return;
    }
    if (!isConnected()) {
        if (mReconnectionStatus == RECONNECTION_STATUS_IN_PROGRESS) {
            setReconnectionStatus(RECONNECTION_STATUS_INACTIVE);
        }
        return;
    }
    try {
        if (isFeatureEnabled(FEATURE_WIFI_RECONNECT)) {
            String ssid = Utils.getWifiSsid(mContext);
            mPreferenceAccessor.saveStringToPreference(PREFS_KEY_SSID, ssid);
        }
        Cast.CastApi.requestStatus(mApiClient);
        launchApp();
        for (BaseCastConsumer consumer : mBaseCastConsumers) {
            consumer.onConnected();
        }
    } catch (IOException | IllegalStateException e) {
        LOGE(TAG, "requestStatus()", e);
    }
}
Also used : IOException(java.io.IOException) BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Example 5 with BaseCastConsumer

use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project Shuttle by timusus.

the class BaseCastManager method onUiVisibilityChanged.

/**
 * This is called when UI visibility of the client has changed
 *
 * @param visible The updated visibility status
 */
protected void onUiVisibilityChanged(boolean visible) {
    if (visible) {
        if (mMediaRouter != null && mMediaRouterCallback != null) {
            LOGD(TAG, "onUiVisibilityChanged() addCallback called");
            startCastDiscovery();
            if (isFeatureEnabled(CastConfiguration.FEATURE_AUTO_RECONNECT)) {
                reconnectSessionIfPossible();
            }
        }
    } else {
        if (mMediaRouter != null) {
            LOGD(TAG, "onUiVisibilityChanged() removeCallback called");
            stopCastDiscovery();
        }
    }
    for (BaseCastConsumer consumer : mBaseCastConsumers) {
        consumer.onUiVisibilityChanged(visible);
    }
}
Also used : BaseCastConsumer(com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)

Aggregations

BaseCastConsumer (com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer)11 IOException (java.io.IOException)2 PendingIntent (android.app.PendingIntent)1 NoConnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException)1 TransientNetworkDisconnectionException (com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)1