예제 #1
0
  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();
    }
  }
  public void applyFromShortcutInfo(
      ShortcutInfo info,
      IconCache iconCache,
      boolean setDefaultPadding,
      boolean promiseStateChanged) {
    Bitmap b = info.getIcon(iconCache);
    LauncherAppState app = LauncherAppState.getInstance();

    // SPRD: bug372523 2014-11-21 Feature show unread mmssms/missed calls info.
    b = app.getUnreadInfoManager().getBitmapWithUnreadInfo(info, b);

    FastBitmapDrawable iconDrawable = Utilities.createIconDrawable(b);
    iconDrawable.setGhostModeEnabled(info.isDisabled != 0);

    setCompoundDrawables(null, iconDrawable, null, null);
    if (setDefaultPadding) {
      DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
      setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
    }
    if (info.contentDescription != null) {
      setContentDescription(info.contentDescription);
    }
    setText(info.title);
    setTag(info);

    if (promiseStateChanged || info.isPromise()) {
      applyState(promiseStateChanged);
    }
  }
  public void applyState(boolean promiseStateChanged) {
    if (getTag() instanceof ShortcutInfo) {
      ShortcutInfo info = (ShortcutInfo) getTag();
      final boolean isPromise = info.isPromise();
      final int progressLevel =
          isPromise
              ? ((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)
                  ? info.getInstallProgress()
                  : 0))
              : 100;

      Drawable[] drawables = getCompoundDrawables();
      Drawable top = drawables[1];
      if (top != null) {
        final PreloadIconDrawable preloadDrawable;
        if (top instanceof PreloadIconDrawable) {
          preloadDrawable = (PreloadIconDrawable) top;
        } else {
          preloadDrawable = new PreloadIconDrawable(top, getPreloaderTheme());
          setCompoundDrawables(drawables[0], preloadDrawable, drawables[2], drawables[3]);
        }

        preloadDrawable.setLevel(progressLevel);
        if (promiseStateChanged) {
          preloadDrawable.maybePerformFinishedAnimation();
        }
      }
    }
  }
예제 #4
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);
 }
예제 #5
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);
 }
  private void setFolderIcon(Object dragInfo) {

    if (mIsFolderIconMode) {
      return;
    }

    if (dragInfo instanceof UserFolderInfo) {
      // it is a foler icon return
      return;
    }
    final ShortcutInfo info = (ShortcutInfo) getTag();
    if (info.container >= 0) {
      // i am in a folder return
      return;
    }
    final Bitmap mFolderIcon = info.getIcon(mLauncher.getIconCache());
    mContent.setCompoundDrawablesWithIntrinsicBounds(
        null,
        new FastBitmapDrawable(
            Utilities.makeGridFolderIcons(new Bitmap[] {mFolderIcon}, getContext())),
        null,
        null);
    showUninstallBtn(false);

    mIsFolderIconMode = true;
  }
예제 #7
0
  @Override
  protected final void writeImpl() {
    writeC(0x45);
    writeD(_shortCuts.size());

    for (final ShortcutInfo sc : _shortCuts) {
      sc.write(this);
    }
  }
예제 #8
0
 /** ApplicationInfo在进入会被归化为ShortcutInfo了,里面只有ShortcutInfo */
 protected boolean findAndSetEmptyCells(ShortcutInfo item) {
   int[] emptyCell = new int[2];
   if (mContent.findCellForSpan(emptyCell, item.spanX, item.spanY)) {
     item.cellX = emptyCell[0];
     item.cellY = emptyCell[1];
     return true;
   } else {
     return false;
   }
 }
예제 #9
0
 /** Fill in {@param shortcutInfo} with the icon and label for {@param info} */
 public synchronized void getTitleAndIcon(
     ShortcutInfo shortcutInfo,
     ComponentName component,
     LauncherActivityInfoCompat info,
     UserHandleCompat user,
     boolean usePkgIcon,
     boolean useLowResIcon) {
   CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon);
   shortcutInfo.setIcon(getNonNullIcon(entry, user));
   shortcutInfo.title = Utilities.trim(entry.title);
   shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
   shortcutInfo.usingLowResIcon = entry.isLowResIcon;
 }
예제 #10
0
 /**
  * Fill in {@param shortcutInfo} with the icon and label for {@param intent}. If the corresponding
  * activity is not found, it reverts to the package icon.
  */
 public synchronized void getTitleAndIcon(
     ShortcutInfo shortcutInfo, Intent intent, UserHandleCompat user, boolean useLowResIcon) {
   ComponentName component = intent.getComponent();
   // null info means not installed, but if we have a component from the intent then
   // we should still look in the cache for restored app icons.
   if (component == null) {
     shortcutInfo.setIcon(getDefaultIcon(user));
     shortcutInfo.title = "";
     shortcutInfo.usingFallbackIcon = true;
     shortcutInfo.usingLowResIcon = false;
   } else {
     LauncherActivityInfoCompat info = mLauncherApps.resolveActivity(intent, user);
     getTitleAndIcon(shortcutInfo, component, info, user, true, useLowResIcon);
   }
 }
  public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
    Bitmap b = info.getIcon(iconCache);

    setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(b), null, null);
    setText(info.title);
    setTag(info);
  }
