Search in sources :

Example 6 with DisplayManager

use of android.hardware.display.DisplayManager in project android_frameworks_base by crdroidandroid.

the class MediaProjection method createVirtualDisplay.

/**
     * @hide
     */
public VirtualDisplay createVirtualDisplay(@NonNull String name, int width, int height, int dpi, boolean isSecure, @Nullable Surface surface, @Nullable VirtualDisplay.Callback callback, @Nullable Handler handler) {
    DisplayManager dm = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
    int flags = isSecure ? DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE : 0;
    return dm.createVirtualDisplay(this, name, width, height, dpi, surface, flags | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION, callback, handler);
}
Also used : DisplayManager(android.hardware.display.DisplayManager)

Example 7 with DisplayManager

use of android.hardware.display.DisplayManager in project android_packages_apps_Dialer by LineageOS.

the class CallCardPresenter method sendAccessibilityEvent.

static boolean sendAccessibilityEvent(Context context, InCallScreen inCallScreen) {
    AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled()) {
        LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "accessibility is off");
        return false;
    }
    if (inCallScreen == null) {
        LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "incallscreen is null");
        return false;
    }
    Fragment fragment = inCallScreen.getInCallScreenFragment();
    if (fragment == null || fragment.getView() == null || fragment.getView().getParent() == null) {
        LogUtil.w("CallCardPresenter.sendAccessibilityEvent", "fragment/view/parent is null");
        return false;
    }
    DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    boolean screenIsOn = display.getState() == Display.STATE_ON;
    LogUtil.d("CallCardPresenter.sendAccessibilityEvent", "screen is on: %b", screenIsOn);
    if (!screenIsOn) {
        return false;
    }
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
    inCallScreen.dispatchPopulateAccessibilityEvent(event);
    View view = inCallScreen.getInCallScreenFragment().getView();
    view.getParent().requestSendAccessibilityEvent(view, event);
    return true;
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) DisplayManager(android.hardware.display.DisplayManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Fragment(android.support.v4.app.Fragment) View(android.view.View) Display(android.view.Display)

Example 8 with DisplayManager

use of android.hardware.display.DisplayManager in project grafika by google.

the class ScreenRecordActivity method startRecording.

@RequiresApi(api = Build.VERSION_CODES.M)
private void startRecording() {
    DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    Display defaultDisplay;
    if (dm != null) {
        defaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
    } else {
        throw new IllegalStateException("Cannot display manager?!?");
    }
    if (defaultDisplay == null) {
        throw new RuntimeException("No display found.");
    }
    // Get the display size and density.
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int screenWidth = metrics.widthPixels;
    int screenHeight = metrics.heightPixels;
    int screenDensity = metrics.densityDpi;
    prepareVideoEncoder(screenWidth, screenHeight);
    try {
        File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/grafika", "Screen-record-" + Long.toHexString(System.currentTimeMillis()) + ".mp4");
        if (!outputFile.getParentFile().exists()) {
            outputFile.getParentFile().mkdirs();
        }
        muxer = new MediaMuxer(outputFile.getCanonicalPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
    } catch (IOException ioe) {
        throw new RuntimeException("MediaMuxer creation failed", ioe);
    }
    // Start the video input.
    mediaProjection.createVirtualDisplay("Recording Display", screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, /* flags */
    inputSurface, null, /* callback */
    null);
}
Also used : DisplayManager(android.hardware.display.DisplayManager) IOException(java.io.IOException) DisplayMetrics(android.util.DisplayMetrics) File(java.io.File) MediaMuxer(android.media.MediaMuxer) Display(android.view.Display) RequiresApi(android.support.annotation.RequiresApi)

Example 9 with DisplayManager

use of android.hardware.display.DisplayManager in project robolectric by robolectric.

the class BootstrapTest method shouldSetUpRealisticDisplay.

@Test
@Config(qualifiers = "w480dp-h640dp")
public void shouldSetUpRealisticDisplay() throws Exception {
    if (Build.VERSION.SDK_INT > JELLY_BEAN) {
        DisplayManager displayManager = (DisplayManager) ApplicationProvider.getApplicationContext().getSystemService(Context.DISPLAY_SERVICE);
        DisplayInfo displayInfo = new DisplayInfo();
        Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
        display.getDisplayInfo(displayInfo);
        assertThat(displayInfo.name).isEqualTo("Built-in screen");
        assertThat(displayInfo.appWidth).isEqualTo(480);
        assertThat(displayInfo.appHeight).isEqualTo(640);
        assertThat(displayInfo.smallestNominalAppWidth).isEqualTo(480);
        assertThat(displayInfo.smallestNominalAppHeight).isEqualTo(480);
        assertThat(displayInfo.largestNominalAppWidth).isEqualTo(640);
        assertThat(displayInfo.largestNominalAppHeight).isEqualTo(640);
        assertThat(displayInfo.logicalWidth).isEqualTo(480);
        assertThat(displayInfo.logicalHeight).isEqualTo(640);
        assertThat(displayInfo.rotation).isEqualTo(ROTATION_0);
        assertThat(displayInfo.logicalDensityDpi).isEqualTo(160);
        assertThat(displayInfo.physicalXDpi).isEqualTo(160f);
        assertThat(displayInfo.physicalYDpi).isEqualTo(160f);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            assertThat(displayInfo.state).isEqualTo(Display.STATE_ON);
        }
    }
    DisplayMetrics displayMetrics = ApplicationProvider.getApplicationContext().getResources().getDisplayMetrics();
    assertThat(displayMetrics.widthPixels).isEqualTo(480);
    assertThat(displayMetrics.heightPixels).isEqualTo(640);
}
Also used : DisplayInfo(android.view.DisplayInfo) DisplayManager(android.hardware.display.DisplayManager) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 10 with DisplayManager

use of android.hardware.display.DisplayManager in project Signal-Android by WhisperSystems.

the class SignalCameraView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    DisplayManager dpyMgr = (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
    dpyMgr.registerDisplayListener(mDisplayListener, new Handler(Looper.getMainLooper()));
}
Also used : DisplayManager(android.hardware.display.DisplayManager) Handler(android.os.Handler)

Aggregations

DisplayManager (android.hardware.display.DisplayManager)23 Display (android.view.Display)13 DisplayInfo (android.view.DisplayInfo)7 DisplayMetrics (android.util.DisplayMetrics)4 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 SuppressLint (android.annotation.SuppressLint)1 Point (android.graphics.Point)1 MediaMuxer (android.media.MediaMuxer)1 Handler (android.os.Handler)1 PowerManager (android.os.PowerManager)1 RequiresApi (android.support.annotation.RequiresApi)1 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1 Nullable (androidx.annotation.Nullable)1 File (java.io.File)1 IOException (java.io.IOException)1