use of android.app.UiModeManager in project android_frameworks_base by ResurrectionRemix.
the class Recents method start.
@Override
public void start() {
sDebugFlags = new RecentsDebugFlags(mContext);
sSystemServicesProxy = SystemServicesProxy.getInstance(mContext);
sTaskLoader = new RecentsTaskLoader(mContext);
sConfiguration = new RecentsConfiguration(mContext);
mHandler = new Handler();
UiModeManager uiModeManager = (UiModeManager) mContext.getSystemService(Context.UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
mImpl = new RecentsTvImpl(mContext);
} else {
mImpl = new RecentsImpl(mContext);
}
// Check if there is a recents override package
if ("userdebug".equals(Build.TYPE) || "eng".equals(Build.TYPE)) {
String cnStr = SystemProperties.get(RECENTS_OVERRIDE_SYSPROP_KEY);
if (!cnStr.isEmpty()) {
mOverrideRecentsPackageName = cnStr;
}
}
// Register with the event bus
EventBus.getDefault().register(this, EVENT_BUS_PRIORITY);
EventBus.getDefault().register(sSystemServicesProxy, EVENT_BUS_PRIORITY);
EventBus.getDefault().register(sTaskLoader, EVENT_BUS_PRIORITY);
// Due to the fact that RecentsActivity is per-user, we need to establish and interface for
// the system user's Recents component to pass events (like show/hide/toggleRecents) to the
// secondary user, and vice versa (like visibility change, screen pinning).
final int processUser = sSystemServicesProxy.getProcessUser();
if (sSystemServicesProxy.isSystemUser(processUser)) {
// For the system user, initialize an instance of the interface that we can pass to the
// secondary user
mSystemToUserCallbacks = new RecentsSystemUser(mContext, mImpl);
} else {
// For the secondary user, bind to the primary user's service to get a persistent
// interface to register its implementation and to later update its state
registerWithSystemUser();
}
putComponent(Recents.class, this);
}
use of android.app.UiModeManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DisplaySettings method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Activity activity = getActivity();
final ContentResolver resolver = activity.getContentResolver();
addPreferencesFromResource(R.xml.display_settings);
PreferenceCategory displayPrefs = (PreferenceCategory) findPreference(KEY_CATEGORY_DISPLAY);
mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER);
if (mScreenSaverPreference != null && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) {
getPreferenceScreen().removePreference(mScreenSaverPreference);
}
mScreenTimeoutPreference = (TimeoutListPreference) findPreference(KEY_SCREEN_TIMEOUT);
if (displayPrefs != null) {
mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
if (mAutoBrightnessPreference != null) {
if (isAutomaticBrightnessAvailable(getResources())) {
mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mAutoBrightnessPreference);
}
}
if (!NightDisplayController.isAvailable(activity)) {
removePreference(KEY_NIGHT_DISPLAY);
}
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
if (mLiftToWakePreference != null) {
if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mLiftToWakePreference);
}
}
mTapToWakePreference = (SwitchPreference) findPreference(KEY_TAP_TO_WAKE);
if (mTapToWakePreference != null) {
if (isTapToWakeAvailable(getResources())) {
mTapToWakePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mTapToWakePreference);
}
}
mCameraGesturePreference = (SwitchPreference) findPreference(KEY_CAMERA_GESTURE);
if (mCameraGesturePreference != null) {
if (isCameraGestureAvailable(getResources())) {
mCameraGesturePreference.setOnPreferenceChangeListener(this);
} else {
displayPrefs.removePreference(mCameraGesturePreference);
}
}
DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE);
if (rotatePreference != null) {
if (RotationPolicy.isRotationLockToggleVisible(activity)) {
int rotateLockedResourceId;
// rotation), then we use a different string to include this information.
if (allowAllRotations(activity)) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_current;
} else {
if (RotationPolicy.getRotationLockOrientation(activity) == Configuration.ORIENTATION_PORTRAIT) {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_portrait;
} else {
rotateLockedResourceId = R.string.display_auto_rotate_stay_in_landscape;
}
}
rotatePreference.setEntries(new CharSequence[] { activity.getString(R.string.display_auto_rotate_rotate), activity.getString(rotateLockedResourceId) });
rotatePreference.setEntryValues(new CharSequence[] { "0", "1" });
rotatePreference.setValueIndex(RotationPolicy.isRotationLocked(activity) ? 1 : 0);
rotatePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean locked = Integer.parseInt((String) newValue) != 0;
MetricsLogger.action(getActivity(), MetricsEvent.ACTION_ROTATION_LOCK, locked);
RotationPolicy.setRotationLock(activity, locked);
return true;
}
});
} else {
displayPrefs.removePreference(rotatePreference);
}
}
DropDownPreference vrDisplayPref = (DropDownPreference) findPreference(KEY_VR_DISPLAY_PREF);
if (vrDisplayPref != null) {
if (isVrDisplayModeAvailable(activity)) {
vrDisplayPref.setEntries(new CharSequence[] { activity.getString(R.string.display_vr_pref_low_persistence), activity.getString(R.string.display_vr_pref_off) });
vrDisplayPref.setEntryValues(new CharSequence[] { "0", "1" });
final Context c = activity;
int currentUser = ActivityManager.getCurrentUser();
int current = Settings.Secure.getIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, /*default*/
Settings.Secure.VR_DISPLAY_MODE_LOW_PERSISTENCE, currentUser);
vrDisplayPref.setValueIndex(current);
vrDisplayPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int i = Integer.parseInt((String) newValue);
int u = ActivityManager.getCurrentUser();
if (!Settings.Secure.putIntForUser(c.getContentResolver(), Settings.Secure.VR_DISPLAY_MODE, i, u)) {
Log.e(TAG, "Could not change setting for " + Settings.Secure.VR_DISPLAY_MODE);
}
return true;
}
});
} else {
displayPrefs.removePreference(vrDisplayPref);
}
}
}
mNightModePreference = (ListPreference) findPreference(KEY_NIGHT_MODE);
if (mNightModePreference != null) {
final UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
final int currentNightMode = uiManager.getNightMode();
mNightModePreference.setValue(String.valueOf(currentNightMode));
mNightModePreference.setOnPreferenceChangeListener(this);
}
}
use of android.app.UiModeManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class DisplaySettings method onPreferenceChange.
@Override
public boolean onPreferenceChange(Preference preference, Object objValue) {
final String key = preference.getKey();
if (KEY_SCREEN_TIMEOUT.equals(key)) {
try {
int value = Integer.parseInt((String) objValue);
Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, value);
updateTimeoutPreferenceDescription(value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist screen timeout setting", e);
}
}
if (preference == mAutoBrightnessPreference) {
boolean auto = (Boolean) objValue;
Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE, auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
}
if (preference == mLiftToWakePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0);
}
if (preference == mTapToWakePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, value ? 1 : 0);
}
if (preference == mCameraGesturePreference) {
boolean value = (Boolean) objValue;
Settings.Secure.putInt(getContentResolver(), CAMERA_GESTURE_DISABLED, value ? 0 : 1);
}
if (preference == mNightModePreference) {
try {
final int value = Integer.parseInt((String) objValue);
final UiModeManager uiManager = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
uiManager.setNightMode(value);
} catch (NumberFormatException e) {
Log.e(TAG, "could not persist night mode setting", e);
}
}
return true;
}
use of android.app.UiModeManager in project android_frameworks_base by ResurrectionRemix.
the class AppCompatibility method getLaunchIntentForPackage.
private Intent getLaunchIntentForPackage(String packageName) {
UiModeManager umm = (UiModeManager) getInstrumentation().getContext().getSystemService(Context.UI_MODE_SERVICE);
boolean isLeanback = umm.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
Intent intent = null;
if (isLeanback) {
intent = mPackageManager.getLeanbackLaunchIntentForPackage(packageName);
} else {
intent = mPackageManager.getLaunchIntentForPackage(packageName);
}
return intent;
}
use of android.app.UiModeManager in project platform_frameworks_base by android.
the class AppCompatibility method getLaunchIntentForPackage.
private Intent getLaunchIntentForPackage(String packageName) {
UiModeManager umm = (UiModeManager) getInstrumentation().getContext().getSystemService(Context.UI_MODE_SERVICE);
boolean isLeanback = umm.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
Intent intent = null;
if (isLeanback) {
intent = mPackageManager.getLeanbackLaunchIntentForPackage(packageName);
} else {
intent = mPackageManager.getLaunchIntentForPackage(packageName);
}
return intent;
}
Aggregations