Esempio n. 1
0
  private void updateAvailableDimensions(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Resources resources = context.getResources();
    DisplayMetrics dm = resources.getDisplayMetrics();
    Configuration config = resources.getConfiguration();

    // There are three possible configurations that the dynamic grid accounts for, portrait,
    // landscape with the nav bar at the bottom, and landscape with the nav bar at the side.
    // To prevent waiting for fitSystemWindows(), we make the observation that in landscape,
    // the height is the smallest height (either with the nav bar at the bottom or to the
    // side) and otherwise, the height is simply the largest possible height for a portrait
    // device.
    Point size = new Point();
    Point smallestSize = new Point();
    Point largestSize = new Point();
    display.getSize(size);
    display.getCurrentSizeRange(smallestSize, largestSize);
    availableWidthPx = size.x;
    if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
      availableHeightPx = smallestSize.y;
    } else {
      availableHeightPx = largestSize.y;
    }

    // Check to see if the icons fit in the new available height.  If not, then we need to
    // shrink the icon size.
    float scale = 1f;
    int drawablePadding = iconDrawablePaddingOriginalPx;
    updateIconSize(1f, drawablePadding, resources, dm);
    float usedHeight = (cellHeightPx * numRows);

    Rect workspacePadding = getWorkspacePadding();
    int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom);
    if (usedHeight > maxHeight) {
      scale = maxHeight / usedHeight;
      drawablePadding = 0;
    }
    updateIconSize(scale, drawablePadding, resources, dm);

    // Make the callbacks
    for (DeviceProfileCallbacks cb : mCallbacks) {
      cb.onAvailableSizeChanged(this);
    }
  }
Esempio n. 2
0
 void addCallback(DeviceProfileCallbacks cb) {
   mCallbacks.add(cb);
   cb.onAvailableSizeChanged(this);
 }