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

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

源代码1 项目: android_9.0.0_r45   文件: DisplayManager.java
private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid) {
    Display display = mDisplays.get(displayId);
    if (display == null) {
        // TODO: We cannot currently provide any override configurations for metrics on displays
        // other than the display the context is associated with.
        final Context context = mContext.getDisplay().getDisplayId() == displayId
                ? mContext : mContext.getApplicationContext();

        display = mGlobal.getCompatibleDisplay(displayId, context.getResources());
        if (display != null) {
            mDisplays.put(displayId, display);
        }
    } else if (!assumeValid && !display.isValid()) {
        display = null;
    }
    return display;
}
 
源代码2 项目: cwac-presentation   文件: PresentationHelper.java
private void handleRoute() {
  if (isEnabled()) {
    Display[] displays=
        mgr.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);

    if (displays.length == 0) {
      if (current != null || isFirstRun) {
        listener.clearPreso(true);
        current=null;
      }
    }
    else {
      Display display=displays[0];

      if (display != null && display.isValid()) {
        if (current == null) {
          listener.showPreso(display);
          current=display;
        }
        else if (current.getDisplayId() != display.getDisplayId()) {
          listener.clearPreso(true);
          listener.showPreso(display);
          current=display;
        }
        else {
          // no-op: should already be set
        }
      }
      else if (current != null) {
        listener.clearPreso(true);
        current=null;
      }
    }

    isFirstRun=false;
  }
}
 
源代码3 项目: AcDisplay   文件: PowerUtils.java
@SuppressLint("NewApi")
public static boolean isScreenOn(@NonNull Context context) {
    display_api:
    if (Device.hasKitKatWatchApi()) {
        DisplayManager dm = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        Display[] displays = dm.getDisplays(null);
        Display display = null;
        if (displays == null || displays.length == 0) {
            break display_api;
        } else if (displays.length > 1) {
            Timber.tag(TAG).i("The number of logical displays is " + displays.length);
        }

        for (Display d : displays) {
            final boolean virtual = Operator.bitAnd(d.getFlags(), Display.FLAG_PRESENTATION);
            if (d.isValid() && !virtual) {
                display = d;

                final int type;
                try {
                    Method method = Display.class.getDeclaredMethod("getType");
                    method.setAccessible(true);
                    type = (int) method.invoke(d);
                } catch (Exception e) {
                    continue;
                }

                if (type == 1 /* built-in display */) {
                    break;
                }
            }
        }

        if (display == null) {
            return false;
        }

        Timber.tag(TAG).i("Display state=" + display.getState());
        return display.getState() == Display.STATE_ON;
    }
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    return isInteractive(pm);
}