修改Launcher3中的workspace中的应用图标的大小

以下函数是把从数据库中加载的应用的信息绑定到workspace中。

    public void bindItems(final ArrayList shortcuts, final int start,

                            final int end, final boolean forceAnimateIcons) {

                   Runnable r = new Runnable() {

                            public void run() {

                                     bindItems(shortcuts, start, end, forceAnimateIcons);

                            }

                   };

                   if (waitUntilResume(r)) {

                            return;

                   }

                   // Get the list of added shortcuts and intersect them with the set of

                   // shortcuts here

                   final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();

                   final Collection bounceAnims = new ArrayList();

                   final boolean animateIcons = forceAnimateIcons

                                     && canRunNewAppsAnimation();

                   Workspace workspace = mWorkspace;

                   long newShortcutsScreenId = -1;

                   for (int i = start; i < end; i++) {

                            final ItemInfo item = shortcuts.get(i);

 

                            // Short circuit if we are loading dock items for a configuration

                            // which has no dock

                            if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT

                                               && mHotseat == null) {

                                     continue;

                            }

 

                            switch (item.itemType) {

                            case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:

                            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:

                                     ShortcutInfo info = (ShortcutInfo) item;

                                     View shortcut = createShortcut(info);

 

                                     /*

                                      * TODO: FIX collision case

                                      */

                                     if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {

                                               CellLayout cl = mWorkspace.getScreenWithId(item.screenId);

                                               if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {

                                                        throw new RuntimeException("OCCUPIED");

                                               }

                                     }

 

                                     workspace.addInScreenFromBind(shortcut, item.container,

                                                        item.screenId, item.cellX, item.cellY, 1, 1);

                                     if (animateIcons) {

                                               // Animate all the applications up now

                                               shortcut.setAlpha(0f);

                                               shortcut.setScaleX(0f);

                                               shortcut.setScaleY(0f);

                                               bounceAnims.add(createNewAppBounceAnimation(shortcut, i));

                                               newShortcutsScreenId = item.screenId;

                                     }

                                     break;

                            case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:

                                     FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon,

                                                        this, (ViewGroup) workspace.getChildAt(workspace

                                                                           .getCurrentPage()), (FolderInfo) item,

                                                        mIconCache);

                                     workspace.addInScreenFromBind(newFolder, item.container,

                                                        item.screenId, item.cellX, item.cellY, 1, 1);

                                     break;

                            default:

                                     throw new RuntimeException("Invalid Item Type");

                            }

                   }

 

                   if (animateIcons) {

                            // Animate to the correct page

                            if (newShortcutsScreenId > -1) {

                                     long currentScreenId = mWorkspace

                                                        .getScreenIdForPageIndex(mWorkspace.getNextPage());

                                     final int newScreenIndex = mWorkspace

                                                        .getPageIndexForScreenId(newShortcutsScreenId);

                                     final Runnable startBounceAnimRunnable = new Runnable() {

                                               public void run() {

                                                        anim.playTogether(bounceAnims);

                                                        anim.start();

                                               }

                                     };

                                     if (newShortcutsScreenId != currentScreenId) {

                                               // We post the animation slightly delayed to prevent

                                               // slowdowns

                                               // when we are loading right after we return to launcher.

                                               mWorkspace.postDelayed(new Runnable() {

                                                        public void run() {

                                                                 if (mWorkspace != null) {

                                                                           mWorkspace.snapToPage(newScreenIndex);

                                                                           mWorkspace.postDelayed(startBounceAnimRunnable,

                                                                                             NEW_APPS_ANIMATION_DELAY);

                                                                 }

                                                        }

                                               }, NEW_APPS_PAGE_MOVE_DELAY);

                                     } else {

                                               mWorkspace.postDelayed(startBounceAnimRunnable,

                                                                 NEW_APPS_ANIMATION_DELAY);

                                     }

                            }

                   }

                   workspace.requestLayout();

         }

 

先看其中的:

ShortcutInfo info = (ShortcutInfo) item;

View shortcut = createShortcut(info);

