2010-08-09 13:37:56 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher2;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2011-04-14 16:08:02 -07:00
|
|
|
import android.content.res.Resources;
|
2010-08-09 13:37:56 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewDebug;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
2011-04-14 16:08:02 -07:00
|
|
|
import com.android.launcher.R;
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
/**
|
|
|
|
|
* An abstraction of the original CellLayout which supports laying out items
|
|
|
|
|
* which span multiple cells into a grid-like layout. Also supports dimming
|
|
|
|
|
* to give a preview of its contents.
|
|
|
|
|
*/
|
2011-02-01 17:53:59 -08:00
|
|
|
public class PagedViewCellLayout extends ViewGroup implements Page {
|
2010-08-09 13:37:56 -07:00
|
|
|
static final String TAG = "PagedViewCellLayout";
|
|
|
|
|
|
|
|
|
|
private int mCellCountX;
|
|
|
|
|
private int mCellCountY;
|
|
|
|
|
private int mCellWidth;
|
|
|
|
|
private int mCellHeight;
|
2010-10-20 17:49:27 -07:00
|
|
|
private int mWidthGap;
|
|
|
|
|
private int mHeightGap;
|
2011-02-01 17:53:59 -08:00
|
|
|
protected PagedViewCellLayoutChildren mChildren;
|
|
|
|
|
private PagedViewCellLayoutChildren mHolographicChildren;
|
2011-03-04 12:06:57 -08:00
|
|
|
private boolean mAllowHardwareLayerCreation = false;
|
|
|
|
|
private boolean mCreateHardwareLayersIfAllowed = false;
|
2010-08-09 13:37:56 -07:00
|
|
|
|
|
|
|
|
public PagedViewCellLayout(Context context) {
|
|
|
|
|
this(context, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedViewCellLayout(Context context, AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PagedViewCellLayout(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
|
|
|
|
|
setAlwaysDrawnWithCacheEnabled(false);
|
|
|
|
|
|
|
|
|
|
// setup default cell parameters
|
2011-04-14 16:08:02 -07:00
|
|
|
Resources resources = context.getResources();
|
|
|
|
|
mCellWidth = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_width);
|
|
|
|
|
mCellHeight = resources.getDimensionPixelSize(R.dimen.apps_customize_cell_height);
|
2010-08-09 13:37:56 -07:00
|
|
|
mCellCountX = LauncherModel.getCellCountX();
|
|
|
|
|
mCellCountY = LauncherModel.getCellCountY();
|
2010-10-20 17:49:27 -07:00
|
|
|
mWidthGap = mHeightGap = -1;
|
2010-08-09 13:37:56 -07:00
|
|
|
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren = new PagedViewCellLayoutChildren(context);
|
|
|
|
|
mChildren.setCellDimensions(mCellWidth, mCellHeight);
|
|
|
|
|
mChildren.setGap(mWidthGap, mHeightGap);
|
|
|
|
|
|
|
|
|
|
addView(mChildren);
|
|
|
|
|
mHolographicChildren = new PagedViewCellLayoutChildren(context);
|
|
|
|
|
mHolographicChildren.setAlpha(0f);
|
|
|
|
|
mHolographicChildren.setCellDimensions(mCellWidth, mCellHeight);
|
|
|
|
|
mHolographicChildren.setGap(mWidthGap, mHeightGap);
|
|
|
|
|
|
|
|
|
|
addView(mHolographicChildren);
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:06:57 -08:00
|
|
|
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
|
|
|
|
|
// parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here
|
|
|
|
|
// before the animation is done slows down the animation
|
|
|
|
|
if (!mAllowHardwareLayerCreation) {
|
|
|
|
|
mAllowHardwareLayerCreation = true;
|
|
|
|
|
if (mCreateHardwareLayersIfAllowed) {
|
|
|
|
|
createHardwareLayers();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-03 16:47:14 -08:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
@Override
|
2010-08-19 14:51:28 -07:00
|
|
|
public void setAlpha(float alpha) {
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren.setAlpha(alpha);
|
|
|
|
|
mHolographicChildren.setAlpha(1.0f - alpha);
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
|
2011-02-03 16:47:14 -08:00
|
|
|
void destroyHardwareLayers() {
|
2011-03-04 12:06:57 -08:00
|
|
|
// called when a page is no longer visible (triggered by loadAssociatedPages ->
|
|
|
|
|
// removeAllViewsOnPage)
|
|
|
|
|
mCreateHardwareLayersIfAllowed = false;
|
|
|
|
|
if (mAllowHardwareLayerCreation) {
|
2011-02-03 16:47:14 -08:00
|
|
|
mChildren.destroyHardwareLayer();
|
|
|
|
|
mHolographicChildren.destroyHardwareLayer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void createHardwareLayers() {
|
2011-03-04 12:06:57 -08:00
|
|
|
// called when a page is visible (triggered by loadAssociatedPages -> syncPageItems)
|
|
|
|
|
mCreateHardwareLayersIfAllowed = true;
|
|
|
|
|
if (mAllowHardwareLayerCreation) {
|
2011-02-03 16:47:14 -08:00
|
|
|
mChildren.createHardwareLayer();
|
|
|
|
|
mHolographicChildren.createHardwareLayer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
@Override
|
|
|
|
|
public void cancelLongPress() {
|
|
|
|
|
super.cancelLongPress();
|
|
|
|
|
|
|
|
|
|
// Cancel long press for all children
|
|
|
|
|
final int count = getChildCount();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
final View child = getChildAt(i);
|
|
|
|
|
child.cancelLongPress();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean addViewToCellLayout(View child, int index, int childId,
|
2011-05-05 17:06:13 -07:00
|
|
|
PagedViewCellLayout.LayoutParams params, boolean createHolographicOutlines) {
|
2010-08-09 13:37:56 -07:00
|
|
|
final PagedViewCellLayout.LayoutParams lp = params;
|
|
|
|
|
|
|
|
|
|
// Generate an id for each view, this assumes we have at most 256x256 cells
|
|
|
|
|
// per workspace screen
|
|
|
|
|
if (lp.cellX >= 0 && lp.cellX <= (mCellCountX - 1) &&
|
|
|
|
|
lp.cellY >= 0 && (lp.cellY <= mCellCountY - 1)) {
|
|
|
|
|
// If the horizontal or vertical span is set to -1, it is taken to
|
|
|
|
|
// mean that it spans the extent of the CellLayout
|
|
|
|
|
if (lp.cellHSpan < 0) lp.cellHSpan = mCellCountX;
|
|
|
|
|
if (lp.cellVSpan < 0) lp.cellVSpan = mCellCountY;
|
|
|
|
|
|
|
|
|
|
child.setId(childId);
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren.addView(child, index, lp);
|
2010-08-09 13:37:56 -07:00
|
|
|
|
2011-02-01 17:53:59 -08:00
|
|
|
if (child instanceof PagedViewIcon) {
|
|
|
|
|
PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
|
2011-03-04 12:06:57 -08:00
|
|
|
if (mAllowHardwareLayerCreation) {
|
2011-02-03 16:47:14 -08:00
|
|
|
pagedViewIcon.disableCache();
|
|
|
|
|
}
|
2011-05-05 17:06:13 -07:00
|
|
|
if (createHolographicOutlines) {
|
|
|
|
|
mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(),
|
|
|
|
|
index, lp);
|
|
|
|
|
}
|
2011-02-01 17:53:59 -08:00
|
|
|
}
|
2010-08-09 13:37:56 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-02-01 17:53:59 -08:00
|
|
|
public void removeAllViewsOnPage() {
|
|
|
|
|
mChildren.removeAllViews();
|
|
|
|
|
mHolographicChildren.removeAllViews();
|
2011-02-16 12:04:02 -08:00
|
|
|
destroyHardwareLayers();
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2011-02-01 17:53:59 -08:00
|
|
|
public void removeViewOnPageAt(int index) {
|
|
|
|
|
mChildren.removeViewAt(index);
|
|
|
|
|
mHolographicChildren.removeViewAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPageChildCount() {
|
|
|
|
|
return mChildren.getChildCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View getChildOnPageAt(int i) {
|
|
|
|
|
return mChildren.getChildAt(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int indexOfChildOnPage(View v) {
|
|
|
|
|
return mChildren.indexOfChild(v);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-13 11:27:36 -07:00
|
|
|
public int getCellCountX() {
|
|
|
|
|
return mCellCountX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCellCountY() {
|
|
|
|
|
return mCellCountY;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
|
// TODO: currently ignoring padding
|
|
|
|
|
|
|
|
|
|
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
|
|
|
|
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
|
|
|
|
|
|
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
|
|
|
|
|
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
|
|
if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
|
|
|
|
|
throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int cellWidth = mCellWidth;
|
|
|
|
|
final int cellHeight = mCellHeight;
|
|
|
|
|
|
|
|
|
|
int numWidthGaps = mCellCountX - 1;
|
|
|
|
|
int numHeightGaps = mCellCountY - 1;
|
|
|
|
|
|
|
|
|
|
int vSpaceLeft = heightSpecSize - mPaddingTop
|
|
|
|
|
- mPaddingBottom - (cellHeight * mCellCountY);
|
|
|
|
|
int heightGap = vSpaceLeft / numHeightGaps;
|
|
|
|
|
|
|
|
|
|
int hSpaceLeft = widthSpecSize - mPaddingLeft
|
|
|
|
|
- mPaddingRight - (cellWidth * mCellCountX);
|
|
|
|
|
int widthGap = hSpaceLeft / numWidthGaps;
|
|
|
|
|
|
|
|
|
|
// center it around the min gaps
|
|
|
|
|
int minGap = Math.min(widthGap, heightGap);
|
|
|
|
|
/*
|
|
|
|
|
if (minGap < heightGap) {
|
|
|
|
|
// vertical space has shrunken, so change padding accordingly
|
|
|
|
|
paddingTop += ((heightGap - minGap) * (mCellCountY - 1)) / 2;
|
|
|
|
|
} else if (minGap < widthGap) {
|
|
|
|
|
// horizontal space has shrunken, so change padding accordingly
|
|
|
|
|
paddingLeft += ((widthGap - minGap) * (mCellCountX - 1)) / 2;
|
|
|
|
|
}
|
|
|
|
|
*/
|
2010-10-20 17:49:27 -07:00
|
|
|
if (mWidthGap > -1 && mHeightGap > -1) {
|
|
|
|
|
widthGap = mWidthGap;
|
|
|
|
|
heightGap = mHeightGap;
|
|
|
|
|
} else {
|
|
|
|
|
widthGap = heightGap = minGap;
|
|
|
|
|
}
|
2010-08-09 13:37:56 -07:00
|
|
|
|
|
|
|
|
int newWidth = mPaddingLeft + mPaddingRight + (mCellCountX * cellWidth) +
|
2010-10-20 17:49:27 -07:00
|
|
|
((mCellCountX - 1) * widthGap);
|
2010-08-09 13:37:56 -07:00
|
|
|
int newHeight = mPaddingTop + mPaddingBottom + (mCellCountY * cellHeight) +
|
2010-10-20 17:49:27 -07:00
|
|
|
((mCellCountY - 1) * heightGap);
|
2010-08-09 13:37:56 -07:00
|
|
|
|
|
|
|
|
final int count = getChildCount();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
View child = getChildAt(i);
|
2011-02-01 17:53:59 -08:00
|
|
|
int childWidthMeasureSpec =
|
|
|
|
|
MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
|
|
|
|
|
int childheightMeasureSpec =
|
|
|
|
|
MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
|
2010-08-09 13:37:56 -07:00
|
|
|
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setMeasuredDimension(newWidth, newHeight);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 11:48:32 -08:00
|
|
|
int getContentWidth() {
|
2011-04-14 16:08:02 -07:00
|
|
|
if (LauncherApplication.isScreenXLarge()) {
|
|
|
|
|
// Return the distance from the left edge of the content of the leftmost icon to
|
|
|
|
|
// the right edge of the content of the rightmost icon
|
2011-02-23 11:48:32 -08:00
|
|
|
|
2011-04-14 16:08:02 -07:00
|
|
|
// icons are centered within cells, find out how much padding that accounts for
|
|
|
|
|
return getWidthBeforeFirstLayout() - (mCellWidth - Utilities.getIconContentSize());
|
|
|
|
|
} else {
|
|
|
|
|
return getWidthBeforeFirstLayout() + mPaddingLeft + mPaddingRight;
|
|
|
|
|
}
|
2011-04-05 16:52:32 -07:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 17:40:20 -07:00
|
|
|
int getContentHeight() {
|
|
|
|
|
return mCellCountY * mCellHeight + (mCellCountY - 1) * Math.max(0, mHeightGap);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 17:07:27 -07:00
|
|
|
int getWidthBeforeFirstLayout() {
|
2011-04-27 17:40:20 -07:00
|
|
|
return mCellCountX * mCellWidth + (mCellCountX - 1) * Math.max(0, mWidthGap);
|
2011-02-23 11:48:32 -08:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
|
int count = getChildCount();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
View child = getChildAt(i);
|
2011-04-14 16:08:02 -07:00
|
|
|
if (LauncherApplication.isScreenXLarge()) {
|
|
|
|
|
child.layout(0, 0, r - l, b - t);
|
|
|
|
|
} else {
|
|
|
|
|
child.layout(mPaddingLeft, mPaddingTop, getMeasuredWidth() - mPaddingRight,
|
|
|
|
|
getMeasuredHeight() - mPaddingBottom);
|
|
|
|
|
}
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
|
return super.onTouchEvent(event) || true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 16:03:15 -07:00
|
|
|
public void enableCenteredContent(boolean enabled) {
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren.enableCenteredContent(enabled);
|
|
|
|
|
mHolographicChildren.enableCenteredContent(enabled);
|
2010-08-09 16:03:15 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
@Override
|
|
|
|
|
protected void setChildrenDrawingCacheEnabled(boolean enabled) {
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren.setChildrenDrawingCacheEnabled(enabled);
|
|
|
|
|
mHolographicChildren.setChildrenDrawingCacheEnabled(enabled);
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCellCount(int xCount, int yCount) {
|
|
|
|
|
mCellCountX = xCount;
|
|
|
|
|
mCellCountY = yCount;
|
|
|
|
|
requestLayout();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-20 17:49:27 -07:00
|
|
|
public void setGap(int widthGap, int heightGap) {
|
|
|
|
|
mWidthGap = widthGap;
|
|
|
|
|
mHeightGap = heightGap;
|
2011-02-01 17:53:59 -08:00
|
|
|
mChildren.setGap(widthGap, heightGap);
|
|
|
|
|
mHolographicChildren.setGap(widthGap, heightGap);
|
2010-10-20 17:49:27 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 16:03:15 -07:00
|
|
|
public int[] getCellCountForDimensions(int width, int height) {
|
|
|
|
|
// Always assume we're working with the smallest span to make sure we
|
|
|
|
|
// reserve enough space in both orientations
|
|
|
|
|
int smallerSize = Math.min(mCellWidth, mCellHeight);
|
|
|
|
|
|
|
|
|
|
// Always round up to next largest cell
|
|
|
|
|
int spanX = (width + smallerSize) / smallerSize;
|
|
|
|
|
int spanY = (height + smallerSize) / smallerSize;
|
|
|
|
|
|
|
|
|
|
return new int[] { spanX, spanY };
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
/**
|
|
|
|
|
* Start dragging the specified child
|
|
|
|
|
*
|
|
|
|
|
* @param child The child that is being dragged
|
|
|
|
|
*/
|
|
|
|
|
void onDragChild(View child) {
|
|
|
|
|
PagedViewCellLayout.LayoutParams lp = (PagedViewCellLayout.LayoutParams) child.getLayoutParams();
|
|
|
|
|
lp.isDragging = true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 11:44:42 -07:00
|
|
|
/**
|
|
|
|
|
* Estimates the number of cells that the specified width would take up.
|
|
|
|
|
*/
|
2010-08-09 16:03:15 -07:00
|
|
|
public int estimateCellHSpan(int width) {
|
2010-09-10 11:44:42 -07:00
|
|
|
// TODO: we need to take widthGap into effect
|
2010-08-09 16:03:15 -07:00
|
|
|
return (width + mCellWidth) / mCellWidth;
|
|
|
|
|
}
|
2010-09-10 11:44:42 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Estimates the number of cells that the specified height would take up.
|
|
|
|
|
*/
|
2010-08-09 16:03:15 -07:00
|
|
|
public int estimateCellVSpan(int height) {
|
2010-09-10 11:44:42 -07:00
|
|
|
// TODO: we need to take heightGap into effect
|
2010-08-09 16:03:15 -07:00
|
|
|
return (height + mCellHeight) / mCellHeight;
|
|
|
|
|
}
|
2010-09-10 11:44:42 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Estimates the width that the number of vSpan cells will take up.
|
|
|
|
|
*/
|
|
|
|
|
public int estimateCellWidth(int hSpan) {
|
|
|
|
|
// TODO: we need to take widthGap into effect
|
|
|
|
|
return hSpan * mCellWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Estimates the height that the number of vSpan cells will take up.
|
|
|
|
|
*/
|
|
|
|
|
public int estimateCellHeight(int vSpan) {
|
|
|
|
|
// TODO: we need to take heightGap into effect
|
|
|
|
|
return vSpan * mCellHeight;
|
2010-08-09 16:03:15 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
@Override
|
|
|
|
|
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
|
|
|
|
return new PagedViewCellLayout.LayoutParams(getContext(), attrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
|
|
|
|
|
return p instanceof PagedViewCellLayout.LayoutParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
|
|
|
|
|
return new PagedViewCellLayout.LayoutParams(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class LayoutParams extends ViewGroup.MarginLayoutParams {
|
|
|
|
|
/**
|
|
|
|
|
* Horizontal location of the item in the grid.
|
|
|
|
|
*/
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
public int cellX;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vertical location of the item in the grid.
|
|
|
|
|
*/
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
public int cellY;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Number of cells spanned horizontally by the item.
|
|
|
|
|
*/
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
public int cellHSpan;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Number of cells spanned vertically by the item.
|
|
|
|
|
*/
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
public int cellVSpan;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this item currently being dragged
|
|
|
|
|
*/
|
|
|
|
|
public boolean isDragging;
|
|
|
|
|
|
2010-08-09 16:03:15 -07:00
|
|
|
// a data object that you can bind to this layout params
|
|
|
|
|
private Object mTag;
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
// X coordinate of the view in the layout.
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
int x;
|
|
|
|
|
// Y coordinate of the view in the layout.
|
|
|
|
|
@ViewDebug.ExportedProperty
|
|
|
|
|
int y;
|
|
|
|
|
|
2010-08-09 16:03:15 -07:00
|
|
|
public LayoutParams() {
|
|
|
|
|
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
|
|
|
cellHSpan = 1;
|
|
|
|
|
cellVSpan = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
public LayoutParams(Context c, AttributeSet attrs) {
|
|
|
|
|
super(c, attrs);
|
|
|
|
|
cellHSpan = 1;
|
|
|
|
|
cellVSpan = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LayoutParams(ViewGroup.LayoutParams source) {
|
|
|
|
|
super(source);
|
|
|
|
|
cellHSpan = 1;
|
|
|
|
|
cellVSpan = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LayoutParams(LayoutParams source) {
|
|
|
|
|
super(source);
|
|
|
|
|
this.cellX = source.cellX;
|
|
|
|
|
this.cellY = source.cellY;
|
|
|
|
|
this.cellHSpan = source.cellHSpan;
|
|
|
|
|
this.cellVSpan = source.cellVSpan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LayoutParams(int cellX, int cellY, int cellHSpan, int cellVSpan) {
|
|
|
|
|
super(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
|
|
|
this.cellX = cellX;
|
|
|
|
|
this.cellY = cellY;
|
|
|
|
|
this.cellHSpan = cellHSpan;
|
|
|
|
|
this.cellVSpan = cellVSpan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setup(int cellWidth, int cellHeight, int widthGap, int heightGap,
|
|
|
|
|
int hStartPadding, int vStartPadding) {
|
|
|
|
|
|
|
|
|
|
final int myCellHSpan = cellHSpan;
|
|
|
|
|
final int myCellVSpan = cellVSpan;
|
|
|
|
|
final int myCellX = cellX;
|
|
|
|
|
final int myCellY = cellY;
|
|
|
|
|
|
|
|
|
|
width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) -
|
|
|
|
|
leftMargin - rightMargin;
|
|
|
|
|
height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) -
|
|
|
|
|
topMargin - bottomMargin;
|
|
|
|
|
|
2011-04-14 16:08:02 -07:00
|
|
|
if (LauncherApplication.isScreenXLarge()) {
|
|
|
|
|
x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin;
|
|
|
|
|
y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin;
|
|
|
|
|
} else {
|
|
|
|
|
x = myCellX * (cellWidth + widthGap) + leftMargin;
|
|
|
|
|
y = myCellY * (cellHeight + heightGap) + topMargin;
|
|
|
|
|
}
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 16:03:15 -07:00
|
|
|
public Object getTag() {
|
|
|
|
|
return mTag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setTag(Object tag) {
|
|
|
|
|
mTag = tag;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 13:37:56 -07:00
|
|
|
public String toString() {
|
2010-08-09 16:03:15 -07:00
|
|
|
return "(" + this.cellX + ", " + this.cellY + ", " +
|
|
|
|
|
this.cellHSpan + ", " + this.cellVSpan + ")";
|
2010-08-09 13:37:56 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-01 17:53:59 -08:00
|
|
|
|
|
|
|
|
interface Page {
|
|
|
|
|
public int getPageChildCount();
|
|
|
|
|
public View getChildOnPageAt(int i);
|
|
|
|
|
public void removeAllViewsOnPage();
|
|
|
|
|
public void removeViewOnPageAt(int i);
|
|
|
|
|
public int indexOfChildOnPage(View v);
|
|
|
|
|
}
|