Search in sources :

Example 16 with UiModeManager

use of android.app.UiModeManager in project platform_packages_apps_Settings by BlissRoms.

the class NightModePreferenceController method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    try {
        final int value = Integer.parseInt((String) newValue);
        final UiModeManager uiManager = (UiModeManager) mContext.getSystemService(UI_MODE_SERVICE);
        uiManager.setNightMode(value);
    } catch (NumberFormatException e) {
        Log.e(TAG, "could not persist night mode setting", e);
        return false;
    }
    return true;
}
Also used : UiModeManager(android.app.UiModeManager)

Example 17 with UiModeManager

use of android.app.UiModeManager in project AntennaPod by AntennaPod.

the class PlaybackService method updateMediaSession.

/**
 * Updates the Media Session for the corresponding status.
 *
 * @param playerStatus the current {@link PlayerStatus}
 */
private void updateMediaSession(final PlayerStatus playerStatus) {
    PlaybackStateCompat.Builder sessionState = new PlaybackStateCompat.Builder();
    int state;
    if (playerStatus != null) {
        switch(playerStatus) {
            case PLAYING:
                state = PlaybackStateCompat.STATE_PLAYING;
                break;
            case PREPARED:
            case PAUSED:
                state = PlaybackStateCompat.STATE_PAUSED;
                break;
            case STOPPED:
                state = PlaybackStateCompat.STATE_STOPPED;
                break;
            case SEEKING:
                state = PlaybackStateCompat.STATE_FAST_FORWARDING;
                break;
            case PREPARING:
            case INITIALIZING:
                state = PlaybackStateCompat.STATE_CONNECTING;
                break;
            case ERROR:
                state = PlaybackStateCompat.STATE_ERROR;
                break;
            // Deliberate fall-through
            case INITIALIZED:
            case INDETERMINATE:
            default:
                state = PlaybackStateCompat.STATE_NONE;
                break;
        }
    } else {
        state = PlaybackStateCompat.STATE_NONE;
    }
    sessionState.setState(state, getCurrentPosition(), getCurrentPlaybackSpeed());
    long capabilities = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_FAST_FORWARD | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_SET_PLAYBACK_SPEED;
    if (useSkipToPreviousForRewindInLockscreen()) {
        // Workaround to fool Android so that Lockscreen will expose a skip-to-previous button,
        // which will be used for rewind.
        // The workaround is used for pre Lollipop (Androidv5) devices.
        // For Androidv5+, lockscreen widges are really notifications (compact),
        // with an independent codepath
        // 
        // @see #sessionCallback in the backing callback, skipToPrevious implementation
        // is actually the same as rewind. So no new inconsistency is created.
        // @see #setupNotification() for the method to create Androidv5+ lockscreen UI
        // with notification (compact)
        capabilities = capabilities | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
    }
    UiModeManager uiModeManager = (UiModeManager) getApplicationContext().getSystemService(Context.UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) {
        sessionState.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(CUSTOM_ACTION_REWIND, getString(R.string.rewind_label), R.drawable.ic_notification_fast_rewind).build());
        sessionState.addCustomAction(new PlaybackStateCompat.CustomAction.Builder(CUSTOM_ACTION_FAST_FORWARD, getString(R.string.fast_forward_label), R.drawable.ic_notification_fast_forward).build());
    } else {
        // This would give the PIP of videos a play button
        capabilities = capabilities | PlaybackStateCompat.ACTION_PLAY;
        if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_WATCH) {
            WearMediaSession.sessionStateAddActionForWear(sessionState, CUSTOM_ACTION_REWIND, getString(R.string.rewind_label), android.R.drawable.ic_media_rew);
            WearMediaSession.sessionStateAddActionForWear(sessionState, CUSTOM_ACTION_FAST_FORWARD, getString(R.string.fast_forward_label), android.R.drawable.ic_media_ff);
            WearMediaSession.mediaSessionSetExtraForWear(mediaSession);
        }
    }
    sessionState.setActions(capabilities);
    mediaSession.setPlaybackState(sessionState.build());
}
Also used : PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) UiModeManager(android.app.UiModeManager)

Example 18 with UiModeManager

use of android.app.UiModeManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NightModePreferenceController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    if (!isAvailable()) {
        setVisible(screen, KEY_NIGHT_MODE, false);
        return;
    }
    final ListPreference mNightModePreference = screen.findPreference(KEY_NIGHT_MODE);
    if (mNightModePreference != null) {
        final UiModeManager uiManager = (UiModeManager) mContext.getSystemService(UI_MODE_SERVICE);
        final int currentNightMode = uiManager.getNightMode();
        mNightModePreference.setValue(String.valueOf(currentNightMode));
        mNightModePreference.setOnPreferenceChangeListener(this);
    }
}
Also used : UiModeManager(android.app.UiModeManager) ListPreference(androidx.preference.ListPreference)

Example 19 with UiModeManager

use of android.app.UiModeManager in project Slide by ccrama.

the class Reddit method setCanUseNightModeAuto.

@TargetApi(Build.VERSION_CODES.M)
private static void setCanUseNightModeAuto() {
    UiModeManager uiModeManager = getAppContext().getSystemService(UiModeManager.class);
    canUseNightModeAuto = uiModeManager != null;
}
Also used : UiModeManager(android.app.UiModeManager) TargetApi(android.annotation.TargetApi)

Example 20 with UiModeManager

use of android.app.UiModeManager in project android_frameworks_opt_telephony by LineageOS.

the class DeviceStateMonitor method isCarModeOn.

/**
 * @return True if car mode (Android Auto) is on.
 */
private boolean isCarModeOn() {
    final UiModeManager umm = (UiModeManager) mPhone.getContext().getSystemService(Context.UI_MODE_SERVICE);
    if (umm == null)
        return false;
    boolean retval = umm.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR;
    log("isCarModeOn=" + retval, true);
    return retval;
}
Also used : UiModeManager(android.app.UiModeManager)

Aggregations

UiModeManager (android.app.UiModeManager)32 ListPreference (android.support.v7.preference.ListPreference)6 Intent (android.content.Intent)5 Point (android.graphics.Point)5 Handler (android.os.Handler)5 RecentsTaskLoader (com.android.systemui.recents.model.RecentsTaskLoader)5 RecentsTvImpl (com.android.systemui.recents.tv.RecentsTvImpl)5 ListPreference (androidx.preference.ListPreference)2 TargetApi (android.annotation.TargetApi)1 Activity (android.app.Activity)1 ContentResolver (android.content.ContentResolver)1 Context (android.content.Context)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)1 DropDownPreference (android.support.v7.preference.DropDownPreference)1 Preference (android.support.v7.preference.Preference)1 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 RestrictedPreference (com.android.settingslib.RestrictedPreference)1 TvPlaybackActivity (com.example.android.uamp.ui.tv.TvPlaybackActivity)1