以上代码是根据ShortcutInfo中保存的应用的信息调用createShortcut()函数重新生成一个应用的快捷方式,就是应用图标。

 

再看createShortcut()函数的实现:

View createShortcut(ShortcutInfo info) {

                   return createShortcut(R.layout.application,

                                     (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()),

                                     info);

}

 

调用以下函数:

View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {

                   BubbleTextView favorite = (BubbleTextView) mInflater.inflate(

                                     layoutResId, parent, false);

                   favorite.applyFromShortcutInfo(info, mIconCache);          //创建shortcut

                   favorite.setOnClickListener(this);

                   return favorite;

         }

再以上的函数中,返回的是一个BubbleTextView类型的View,作为应用的shortcut,调用

该对象的applyFromShortcutInfo()方法根据ShortcutInfo创建一个新的View

 

 

再看applyFromShortcufInfo()方法的实现:

public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) {

        Bitmap b = info.getIcon(iconCache);

        LauncherAppState app = LauncherAppState.getInstance();

        DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

 

        setText(info.title);

        setTag(info);

        mRawIcon = b;

    if (info.intent.getComponent() == null) {

        setCompoundDrawables(null,

                Utilities.createIconDrawable(b), null, null);

        setCompoundDrawablePadding(grid.iconDrawablePaddingPx);

 

        return;

    }

         int cctemp = CornerMarkManager.getInstance(getContext()).getNotificationCount(

                info.intent.getComponent().getPackageName());

        if (currentCount != cctemp) {

             currentCount = cctemp;

        FastBitmapDrawable fbd =  (FastBitmapDrawable) Utilities.createIconDrawable(mRawIcon, currentCount);

        fbd.setRawIcon(mRawIcon);

        setCompoundDrawables(null,

                fbd, null, null);

        }else {

                 Log.i("Garment16", "111111111111111111111");

            setCompoundDrawables(null,

                    Utilities.createIconDrawable(b), null, null);

            setCompoundDrawablePadding(grid.iconDrawablePaddingPx);

        }

            mCornerMarkMessageReceiver = new CornerMarkMessageReceiver(

                    CornerMarkManager.getInstance(getContext()),

                    info.intent.getComponent().getPackageName()) {

 

                @Override

                public void onRecieve(int messagecount) {

 

                    if (currentCount == messagecount) {

                        return;

                    }

                    currentCount = messagecount;

                    FastBitmapDrawable fbd =  (FastBitmapDrawable) Utilities.createIconDrawable(mRawIcon, currentCount);

                    fbd.setRawIcon(mRawIcon);

                    setCompoundDrawables(null,

                            fbd, null, null);

                }

            };

}

 

该函数中setText(info.title)用于Icon的名称,

创建图标的主要的代码是:

setCompoundDrawables(null,Utilities.createIconDrawable(b), null, null);

其中Utilities.createIconDrawable(b)创建一个确定大小的Icon图标,再看createIconDrawable(b)的代码的实现:

static Drawable createIconDrawable(Bitmap icon) {

                   return createIconDrawableWithRawSize(icon);

         }

 

static Drawable createIconDrawableWithRawSize(Bitmap icon) {

 

                   FastBitmapDrawable d = new FastBitmapDrawable(icon);

                   d.setFilterBitmap(true);

                   resizeIconDrawable(d);

                   return d;

         }

 

以上代码的resizeIconDrawable(d)函数用于重新生成大小确定的应用Icon

再看resizeIconDrawable()函数的实现:

 

 

 

static void resizeIconDrawable(Drawable icon) {

//               icon.setBounds(0, 0, sIconTextureWidth, sIconTextureHeight);

                   icon.setBounds(0, 0, sIconTextureWidth+56, sIconTextureHeight+56);

         }

其中调用setBounds()函数进行icon的大小的设置,该函数的作用:Specify a bounding rectangle for the Drawable. This is where the drawable will draw when its draw() method is called.

 

暂时的做法就是直接修改是sIconTextureWidthsIconTextureHeight的值的大小,达到修改应用Icon的大小的目的。

你可能感兴趣的:(修改Launcher3中的workspace中的应用图标的大小)