类android.hardware.display.DisplayManager源码实例Demo

下面列出了怎么用android.hardware.display.DisplayManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: OverlayDisplayWindow.java
public OverlayDisplayWindow(Context context, String name,
        int width, int height, int densityDpi, int gravity, boolean secure,
        Listener listener) {
    // Workaround device freeze (b/38372997)
    ThreadedRenderer.disableVsync();
    mContext = context;
    mName = name;
    mGravity = gravity;
    mSecure = secure;
    mListener = listener;

    mDisplayManager = (DisplayManager)context.getSystemService(
            Context.DISPLAY_SERVICE);
    mWindowManager = (WindowManager)context.getSystemService(
            Context.WINDOW_SERVICE);

    mDefaultDisplay = mWindowManager.getDefaultDisplay();
    updateDefaultDisplayInfo();

    resize(width, height, densityDpi, false /* doLayout */);

    createWindow();
}
 
@Override // Binder call
public int applyVirtualDisplayFlags(int flags) {
    if (mType == MediaProjectionManager.TYPE_SCREEN_CAPTURE) {
        flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR
                | DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
        return flags;
    } else if (mType == MediaProjectionManager.TYPE_MIRRORING) {
        flags &= ~(DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR);
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION;
        return flags;
    } else if (mType == MediaProjectionManager.TYPE_PRESENTATION) {
        flags &= ~DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION |
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
        return flags;
    } else  {
        throw new RuntimeException("Unknown MediaProjection type");
    }
}
 
源代码3 项目: actor-platform   文件: AndroidMessenger.java
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();
    }
}
 
源代码4 项目: FirefoxReality   文件: OffscreenDisplay.java
public void onResume() {
    if (mVirtualDisplay == null) {
        DisplayManager manager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
        Display defaultDisplay = manager.getDisplay(Display.DEFAULT_DISPLAY);

        int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY;
        defaultDisplay.getMetrics(mDefaultMetrics);

        mVirtualDisplay = manager.createVirtualDisplay("OffscreenViews", mWidth, mHeight,
                mDefaultMetrics.densityDpi, mSurface, flags);
    }

    if (mPresentation == null) {
        mPresentation = new OffscreenPresentation(mContext, mVirtualDisplay.getDisplay());
        mPresentation.show();
        if (mContentView != null) {
            mPresentation.setContentView(mContentView);
        }
    }
}
 
源代码5 项目: ViewCapture   文件: WindowCaptureFragment.java
public Bitmap capture() {
    try {
        mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG, windowWidth, windowHeight, mScreenDensity, //
                                                                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,//
                                                                mImageReader.getSurface(), null, null);
        Log.i(TAG, "screen capture completed");
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return createBitmap();
    } finally {
        release();
    }
}
 
/**
 * 将录屏服务的内容显示到Image面板上.
 */
private void initVirtualDisplay() {

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        DisplayManager mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
        if (mDisplayManager == null) {
            L.e(" 获取 播放管理器失败 ... ");
        }
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            L.d("当前安卓 版本 " + Build.VERSION.SDK_INT + " 进入到图片展示 ");
            mVirtualDisplay = mDisplayManager.createVirtualDisplay("Remote Droid", mScreenWidth,
                    mScreenHeight, mScreenDensity,
                    mImageReader.getSurface(),
                    DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE);
        }
    } else {
        if (mMediaProjection == null) {
            L.e("mMediaProjection is null ...");
            return;
        } else {
            mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
                    mScreenWidth, mScreenHeight, mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                    mImageReader.getSurface(), null, null);
        }
    }
}
 
源代码7 项目: iGap-Android   文件: HelperNotificationAndBadge.java
/**
 * Is the screen of the device on.
 *
 * @param context the context
 * @return true when (at least one) screen is on
 */
public boolean isScreenOn(Context context) {
    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);
        return pm.isScreenOn();
    }
}
 
源代码8 项目: Taskbar   文件: DimScreenActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tb_activity_hsl_config);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    TextView textView = findViewById(R.id.textView);
    textView.setText(R.string.tb_desktop_mode_is_active);

    DisplayManager manager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    manager.registerDisplayListener(listener, null);

    U.registerReceiver(this, unDimScreenReceiver, ACTION_UNDIM_SCREEN);
    U.registerReceiver(this, finishReceiver,
            ACTION_FINISH_DIM_SCREEN_ACTIVITY, ACTION_KILL_HOME_ACTIVITY);

    if(getSupportActionBar() == null) return;

    // Make action bar invisible
    getSupportActionBar().setElevation(0);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0));

    setTitle(null);
}
 
源代码9 项目: media-samples   文件: ScreenCaptureFragment.java
private void setUpVirtualDisplay() {
    Log.i(TAG, "Setting up a VirtualDisplay: " +
            mSurfaceView.getWidth() + "x" + mSurfaceView.getHeight() +
            " (" + mScreenDensity + ")");
    mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
            mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity,
            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
            mSurface, null, null);
    mButtonToggle.setText(R.string.stop);
}
 
