Пример #1
0
  /** 向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;
  }
Пример #2
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);
 }
Пример #3
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);
 }
Пример #4
0
  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;
  }
Пример #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);
  }
  protected View createAndAddShortcut(ShortcutInfo item) {
    final BubbleTextView textView =
        (BubbleTextView) mInflater.inflate(R.layout.folder_application, this, false);
    textView.applyFromShortcutInfo(item, mIconCache, false);

    int color =
        SettingsProvider.getInt(
            getContext(),
            SettingsProvider.FOLDER_ICON_TEXT_COLOR,
            getResources().getColor(R.color.folder_items_text_color));
    textView.setTextColor(color);

    textView.setOnClickListener(this);
    textView.setOnLongClickListener(this);
    textView.setOnFocusChangeListener(mFocusIndicatorHandler);

    // We need to check here to verify that the given item's location isn't already occupied
    // by another item.
    if (mContent.getChildAt(item.cellX, item.cellY) != null
        || item.cellX < 0
        || item.cellY < 0
        || item.cellX >= mContent.getCountX()
        || item.cellY >= mContent.getCountY()) {
      // This shouldn't happen, log it.
      Log.e(TAG, "Folder order not properly persisted during bind");
      if (!findAndSetEmptyCells(item)) {
        return null;
      }
    }

    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 textView;
  }
Пример #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;
  }