Пример #1
0
  /** 以图标为中心,中心对齐,比如缩放时要以中心对齐 */
  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;
  }
  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;
  }
Пример #3
0
  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);
    }
  }
Пример #4
0
  public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, boolean success) {
    if (success) {
      if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
        replaceFolderWithFinalItem();
      }
    } else {
      // 拖动失败,将item还给folder。这是由Folder向外拖出时调用的
      mFolderIcon.onDrop(d);

      // TODO
      // We're going to trigger a "closeFolder" which may occur before
      // this item has
      // been added back to the folder -- this could cause the folder to
      // be deleted
      if (mOnExitAlarm.alarmPending()) {
        mSuppressFolderDeletion = true;
      }
    }

    if (target != this) {
      if (mOnExitAlarm.alarmPending()) {
        mOnExitAlarm.cancelAlarm();
        completeDragExit();
      }
    }
    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragInfo = null;
    mCurrentDragView = null;
    mSuppressOnAdd = false;

    // 可能要重新排序,保存到数据库中
    updateItemLocationsInDatabase();
  }
Пример #5
0
  public void onDropCompleted(View target, DragObject d, boolean success) {
    if (success) {
      if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
        replaceFolderWithFinalItem();
      }
    } else {
      // The drag failed, we need to return the item to the folder
      mFolderIcon.onDrop(d);

      // We're going to trigger a "closeFolder" which may occur before this item has
      // been added back to the folder -- this could cause the folder to be deleted
      if (mOnExitAlarm.alarmPending()) {
        mSuppressFolderDeletion = true;
      }
    }

    if (target != this) {
      if (mOnExitAlarm.alarmPending()) {
        mOnExitAlarm.cancelAlarm();
        completeDragExit();
      }
    }
    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragInfo = null;
    mCurrentDragView = null;
    mSuppressOnAdd = false;

    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    updateItemLocationsInDatabase();
  }
Пример #6
0
  void addAllAppsFolder(
      IconCache iconCache,
      ArrayList<AppInfo> allApps,
      ArrayList<ComponentName> onWorkspace,
      Launcher launcher,
      Workspace workspace) {
    if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
      FolderInfo fi = new FolderInfo();

      fi.cellX = getCellXFromOrder(mAllAppsButtonRank);
      fi.cellY = getCellYFromOrder(mAllAppsButtonRank);
      fi.spanX = 1;
      fi.spanY = 1;
      fi.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT;
      fi.screenId = mAllAppsButtonRank;
      fi.itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
      fi.title = "More Apps";
      LauncherModel.addItemToDatabase(
          launcher, fi, fi.container, fi.screenId, fi.cellX, fi.cellY, false);
      FolderIcon folder =
          FolderIcon.fromXml(R.layout.folder_icon, launcher, getLayout(), fi, iconCache);
      workspace.addInScreen(
          folder, fi.container, fi.screenId, fi.cellX, fi.cellY, fi.spanX, fi.spanY);

      for (AppInfo info : allApps) {
        ComponentName cn = info.intent.getComponent();
        if (!onWorkspace.contains(cn)) {
          Log.d(TAG, "Adding to 'more apps': " + info.intent);
          ShortcutInfo si = info.makeShortcut();
          fi.add(si);
        }
      }
    }
  }
  private void replaceFolderWithFinalItem() {
    // Add the last remaining child to the workspace in place of the folder
    Runnable onCompleteRunnable =
        new Runnable() {
          @Override
          public void run() {
            CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId);

            View child = null;
            // Move the item from the folder to the workspace, in the position of the folder
            if (getItemCount() == 1) {
              ShortcutInfo finalItem = mInfo.contents.get(0);
              child = mLauncher.createShortcut(R.layout.application, cellLayout, finalItem);
              LauncherModel.addOrMoveItemInDatabase(
                  mLauncher, finalItem, mInfo.container, mInfo.screenId, mInfo.cellX, mInfo.cellY);
            }
            if (getItemCount() <= 1) {
              // Remove the folder
              LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
              if (cellLayout != null) {
                // b/12446428 -- sometimes the cell layout has already gone away?
                cellLayout.removeView(mFolderIcon);
              }
              if (mFolderIcon instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) mFolderIcon);
              }
              mLauncher.removeFolder(mInfo);
            }
            // We add the child after removing the folder to prevent both from existing at
            // the same time in the CellLayout.  We need to add the new item with
            // addInScreenFromBind()
            // to ensure that hotseat items are placed correctly.
            if (child != null) {
              mLauncher
                  .getWorkspace()
                  .addInScreenFromBind(
                      child,
                      mInfo.container,
                      mInfo.screenId,
                      mInfo.cellX,
                      mInfo.cellY,
                      mInfo.spanX,
                      mInfo.spanY);
            }
          }
        };
    View finalChild = getItemAt(0);
    if (finalChild != null) {
      mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
    } else {
      onCompleteRunnable.run();
    }
    mDestroyed = true;
  }
