天天看點

Android8.1 Launcher3 去掉抽屜(二)Android8.1 Launcher3 去掉抽屜(二)

Android8.1 Launcher3 去掉抽屜(二)

上篇部落格是如何把allapp放到workspace中,但是遺留了幾個問題:

a.有app變化時,更新workspace;

b.隐藏allapp;

c.去掉長按時的删除選項。

這篇部落格會解決這幾個問題:

1:有app變化時,更新workspace

src/com/android/launcher3/model/PackageUpdatedTask.java -> execute():

......
final ArrayList<AppInfo> addedOrModified = new ArrayList<>();
        addedOrModified.addAll(appsList.added);
        appsList.added.clear();
        addedOrModified.addAll(appsList.modified);
        appsList.modified.clear();

//更新begin
        ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> items = new ArrayList<>();
        synchronized (this) {
            for (AppInfo ai : addedOrModified) {
                Intent data = ai.getIntent();
                data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, data);
                data.putExtra(Intent.EXTRA_SHORTCUT_ICON, ai.iconBitmap);
                data.putExtra(Intent.EXTRA_SHORTCUT_NAME, ai.title);
                InstallShortcutReceiver.PendingInstallShortcutInfo info = new InstallShortcutReceiver.PendingInstallShortcutInfo(
                        data, ai.user, context);
                items.add(info);

            }
        }
        if (!items.isEmpty()) {
            app.getModel().addAndBindAddedWorkspaceItems(
                    new InstallShortcutReceiver.LazyShortcutsProvider(context.getApplicationContext(), items));
        }
//更新end

        final ArrayList<AppInfo> removedApps = new ArrayList<>(appsList.removed);
        appsList.removed.clear();
......
           

2:隐藏allapp;

這裡比較複雜,我用的方法簡單粗暴;首先将展示allapp的地方注釋

src/com/android/launcher3/Launcher.java -> showAppsView():

/**
     * Shows the apps view.
     */
    public void showAppsView(boolean animated, boolean updatePredictedApps) {
//        markAppsViewShown();
//        if (updatePredictedApps) {
//            tryAndUpdatePredictedApps();
//        }
//        showAppsOrWidgets(State.APPS, animated);
    }
           

把方法内的代碼全部注釋;但是還沒結束,因為這個時候你會發現在launcher中上滑還是能調出allapp的,于是又檢視touch事件的調用地方,最終找到了是在AllAppsTransitionController.java這個類裡面

src/com/android/launcher3/allapps/AllAppsTransitionController.java -> onDrag():

@Override
    public boolean onDrag(float displacement, float velocity) {
        if (mAppsView == null) {
            return false;   // early termination.
        }

        mContainerVelocity = velocity;

        float shift = Math.min(Math.max(, mShiftStart + displacement), mShiftRange);
        //把調用的地方注釋 bengin
//        setProgress(shift / mShiftRange);
        //把調用的地方注釋 end

        return true;
    }
           

做完這兩步,allapp終于不出現了,但是這個時候還有問題,因為HotSeat上面一點,還有有一個向上的箭頭,并且在launcher的onResume狀态時,HotSeat和這個箭頭會一起做一個向上跳動的動畫;

這個肯定也是要去掉的,于是又去找動畫的代碼,用Hierarchy View工具找到箭頭的View是PageIndicatorLineCaret.java,于是以這個為切入點,找了很久都沒有找到地方,這個時候果斷出去抽了根煙,抽煙的過程中猛然想起這個動畫的效果應該是用BounceInterpolator來做的(這裡裝個13 ^_^),于是在代碼中查找,發現在AllAppsTransitionController.java這個類中有showDiscoveryBounce()這個方法

public void showDiscoveryBounce() {
        // cancel existing animation in case user locked and unlocked at a super human speed.
        cancelDiscoveryAnimation();

        // assumption is that this variable is always null
        mDiscoBounceAnimation = AnimatorInflater.loadAnimator(mLauncher,
                R.animator.discovery_bounce);
        mDiscoBounceAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mIsTranslateWithoutWorkspace = true;
                preparePull(true);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                finishPullDown();
                mDiscoBounceAnimation = null;
                mIsTranslateWithoutWorkspace = false;
            }
        });
        mDiscoBounceAnimation.setTarget(this);
        mAppsView.post(new Runnable() {
            @Override
            public void run() {
                if (mDiscoBounceAnimation == null) {
                    return;
                }
                mDiscoBounceAnimation.start();
            }
        });
    }
           

檢視調用的地方,是在

src/com/android/launcher3/Launcher.java -> onResume():

将調用的地方注釋:

......

        if (shouldShowDiscoveryBounce()) {
//注釋 begin
//            mAllAppsController.showDiscoveryBounce();
//注釋 end
        }
        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onResume();
        }
......
           

最後把箭頭去掉,因為調用地方比較多,我就直接把Imageview的圖檔設定為空了

src/com/android/launcher3/pageindicators/PageIndicatorLineCaret.java -> onFinishInflate()

@Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mAllAppsHandle = (ImageView) findViewById(R.id.all_apps_handle);
//修改 begin
//        mAllAppsHandle.setImageDrawable(getCaretDrawable());
        mAllAppsHandle.setImageDrawable(null);
//修改 end
        mAllAppsHandle.setOnClickListener(mLauncher);
        mAllAppsHandle.setOnFocusChangeListener(mLauncher.mFocusHandler);
        mLauncher.setAllAppsButton(mAllAppsHandle);
    }
           

終于把這個搞定了!

3:去掉長按時的删除選項:

現在所有應用都已經在workspace中了,并且allapp也已經隐藏,但是長按workspace中的APP會發現,可以 移除,這個肯定不是我們需要的,我們需要的是解除安裝

src/com/android/launcher3/DeleteDropTarget.java :

@Override
    protected boolean supportsDrop(DragSource source, ItemInfo info) {
//添加判斷 begin
        if (info instanceof ShortcutInfo || info instanceof FolderInfo) {
            return false;
        }
//添加判斷 end
        return true;
    }
           

下面這個看情況是否需要添加

src/com/android/launcher3/popup/PopupContainerWithArrow.java -> showForIcon():

public static PopupContainerWithArrow showForIcon(BubbleTextView icon) {
        Launcher launcher = Launcher.getLauncher(icon.getContext());
        if (getOpen(launcher) != null) {
            // There is already an items container open, so don't open this one.
            icon.clearFocus();
            return null;
        }
        ItemInfo itemInfo = (ItemInfo) icon.getTag();
//修改類型 begin
        itemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
//修改類型 end
        if (!DeepShortcutManager.supportsShortcuts(itemInfo)) {
            return null;
        }
        ......
}
           

到這裡就基本可以了。

但是還有遺留問題:

a.HotSeat中出現過的APP在Workspace仍然有;

b.HotSeat可以建立檔案夾

革命尚未成功,苦逼的程式員晚上繼續研究!