@Override public void show() { if (!mWindowVisible) { mDisplayManager.registerDisplayListener(mDisplayListener, null); if (!updateDefaultDisplayInfo()) { mDisplayManager.unregisterDisplayListener(mDisplayListener); return; } clearLiveState(); updateWindowParams(); mWindowManager.addView(mWindowContent, mWindowParams); mWindowVisible = true; } }
private boolean isScreenOn() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); boolean screenOn = false; for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { screenOn = true; } } return screenOn; } else { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); //noinspection deprecation return pm.isScreenOn(); } }
@Override public void dismiss() { if (mWindowVisible) { mDisplayManager.unregisterDisplayListener(mDisplayListener); mWindowManager.removeView(mWindowContent); mWindowVisible = false; } }
private boolean isScreenOn() { // Take special care for API20+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { DisplayManager dm = (DisplayManager) mContext.getSystemService(mContext.DISPLAY_SERVICE); // We iterate through all available displays for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) return false; } // If we are here, all displays are on; return true; } else { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); return !pm.isScreenOn(); } }
@TargetApi(19) public void startDisplayManager() { DisplayManager mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); Surface encoderInputSurface = null; try { encoderInputSurface = createDisplaySurface(); } catch (IOException e) { e.printStackTrace(); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { virtualDisplay = mDisplayManager.createVirtualDisplay( "Remote Droid", CodecUtils.WIDTH, CodecUtils.HEIGHT, 50, encoderInputSurface, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE); } else { if (MainActivity.mMediaProjection != null) { virtualDisplay = MainActivity.mMediaProjection.createVirtualDisplay( "Remote Droid", CodecUtils.WIDTH, CodecUtils.HEIGHT, 50, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, encoderInputSurface, null, null); } else { showToast("Something went wrong. Please restart the app."); } } encoder.start(); }
void updateDisplayLocked() { boolean screenOn = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY).getState() != Display.STATE_OFF; if (screenOn == mScreenOn) return; mScreenOn = screenOn; long now = System.currentTimeMillis(); if (mScreenOn) { mScreenOnSystemTimeSnapshot = now; } else { mScreenOnTime += now - mScreenOnSystemTimeSnapshot; writeScreenOnTimeLocked(mScreenOnTime); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ContentResolver resolver = getActivity().getContentResolver(); addPreferencesFromResource(R.xml.display_settings); mDisplayRotationPreference = (PreferenceScreen) findPreference(KEY_DISPLAY_ROTATION); mScreenSaverPreference = findPreference(KEY_SCREEN_SAVER); if (mScreenSaverPreference != null && getResources().getBoolean(com.android.internal.R.bool.config_dreamsSupported) == false) { getPreferenceScreen().removePreference(mScreenSaverPreference); } mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT); final long currentTimeout = Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT, FALLBACK_SCREEN_TIMEOUT_VALUE); mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout)); mScreenTimeoutPreference.setOnPreferenceChangeListener(this); disableUnusableTimeouts(mScreenTimeoutPreference); updateTimeoutPreferenceDescription(currentTimeout); updateDisplayRotationPreferenceDescription(); mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE); mFontSizePref.setOnPreferenceChangeListener(this); mFontSizePref.setOnPreferenceClickListener(this); mDisplayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE); mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus(); mWifiDisplayPreference = (Preference) findPreference(KEY_WIFI_DISPLAY); if (mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE) { getPreferenceScreen().removePreference(mWifiDisplayPreference); mWifiDisplayPreference = null; } mVolumeWake = (CheckBoxPreference) findPreference(KEY_VOLUME_WAKE); if (mVolumeWake != null) { if (!getResources().getBoolean(R.bool.config_show_volumeRockerWake)) { getPreferenceScreen().removePreference(mVolumeWake); getPreferenceScreen() .removePreference((PreferenceCategory) findPreference(KEY_WAKEUP_CATEGORY)); } else { mVolumeWake.setChecked( Settings.System.getInt(resolver, Settings.System.VOLUME_WAKE_SCREEN, 0) == 1); } } }
@Override protected void onStart() { super.onStart(); mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); // Since we were not watching for display changes until just now, there is a // chance that the display metrics have changed. If so, we will need to // dismiss the presentation immediately. This case is expected // to be rare but surprising, so we'll write a log message about it. if (!isConfigurationStillValid()) { Log.i( TAG, "Presentation is being dismissed because the " + "display metrics have changed since it was created."); mHandler.sendEmptyMessage(MSG_CANCEL); } }
@Override public void run() { try { try { prepareEncode(); mediaMuxer = new MediaMuxer(filePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); } catch (IOException e) { throw new RuntimeException(e); } mVirtualDisplay = displayManager.createVirtualDisplay( TAG, mWidth, mHeight, mDpi, mSurface, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC); // Log.d(TAG, "created virtual display: " + mVirtualDisplay); recordVideo(); } finally { try { release(); } catch (Exception e) { e.printStackTrace(); } } }
@Override public void onResume() { super.onResume(); updateDisplayRotationPreferenceDescription(); RotationPolicy.registerRotationPolicyListener(getActivity(), mRotationPolicyListener); // Display rotation observer getContentResolver() .registerContentObserver( Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, mAccelerometerRotationObserver); if (mWifiDisplayPreference != null) { getActivity() .registerReceiver( mReceiver, new IntentFilter(DisplayManager.ACTION_WIFI_DISPLAY_STATUS_CHANGED)); mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus(); } updateState(); }
@Override public void onBootPhase(int phase) { if (phase == PHASE_SYSTEM_SERVICES_READY) { // Observe changes to the threshold new SettingsObserver(mHandler).registerObserver(); mAppWidgetManager = getContext().getSystemService(AppWidgetManager.class); mDeviceIdleController = IDeviceIdleController.Stub.asInterface( ServiceManager.getService(DeviceIdleController.SERVICE_NAME)); mDisplayManager = (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE); mPowerManager = getContext().getSystemService(PowerManager.class); mScreenOnSystemTimeSnapshot = System.currentTimeMillis(); synchronized (this) { mScreenOnTime = readScreenOnTimeLocked(); } mDisplayManager.registerDisplayListener(mDisplayListener, null); synchronized (this) { updateDisplayLocked(); } } else if (phase == PHASE_BOOT_COMPLETED) { setAppIdleParoled(getContext().getSystemService(BatteryManager.class).isCharging()); } }
public static boolean deviceSupportsWifiDisplay(Context ctx) { DisplayManager dm = (DisplayManager) ctx.getSystemService(Context.DISPLAY_SERVICE); return (dm.getWifiDisplayStatus().getFeatureState() != WifiDisplayStatus.FEATURE_STATE_UNAVAILABLE); }
@Override protected void onStop() { mDisplayManager.unregisterDisplayListener(mDisplayListener); super.onStop(); }