文件夹改成九宫格模式
This commit is contained in:
@@ -471,7 +471,7 @@ public class CellLayout extends ViewGroup implements Transposable {
|
||||
cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation);
|
||||
canvas.save();
|
||||
canvas.translate(mTempLocation[0], mTempLocation[1]);
|
||||
bg.drawBackground(canvas);
|
||||
bg.drawBackground(canvas,getContext());
|
||||
if (!bg.isClipping) {
|
||||
bg.drawBackgroundStroke(canvas);
|
||||
}
|
||||
@@ -813,9 +813,9 @@ public class CellLayout extends ViewGroup implements Transposable {
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
int left = getPaddingLeft();
|
||||
left += (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
|
||||
// left += (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
|
||||
int right = r - l - getPaddingRight();
|
||||
right -= (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
|
||||
// right -= (int) Math.ceil(getUnusedHorizontalSpace() / 2f);
|
||||
|
||||
int top = getPaddingTop();
|
||||
int bottom = b - t - getPaddingBottom();
|
||||
@@ -2553,11 +2553,13 @@ public class CellLayout extends ViewGroup implements Transposable {
|
||||
}
|
||||
|
||||
public int getDesiredWidth() {
|
||||
return getPaddingLeft() + getPaddingRight() + (mCountX * mCellWidth);
|
||||
return getPaddingLeft() + getPaddingRight() + (4 * mCellWidth);
|
||||
//固定返回文件夹宽度
|
||||
}
|
||||
|
||||
public int getDesiredHeight() {
|
||||
return getPaddingTop() + getPaddingBottom() + (mCountY * mCellHeight);
|
||||
return getPaddingTop() + getPaddingBottom() + (4 * mCellHeight);
|
||||
//固定返回文件夹高度
|
||||
}
|
||||
|
||||
public boolean isOccupied(int x, int y) {
|
||||
|
||||
@@ -102,8 +102,8 @@ public class FolderAdaptiveIcon extends AdaptiveIconDrawable {
|
||||
|
||||
// Initialize badge
|
||||
c.setBitmap(badgeBitmap);
|
||||
bg.drawShadow(c);
|
||||
bg.drawBackgroundStroke(c);
|
||||
// bg.drawShadow(c);
|
||||
// bg.drawBackgroundStroke(c);
|
||||
icon.drawDot(c);
|
||||
|
||||
// Initialize preview
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.android.uiuios.folder;
|
||||
|
||||
public class ClippedFolderIconLayoutRule {
|
||||
|
||||
public static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
|
||||
// public static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
|
||||
static final int MAX_NUM_ITEMS_IN_PREVIEW = Integer.MAX_VALUE;
|
||||
private static final int MIN_NUM_ITEMS_IN_PREVIEW = 2;
|
||||
|
||||
private static final float MIN_SCALE = 0.48f;
|
||||
private static final float MIN_SCALE = 0.15f;
|
||||
private static final float MAX_SCALE = 0.58f;
|
||||
private static final float MAX_RADIUS_DILATION = 0.15f;
|
||||
private static final float ITEM_RADIUS_SCALE_FACTOR = 1.33f;
|
||||
@@ -53,6 +54,11 @@ public class ClippedFolderIconLayoutRule {
|
||||
|
||||
transX = mTmpPoint[0];
|
||||
transY = mTmpPoint[1];
|
||||
int padl = 15;
|
||||
int padt = 15;
|
||||
int tempIndex = index % 9;
|
||||
transX = padl + mIconSize * MIN_SCALE * getCol(tempIndex) + getCol(tempIndex) * 5;
|
||||
transY = padt + mIconSize * MIN_SCALE * (getRow(tempIndex) - 1) + (getRow(tempIndex) - 1) * 5;
|
||||
|
||||
if (params == null) {
|
||||
params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
|
||||
@@ -63,6 +69,16 @@ public class ClippedFolderIconLayoutRule {
|
||||
return params;
|
||||
}
|
||||
|
||||
/* 20180702 modify begin */
|
||||
private int getRow(int index) {
|
||||
return index / 4 + 1;
|
||||
}
|
||||
|
||||
private int getCol(int index) {
|
||||
return (index) % 4;
|
||||
}
|
||||
/* 20180702 modify end */
|
||||
|
||||
/**
|
||||
* Builds a grid based on the positioning of the items when there are
|
||||
* {@link #MAX_NUM_ITEMS_IN_PREVIEW} in the preview.
|
||||
@@ -137,7 +153,8 @@ public class ClippedFolderIconLayoutRule {
|
||||
} else {
|
||||
scale = MIN_SCALE;
|
||||
}
|
||||
return scale * mBaselineIconScale;
|
||||
return MIN_SCALE * mBaselineIconScale;
|
||||
// return scale * mBaselineIconScale;
|
||||
}
|
||||
|
||||
public float getIconSize() {
|
||||
|
||||
@@ -490,7 +490,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
|
||||
mPreviewItemManager.recomputePreviewDrawingParams();
|
||||
|
||||
if (!mBackground.drawingDelegated()) {
|
||||
mBackground.drawBackground(canvas);
|
||||
mBackground.drawBackground(canvas,getContext());
|
||||
}
|
||||
|
||||
if (mFolder == null) return;
|
||||
@@ -502,7 +502,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
|
||||
canvas.restoreToCount(saveCount);
|
||||
|
||||
if (!mBackground.drawingDelegated()) {
|
||||
mBackground.drawBackgroundStroke(canvas);
|
||||
// mBackground.drawBackgroundStroke(canvas);
|
||||
//边框
|
||||
}
|
||||
|
||||
drawDot(canvas);
|
||||
|
||||
@@ -91,9 +91,10 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
public FolderPagedView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
InvariantDeviceProfile profile = LauncherAppState.getIDP(context);
|
||||
mMaxCountX = profile.numFolderColumns;
|
||||
mMaxCountY = profile.numFolderRows;
|
||||
|
||||
// mMaxCountX = profile.numFolderColumns;
|
||||
// mMaxCountY = profile.numFolderRows;
|
||||
mMaxCountX = 4;
|
||||
mMaxCountY = 4;
|
||||
mMaxItemsPerPage = mMaxCountX * mMaxCountY;
|
||||
|
||||
mInflater = LayoutInflater.from(context);
|
||||
@@ -127,27 +128,36 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
done = true;
|
||||
} else {
|
||||
done = false;
|
||||
/* 添加新计算 begin */
|
||||
if(count >4){
|
||||
gridCountX = 4;
|
||||
gridCountY = (count+1)/4 + 1;
|
||||
}else{
|
||||
gridCountX = count;
|
||||
gridCountY =1 ;
|
||||
}
|
||||
/* 添加新计算 end */
|
||||
}
|
||||
|
||||
while (!done) {
|
||||
int oldCountX = gridCountX;
|
||||
int oldCountY = gridCountY;
|
||||
if (gridCountX * gridCountY < count) {
|
||||
// Current grid is too small, expand it
|
||||
if ((gridCountX <= gridCountY || gridCountY == maxCountY)
|
||||
&& gridCountX < maxCountX) {
|
||||
gridCountX++;
|
||||
} else if (gridCountY < maxCountY) {
|
||||
gridCountY++;
|
||||
}
|
||||
if (gridCountY == 0) gridCountY++;
|
||||
} else if ((gridCountY - 1) * gridCountX >= count && gridCountY >= gridCountX) {
|
||||
gridCountY = Math.max(0, gridCountY - 1);
|
||||
} else if ((gridCountX - 1) * gridCountY >= count) {
|
||||
gridCountX = Math.max(0, gridCountX - 1);
|
||||
}
|
||||
done = gridCountX == oldCountX && gridCountY == oldCountY;
|
||||
}
|
||||
// while (!done) {
|
||||
// int oldCountX = gridCountX;
|
||||
// int oldCountY = gridCountY;
|
||||
// if (gridCountX * gridCountY < count) {
|
||||
// // Current grid is too small, expand it
|
||||
// if ((gridCountX <= gridCountY || gridCountY == maxCountY)
|
||||
// && gridCountX < maxCountX) {
|
||||
// gridCountX++;
|
||||
// } else if (gridCountY < maxCountY) {
|
||||
// gridCountY++;
|
||||
// }
|
||||
// if (gridCountY == 0) gridCountY++;
|
||||
// } else if ((gridCountY - 1) * gridCountX >= count && gridCountY >= gridCountX) {
|
||||
// gridCountY = Math.max(0, gridCountY - 1);
|
||||
// } else if ((gridCountX - 1) * gridCountY >= count) {
|
||||
// gridCountX = Math.max(0, gridCountX - 1);
|
||||
// }
|
||||
// done = gridCountX == oldCountX && gridCountY == oldCountY;
|
||||
// }
|
||||
|
||||
out[0] = gridCountX;
|
||||
out[1] = gridCountY;
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.graphics.RadialGradient;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.Shader;
|
||||
import android.util.Log;
|
||||
import android.util.Property;
|
||||
import android.view.View;
|
||||
|
||||
@@ -210,12 +211,31 @@ public class PreviewBackground {
|
||||
return mDotColor;
|
||||
}
|
||||
|
||||
public void drawBackground(Canvas canvas) {
|
||||
public void drawBackground(Canvas canvas,Context context) {
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
mPaint.setColor(getBgColor());
|
||||
// Bitmap bitmap =BitmapFactory.decodeResource(context.getResources(), R.drawable.square);
|
||||
// float radius = getScaledRadius();
|
||||
// canvas.drawBitmap(bitmap,0 + getOffsetX(),0 + getOffsetY() ,mPaint);
|
||||
drawCircle(canvas, 0 /* deltaRadius */);
|
||||
// getShape().drawShape(canvas, getOffsetX(), getOffsetY(), getScaledRadius(), mPaint);
|
||||
// drawShadow(canvas);
|
||||
}
|
||||
|
||||
getShape().drawShape(canvas, getOffsetX(), getOffsetY(), getScaledRadius(), mPaint);
|
||||
drawShadow(canvas);
|
||||
private void drawCircle(Canvas canvas,float deltaRadius) {
|
||||
Log.e("fht", "drawCircle: previewSize:" + previewSize );
|
||||
Log.e("fht", "drawCircle: getScaledRadius:" + getScaledRadius() );
|
||||
Log.e("fht", "drawCircle: getOffsetX:" + getOffsetX());
|
||||
Log.e("fht", "drawCircle: getOffsetY:" + getOffsetY());
|
||||
float radius = getScaledRadius()-4;
|
||||
Log.e("fht", "drawCircle: radius:" + radius);
|
||||
|
||||
/* 20180702 modify begin */
|
||||
// canvas.drawCircle(radius + getOffsetX(), radius + getOffsetY(),
|
||||
// radius - deltaRadius, mPaint);
|
||||
mPaint.setAlpha(76);
|
||||
canvas.drawRoundRect(0 + getOffsetX() + 6, 0 + getOffsetY() + 6 , radius * 2 + getOffsetX() + 2,radius * 2 + getOffsetY() + 2, 30, 30, mPaint);
|
||||
/* 20180702 modify end */
|
||||
}
|
||||
|
||||
public void drawShadow(Canvas canvas) {
|
||||
|
||||
Reference in New Issue
Block a user