android.view.Display#Mode ( )源码实例Demo

下面列出了android.view.Display#Mode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Detect-Resolution   文件: DisplayCapabilities.java
public String getSupportedResolutions() {
    String allSupportedResolutions = "";
    Set<Integer> supportedResolutions = new LinkedHashSet<Integer>();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Display.Mode[] modes = mWindowManager.getDefaultDisplay().getSupportedModes();
        for (Display.Mode mode : modes) {
            supportedResolutions.add(mode.getPhysicalWidth());
        }
        if (supportedResolutions.size() > 1) {
            for (int i : supportedResolutions) {
                if (!allSupportedResolutions.equals("")) {
                    allSupportedResolutions += ", ";
                }
                allSupportedResolutions = allSupportedResolutions + i + "p";
            }
        }

        if (!allSupportedResolutions.equals("")) {
            allSupportedResolutions = " (" + allSupportedResolutions + ")";
        }
    }
    return allSupportedResolutions;
}
 
源代码2 项目: Detect-Resolution   文件: DisplayCapabilities.java
public String getSupportedRefreshRates() {
    String allSupportedRefreshRates = "";
    Set<Float> supportedRefreshRates = new LinkedHashSet<Float>();
    DecimalFormat df = new DecimalFormat("###.###");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Display.Mode[] modes = mWindowManager.getDefaultDisplay().getSupportedModes();
        for (Display.Mode mode : modes) {
            supportedRefreshRates.add(mode.getRefreshRate());
        }
        if (supportedRefreshRates.size() > 1) {
            for (float i : supportedRefreshRates) {
                if (!allSupportedRefreshRates.equals("")) {
                    allSupportedRefreshRates += ", ";
                }
                allSupportedRefreshRates = allSupportedRefreshRates + df.format(i);
            }
        }
        if (!allSupportedRefreshRates.equals("")) {
            allSupportedRefreshRates = " (" + allSupportedRefreshRates + ")";
        }
    }
    return allSupportedRefreshRates;
}
 
源代码3 项目: android_9.0.0_r45   文件: OverlayDisplayAdapter.java
public OverlayDisplayDevice(IBinder displayToken, String name,
        List<OverlayMode> modes, int activeMode, int defaultMode,
        float refreshRate, long presentationDeadlineNanos,
        boolean secure, int state,
        SurfaceTexture surfaceTexture, int number) {
    super(OverlayDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + number);
    mName = name;
    mRefreshRate = refreshRate;
    mDisplayPresentationDeadlineNanos = presentationDeadlineNanos;
    mSecure = secure;
    mState = state;
    mSurfaceTexture = surfaceTexture;
    mRawModes = modes;
    mModes = new Display.Mode[modes.size()];
    for (int i = 0; i < modes.size(); i++) {
        OverlayMode mode = modes.get(i);
        mModes[i] = createMode(mode.mWidth, mode.mHeight, refreshRate);
    }
    mActiveMode = activeMode;
    mDefaultMode = defaultMode;
}
 
源代码4 项目: android_9.0.0_r45   文件: WifiDisplayAdapter.java
@Override
public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
    if (mInfo == null) {
        mInfo = new DisplayDeviceInfo();
        mInfo.name = mName;
        mInfo.uniqueId = getUniqueId();
        mInfo.width = mWidth;
        mInfo.height = mHeight;
        mInfo.modeId = mMode.getModeId();
        mInfo.defaultModeId = mMode.getModeId();
        mInfo.supportedModes = new Display.Mode[] { mMode };
        mInfo.presentationDeadlineNanos = 1000000000L / (int) mRefreshRate; // 1 frame
        mInfo.flags = mFlags;
        mInfo.type = Display.TYPE_WIFI;
        mInfo.address = mAddress;
        mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL;
        mInfo.setAssumedDensityForExternalDisplay(mWidth, mHeight);
    }
    return mInfo;
}
 
源代码5 项目: jellyfin-androidtv   文件: PlaybackController.java
@TargetApi(23)
private void setRefreshRate(MediaStream videoStream) {
    if (videoStream == null) {
        Timber.e("Null video stream attempting to set refresh rate");
        return;
    }

    Display.Mode current = mApplication.getCurrentActivity().getWindowManager().getDefaultDisplay().getMode();
    Display.Mode best = findBestDisplayMode(videoStream.getRealFrameRate());
    if (best != null) {
        Timber.i("*** Best refresh mode is: %s/%s",best.getModeId(), best.getRefreshRate());
        if (current.getModeId() != best.getModeId()) {
            Timber.i("*** Attempting to change refresh rate from %s/%s",current.getModeId(), current.getRefreshRate());
            WindowManager.LayoutParams params = mApplication.getCurrentActivity().getWindow().getAttributes();
            params.preferredDisplayModeId = best.getModeId();
            mApplication.getCurrentActivity().getWindow().setAttributes(params);
        } else {
            Timber.i("Display is already in best mode");
        }
    } else {
        Timber.i("*** Unable to find display mode for refresh rate: %s",videoStream.getRealFrameRate());
    }


}
 
