示例#1
0
  private void updateIconSize(
      float scale, int drawablePadding, Resources resources, DisplayMetrics dm) {
    iconSizePx = (int) (DynamicGrid.pxFromDp(iconSize, dm) * scale);
    iconTextSizePx = (int) (DynamicGrid.pxFromSp(iconTextSize, dm) * scale);
    iconDrawablePaddingPx = drawablePadding;
    hotseatIconSizePx = (int) (DynamicGrid.pxFromDp(hotseatIconSize, dm) * scale);

    // Search Bar
    searchBarSpaceWidthPx =
        Math.min(
            widthPx, resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
    searchBarSpaceHeightPx =
        getSearchBarTopOffset()
            + resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);

    // Calculate the actual text height
    Paint textPaint = new Paint();
    textPaint.setTextSize(iconTextSizePx);
    FontMetrics fm = textPaint.getFontMetrics();
    cellWidthPx = iconSizePx;
    cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top);
    final float scaleDps = resources.getDimensionPixelSize(R.dimen.dragViewScale);
    dragViewScale = (iconSizePx + scaleDps) / iconSizePx;

    // Hotseat
    hotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx;
    hotseatCellWidthPx = iconSizePx;
    // revise the hotseatCellHeightPx from iconSizePx to iconSizePx*1.5
    hotseatCellHeightPx = (int) (iconSizePx * 1.5);

    // Folder
    folderCellWidthPx = cellWidthPx + 3 * edgeMarginPx;
    folderCellHeightPx = cellHeightPx + edgeMarginPx;
    folderBackgroundOffset = -edgeMarginPx;
    folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;

    // All Apps
    allAppsCellWidthPx = allAppsIconSizePx;
    allAppsCellHeightPx = allAppsIconSizePx + drawablePadding + iconTextSizePx;
    int maxLongEdgeCellCount =
        resources.getInteger(R.integer.config_dynamic_grid_max_long_edge_cell_count);
    int maxShortEdgeCellCount =
        resources.getInteger(R.integer.config_dynamic_grid_max_short_edge_cell_count);
    int minEdgeCellCount = resources.getInteger(R.integer.config_dynamic_grid_min_edge_cell_count);
    int maxRows = (isLandscape ? maxShortEdgeCellCount : maxLongEdgeCellCount);
    int maxCols = (isLandscape ? maxLongEdgeCellCount : maxShortEdgeCellCount);

    if (allAppsShortEdgeCount > 0 && allAppsLongEdgeCount > 0) {
      allAppsNumRows = isLandscape ? allAppsShortEdgeCount : allAppsLongEdgeCount;
      allAppsNumCols = isLandscape ? allAppsLongEdgeCount : allAppsShortEdgeCount;
    } else {
      allAppsNumRows =
          (availableHeightPx - pageIndicatorHeightPx)
              / (allAppsCellHeightPx + allAppsCellPaddingPx);
      allAppsNumRows = Math.max(minEdgeCellCount, Math.min(maxRows, allAppsNumRows));
      allAppsNumCols = (availableWidthPx) / (allAppsCellWidthPx + allAppsCellPaddingPx);
      allAppsNumCols = Math.max(minEdgeCellCount, Math.min(maxCols, allAppsNumCols));
    }
  }
示例#2
0
 /**
  * Apply any Partner customization grid overrides.
  *
  * <p>Currently we support: all apps row / column count.
  */
 private void applyPartnerDeviceProfileOverrides(Context ctx, DisplayMetrics dm) {
   Partner p = Partner.get(ctx.getPackageManager());
   if (p != null) {
     DeviceProfile partnerDp = p.getDeviceProfileOverride(dm);
     if (partnerDp != null) {
       if (partnerDp.numRows > 0 && partnerDp.numColumns > 0) {
         numRows = partnerDp.numRows;
         numColumns = partnerDp.numColumns;
       }
       if (partnerDp.allAppsShortEdgeCount > 0 && partnerDp.allAppsLongEdgeCount > 0) {
         allAppsShortEdgeCount = partnerDp.allAppsShortEdgeCount;
         allAppsLongEdgeCount = partnerDp.allAppsLongEdgeCount;
       }
       if (partnerDp.iconSize > 0) {
         iconSize = partnerDp.iconSize;
         // AllApps uses the original non-scaled icon size
         allAppsIconSizePx = DynamicGrid.pxFromDp(iconSize, dm);
       }
     }
   }
 }
