Java Code Examples for android.view.Display#isValid()

The following examples show how to use android.view.Display#isValid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: PresentationHelper.java    From cwac-presentation with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 3
Source File: PowerUtils.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@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);
}