Пример #8
0
  void addAppsToAllAppsFolder(ArrayList<AppInfo> apps) {
    if (AppsCustomizePagedView.DISABLE_ALL_APPS) {
      View v =
          mContent.getChildAt(
              getCellXFromOrder(mAllAppsButtonRank), getCellYFromOrder(mAllAppsButtonRank));
      FolderIcon fi = null;

      if (v instanceof FolderIcon) {
        fi = (FolderIcon) v;
      } else {
        return;
      }

      FolderInfo info = fi.getFolderInfo();
      for (AppInfo a : apps) {
        ShortcutInfo si = a.makeShortcut();
        info.add(si);
      }
    }
  }
  public void onDropCompleted(
      final View target, final DragObject d, final boolean isFlingToDelete, final boolean success) {
    if (mDeferDropAfterUninstall) {
      Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
      mDeferredAction =
          new Runnable() {
            public void run() {
              onDropCompleted(target, d, isFlingToDelete, success);
              mDeferredAction = null;
            }
          };
      return;
    }

    boolean beingCalledAfterUninstall = mDeferredAction != null;
    boolean successfulDrop = success && (!beingCalledAfterUninstall || mUninstallSuccessful);

    if (successfulDrop) {
      if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) {
        replaceFolderWithFinalItem();
      }
    } else {
      setupContentForNumItems(getItemCount());
      // The drag failed, we need to return the item to the folder
      mFolderIcon.onDrop(d);
    }

    if (target != this) {
      if (mOnExitAlarm.alarmPending()) {
        mOnExitAlarm.cancelAlarm();
        if (!successfulDrop) {
          mSuppressFolderDeletion = true;
        }
        completeDragExit();
      }
    }

    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragInfo = null;
    mCurrentDragView = null;
    mSuppressOnAdd = false;

    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    updateItemLocationsInDatabaseBatch();
  }
  void bind(FolderInfo info) {
    mInfo = info;
    ArrayList<ShortcutInfo> children = info.contents;
    ArrayList<ShortcutInfo> overflow = new ArrayList<ShortcutInfo>();
    setupContentForNumItems(children.size());
    placeInReadingOrder(children);
    int count = 0;
    for (int i = 0; i < children.size(); i++) {
      ShortcutInfo child = (ShortcutInfo) children.get(i);
      if (createAndAddShortcut(child) == null) {
        overflow.add(child);
      } else {
        count++;
      }
    }

    // We rearrange the items in case there are any empty gaps
    setupContentForNumItems(count);

    // If our folder has too many items we prune them from the list. This is an issue
    // when upgrading from the old Folders implementation which could contain an unlimited
    // number of items.
    for (ShortcutInfo item : overflow) {
      mInfo.remove(item);
      LauncherModel.deleteItemFromDatabase(mLauncher, item);
    }

    mItemsInvalidated = true;
    updateTextViewFocus();
    mInfo.addListener(this);

    if (!sDefaultFolderName.contentEquals(mInfo.title)) {
      mFolderName.setText(mInfo.title);
    } else {
      mFolderName.setText("");
    }
    updateItemLocationsInDatabase();

    // In case any children didn't come across during loading, clean up the folder accordingly
    mFolderIcon.post(
        new Runnable() {
          public void run() {
            if (getItemCount() <= 1) {
              replaceFolderWithFinalItem();
            }
          }
        });
  }
Пример #11
0
  /** 用最后一个剩余的item代替当前folder显示在桌面上,这发生在Folder里面只有一个item的时候 */
  private void replaceFolderWithFinalItem() {
    Runnable onCompleteRunnable =
        new Runnable() {
          @Override
          public void run() {
            CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screen);

            View child = null;
            // 将最后一个item从Folder移动到桌面上,与Folder一个位置。
            // 但是在这个if块里面并没有实际移动,而仅仅是生成数据并放到了数据库中。
            if (getItemCount() == 1) {
              ShortcutInfo finalItem = mInfo.contents.get(0);
              child = mLauncher.createShortcut(R.layout.application, cellLayout, finalItem);
              LauncherModel.addOrMoveItemInDatabase(
                  mLauncher, finalItem, mInfo.container, mInfo.screen, mInfo.cellX, mInfo.cellY);
            }
            if (getItemCount() <= 1) {
              // 删除Folder
              LauncherModel.deleteItemFromDatabase(mLauncher, mInfo);
              cellLayout.removeView(mFolderIcon);
              if (mFolderIcon instanceof DropTarget) {
                mDragController.removeDropTarget((DropTarget) mFolderIcon);
              }
              mLauncher.removeFolder(mInfo);
            }
            // 在删除文件夹后才添加最后一个item到桌面,这是为了防止在同一时间同一位置有两个item
            if (child != null) {
              mLauncher
                  .getWorkspace()
                  .addInScreen(
                      child,
                      mInfo.container,
                      mInfo.screen,
                      mInfo.cellX,
                      mInfo.cellY,
                      mInfo.spanX,
                      mInfo.spanY);
            }
          }
        };
    View finalChild = getItemAt(0);
    if (finalChild != null) {
      // 文件夹销毁动画
      mFolderIcon.performDestroyAnimation(finalChild, onCompleteRunnable);
    }
    mDestroyed = true;
  }