源代码6 项目: android_9.0.0_r45   文件: OverlayDisplayAdapter.java
@Override
public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
    if (mInfo == null) {
        Display.Mode mode = mModes[mActiveMode];
        OverlayMode rawMode = mRawModes.get(mActiveMode);
        mInfo = new DisplayDeviceInfo();
        mInfo.name = mName;
        mInfo.uniqueId = getUniqueId();
        mInfo.width = mode.getPhysicalWidth();
        mInfo.height = mode.getPhysicalHeight();
        mInfo.modeId = mode.getModeId();
        mInfo.defaultModeId = mModes[0].getModeId();
        mInfo.supportedModes = mModes;
        mInfo.densityDpi = rawMode.mDensityDpi;
        mInfo.xDpi = rawMode.mDensityDpi;
        mInfo.yDpi = rawMode.mDensityDpi;
        mInfo.presentationDeadlineNanos = mDisplayPresentationDeadlineNanos +
                1000000000L / (int) mRefreshRate;   // display's deadline + 1 frame
        mInfo.flags = DisplayDeviceInfo.FLAG_PRESENTATION;
        if (mSecure) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE;
        }
        mInfo.type = Display.TYPE_OVERLAY;
        mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;
        mInfo.state = mState;
    }
    return mInfo;
}
 
源代码7 项目: jellyfin-androidtv   文件: PlaybackController.java
@TargetApi(23)
private void getDisplayModes() {
    Display display = mApplication.getCurrentActivity().getWindowManager().getDefaultDisplay();
    mDisplayModes = display.getSupportedModes();
    Timber.i("** Available display refresh rates:");
    for (Display.Mode mDisplayMode : mDisplayModes) {
        Timber.i("%f", mDisplayMode.getRefreshRate());
    }

}
 
源代码8 项目: jellyfin-androidtv   文件: PlaybackController.java
@TargetApi(23)
private Display.Mode findBestDisplayMode(Float refreshRate) {
    if (mDisplayModes == null || refreshRate == null) return null;

    int sourceRate = Math.round(refreshRate);
    for (Display.Mode mode : mDisplayModes){
        int rate = Math.round(mode.getRefreshRate());
        if (rate == sourceRate || rate == sourceRate * 2) return mode;
    }

    return null;
}
 
源代码9 项目: leanback-extensions   文件: ScreenUtils.java
@RequiresApi(api = Build.VERSION_CODES.M)
private static void getDisplaySizeV23(@NonNull final Display display, @NonNull final Point outSize) {
	/*
		Still not worth enabling 4K, but that's where video modes can be checked.
	 */
	Display.Mode[] modes = display.getSupportedModes();
	if (modes != null && modes.length > 0) {
		Display.Mode mode = modes[0];
		outSize.x = mode.getPhysicalWidth();
		outSize.y = mode.getPhysicalHeight();
	} else {
		display.getRealSize(outSize);
	}
}
 
源代码10 项目: MediaSDK   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}
 
