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;
}
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());
}
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);
}
}
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;
}
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;
}
Aggregations