@Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = getChildCount();
    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      if (child.getVisibility() != GONE) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        int childLeft = lp.x;
        int childTop = lp.y;
        child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);

        if (lp.dropped) {
          lp.dropped = false;

          final int[] cellXY = mTmpCellXY;
          getLocationOnScreen(cellXY);
          mWallpaperManager.sendWallpaperCommand(
              getWindowToken(),
              WallpaperManager.COMMAND_DROP,
              cellXY[0] + childLeft + lp.width / 2,
              cellXY[1] + childTop + lp.height / 2,
              0,
              null);
        }
      }
    }
  }
Пример #2
0
 public void onDrop(DragObject d) {
   ShortcutInfo item;
   if (d.dragInfo instanceof ApplicationInfo) {
     // Came from all apps -- make a copy
     item = ((ApplicationInfo) d.dragInfo).makeShortcut();
     item.spanX = 1;
     item.spanY = 1;
   } else {
     item = (ShortcutInfo) d.dragInfo;
   }
   // Dragged from self onto self, currently this is the only path possible, however
   // we keep this as a distinct code path.
   if (item == mCurrentDragInfo) {
     ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
     CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
     si.cellX = lp.cellX = mEmptyCell[0];
     si.cellX = lp.cellY = mEmptyCell[1];
     mContent.addViewToCellLayout(mCurrentDragView, -1, (int) item.id, lp, true);
     if (d.dragView.hasDrawn()) {
       mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
     } else {
       mCurrentDragView.setVisibility(VISIBLE);
     }
     mItemsInvalidated = true;
     setupContentDimensions(getItemCount());
     mSuppressOnAdd = true;
   }
   mInfo.add(item);
 }
Пример #3
0
 public void onDrop(DragObject d) {
   ShortcutInfo item;
   if (d.dragInfo instanceof ApplicationInfo) {
     // 如果是来自“所有程序”界面,那么复制这个item
     item = ((ApplicationInfo) d.dragInfo).makeShortcut();
     item.spanX = 1;
     item.spanY = 1;
   } else {
     item = (ShortcutInfo) d.dragInfo;
   }
   // Dragged from self onto self, currently this is the only path
   // possible, however
   // we keep this as a distinct code path.
   // 这个判断应该不可能出现别的情况,当前手动对象当然应该是这个d,这是过于谨慎的判断
   if (item == mCurrentDragInfo) {
     ShortcutInfo si = (ShortcutInfo) mCurrentDragView.getTag();
     CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mCurrentDragView.getLayoutParams();
     si.cellX = lp.cellX = mEmptyCell[0];
     si.cellX = lp.cellY = mEmptyCell[1];
     mContent.addViewToCellLayout(mCurrentDragView, -1, (int) item.id, lp, true);
     if (d.dragView.hasDrawn()) {
       mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, mCurrentDragView);
     } else {
       d.deferDragViewCleanupPostAnimation = false;
       mCurrentDragView.setVisibility(VISIBLE);
     }
     mItemsInvalidated = true;
     // 拖进来后重新设置Folder的大小
     setupContentDimensions(getItemCount());
     mSuppressOnAdd = true;
   }
   mInfo.add(item);
 }
Пример #4
0
  public void measureChild(View child) {
    final int cellWidth = mCellWidth;
    final int cellHeight = mCellHeight;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();

    lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap);
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
    int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
  }
Пример #5
0
  void resetLayout() {
    mContent.removeAllViewsInLayout();

    // Add the Apps button
    Context context = getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    BubbleTextView allAppsButton =
        (BubbleTextView) inflater.inflate(R.layout.application_allapps, mContent, false);
    allAppsButton.setCompoundDrawablesWithIntrinsicBounds(
        null, context.getResources().getDrawable(R.drawable.all_apps_button_icon), null, null);
    allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
    allAppsButton.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (mLauncher != null
                && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
              mLauncher.onTouchDownAllAppsButton(v);
            }
            return false;
          }
        });

    allAppsButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(android.view.View v) {
            if (LauncherLog.DEBUG) {
              LauncherLog.d(TAG, "Click on all apps view on hotseat: mLauncher = " + mLauncher);
            }
            if (mLauncher != null) {
              mLauncher.onClickAllAppsButton(v);
            }
          }
        });

    // Note: We do this to ensure that the hotseat is always laid out in the orientation of
    // the hotseat in order regardless of which orientation they were added
    int x = getCellXFromOrder(mAllAppsButtonRank);
    int y = getCellYFromOrder(mAllAppsButtonRank);
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
    lp.canReorder = false;
    mContent.addViewToCellLayout(allAppsButton, -1, 0, lp, true);
  }
  public void measureChild(View child) {
    final LauncherAppState app = LauncherAppState.getInstance();
    final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    final int cellWidth = mCellWidth;
    final int cellHeight = mCellHeight;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    if (!lp.isFullscreen) {
      lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(), mCountX);

      if (child instanceof LauncherAppWidgetHostView) {
        // Widgets have their own padding, so skip
      } else {
        // Otherwise, center the icon
        int cHeight = getCellContentHeight();
        int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
        int cellPaddingX = (int) (grid.edgeMarginPx / 2f);
        child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0);
      }
    } else {
      lp.x = 0;
      lp.y = 0;
      lp.width = getMeasuredWidth();
      lp.height = getMeasuredHeight();
    }
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
    int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    child.measure(childWidthMeasureSpec, childheightMeasureSpec);
  }
