am e61c6a35: Dynamically determine # of rows/cols in All Apps.
* commit 'e61c6a35b26d3602f91b0069b6dd4407ae995951': Dynamically determine # of rows/cols in All Apps.
This commit is contained in:
@@ -94,8 +94,6 @@
|
||||
android:id="@+id/all_apps_paged_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
launcher:cellCountX="@integer/all_apps_view_cellCountX"
|
||||
launcher:cellCountY="@integer/all_apps_view_cellCountY"
|
||||
launcher:pageLayoutWidthGap="@dimen/all_apps_view_pageLayoutWidthGap"
|
||||
launcher:pageLayoutHeightGap="@dimen/all_apps_view_pageLayoutHeightGap"
|
||||
launcher:pageLayoutPaddingTop="@dimen/all_apps_view_pageLayoutPaddingTop"
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
<dimen name="customization_drawer_height">480dp</dimen>
|
||||
<dimen name="customization_drawer_content_height">420dp</dimen>
|
||||
|
||||
<integer name="all_apps_view_cellCountX">7</integer>
|
||||
<integer name="all_apps_view_cellCountY">5</integer>
|
||||
<dimen name="all_apps_view_pageLayoutWidthGap">36dp</dimen>
|
||||
<dimen name="all_apps_view_pageLayoutHeightGap">6dp</dimen>
|
||||
<dimen name="all_apps_view_pageLayoutPaddingTop">20dp</dimen>
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
<dimen name="customization_drawer_height">800dp</dimen>
|
||||
<dimen name="customization_drawer_content_height">420dp</dimen>
|
||||
|
||||
<integer name="all_apps_view_cellCountX">5</integer>
|
||||
<integer name="all_apps_view_cellCountY">7</integer>
|
||||
<dimen name="all_apps_view_pageLayoutWidthGap">36dp</dimen>
|
||||
<dimen name="all_apps_view_pageLayoutHeightGap">36dp</dimen>
|
||||
<dimen name="all_apps_view_pageLayoutPaddingTop">25dp</dimen>
|
||||
|
||||
@@ -58,6 +58,9 @@
|
||||
<integer name="config_dragViewOffsetX">0</integer>
|
||||
<integer name="config_dragViewOffsetY">-12</integer>
|
||||
|
||||
<!-- When shrinking the workspace, this is the percentage of its original size. -->
|
||||
<integer name="config_workspaceShrinkPercent">17</integer>
|
||||
|
||||
<!-- When items are dropped on the mini screens in customize mode, we have a bounce animation
|
||||
of the bright green hover outline, and then fade out the outline at the end. These are
|
||||
the values used in that animation -->
|
||||
|
||||
@@ -65,10 +65,11 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
|
||||
private final LayoutInflater mInflater;
|
||||
private boolean mAllowHardwareLayerCreation;
|
||||
|
||||
private boolean mFirstMeasure = true;
|
||||
|
||||
private int mPageContentWidth;
|
||||
|
||||
private int mLastMeasureWidth = -1;
|
||||
private int mLastMeasureHeight = -1;
|
||||
|
||||
public AllAppsPagedView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -80,8 +81,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
|
||||
public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
|
||||
mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6);
|
||||
mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4);
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mApps = new ArrayList<ApplicationInfo>();
|
||||
mFilteredApps = new ArrayList<ApplicationInfo>();
|
||||
@@ -106,27 +105,76 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
if (mFirstMeasure) {
|
||||
mFirstMeasure = false;
|
||||
|
||||
// TODO: actually calculate mCellCountX/mCellCountY as some function of
|
||||
// widthSize and heightSize
|
||||
//mCellCountX = ?;
|
||||
//mCellCountY = ?;
|
||||
|
||||
// Since mCellCountX/mCellCountY changed, we need to update the pages
|
||||
invalidatePageData();
|
||||
final int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
final int height = MeasureSpec.getSize(heightMeasureSpec);
|
||||
|
||||
if (mLastMeasureWidth != width || mLastMeasureHeight != height) {
|
||||
// Create a dummy page and set it up to find out the content width (used by our parent)
|
||||
PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
|
||||
setupPage(layout);
|
||||
mPageContentWidth = layout.getContentWidth();
|
||||
|
||||
mCellCountX = determineCellCountX(width, layout);
|
||||
mCellCountY = determineCellCountY(height, layout);
|
||||
mLastMeasureWidth = width;
|
||||
mLastMeasureHeight = height;
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
if (mFirstLayout) {
|
||||
invalidatePageData();
|
||||
|
||||
// invalidatePageData() is what causes the child pages to be created. We need the
|
||||
// children to be measured before layout, so force a new measure here.
|
||||
measure(MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY));
|
||||
}
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
}
|
||||
|
||||
private int determineCellCountX(int availableWidth, PagedViewCellLayout layout) {
|
||||
int cellCountX = 0;
|
||||
final int cellWidth = layout.getCellWidth();
|
||||
|
||||
// Subtract padding for current page and adjacent pages
|
||||
availableWidth -= mPageLayoutPaddingLeft * 2 + mPageLayoutPaddingRight * 2;
|
||||
|
||||
availableWidth -= cellWidth; // Assume at least one column
|
||||
cellCountX = 1 + availableWidth / (cellWidth + mPageLayoutWidthGap);
|
||||
availableWidth = availableWidth % (cellWidth + mPageLayoutWidthGap);
|
||||
|
||||
// Ensures that we show at least 30% of the holo icons on each side
|
||||
final int minLeftoverWidth = (int) (cellWidth * 0.6f);
|
||||
|
||||
// Reserve room for the holo outlines
|
||||
if (cellCountX <= 4) {
|
||||
// When we're really tight on space, just pack the icons a bit closer together
|
||||
final int missingWidth = minLeftoverWidth - availableWidth;
|
||||
if (missingWidth > 0) {
|
||||
mPageLayoutWidthGap -= Math.ceil(missingWidth * 1.0f / (cellCountX - 1));
|
||||
}
|
||||
} else {
|
||||
if (cellCountX >= 8) {
|
||||
// Carve out a few extra columns for very large widths
|
||||
cellCountX = (int) (cellCountX * 0.9f);
|
||||
} else if (availableWidth < minLeftoverWidth) {
|
||||
cellCountX -= 1;
|
||||
}
|
||||
}
|
||||
return cellCountX;
|
||||
}
|
||||
|
||||
private int determineCellCountY(int availableHeight, PagedViewCellLayout layout) {
|
||||
final int cellHeight = layout.getCellHeight();
|
||||
final int screenHeight = mLauncher.getResources().getDisplayMetrics().heightPixels;
|
||||
|
||||
availableHeight -= mPageLayoutPaddingTop + mPageLayoutPaddingBottom;
|
||||
availableHeight -= cellHeight; // Assume at least one row
|
||||
availableHeight -= screenHeight * 0.16f;
|
||||
return (1 + availableHeight / (cellHeight + mPageLayoutHeightGap));
|
||||
}
|
||||
|
||||
void allowHardwareLayerCreation() {
|
||||
@@ -486,7 +534,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
|
||||
|
||||
@Override
|
||||
public void syncPages() {
|
||||
if (mFirstMeasure) {
|
||||
if (mCellCountX <= 0 || mCellCountY <= 0) {
|
||||
// We don't know our size yet, which means we haven't calculated cell count x/y;
|
||||
// onMeasure will call us once we figure out our size
|
||||
return;
|
||||
|
||||
@@ -111,8 +111,8 @@ public abstract class PagedView extends ViewGroup {
|
||||
protected int mPageLayoutWidthGap;
|
||||
protected int mPageLayoutHeightGap;
|
||||
protected int mPageLayoutMaxHeight;
|
||||
protected int mCellCountX;
|
||||
protected int mCellCountY;
|
||||
protected int mCellCountX = -1;
|
||||
protected int mCellCountY = -1;
|
||||
protected boolean mCenterPagesVertically;
|
||||
protected boolean mAllowOverScroll = true;
|
||||
protected int mUnboundedScrollX;
|
||||
@@ -1514,7 +1514,7 @@ public abstract class PagedView extends ViewGroup {
|
||||
*/
|
||||
public abstract void syncPageItems(int page);
|
||||
|
||||
public void invalidatePageData() {
|
||||
protected void invalidatePageData() {
|
||||
if (mContentIsRefreshable) {
|
||||
// Update all the pages
|
||||
syncPages();
|
||||
|
||||
@@ -75,6 +75,14 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
|
||||
addView(mHolographicChildren);
|
||||
}
|
||||
|
||||
public int getCellWidth() {
|
||||
return mCellWidth;
|
||||
}
|
||||
|
||||
public int getCellHeight() {
|
||||
return mCellHeight;
|
||||
}
|
||||
|
||||
public void allowHardwareLayerCreation() {
|
||||
// This is called after the first time we launch into All Apps. Before that point,
|
||||
// there's no need for hardware layers here since there's a hardware layer set on the
|
||||
|
||||
@@ -82,10 +82,6 @@ public class Workspace extends SmoothPagedView
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
private static final String TAG = "Launcher.Workspace";
|
||||
|
||||
// This is how much the workspace shrinks when we enter all apps or
|
||||
// customization mode
|
||||
private static final float SHRINK_FACTOR = 0.16f;
|
||||
|
||||
// How much the screens shrink when we enter spring loaded drag mode
|
||||
private static final float SPRING_LOADED_DRAG_SHRINK_FACTOR = 0.7f;
|
||||
|
||||
@@ -1482,12 +1478,15 @@ public class Workspace extends SmoothPagedView
|
||||
final int screenWidth = getWidth();
|
||||
final int screenHeight = getHeight();
|
||||
|
||||
// How much the workspace shrinks when we enter all apps or customization mode
|
||||
final float shrinkFactor = res.getInteger(R.integer.config_workspaceShrinkPercent) / 100.0f;
|
||||
|
||||
// Making the assumption that all pages have the same width as the 0th
|
||||
final int pageWidth = getChildAt(0).getMeasuredWidth();
|
||||
final int pageHeight = getChildAt(0).getMeasuredHeight();
|
||||
|
||||
final int scaledPageWidth = (int) (SHRINK_FACTOR * pageWidth);
|
||||
final int scaledPageHeight = (int) (SHRINK_FACTOR * pageHeight);
|
||||
final int scaledPageWidth = (int) (shrinkFactor * pageWidth);
|
||||
final int scaledPageHeight = (int) (shrinkFactor * pageHeight);
|
||||
final float extraScaledSpacing = res.getDimension(R.dimen.smallScreenExtraSpacing);
|
||||
|
||||
final int screenCount = getChildCount();
|
||||
@@ -1538,20 +1537,21 @@ public class Workspace extends SmoothPagedView
|
||||
|
||||
mAnimator = new AnimatorSet();
|
||||
|
||||
final float[] oldXs = new float[getChildCount()];
|
||||
final float[] oldYs = new float[getChildCount()];
|
||||
final float[] oldScaleXs = new float[getChildCount()];
|
||||
final float[] oldScaleYs = new float[getChildCount()];
|
||||
final float[] oldBackgroundAlphas = new float[getChildCount()];
|
||||
final float[] oldAlphas = new float[getChildCount()];
|
||||
final float[] oldRotationYs = new float[getChildCount()];
|
||||
final float[] newXs = new float[getChildCount()];
|
||||
final float[] newYs = new float[getChildCount()];
|
||||
final float[] newScaleXs = new float[getChildCount()];
|
||||
final float[] newScaleYs = new float[getChildCount()];
|
||||
final float[] newBackgroundAlphas = new float[getChildCount()];
|
||||
final float[] newAlphas = new float[getChildCount()];
|
||||
final float[] newRotationYs = new float[getChildCount()];
|
||||
final int childCount = getChildCount();
|
||||
final float[] oldXs = new float[childCount];
|
||||
final float[] oldYs = new float[childCount];
|
||||
final float[] oldScaleXs = new float[childCount];
|
||||
final float[] oldScaleYs = new float[childCount];
|
||||
final float[] oldBackgroundAlphas = new float[childCount];
|
||||
final float[] oldAlphas = new float[childCount];
|
||||
final float[] oldRotationYs = new float[childCount];
|
||||
final float[] newXs = new float[childCount];
|
||||
final float[] newYs = new float[childCount];
|
||||
final float[] newScaleXs = new float[childCount];
|
||||
final float[] newScaleYs = new float[childCount];
|
||||
final float[] newBackgroundAlphas = new float[childCount];
|
||||
final float[] newAlphas = new float[childCount];
|
||||
final float[] newRotationYs = new float[childCount];
|
||||
|
||||
for (int i = 0; i < screenCount; i++) {
|
||||
final CellLayout cl = (CellLayout) getChildAt(i);
|
||||
@@ -1576,15 +1576,15 @@ public class Workspace extends SmoothPagedView
|
||||
oldRotationYs[i] = cl.getRotationY();
|
||||
newXs[i] = x;
|
||||
newYs[i] = y;
|
||||
newScaleXs[i] = SHRINK_FACTOR * rotationScaleX * extraShrinkFactor;
|
||||
newScaleYs[i] = SHRINK_FACTOR * rotationScaleY * extraShrinkFactor;
|
||||
newScaleXs[i] = shrinkFactor * rotationScaleX * extraShrinkFactor;
|
||||
newScaleYs[i] = shrinkFactor * rotationScaleY * extraShrinkFactor;
|
||||
newBackgroundAlphas[i] = finalAlpha;
|
||||
newRotationYs[i] = rotation;
|
||||
} else {
|
||||
cl.setX((int)x);
|
||||
cl.setY((int)y);
|
||||
cl.setScaleX(SHRINK_FACTOR * rotationScaleX * extraShrinkFactor);
|
||||
cl.setScaleY(SHRINK_FACTOR * rotationScaleY * extraShrinkFactor);
|
||||
cl.setScaleX(shrinkFactor * rotationScaleX * extraShrinkFactor);
|
||||
cl.setScaleY(shrinkFactor * rotationScaleY * extraShrinkFactor);
|
||||
cl.setBackgroundAlpha(finalAlpha);
|
||||
cl.setAlpha(finalAlpha);
|
||||
cl.setRotationY(rotation);
|
||||
|
||||
Reference in New Issue
Block a user