1. 程式人生 > >launcher3 修改資料夾圖示九宮格顯示

launcher3 修改資料夾圖示九宮格顯示

res/layout/folder_icon.xml:        android:src="@drawable/icon_bg_6"/>     換個方形的背景

packages\apps\Launcher3\src\com\android\launcher3\FolderIcon.java

    private PreviewItemDrawingParams computePreviewItemDrawingParams(int index,
            PreviewItemDrawingParams params) {
// add by x
int index_order = index;
final int previewPadding = FolderRingAnimator.sPreviewPadding;
// add end
        index = NUM_ITEMS_IN_PREVIEW - index - 1;
        float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1);
        float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
        float offset = (1 - r) * mMaxPerspectiveShift;
        float scaledSize = scale * mBaselineIconSize;
        float scaleOffsetCorrection = (1 - scale) * mBaselineIconSize;
        // We want to imagine our coordinates from the bottom left, growing up and to the
        // right. This is natural for the x-axis, but for the y-axis, we have to invert things.
        float transY = mAvailableSpaceInPreview - (offset + scaledSize + scaleOffsetCorrection) + getPaddingTop();
        float transX = offset + scaleOffsetCorrection;
        float totalScale = mBaselineIconScale * scale;
        final int overlayAlpha = (int) (80 * (1 - r));

// add by x
if( PERSPECTIVE_SHIFT_FACTOR ==0.24f){

}else{
if(0 <= index_order&&index_order < 3){ // 0 1 2 
transX=index_order*mBaselineIconSize + 1*previewPadding;
transY=mAvailableSpaceInPreview - (2*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;

}else if(3 <= index_order&&index_order < 6){ // 3 4 5 
transX=(index_order-3)*mBaselineIconSize + 1*previewPadding;
//transY=1*mBaselineIconSize+9*previewPadding;
transY=mAvailableSpaceInPreview - (1*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;
}else if(6 <= index_order&&index_order < 9){ // 6 7 8 
transX=(index_order-6)*mBaselineIconSize + 1*previewPadding;
//transY=2*mBaselineIconSize+9*previewPadding;
transY=mAvailableSpaceInPreview - (0*mBaselineIconSize + scaledSize + scaleOffsetCorrection) + getPaddingTop()+0.2f*mBaselineIconSize;
}
totalScale = mBaselineIconScale * 1 - 0.1f;
}
//add end



        if (params == null) {
            params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
        } else {
            params.transX = transX;
            params.transY = transY;
            params.scale = totalScale ;
            params.overlayAlpha = overlayAlpha;
        }
        return params;
    }

    // The number of icons to display in the
    private static final int NUM_ITEMS_IN_PREVIEW = 4;     // 顯示的個數

    // The amount of vertical spread between items in the stack [0...1]
    private static final float PERSPECTIVE_SHIFT_FACTOR = 1.59f;//1.59f //0.24f     //控制資料夾內的子圖示大小,值越大,圖示越小

    因為這個值關係到 mBaselineIconSize ,如下

private void computePreviewDrawingParams(int drawableSize, int totalSize) {

            int unscaledHeight = (int) (mIntrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR));
            mBaselineIconScale = (1.0f * adjustedAvailableSpace / unscaledHeight);
            mBaselineIconSize = (int) (mIntrinsicIconSize * mBaselineIconScale);

...

}

    @Override
    protected void dispatchDraw(Canvas canvas) {

~         // 顯示子圖示的 順序

        int nItemsInPreview = Math.min(items.size(), NUM_ITEMS_IN_PREVIEW);
        if (!mAnimating) {
            //for (int i = nItemsInPreview - 1; i >= 0; i--) {       
for (int i = 0; i <= nItemsInPreview - 1; i++) {
                v = (TextView) items.get(i);
                if (!mHiddenItems.contains(v.getTag())) {
                    d = v.getCompoundDrawables()[1];
                    mParams = computePreviewItemDrawingParams(i, mParams);
                    mParams.drawable = d;
                    drawPreviewItem(canvas, mParams);
                }
            }
        } else {
            drawPreviewItem(canvas, mAnimParams);
        }
                                  

~

}