static void updateWidgetSizeRanges(
      AppWidgetHostView widgetView, Launcher launcher, int spanX, int spanY) {

    getWidgetSizeRanges(launcher, spanX, spanY, mTmpRect);
    widgetView.updateAppWidgetSize(
        null, mTmpRect.left, mTmpRect.top, mTmpRect.right, mTmpRect.bottom);
  }
  private void performAppWidgetSizeCallbacksIfNecessary() {
    View content = getContent();
    if (!(content instanceof AppWidgetHostView)) return;

    if (!KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) {
      mPerformAppWidgetSizeUpdateOnBootComplete = true;
      return;
    }

    // TODO: there's no reason to force the AppWidgetHostView to catch duplicate size calls.
    // We can do that even more cheaply here. It's not an issue right now since we're in the
    // system process and hence no binder calls.
    AppWidgetHostView awhv = (AppWidgetHostView) content;
    float density = getResources().getDisplayMetrics().density;

    int width = (int) (content.getMeasuredWidth() / density);
    int height = (int) (content.getMeasuredHeight() / density);
    awhv.updateAppWidgetSize(null, width, height, width, height, true);
  }
 @Override
 public void updateAppWidget(RemoteViews remoteViews) {
   // Store the orientation in which the widget was inflated
   mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
   super.updateAppWidget(remoteViews);
 }
 @Override
 public void cancelLongPress() {
   super.cancelLongPress();
   mLongPressHelper.cancelLongPress();
 }
 @Override
 protected void onAttachedToWindow() {
   super.onAttachedToWindow();
   mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
 }
Exemple #6
0
 public void setWidgetTouch(MotionEvent ev) {
   if (wv != null) wv.onTouchEvent(ev);
 }
 @Override
 public void updateAppWidget(RemoteViews remoteViews) {
   // Store the orientation in which the widget was inflated
   updateLastInflationOrientation();
   super.updateAppWidget(remoteViews);
 }
  public AppWidgetResizeFrame(
      Context context,
      LauncherAppWidgetHostView widgetView,
      CellLayout cellLayout,
      DragLayer dragLayer) {

    super(context);
    mLauncher = (Launcher) context;
    mCellLayout = cellLayout;
    mWidgetView = widgetView;
    mResizeMode = widgetView.getAppWidgetInfo().resizeMode;
    mDragLayer = dragLayer;

    final AppWidgetProviderInfo info = widgetView.getAppWidgetInfo();
    int[] result = Launcher.getMinSpanForWidget(mLauncher, info);
    mMinHSpan = result[0];
    mMinVSpan = result[1];

    setBackgroundResource(R.drawable.widget_resize_frame_holo);
    setPadding(0, 0, 0, 0);

    LayoutParams lp;
    mLeftHandle = new ImageView(context);
    mLeftHandle.setImageResource(R.drawable.widget_resize_handle_left);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.LEFT | Gravity.CENTER_VERTICAL);
    addView(mLeftHandle, lp);

    mRightHandle = new ImageView(context);
    mRightHandle.setImageResource(R.drawable.widget_resize_handle_right);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    addView(mRightHandle, lp);

    mTopHandle = new ImageView(context);
    mTopHandle.setImageResource(R.drawable.widget_resize_handle_top);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.TOP);
    addView(mTopHandle, lp);

    mBottomHandle = new ImageView(context);
    mBottomHandle.setImageResource(R.drawable.widget_resize_handle_bottom);
    lp =
        new LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT,
            Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    addView(mBottomHandle, lp);

    Rect p =
        AppWidgetHostView.getDefaultPaddingForWidget(
            context, widgetView.getAppWidgetInfo().provider, null);
    mWidgetPaddingLeft = p.left;
    mWidgetPaddingTop = p.top;
    mWidgetPaddingRight = p.right;
    mWidgetPaddingBottom = p.bottom;

    if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
      mTopHandle.setVisibility(GONE);
      mBottomHandle.setVisibility(GONE);
    } else if (mResizeMode == AppWidgetProviderInfo.RESIZE_VERTICAL) {
      mLeftHandle.setVisibility(GONE);
      mRightHandle.setVisibility(GONE);
    }

    final float density = mLauncher.getResources().getDisplayMetrics().density;
    mBackgroundPadding = (int) Math.ceil(density * BACKGROUND_PADDING);
    mTouchTargetWidth = 2 * mBackgroundPadding;

    // When we create the resize frame, we first mark all cells as unoccupied. The appropriate
    // cells (same if not resized, or different) will be marked as occupied when the resize
    // frame is dismissed.
    mCellLayout.markCellsAsUnoccupiedForView(mWidgetView);
  }
  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);
  }