示例#3
0
  DeviceProfile(
      Context context,
      ArrayList<DeviceProfile> profiles,
      float minWidth,
      float minHeight,
      int wPx,
      int hPx,
      int awPx,
      int ahPx,
      Resources res) {
    DisplayMetrics dm = res.getDisplayMetrics();
    ArrayList<DeviceProfileQuery> points = new ArrayList<DeviceProfileQuery>();
    transposeLayoutWithOrientation =
        res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation);
    minWidthDps = minWidth;
    minHeightDps = minHeight;

    ComponentName cn = new ComponentName(context.getPackageName(), this.getClass().getName());
    defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
    edgeMarginPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_edge_margin);
    desiredWorkspaceLeftRightMarginPx = 2 * edgeMarginPx;
    pageIndicatorHeightPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height);
    defaultPageSpacingPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing);
    allAppsCellPaddingPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_all_apps_cell_padding);
    overviewModeMinIconZoneHeightPx =
        res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height);
    overviewModeMaxIconZoneHeightPx =
        res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height);
    overviewModeBarItemWidthPx =
        res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width);
    overviewModeBarSpacerWidthPx =
        res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width);
    overviewModeIconZoneRatio =
        res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f;
    overviewModeScaleFactor =
        res.getInteger(R.integer.config_dynamic_grid_overview_scale_percentage) / 100f;

    // Find the closes profile given the width/height
    for (DeviceProfile p : profiles) {
      points.add(new DeviceProfileQuery(p, 0f));
    }
    DeviceProfile closestProfile = findClosestDeviceProfile(minWidth, minHeight, points);

    // Snap to the closest row count
    numRows = closestProfile.numRows;

    // Snap to the closest column count
    numColumns = closestProfile.numColumns;

    // Snap to the closest hotseat size
    numHotseatIcons = closestProfile.numHotseatIcons;
    hotseatAllAppsRank = (int) (numHotseatIcons / 2);

    // Snap to the closest default layout id
    defaultLayoutId = closestProfile.defaultLayoutId;

    // Interpolate the icon size
    points.clear();
    for (DeviceProfile p : profiles) {
      points.add(new DeviceProfileQuery(p, p.iconSize));
    }
    iconSize = invDistWeightedInterpolate(minWidth, minHeight, points);

    // AllApps uses the original non-scaled icon size
    allAppsIconSizePx = DynamicGrid.pxFromDp(iconSize, dm);

    // Interpolate the icon text size
    points.clear();
    for (DeviceProfile p : profiles) {
      points.add(new DeviceProfileQuery(p, p.iconTextSize));
    }
    iconTextSize = invDistWeightedInterpolate(minWidth, minHeight, points);
    iconDrawablePaddingOriginalPx =
        res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding);
    // AllApps uses the original non-scaled icon text size
    allAppsIconTextSizePx = DynamicGrid.pxFromDp(iconTextSize, dm);

    // Interpolate the hotseat icon size
    points.clear();
    for (DeviceProfile p : profiles) {
      points.add(new DeviceProfileQuery(p, p.hotseatIconSize));
    }
    // Hotseat
    hotseatIconSize = invDistWeightedInterpolate(minWidth, minHeight, points);

    // If the partner customization apk contains any grid overrides, apply them
    applyPartnerDeviceProfileOverrides(context, dm);

    // Calculate the remaining vars
    updateFromConfiguration(context, res, wPx, hPx, awPx, ahPx);
    updateAvailableDimensions(context);
    computeAllAppsButtonSize(context);
  }