Пример #12
0
  private void onCloseComplete() {
    DragLayer parent = (DragLayer) getParent();
    parent.removeView(this);
    mDragController.removeDropTarget((DropTarget) this);
    clearFocus();
    mFolderIcon.requestFocus();

    if (mRearrangeOnClose) {
      setupContentForNumItems(getItemCount());
      mRearrangeOnClose = false;
    }
    if (getItemCount() <= 1) {
      if (!mDragInProgress && !mSuppressFolderDeletion) {
        replaceFolderWithFinalItem();
      } else if (mDragInProgress) {
        mDeleteFolderOnDropCompleted = true;
      }
    }
    mSuppressFolderDeletion = false;
  }
Пример #13
0
  @Override
  public void onThemeChanged() {
    /*mModel.resetLoadedState(false, true);
    //##date:2013/12/08 ##author:hongxing.whx ##bugid: 72248
    mModel.setThemeChanged(true);
    YUNOS END
    mModel.startLoaderFromBackground();*/

    /*YUNOS BEGIN*/
    // ##date:2014/8/1 ##author:zhangqiang.zq
    // favorite app
    GadgetCardHelper.onThemeChanged();
    LauncherGadgetHelper.cleanUp();
    mRecommendTask.refreshFavoriteAppIcons();
    /* YUNOS END */
    ThemeResources.reset();
    FolderIcon.onThemeChanged();
    mModel.onThemeChange();
    LauncherAnimUtils.onDestroyActivity();
  }
  public void onDrop(
      DragSource source,
      int x,
      int y,
      int xOffset,
      int yOffset,
      DragView dragView,
      Object dragInfo) {
    // get workspace
    ViewParent parent = getParent();
    if (parent == null) {
      return;
    }

    Workspace mTargetWorkspace = (Workspace) parent.getParent();

    final int workspaceType = mTargetWorkspace.getType();
    int container = 0;
    switch (workspaceType) {
      case Workspace.WORKSPACE_NAVIGATEBAR:
        container = LauncherSettings.Favorites.CONTAINER_NAVIGATEBAR;
        break;
      case Workspace.WORKSPACE_WORKSPACE:
        container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
        break;
      default:
        return;
    }

    final CellLayout.LayoutParams currentLp = (CellLayout.LayoutParams) getLayoutParams();
    // CellLayout targetCelllayout = (CellLayout) getParent();

    // remove my in parent
    removeSelfInParent(mLauncher.getDragController());
    // clearAnimation();
    // targetCelllayout.removeView(this);

    // make the folder info.

    final UserFolderInfo folderInfo = new UserFolderInfo();
    folderInfo.title = getResources().getText(R.string.folder_name);
    // add folder into db
    LauncherModel.addItemToDatabase(
        getContext(),
        folderInfo,
        container,
        mTargetWorkspace.getCurrentScreen(),
        currentLp.cellX,
        currentLp.cellY,
        true);

    // add into new folder
    // CellLayout.CellInfo cellInfo = mSourceWorkspace.getCurrentDragInfo();

    final ShortcutInfo thisTag = (ShortcutInfo) getTag();
    final ShortcutInfo sourceTag = (ShortcutInfo) dragInfo;
    final int oldSourceScreen = sourceTag.screen;
    folderInfo.add(thisTag);
    folderInfo.add(sourceTag);

    // add folder items into db
    LauncherModel.addOrMoveItemInDatabase(mLauncher, thisTag, folderInfo.id, 0, 0, 0);
    LauncherModel.addOrMoveItemInDatabase(mLauncher, sourceTag, folderInfo.id, 0, 0, 0);

    // Create the view
    final FolderIcon newFolder =
        FolderIcon.fromXml(
            R.layout.folder_icon,
            mLauncher,
            (ViewGroup) mTargetWorkspace.getChildAt(mTargetWorkspace.getCurrentScreen()),
            folderInfo);

    // add into target cell
    mTargetWorkspace.addInCurrentScreen(newFolder, currentLp.cellX, currentLp.cellY, 1, 1, false);

    // start anim
    AnimManager.getInstance().startSingle(newFolder);

    // range cell
    Workspace sourceWorkspace = (Workspace) source;
    CellLayout sourceCellLayout = (CellLayout) sourceWorkspace.getChildAt(oldSourceScreen);
    sourceCellLayout.rangeChilds(false);

    // open folder
    mTargetWorkspace
        .getHandler()
        .postDelayed(
            new Runnable() {
              public void run() {
                mLauncher.handleIphoneFolderClick(folderInfo, newFolder);
              }
            },
            200);
  }