protected boolean createAndAddShortcut(ShortcutInfo item) { final StyledTextFoo textView = (StyledTextFoo) mInflater.inflate(R.layout.application, this, false); textView.setCompoundDrawablesWithIntrinsicBounds( null, new FastBitmapDrawable(item.getIcon(mIconCache)), null, null); textView.setText(item.title); textView.setTag(item); textView.setOnClickListener(this); textView.setOnLongClickListener(this); // We need to check here to verify that the given item's location isn't already occupied // by another item. If it is, we need to find the next available slot and assign // it that position. This is an issue when upgrading from the old Folders implementation // which could contain an unlimited number of items. if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) { if (!findAndSetEmptyCells(item)) { return false; } } CellLayout.LayoutParams lp = new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY); boolean insert = false; textView.setOnKeyListener(new FolderKeyEventListener()); mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int) item.id, lp, true); return true; }
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft(); r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; } } }
/** 向Folder添加ShortcutInfo */ protected boolean createAndAddShortcut(ShortcutInfo item) { final TextView textView = (TextView) mInflater.inflate(R.layout.application, this, false); textView.setCompoundDrawablesWithIntrinsicBounds( null, new FastBitmapDrawable(item.getIcon(mIconCache)), null, null); textView.setText(item.title); textView.setTag(item); textView.setOnClickListener(this); textView.setOnLongClickListener(this); // 检查这个地方是否被其他item占据 if (mContent.getChildAt(item.cellX, item.cellY) != null || item.cellX < 0 || item.cellY < 0 || item.cellX >= mContent.getCountX() || item.cellY >= mContent.getCountY()) { // 其实不应该发生 Log.e(TAG, "Folder order not properly persisted during bind"); if (!findAndSetEmptyCells(item)) { return false; } } CellLayout.LayoutParams lp = new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY); boolean insert = false; textView.setOnKeyListener(new FolderKeyEventListener()); mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int) item.id, lp, true); return true; }
private void setupContentDimensions(int count) { ArrayList<View> list = getItemsInReadingOrder(); int countX = mContent.getCountX(); int countY = mContent.getCountY(); boolean done = false; while (!done) { int oldCountX = countX; int oldCountY = countY; if (countX * countY < count) { // Current grid is too small, expand it if ((countX <= countY || countY == mMaxCountY) && countX < mMaxCountX) { countX++; } else if (countY < mMaxCountY) { countY++; } if (countY == 0) countY++; } else if ((countY - 1) * countX >= count && countY >= countX) { countY = Math.max(0, countY - 1); } else if ((countX - 1) * countY >= count) { countX = Math.max(0, countX - 1); } done = countX == oldCountX && countY == oldCountY; } mContent.setGridSize(countX, countY); arrangeChildren(list); }
@Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (mInScrollArea && !LauncherApplication.isScreenLarge()) { Workspace workspace = mLauncher.getWorkspace(); int width = workspace.getWidth(); Rect childRect = new Rect(); getDescendantRectRelativeToSelf(workspace.getChildAt(0), childRect); int page = workspace.getNextPage(); final boolean isRtl = isLayoutDirectionRtl(); CellLayout leftPage = (CellLayout) workspace.getChildAt(isRtl ? page + 1 : page - 1); CellLayout rightPage = (CellLayout) workspace.getChildAt(isRtl ? page - 1 : page + 1); if (leftPage != null && leftPage.getIsDragOverlapping()) { mLeftHoverDrawable.setBounds( 0, childRect.top, mLeftHoverDrawable.getIntrinsicWidth(), childRect.bottom); mLeftHoverDrawable.draw(canvas); } else if (rightPage != null && rightPage.getIsDragOverlapping()) { mRightHoverDrawable.setBounds( width - mRightHoverDrawable.getIntrinsicWidth(), childRect.top, width, childRect.bottom); mRightHoverDrawable.draw(canvas); } } }
@Override protected void onFinishInflate() { super.onFinishInflate(); mContent = (CellLayout) findViewById(R.id.folder_content); mContent.setGridSize(0, 0); mContent.getChildrenLayout().setMotionEventSplittingEnabled(false); mFolderName = (FolderEditText) findViewById(R.id.folder_name); mFolderName.setFolder(this); mFolderName.setOnFocusChangeListener(this); // We find out how tall the text view wants to be (it is set to wrap_content), so that // we can allocate the appropriate amount of space for it. int measureSpec = MeasureSpec.UNSPECIFIED; mFolderName.measure(measureSpec, measureSpec); mFolderNameHeight = mFolderName.getMeasuredHeight(); // We disable action mode for now since it messes up the view on phones mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); mFolderName.setOnEditorActionListener(this); mFolderName.setSelectAllOnFocus(true); mFolderName.setInputType( mFolderName.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); }
void clearChildrenCache() { final int count = getChildCount(); for (int i = 0; i < count; i++) { final CellLayout layout = (CellLayout) getChildAt(i); layout.setChildrenDrawnWithCacheEnabled(false); } }
public void onDrop( DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { final ItemInfo item = (ItemInfo) dragInfo; if (item instanceof ShortcutInfo) { final ShortcutInfo mShortcutInfo = (ShortcutInfo) item; if ((mShortcutInfo.title.equals("天气") || mShortcutInfo.title.equals("发现") || mShortcutInfo.title.equals("扫一扫") || mShortcutInfo.title.equals("账户")) && mShortcutInfo.url.equals("")) { shortcutCreate_ZhiDing(mLauncher, mShortcutInfo, mShortcutInfo.title.toString()); } else { Tools.shortcutCreate( mLauncher, mShortcutInfo.title.toString(), mShortcutInfo.getIcon(), mShortcutInfo.url.toString()); } CellLayout child = (CellLayout) mWorkspace.getChildAt(mShortcutInfo.screen); child.animateGapRover(); child.requestLayout(); } }
@Override protected void onFinishInflate() { super.onFinishInflate(); mContent = (CellLayout) findViewById(R.id.folder_content); mContent.setGridSize(0, 0); mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false); mFolderName = (FolderEditText) findViewById(R.id.folder_name); mFolderName.setFolder(this); mFolderName.setOnFocusChangeListener(this); // 算出TextView最终需要多大,以便可以给它腾出适合大小的地方 int measureSpec = MeasureSpec.UNSPECIFIED; mFolderName.measure(measureSpec, measureSpec); mFolderNameHeight = mFolderName.getMeasuredHeight(); // We disable action mode for now since it messes up the view on phones // 暂时禁止action mode,因为它有可能会情致view混乱 mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); mFolderName.setOnEditorActionListener(this); mFolderName.setSelectAllOnFocus(true); mFolderName.setInputType( mFolderName.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); }
void setCellLayoutPressedOrFocusedIcon() { if (getParent() instanceof ShortcutAndWidgetContainer) { ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) getParent(); if (parent != null) { CellLayout layout = (CellLayout) parent.getParent(); layout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null); } } }
public void onDragEnter(Object dragInfo) { if (!willAcceptItem((ItemInfo) dragInfo)) return; CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams(); CellLayout layout = (CellLayout) getParent().getParent(); mFolderRingAnimator.setCell(lp.cellX, lp.cellY); mFolderRingAnimator.setCellLayout(layout); mFolderRingAnimator.animateToAcceptState(); layout.showFolderAccept(mFolderRingAnimator); }
void setCellLayoutPressedOrFocusedIcon() { final View shortcutView = (View) getParent(); if (shortcutView != null) { final View cellLayoutChildren = (View) shortcutView.getParent(); if (cellLayoutChildren != null && cellLayoutChildren instanceof CellLayoutChildren) { CellLayout layout = (CellLayout) cellLayoutChildren.getParent(); layout.setPressedOrFocusedIcon((mPressedOrFocusedBackground != null) ? this : null); } } }
/** 以图标为中心,中心对齐,比如缩放时要以中心对齐 */ private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight; DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; int currentPage = mLauncher.getWorkspace().getCurrentPage(); // In case the workspace is scrolling, we need to use the final scroll // to compute // the folders bounds. // 如果workspace正在滚动,就强制滚动到最后以计算最终的位置 mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren // 首先获取可见CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll // 强制重置workspace的滚动状态 mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // 重新调整folder的边界,如果有需要的话,比如实际内容比folder要更大或者更小 int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); // 如果实际内容比folder要更大或者更小,那么调整为实际大小 if (width >= bounds.width()) { left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); // 设置Folder的锚点 setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
public boolean onDragOver( DragSource source, int x, int y, int xOffset, int yOffset, DragView dragView, Object dragInfo) { Log.d(TAG, "onDragOver " + x + "," + y + "," + xOffset + "," + yOffset); // if (!mContent.mOverLeftRect.contains(x, y)) { // return false; // } CellLayout targetCelllayout = (CellLayout) getParent(); if (targetCelllayout == null) { return false; } CellLayout.LayoutParams targetLp = (CellLayout.LayoutParams) getLayoutParams(); final int tempTargetCellX = targetLp.cellX; final int tempTargetCellY = targetLp.cellY; boolean result = false; boolean needToShowAsFolderIcon = false; if (mContent.mOverLeftRect.contains(x, y)) { result = targetCelllayout.movePos(tempTargetCellX, tempTargetCellY, true); } else if (mContent.mOverRightrRect.contains(x, y)) { result = targetCelllayout.movePos(tempTargetCellX, tempTargetCellY, false); } else if (mContent.mCenterRect.contains(x, y)) { needToShowAsFolderIcon = true; } if (needToShowAsFolderIcon) { setFolderIcon(dragInfo); } else { setOrilIcon(dragInfo); } return result; // if (!targetCelllayout.movePos(tempTargetCellX, tempTargetCellY, // false)) { // return false; // } // final ShortcutInfo info = (ShortcutInfo) getTag(); // final Bitmap mFolderIcon = info.getIcon(mLauncher.getIconCache()); // mContent.setIphoneIcon(mFolderIcon); // if (getAnimation() != null && getAnimation().hasStarted()) // showUninstallBtn(true); // return true; }
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float scale = parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); int centerX = (int) (mTempRect.left + mTempRect.width() * scale / 2); int centerY = (int) (mTempRect.top + mTempRect.height() * scale / 2); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; int currentPage = mLauncher.getWorkspace().getNextPage(); // In case the workspace is scrolling, we need to use the final scroll to compute // the folders bounds. mLauncher.getWorkspace().setFinalScrollForPageChange(currentPage); // We first fetch the currently visible CellLayoutChildren CellLayout currentLayout = (CellLayout) mLauncher.getWorkspace().getChildAt(currentPage); ShortcutAndWidgetContainer boundingLayout = currentLayout.getShortcutsAndWidgets(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We reset the workspaces scroll mLauncher.getWorkspace().resetFinalScrollForPageChange(currentPage); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); if (grid.isPhone() && (grid.availableWidthPx - width) < grid.iconSizePx) { // Center the folder if it is full (on phones only) left = (grid.availableWidthPx - width) / 2; } else if (width >= bounds.width()) { // If the folder doesn't fit within the bounds, center it about the desired bounds left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); mFolderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); mFolderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); lp.width = width; lp.height = height; lp.x = left; lp.y = top; }
@Override protected void onFinishInflate() { super.onFinishInflate(); if (mCellCountX < 0) mCellCountX = DEFAULT_CELL_COUNT_X; if (mCellCountY < 0) mCellCountY = DEFAULT_CELL_COUNT_Y; mContent = (CellLayout) findViewById(R.id.layout); mContent.setGridSize(mCellCountX, mCellCountY); mContent.setIsHotseat(true); resetLayout(); }
@Override protected void onFinishInflate() { super.onFinishInflate(); if (mCellCountX < 0) mCellCountX = LauncherModel.getCellCountX(); if (mCellCountY < 0) mCellCountY = LauncherModel.getCellCountY(); mContent = (CellLayout) findViewById(R.id.layout); mContent.setGridSize(mCellCountX, mCellCountY); mContent.setIsHotseat(true); resetLayout(); }
private View getViewForInfo(ShortcutInfo item) { for (int j = 0; j < mContent.getCountY(); j++) { for (int i = 0; i < mContent.getCountX(); i++) { View v = mContent.getChildAt(i, j); if (v.getTag() == item) { return v; } } } return null; }
@Override protected void onFinishInflate() { super.onFinishInflate(); mScrollView = (ScrollView) findViewById(R.id.scroll_view); mContent = (CellLayout) findViewById(R.id.folder_content); mFocusIndicatorHandler = new FocusIndicatorView(getContext()); mContent.addView(mFocusIndicatorHandler, 0); mFocusIndicatorHandler.getLayoutParams().height = FocusIndicatorView.DEFAULT_LAYOUT_SIZE; mFocusIndicatorHandler.getLayoutParams().width = FocusIndicatorView.DEFAULT_LAYOUT_SIZE; LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx); mContent.setGridSize(0, 0); mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false); mContent.setInvertIfRtl(true); mFolderName = (FolderEditText) findViewById(R.id.folder_name); mFolderName.setFolder(this); if (mLauncher.getLockWorkspace()) { mFolderName.setKeyListener(null); mFolderName.setFocusable(false); } else { mFolderName.setOnFocusChangeListener(this); } // We find out how tall the text view wants to be (it is set to wrap_content), so that // we can allocate the appropriate amount of space for it. int measureSpec = MeasureSpec.UNSPECIFIED; mFolderName.measure(measureSpec, measureSpec); mFolderNameHeight = mFolderName.getMeasuredHeight(); // We disable action mode for now since it messes up the view on phones mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback); mFolderName.setOnEditorActionListener(this); mFolderName.setSelectAllOnFocus(true); mFolderName.setInputType( mFolderName.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_CAP_WORDS); mAutoScrollHelper = new FolderAutoScrollHelper(mScrollView); boolean hideFolderName = SettingsProvider.getBoolean(mLauncher, SettingsProvider.HIDE_FOLDER_NAME, false); if (hideFolderName) { mFolderName.setVisibility(View.GONE); mFolderNameHeight = 0; } }
public View getViewForTag(Object tag) { int screenCount = mItemCount; for (int screen = 0; screen < screenCount; screen++) { CellLayout currentScreen = ((CellLayout) getChildAt(screen)); int count = currentScreen.getChildCount(); for (int i = 0; i < count; i++) { View child = currentScreen.getChildAt(i); if (child.getTag() == tag) { return child; } } } return null; }
private void centerAboutIcon() { DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight; DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer); parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect); int centerX = mTempRect.centerX(); int centerY = mTempRect.centerY(); int centeredLeft = centerX - width / 2; int centeredTop = centerY - height / 2; // We first fetch the currently visible CellLayoutChildren CellLayout currentPage = mLauncher.getWorkspace().getCurrentDropLayout(); CellLayoutChildren boundingLayout = currentPage.getChildrenLayout(); Rect bounds = new Rect(); parent.getDescendantRectRelativeToSelf(boundingLayout, bounds); // We need to bound the folder to the currently visible CellLayoutChildren int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width); int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height); // If the folder doesn't fit within the bounds, center it about the desired bounds if (width >= bounds.width()) { left = bounds.left + (bounds.width() - width) / 2; } if (height >= bounds.height()) { top = bounds.top + (bounds.height() - height) / 2; } int folderPivotX = width / 2 + (centeredLeft - left); int folderPivotY = height / 2 + (centeredTop - top); setPivotX(folderPivotX); setPivotY(folderPivotY); int folderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width)); int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height)); mFolderIcon.setPivotX(folderIconPivotX); mFolderIcon.setPivotY(folderIconPivotY); if (mMode == PARTIAL_GROW) { lp.width = width; lp.height = height; lp.x = left; lp.y = top; } else { mNewSize.set(left, top, left + width, top + height); } }
void setStayPressed(boolean stayPressed) { mStayPressed = stayPressed; if (!stayPressed) { mPressedBackground = null; } // Only show the shadow effect when persistent pressed state is set. if (getParent() instanceof ShortcutAndWidgetContainer) { CellLayout layout = (CellLayout) getParent().getParent(); layout.setPressedIcon(this, mPressedBackground, mOutlineHelper.shadowBitmapPadding); } updateIconState(); }
public ArrayList<View> getItemsInReadingOrder() { if (mItemsInvalidated) { mItemsInReadingOrder.clear(); for (int j = 0; j < mContent.getCountY(); j++) { for (int i = 0; i < mContent.getCountX(); i++) { View v = mContent.getChildAt(i, j); if (v != null) { mItemsInReadingOrder.add(v); } } } mItemsInvalidated = false; } return mItemsInReadingOrder; }
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight; int contentWidthSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredWidth(), MeasureSpec.EXACTLY); int contentHeightSpec = MeasureSpec.makeMeasureSpec(mContent.getDesiredHeight(), MeasureSpec.EXACTLY); mContent.measure(contentWidthSpec, contentHeightSpec); mFolderName.measure( contentWidthSpec, MeasureSpec.makeMeasureSpec(mFolderNameHeight, MeasureSpec.EXACTLY)); setMeasuredDimension(width, height); }
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); }
public boolean onLongClick(View v) { // 返回是否全局拖动被禁止,如果是,则不执行下面的动作 if (!mLauncher.isDraggingEnabled()) return true; Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { ShortcutInfo item = (ShortcutInfo) tag; if (!v.isInTouchMode()) { return false; } mLauncher.dismissFolderCling(null); mLauncher.getWorkspace().onDragStartedWithItem(v); mLauncher.getWorkspace().beginDragShared(v, this); // 此处发起拖动 mIconDrawable = ((TextView) v).getCompoundDrawables()[1]; mCurrentDragInfo = item; mEmptyCell[0] = item.cellX; mEmptyCell[1] = item.cellY; mCurrentDragView = v; mContent.removeView(mCurrentDragView); mInfo.remove(mCurrentDragInfo); mDragInProgress = true; mItemAddedBackToSelfViaIcon = false; } return true; }
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); }
public boolean onLongClick(View v) { // Return if workspace is locked if (mLauncher.getLockWorkspace()) return false; // Return if global dragging is not enabled if (!mLauncher.isDraggingEnabled()) return true; Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { ShortcutInfo item = (ShortcutInfo) tag; if (!v.isInTouchMode()) { return false; } mLauncher.getWorkspace().beginDragShared(v, this); mCurrentDragInfo = item; mEmptyCell[0] = item.cellX; mEmptyCell[1] = item.cellY; mCurrentDragView = v; mContent.removeView(mCurrentDragView); mInfo.remove(mCurrentDragInfo); mDragInProgress = true; mItemAddedBackToSelfViaIcon = false; } return true; }
public void onTouchUp() { int xThreshold = mCellLayout.getCellWidth() + mCellLayout.getWidthGap(); int yThreshold = mCellLayout.getCellHeight() + mCellLayout.getHeightGap(); mDeltaXAddOn = mRunningHInc * xThreshold; mDeltaYAddOn = mRunningVInc * yThreshold; mDeltaX = 0; mDeltaY = 0; post( new Runnable() { @Override public void run() { snapToWidget(true); } }); }
/** 数据有变化,则清空数据并且重建 */ void notifyDataSetChanged() { // recreate all the children if the data set changes under us. We may // want to do this more // intelligently (ie just removing the views that should no longer // exist) mContent.removeAllViewsInLayout(); bind(mInfo); }