Пример #7
0
  void resetLayout() {
    mContent.removeAllViewsInLayout();

    if (!AppsCustomizePagedView.DISABLE_ALL_APPS) {
      // Add the Apps button
      Context context = getContext();

      LayoutInflater inflater = LayoutInflater.from(context);
      TextView allAppsButton =
          (TextView) inflater.inflate(R.layout.all_apps_button, mContent, false);
      Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
      Utilities.resizeIconDrawable(d);
      allAppsButton.setCompoundDrawables(null, d, null, null);

      allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
      if (mLauncher != null) {
        allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
      }
      allAppsButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
              if (mLauncher != null) {
                mLauncher.onClickAllAppsButton(v);
              }
            }
          });

      // Note: We do this to ensure that the hotseat is always laid out in the orientation of
      // the hotseat in order regardless of which orientation they were added
      int x = getCellXFromOrder(mAllAppsButtonRank);
      int y = getCellYFromOrder(mAllAppsButtonRank);
      CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
      lp.canReorder = false;
      mContent.addViewToCellLayout(allAppsButton, -1, 0, lp, true);
    }
  }
  private void arrangeChildren(ArrayList<View> list) {
    int[] vacant = new int[2];
    if (list == null) {
      list = getItemsInReadingOrder();
    }
    mContent.removeAllViews();

    for (int i = 0; i < list.size(); i++) {
      View v = list.get(i);
      mContent.getVacantCell(vacant, 1, 1);
      CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
      lp.cellX = vacant[0];
      lp.cellY = vacant[1];
      ItemInfo info = (ItemInfo) v.getTag();
      if (info.cellX != vacant[0] || info.cellY != vacant[1]) {
        info.cellX = vacant[0];
        info.cellY = vacant[1];
        LauncherModel.addOrMoveItemInDatabase(mLauncher, info, mInfo.id, 0, info.cellX, info.cellY);
      }
      boolean insert = false;
      mContent.addViewToCellLayout(v, insert ? 0 : -1, (int) info.id, lp, true);
    }
    mItemsInvalidated = true;
  }
  public void onDrop(DragObject d) {
    Runnable cleanUpRunnable = null;

    // If we are coming from All Apps space, we defer removing the extra empty screen
    // until the folder closes
    if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) {
      cleanUpRunnable =
          new Runnable() {
            @Override
            public void run() {
              mLauncher.exitSpringLoadedDragModeDelayed(
                  true, Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
            }
          };
    }

    View currentDragView;
    ShortcutInfo si = mCurrentDragInfo;
    if (mIsExternalDrag) {
      si.cellX = mEmptyCell[0];
      si.cellY = mEmptyCell[1];

      // Actually move the item in the database if it was an external drag. Call this
      // before creating the view, so that ShortcutInfo is updated appropriately.
      LauncherModel.addOrMoveItemInDatabase(mLauncher, si, mInfo.id, 0, si.cellX, si.cellY);

      // We only need to update the locations if it doesn't get handled in #onDropCompleted.
      if (d.dragSource != this) {
        updateItemLocationsInDatabaseBatch();
      }
      mIsExternalDrag = false;

      currentDragView = createAndAddShortcut(si);
    } else {
      currentDragView = mCurrentDragView;
      CellLayout.LayoutParams lp = (CellLayout.LayoutParams) currentDragView.getLayoutParams();
      si.cellX = lp.cellX = mEmptyCell[0];
      si.cellX = lp.cellY = mEmptyCell[1];
      mContent.addViewToCellLayout(currentDragView, -1, (int) si.id, lp, true);
    }

    if (d.dragView.hasDrawn()) {

      // Temporarily reset the scale such that the animation target gets calculated correctly.
      float scaleX = getScaleX();
      float scaleY = getScaleY();
      setScaleX(1.0f);
      setScaleY(1.0f);
      mLauncher
          .getDragLayer()
          .animateViewIntoPosition(d.dragView, currentDragView, cleanUpRunnable, null);
      setScaleX(scaleX);
      setScaleY(scaleY);
    } else {
      d.deferDragViewCleanupPostAnimation = false;
      currentDragView.setVisibility(VISIBLE);
    }
    mItemsInvalidated = true;
    setupContentDimensions(getItemCount());

    // Temporarily suppress the listener, as we did all the work already here.
    mSuppressOnAdd = true;
    mInfo.add(si);
    mSuppressOnAdd = false;
    // Clear the drag info, as it is no longer being dragged.
    mCurrentDragInfo = null;
  }
 public void setupLp(CellLayout.LayoutParams lp) {
   lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(), mCountX);
 }