源代码11 项目: android_9.0.0_r45   文件: LocalDisplayAdapter.java
@Override
public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
    if (mInfo == null) {
        SurfaceControl.PhysicalDisplayInfo phys = mDisplayInfos[mActivePhysIndex];
        mInfo = new DisplayDeviceInfo();
        mInfo.width = phys.width;
        mInfo.height = phys.height;
        mInfo.modeId = mActiveModeId;
        mInfo.defaultModeId = mDefaultModeId;
        mInfo.supportedModes = new Display.Mode[mSupportedModes.size()];
        for (int i = 0; i < mSupportedModes.size(); i++) {
            DisplayModeRecord record = mSupportedModes.valueAt(i);
            mInfo.supportedModes[i] = record.mMode;
        }
        mInfo.colorMode = mActiveColorMode;
        mInfo.supportedColorModes =
                new int[mSupportedColorModes.size()];
        for (int i = 0; i < mSupportedColorModes.size(); i++) {
            mInfo.supportedColorModes[i] = mSupportedColorModes.get(i);
        }
        mInfo.hdrCapabilities = mHdrCapabilities;
        mInfo.appVsyncOffsetNanos = phys.appVsyncOffsetNanos;
        mInfo.presentationDeadlineNanos = phys.presentationDeadlineNanos;
        mInfo.state = mState;
        mInfo.uniqueId = getUniqueId();

        // Assume that all built-in displays that have secure output (eg. HDCP) also
        // support compositing from gralloc protected buffers.
        if (phys.secure) {
            mInfo.flags = DisplayDeviceInfo.FLAG_SECURE
                    | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
        }

        final Resources res = getOverlayContext().getResources();
        if (mBuiltInDisplayId == SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN) {
            mInfo.name = res.getString(
                    com.android.internal.R.string.display_manager_built_in_display_name);
            mInfo.flags |= DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY
                    | DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
            if (res.getBoolean(com.android.internal.R.bool.config_mainBuiltInDisplayIsRound)
                    || (Build.IS_EMULATOR
                    && SystemProperties.getBoolean(PROPERTY_EMULATOR_CIRCULAR, false))) {
                mInfo.flags |= DisplayDeviceInfo.FLAG_ROUND;
            }
            if (res.getBoolean(
                    com.android.internal.R.bool.config_maskMainBuiltInDisplayCutout)) {
                mInfo.flags |= DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT;
            }
            mInfo.displayCutout = DisplayCutout.fromResourcesRectApproximation(res,
                    mInfo.width, mInfo.height);
            mInfo.type = Display.TYPE_BUILT_IN;
            mInfo.densityDpi = (int)(phys.density * 160 + 0.5f);
            mInfo.xDpi = phys.xDpi;
            mInfo.yDpi = phys.yDpi;
            mInfo.touch = DisplayDeviceInfo.TOUCH_INTERNAL;
        } else {
            mInfo.displayCutout = null;
            mInfo.type = Display.TYPE_HDMI;
            mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;
            mInfo.name = getContext().getResources().getString(
                    com.android.internal.R.string.display_manager_hdmi_display_name);
            mInfo.touch = DisplayDeviceInfo.TOUCH_EXTERNAL;
            mInfo.setAssumedDensityForExternalDisplay(phys.width, phys.height);

            // For demonstration purposes, allow rotation of the external display.
            // In the future we might allow the user to configure this directly.
            if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
                mInfo.rotation = Surface.ROTATION_270;
            }

            // For demonstration purposes, allow rotation of the external display
            // to follow the built-in display.
            if (SystemProperties.getBoolean("persist.demo.hdmirotates", false)) {
                mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
            }

            if (!res.getBoolean(
                        com.android.internal.R.bool.config_localDisplaysMirrorContent)) {
                mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
            }

            if (res.getBoolean(com.android.internal.R.bool.config_localDisplaysPrivate)) {
                mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE;
            }
        }
    }
    return mInfo;
}
 
源代码12 项目: android_9.0.0_r45   文件: DisplayAdapter.java
public static Display.Mode createMode(int width, int height, float refreshRate) {
    return new Display.Mode(
            NEXT_DISPLAY_MODE_ID.getAndIncrement(), width, height, refreshRate);
}
 
源代码13 项目: android_9.0.0_r45   文件: VirtualDisplayAdapter.java
@Override
public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
    if (mInfo == null) {
        mInfo = new DisplayDeviceInfo();
        mInfo.name = mName;
        mInfo.uniqueId = getUniqueId();
        mInfo.width = mWidth;
        mInfo.height = mHeight;
        mInfo.modeId = mMode.getModeId();
        mInfo.defaultModeId = mMode.getModeId();
        mInfo.supportedModes = new Display.Mode[] { mMode };
        mInfo.densityDpi = mDensityDpi;
        mInfo.xDpi = mDensityDpi;
        mInfo.yDpi = mDensityDpi;
        mInfo.presentationDeadlineNanos = 1000000000L / (int) REFRESH_RATE; // 1 frame
        mInfo.flags = 0;
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE
                    | DisplayDeviceInfo.FLAG_NEVER_BLANK;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR) != 0) {
            mInfo.flags &= ~DisplayDeviceInfo.FLAG_NEVER_BLANK;
        } else {
            mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
        }

        if ((mFlags & VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;

            if ((mFlags & VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
                // For demonstration purposes, allow rotation of the external display.
                // In the future we might allow the user to configure this directly.
                if ("portrait".equals(SystemProperties.get(
                        "persist.demo.remoterotation"))) {
                    mInfo.rotation = Surface.ROTATION_270;
                }
            }
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT) != 0) {
            mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
        }
        if ((mFlags & VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL) != 0) {
          mInfo.flags |= DisplayDeviceInfo.FLAG_DESTROY_CONTENT_ON_REMOVAL;
        }

        mInfo.type = Display.TYPE_VIRTUAL;
        mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ?
                DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL;
        mInfo.state = mSurface != null ? Display.STATE_ON : Display.STATE_OFF;
        mInfo.ownerUid = mOwnerUid;
        mInfo.ownerPackageName = mOwnerPackageName;
    }
    return mInfo;
}
 
源代码14 项目: TelePlus-Android   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}
 
源代码15 项目: TelePlus-Android   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}
 
源代码16 项目: K-Sonic   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}
 
源代码17 项目: Telegram-FOSS   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}
 
源代码18 项目: Telegram   文件: Util.java
@TargetApi(23)
private static void getDisplaySizeV23(Display display, Point outSize) {
  Display.Mode mode = display.getMode();
  outSize.x = mode.getPhysicalWidth();
  outSize.y = mode.getPhysicalHeight();
}