예제 #12
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;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final ShortcutInfo info = getItem(position);

    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.application_boxed, parent, false);
    }

    final TextView textView = (TextView) convertView;
    Log.i("==ShortcutsAdapter===getView=", "=============");
    textView.setCompoundDrawablesWithIntrinsicBounds(
        null, new FastBitmapDrawable(info.getIcon(mIconCache), res), null, null);
    textView.setText(info.title);

    return convertView;
  }
예제 #14
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;
  }
예제 #15
0
  public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    Bitmap b = info.getIcon(iconCache);
    setCompoundDrawables(null, Utilities.createIconDrawable(b), null, null);
    setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
    setText(info.title);
    setTag(info);
  }
  private void setOrilIcon(Object dragInfo) {
    if (!mIsFolderIconMode) {
      return;
    }
    if (dragInfo instanceof UserFolderInfo) {
      // it is a foler icon return
      return;
    }
    final ShortcutInfo info = (ShortcutInfo) getTag();
    if (info.container >= 0) {
      // i am in a folder return
      return;
    }
    final Bitmap mFolderIcon = info.getIcon(mLauncher.getIconCache());
    mContent.setIphoneIcon(mFolderIcon);
    if (AnimManager.getInstance().isAnim()) showUninstallBtn(true);

    mIsFolderIconMode = false;
  }
예제 #17
0
 public ShortcutInfo getShortcutInfo() {
   if (activityInfo != null) {
     final ShortcutInfo info = new ShortcutInfo();
     info.user = user;
     info.title = label;
     info.contentDescription = label;
     info.customIcon = false;
     info.intent = launchIntent;
     info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
     info.flags = AppInfo.initFlags(activityInfo);
     info.firstInstallTime = activityInfo.getFirstInstallTime();
     return info;
   } else {
     return LauncherAppState.getInstance().getModel().infoFromShortcutIntent(mContext, data);
   }
 }
예제 #18
0
  /** 按阅读顺序排列?从左到右,从上到下。用于从数据库里面读出来的时候放置对象用 */
  private void placeInReadingOrder(ArrayList<ShortcutInfo> items) {
    int maxX = 0;
    int count = items.size();
    for (int i = 0; i < count; i++) {
      ShortcutInfo item = items.get(i);
      if (item.cellX > maxX) {
        maxX = item.cellX;
      }
    }

    GridComparator gridComparator = new GridComparator(maxX + 1);
    Collections.sort(items, gridComparator);
    final int countX = mContent.getCountX();
    for (int i = 0; i < count; i++) {
      int x = i % countX;
      int y = i / countX;
      ShortcutInfo item = items.get(i);
      item.cellX = x;
      item.cellY = y;
    }
  }
예제 #19
0
  /** 创建指定四个快捷方式 天气 发现 扫一扫 账户 */
  private static void shortcutCreate_ZhiDing(
      Context context, ShortcutInfo mShortcutInfo, String type) {

    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra("duplicate", false);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mShortcutInfo.title);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, mShortcutInfo.getIcon());

    Intent intent = new Intent(context, Launcher.class);

    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    Uri uri = Uri.parse(type);
    intent.setData(uri);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    // 发送广播
    context.sendBroadcast(shortcut);
  }
예제 #20
0
  private void onDrop(
      final ShortcutInfo item,
      View animateView,
      Rect finalRect,
      float scaleRelativeToDragLayer,
      int index,
      Runnable postAnimationRunnable) {
    item.cellX = -1;
    item.cellY = -1;

    // Typically, the animateView corresponds to the DragView; however, if this is being done
    // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we
    // will not have a view to animate
    if (animateView != null) {
      DragLayer dragLayer = mLauncher.getDragLayer();
      Rect from = new Rect();
      dragLayer.getViewRectRelativeToSelf(animateView, from);
      Rect to = finalRect;
      if (to == null) {
        to = new Rect();
        Workspace workspace = mLauncher.getWorkspace();
        // Set cellLayout and this to it's final state to compute final animation locations
        workspace.setFinalTransitionTransform((CellLayout) getParent().getParent());
        float scaleX = getScaleX();
        float scaleY = getScaleY();
        setScaleX(1.0f);
        setScaleY(1.0f);
        scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
        // Finished computing final animation locations, restore current state
        setScaleX(scaleX);
        setScaleY(scaleY);
        workspace.resetTransitionTransform((CellLayout) getParent().getParent());
      }

      int[] center = new int[2];
      float scale = getLocalCenterForIndex(index, center);
      center[0] = Math.round(scaleRelativeToDragLayer * center[0]);
      center[1] = Math.round(scaleRelativeToDragLayer * center[1]);

      to.offset(
          center[0] - animateView.getMeasuredWidth() / 2,
          center[1] - animateView.getMeasuredHeight() / 2);

      float finalAlpha = index < NUM_ITEMS_IN_PREVIEW ? 0.5f : 0f;

      dragLayer.animateView(
          animateView,
          from,
          to,
          finalAlpha,
          scale * scaleRelativeToDragLayer,
          DROP_IN_ANIMATION_DURATION,
          new DecelerateInterpolator(2),
          new AccelerateInterpolator(2),
          postAnimationRunnable,
          false);
      postDelayed(
          new Runnable() {
            public void run() {
              addItem(item);
            }
          },
          DROP_IN_ANIMATION_DURATION);
    } else {
      addItem(item);
    }
  }