Пример #11
0
 public void setupLp(CellLayout.LayoutParams lp) {
   lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap);
 }
Пример #12
0
  /** Based on the current deltas, we determine if and how to resize the widget. */
  private void resizeWidgetIfNeeded(boolean onDismiss) {
    int xThreshold = mCellLayout.getCellWidth() + mCellLayout.getWidthGap();
    int yThreshold = mCellLayout.getCellHeight() + mCellLayout.getHeightGap();

    int deltaX = mDeltaX + mDeltaXAddOn;
    int deltaY = mDeltaY + mDeltaYAddOn;

    float hSpanIncF = 1.0f * deltaX / xThreshold - mRunningHInc;
    float vSpanIncF = 1.0f * deltaY / yThreshold - mRunningVInc;

    int hSpanInc = 0;
    int vSpanInc = 0;
    int cellXInc = 0;
    int cellYInc = 0;

    int countX = mCellLayout.getCountX();
    int countY = mCellLayout.getCountY();

    if (Math.abs(hSpanIncF) > RESIZE_THRESHOLD) {
      hSpanInc = Math.round(hSpanIncF);
    }
    if (Math.abs(vSpanIncF) > RESIZE_THRESHOLD) {
      vSpanInc = Math.round(vSpanIncF);
    }

    if (!onDismiss && (hSpanInc == 0 && vSpanInc == 0)) return;

    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams();

    int spanX = lp.cellHSpan;
    int spanY = lp.cellVSpan;
    int cellX = lp.useTmpCoords ? lp.tmpCellX : lp.cellX;
    int cellY = lp.useTmpCoords ? lp.tmpCellY : lp.cellY;

    int hSpanDelta = 0;
    int vSpanDelta = 0;

    // For each border, we bound the resizing based on the minimum width, and the maximum
    // expandability.
    if (mLeftBorderActive) {
      cellXInc = Math.max(-cellX, hSpanInc);
      cellXInc = Math.min(lp.cellHSpan - mMinHSpan, cellXInc);
      hSpanInc *= -1;
      hSpanInc = Math.min(cellX, hSpanInc);
      hSpanInc = Math.max(-(lp.cellHSpan - mMinHSpan), hSpanInc);
      hSpanDelta = -hSpanInc;

    } else if (mRightBorderActive) {
      hSpanInc = Math.min(countX - (cellX + spanX), hSpanInc);
      hSpanInc = Math.max(-(lp.cellHSpan - mMinHSpan), hSpanInc);
      hSpanDelta = hSpanInc;
    }

    if (mTopBorderActive) {
      cellYInc = Math.max(-cellY, vSpanInc);
      cellYInc = Math.min(lp.cellVSpan - mMinVSpan, cellYInc);
      vSpanInc *= -1;
      vSpanInc = Math.min(cellY, vSpanInc);
      vSpanInc = Math.max(-(lp.cellVSpan - mMinVSpan), vSpanInc);
      vSpanDelta = -vSpanInc;
    } else if (mBottomBorderActive) {
      vSpanInc = Math.min(countY - (cellY + spanY), vSpanInc);
      vSpanInc = Math.max(-(lp.cellVSpan - mMinVSpan), vSpanInc);
      vSpanDelta = vSpanInc;
    }

    mDirectionVector[0] = 0;
    mDirectionVector[1] = 0;
    // Update the widget's dimensions and position according to the deltas computed above
    if (mLeftBorderActive || mRightBorderActive) {
      spanX += hSpanInc;
      cellX += cellXInc;
      if (hSpanDelta != 0) {
        mDirectionVector[0] = mLeftBorderActive ? -1 : 1;
      }
    }

    if (mTopBorderActive || mBottomBorderActive) {
      spanY += vSpanInc;
      cellY += cellYInc;
      if (vSpanDelta != 0) {
        mDirectionVector[1] = mTopBorderActive ? -1 : 1;
      }
    }

    if (!onDismiss && vSpanDelta == 0 && hSpanDelta == 0) return;

    // We always want the final commit to match the feedback, so we make sure to use the
    // last used direction vector when committing the resize / reorder.
    if (onDismiss) {
      mDirectionVector[0] = mLastDirectionVector[0];
      mDirectionVector[1] = mLastDirectionVector[1];
    } else {
      mLastDirectionVector[0] = mDirectionVector[0];
      mLastDirectionVector[1] = mDirectionVector[1];
    }

    if (mCellLayout.createAreaForResize(
        cellX, cellY, spanX, spanY, mWidgetView, mDirectionVector, onDismiss)) {
      lp.tmpCellX = cellX;
      lp.tmpCellY = cellY;
      lp.cellHSpan = spanX;
      lp.cellVSpan = spanY;
      mRunningVInc += vSpanDelta;
      mRunningHInc += hSpanDelta;
      if (!onDismiss) {
        updateWidgetSizeRanges(mWidgetView, mLauncher, spanX, spanY);
      }
    }
    mWidgetView.requestLayout();
  }