源代码10 项目: media-samples   文件: OverlayDisplayWindow.java
public JellybeanMr1Impl(Context context, String name,
        int width, int height, int gravity) {
    super(context, name, width, height, gravity);

    mDisplayManager = (DisplayManager)context.getSystemService(
            Context.DISPLAY_SERVICE);
    mWindowManager = (WindowManager)context.getSystemService(
            Context.WINDOW_SERVICE);

    mDefaultDisplay = mWindowManager.getDefaultDisplay();
    updateDefaultDisplayInfo();

    createWindow();
}
 
public ActiveScanWorkaround(Context context, Handler handler) {
    if (Build.VERSION.SDK_INT != 17) {
        throw new UnsupportedOperationException();
    }

    mDisplayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    mHandler = handler;
    try {
        mScanWifiDisplaysMethod = DisplayManager.class.getMethod("scanWifiDisplays");
    } catch (NoSuchMethodException ex) {
    }
}
 
源代码12 项目: mollyim-android   文件: CameraXView.java
@Override
protected void onAttachedToWindow() {
  super.onAttachedToWindow();
  DisplayManager dpyMgr =
      (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
  dpyMgr.registerDisplayListener(mDisplayListener, new Handler(Looper.getMainLooper()));
}
 
源代码13 项目: mollyim-android   文件: CameraXView.java
@Override
protected void onDetachedFromWindow() {
  super.onDetachedFromWindow();
  DisplayManager dpyMgr =
      (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
  dpyMgr.unregisterDisplayListener(mDisplayListener);
}
 
源代码14 项目: always-on-amoled   文件: StarterService.java
boolean isScreenOn() {
    if (Utils.isAndroidNewerThanL()) {
        DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码15 项目: android-MediaRouter   文件: OverlayDisplayWindow.java
public JellybeanMr1Impl(Context context, String name,
        int width, int height, int gravity) {
    super(context, name, width, height, gravity);

    mDisplayManager = (DisplayManager)context.getSystemService(
            Context.DISPLAY_SERVICE);
    mWindowManager = (WindowManager)context.getSystemService(
            Context.WINDOW_SERVICE);

    mDefaultDisplay = mWindowManager.getDefaultDisplay();
    updateDefaultDisplayInfo();

    createWindow();
}
 
源代码16 项目: AndroidScreenShare   文件: MediaReader.java
private void initVirtualDisplay() {
    mSurface = super.getmSurface();
    mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG + "-display",
            mWidth, mHeight, mDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
            mSurface, null, null);
    Log.d(TAG, "created virtual display: " + mVirtualDisplay);
}
 
源代码17 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        if (mDefaultDisplay == null) {
            DisplayManager dm = (DisplayManager)ctx.getOuterContext().
                    getSystemService(Context.DISPLAY_SERVICE);
            mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
        }
        display = mDefaultDisplay;
    }
    return new WindowManagerImpl(display);
}
 
源代码18 项目: DeviceConnect-Android   文件: AbstractScreenCast.java
private VirtualDisplay createVirtualDisplay() {
    int w = mWidth;
    int h = mHeight;

    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    if (wm == null) {
        throw new RuntimeException("WindowManager is not supported.");
    }

    DisplayMetrics dm = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(dm);
    if (dm.widthPixels > dm.heightPixels) {
        if (w < h) {
            w = mHeight;
            h = mWidth;
        }
    } else {
        if (w > h) {
            w = mHeight;
            h = mWidth;
        }
    }

    return mMediaProjection.createVirtualDisplay(
            "Android Host Screen",
            w,
            h,
            mDisplayDensityDpi,
            DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
            getSurface(),
            mCallback,
            new Handler(Looper.getMainLooper()));
}
 
源代码19 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        DisplayManager dm = (DisplayManager)ctx.getOuterContext().getSystemService(
                Context.DISPLAY_SERVICE);
        display = dm.getDisplay(Display.DEFAULT_DISPLAY);
    }
    return new WindowManagerImpl(display);
}
 
源代码20 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        DisplayManager dm = (DisplayManager)ctx.getOuterContext().getSystemService(
                Context.DISPLAY_SERVICE);
        display = dm.getDisplay(Display.DEFAULT_DISPLAY);
    }
    return new WindowManagerImpl(display);
}
 
源代码21 项目: miracast-widget   文件: MiracastWidgetProvider.java
public MiracastDisplayListener(int currentDisplay, RemoteViews widgetRemoteViews, DisplayManager displayManager, AppWidgetManager appWidgetManager, int appWidgetId, Context context){
	mCurrentDisplay = currentDisplay;
	mViews = widgetRemoteViews;
	mDisplayManager = displayManager;
	mAppWidgetManager = appWidgetManager;
	mAppWidgetId = appWidgetId;
	mContext = context;
          MiracastApplication application
                  = (MiracastApplication) mContext.getApplicationContext();
          mTracker = application.getDefaultTracker();
}
 
源代码22 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object getService(ContextImpl ctx) {
    Display display = ctx.mDisplay;
    if (display == null) {
        if (mDefaultDisplay == null) {
            DisplayManager dm = (DisplayManager)ctx.getOuterContext().
                    getSystemService(Context.DISPLAY_SERVICE);
            mDefaultDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY);
        }
        display = mDefaultDisplay;
    }
    return new WindowManagerImpl(display);
}
 
