Launcher3 HotSeat顯示名稱

今天閒的無聊,研究了下launcher代碼,看到Hotseat.java的時候,想起來以前有做過顯示hotseat中應用名稱,因爲換了公司代碼都沒拿出來,就想在試着修改,看了很久發現無從下手,記得hotseat中默認是顯示應用名稱的,只是hotseat位置靠下所以名稱顯示不出來,只要把hotseat向上移一下就可以顯示出來了,可是找了半天不知道修改那個位置,只能重新研究下hotseat的代碼了。
看hotseat.java中

 @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        LauncherAppState app = LauncherAppState.getInstance();
        DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

        mAllAppsButtonRank = grid.hotseatAllAppsRank;
        mContent = (CellLayout) findViewById(R.id.layout);
        if (grid.isLandscape && !grid.isLargeTablet()) {
            mContent.setGridSize(1, (int) grid.numHotseatIcons);
        } else {
            mContent.setGridSize((int) grid.numHotseatIcons, 1);
        }
        mContent.setIsHotseat(true);

        Log.i(TAG, "onFinishInflate,(int) grid.numHotseatIcons: " + (int) grid.numHotseatIcons);

        resetLayout();
    }

mContent.setIsHotseat(true); 這個是判斷是否是Hotseat的地方,簡便的做法是直接修改爲false,意思是這個這個不是HotSeat,那麼作爲普通快捷圖標肯定是能顯示名稱的,但是這有一個問題那個allapp的名稱還是沒顯示出來,暫時的做法是allAppsButton.setText(context.getString(R.string.all_apps_button_label));
這樣hotseat就可以正常顯示應用名稱了。
在cellLayout.java中

   public void setIsHotseat(boolean isHotseat) {
        mIsHotseat = isHotseat;
     mShortcutsAndWidgets.setIsHotseat(false);}


     public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,
            boolean markCells) {
        final LayoutParams lp = params;

        // Hotseat icons - remove text
        if (child instanceof BubbleTextView) {
            BubbleTextView bubbleChild = (BubbleTextView) child;
            bubbleChild.setTextVisibility(!mIsHotseat);
        }
  ...
  }  

發現 addview的時候會根據是否是HotSeat去顯示和隱藏,但是隻改這裏會發現字體只顯示了一半,繼續跟蹤mShortcutsAndWidgets.setIsHotseat(false);
終於明白了

 public void setIsHotseat(boolean isHotseat) {
        mIsHotseatLayout = isHotseat;
    }

    int getCellContentWidth() {
        final LauncherAppState app = LauncherAppState.getInstance();
        final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();     
        return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
                grid.hotseatCellWidthPx: grid.cellWidthPx);
    }

    int getCellContentHeight() {
        final LauncherAppState app = LauncherAppState.getInstance();
        final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
        return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
                grid.hotseatCellHeightPx : grid.cellHeightPx);
    }

原來這裏會通過會通過判斷是否是HotSeat而去設置icon的寬高。到這裏Hotseat顯示名稱的分析就結束了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章