源代码23 项目: SecondScreen   文件: NotificationService.java
@Override
public void onDisplayRemoved(int displayId) {
    DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();

    try {
        if(displays[displays.length - 1].getDisplayId() == Display.DEFAULT_DISPLAY) {
            Intent serviceIntent = new Intent(NotificationService.this, TempBacklightOnService.class);
            U.startService(NotificationService.this, serviceIntent);

            SharedPreferences prefMain = U.getPrefMain(NotificationService.this);
            ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
            boolean displayConnectionServiceRunning = false;

            for(ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                if(DisplayConnectionService.class.getName().equals(service.service.getClassName()))
                    displayConnectionServiceRunning = true;
            }

            if(prefMain.getBoolean("inactive", true) && !displayConnectionServiceRunning) {
                Intent turnOffIntent = new Intent(NotificationService.this, TurnOffActivity.class);
                turnOffIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(turnOffIntent);
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) { /* Gracefully fail */ }
}
 
源代码24 项目: cwac-presentation   文件: PresentationHelper.java
/**
 * Basic constructor.
 *
 * @param ctxt a Context, typically the activity that is planning on showing
 *             the Presentation
 * @param listener the callback for show/hide events
 */
public PresentationHelper(Context ctxt, Listener listener) {
  this.listener=listener;

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    mgr=
        (DisplayManager)ctxt.getSystemService(Context.DISPLAY_SERVICE);
  }
}
 
源代码25 项目: ForceDoze   文件: Utils.java
public static boolean isScreenOn(Context context) {
    DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    for (Display display : dm.getDisplays()) {
        if (display.getState() == Display.STATE_ON
                || display.getState() == Display.STATE_UNKNOWN) {
            return true;
        }
    }
    return false;
}
 
源代码26 项目: RobotHelper   文件: ScreenCaptureUtilByMediaPro.java
public static void init() {
        sMediaProjection = mProjectionManager.getMediaProjection(resultCode, data);
        //start capture reader
        mImageReader = ImageReader.newInstance(MainApplication.sceenWidth, MainApplication.sceenHeight,
                PixelFormat.RGBA_8888, 2);
        mVirtualDisplay = sMediaProjection.createVirtualDisplay(
                "ScreenShot",
                MainApplication.sceenWidth,
                MainApplication.sceenHeight,
                MainApplication.dpi,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
                mImageReader.getSurface(),
                null,
                null);
//        mImageReader.setOnImageAvailableListener(reader -> {
//            Bitmap bitmap = null;
//            try (android.media.Image image = reader.acquireLatestImage()) {
//                if (image != null) {
//                    bitmap = covetBitmap(image);
////                    if (ScreenCaptureUtil.screenCache != null) {
////                        ScreenCaptureUtil.screenCache.recycle();
////                    }
//                    ScreenCaptureUtil.screenCache = bitmap;
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//        }, getBackgroundHandler());

    }
 
源代码27 项目: Reader   文件: ScreenUtils.java
private static DisplayMetrics getEPDDisplayMetrics() {
    Context context = AppUtils.getAppContext();
    DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    Display[] presentationDisplays = displayManager.getDisplays();
    Display display;
    if (presentationDisplays.length > 1) {
        display = presentationDisplays[1];
    } else {
        display = presentationDisplays[0];
    }
    DisplayMetrics metrics = new DisplayMetrics();
    display.getRealMetrics(metrics);
    LogUtils.d("widthPixels=" + metrics.widthPixels + " heightPixels=" + metrics.heightPixels);
    return metrics;
}
 
源代码28 项目: KernelAdiutor   文件: Utils.java
public static boolean isScreenOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码29 项目: always-on-amoled   文件: ChargeChangeReceiver.java
private boolean isDisplayOn(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        for (Display display : dm.getDisplays()) {
            if (display.getState() != Display.STATE_OFF) {
                return true;
            }
        }
        return false;
    } else {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        return powerManager.isScreenOn();
    }
}
 
源代码30 项目: QPM   文件: QPMScreenRecorderManager.java
private void start(Activity activity, int resultCode, Intent data) {
    if (mediaProjectionManager == null) {
        return;
    }
    startTime = System.currentTimeMillis();
    try {
        mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data);
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int screenWidth = metrics.widthPixels;
        int screenHeight = metrics.heightPixels;
        int density = metrics.densityDpi;

        mediaRecorder = new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setOutputFile(getSaveFile());
        mediaRecorder.setVideoSize(screenWidth, screenHeight);
        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        mediaRecorder.setVideoEncodingBitRate(screenWidth * screenHeight);
        mediaRecorder.setVideoFrameRate(30);
        mediaRecorder.prepare();
        display = mediaProjection.createVirtualDisplay(QPMScreenRecorderManager.class.getSimpleName(),
                screenWidth, screenHeight, density, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
                mediaRecorder.getSurface(), null, null);
        mediaRecorder.start();
    } catch (Exception e){
        e.printStackTrace();
        onRecorderFailed(activity);
    }
}
 
 类所在包
 同包方法