am a1192eac: Merge "Adding hardware layers to All Apps" into honeycomb

* commit 'a1192eacc25eafad25bf409d4383a1e16edb9c71':
  Adding hardware layers to All Apps
This commit is contained in:
Michael Jurka
2011-02-02 23:51:49 -08:00
committed by Android Git Automerger
8 changed files with 343 additions and 101 deletions
@@ -154,8 +154,8 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
private int getChildIndexForGrandChild(View v) {
final int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
if (layout.indexOfChild(v) > -1) {
final Page layout = (Page) getChildAt(i);
if (layout.indexOfChildOnPage(v) > -1) {
return i;
}
}
@@ -445,13 +445,13 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
if (!mFilteredApps.isEmpty()) {
int curNumPageItems = layout.getChildCount();
int curNumPageItems = layout.getPageChildCount();
int numPageItems = endIndex - startIndex;
// If we were previously an empty page, then restart anew
boolean wasEmptyPage = false;
if (curNumPageItems == 1) {
View icon = layout.getChildAt(0);
View icon = layout.getChildOnPageAt(0);
if (icon.getTag() == null) {
wasEmptyPage = true;
}
@@ -460,12 +460,12 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
if (wasEmptyPage) {
// Remove all the previous items
curNumPageItems = 0;
layout.removeAllViews();
layout.removeAllViewsOnPage();
} else {
// Remove any extra items
int extraPageItemsDiff = curNumPageItems - numPageItems;
for (int i = 0; i < extraPageItemsDiff; ++i) {
layout.removeViewAt(numPageItems);
layout.removeViewOnPageAt(numPageItems);
}
}
@@ -486,7 +486,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
for (int i = startIndex; i < endIndex; ++i) {
final int index = i - startIndex;
final ApplicationInfo info = mFilteredApps.get(i);
PagedViewIcon icon = (PagedViewIcon) layout.getChildAt(index);
PagedViewIcon icon = (PagedViewIcon) layout.getChildOnPageAt(index);
icon.applyFromApplicationInfo(info, mPageViewIconCache, true, (numPages > 1));
PagedViewCellLayout.LayoutParams params =
@@ -510,7 +510,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
// Center-align the message
layout.enableCenteredContent(true);
layout.removeAllViews();
layout.removeAllViewsOnPage();
layout.addViewToCellLayout(icon, -1, 0,
new PagedViewCellLayout.LayoutParams(0, 0, 4, 1));
}
@@ -930,7 +930,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
final int endIndex = Math.min(startIndex + numCells, list.size());
final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
// TODO: we can optimize by just re-applying to existing views
layout.removeAllViews();
layout.removeAllViewsOnPage();
for (int i = startIndex; i < endIndex; ++i) {
ResolveInfo info = list.get(i);
PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
@@ -990,7 +990,7 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
final int endIndex = Math.min(startIndex + numCells, mApps.size());
final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
// TODO: we can optimize by just re-applying to existing views
layout.removeAllViews();
layout.removeAllViewsOnPage();
for (int i = startIndex; i < endIndex; ++i) {
final ApplicationInfo info = mApps.get(i);
PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
@@ -0,0 +1,56 @@
/*
* 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;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.widget.TextView;
/**
* An icon on a PagedView, specifically for items in the launcher's paged view (with compound
* drawables on the top).
*/
public class HolographicPagedViewIcon extends TextView {
PagedViewIcon mOriginalIcon;
Paint mPaint;
public HolographicPagedViewIcon(Context context, PagedViewIcon original) {
super(context);
mOriginalIcon = original;
mPaint = new Paint();
}
@Override
protected void onDraw(Canvas canvas) {
Bitmap overlay = mOriginalIcon.getHolographicOutline();
if (overlay != null) {
final int offset = getScrollX();
final int compoundPaddingLeft = getCompoundPaddingLeft();
final int compoundPaddingRight = getCompoundPaddingRight();
int hspace = getWidth() - compoundPaddingRight - compoundPaddingLeft;
canvas.drawBitmap(overlay,
offset + compoundPaddingLeft + (hspace - overlay.getWidth()) / 2,
mPaddingTop,
mPaint);
}
}
}
+9 -9
View File
@@ -1308,8 +1308,8 @@ public abstract class PagedView extends ViewGroup {
int lowerPageBound = getAssociatedLowerPageBound(page);
int upperPageBound = getAssociatedUpperPageBound(page);
for (int i = 0; i < count; ++i) {
final ViewGroup layout = (ViewGroup) getChildAt(i);
final int childCount = layout.getChildCount();
Page layout = (Page) getChildAt(i);
final int childCount = layout.getPageChildCount();
if (lowerPageBound <= i && i <= upperPageBound) {
if (mDirtyPageContent.get(i)) {
syncPageItems(i);
@@ -1317,7 +1317,7 @@ public abstract class PagedView extends ViewGroup {
}
} else {
if (childCount > 0) {
layout.removeAllViews();
layout.removeAllViewsOnPage();
}
mDirtyPageContent.set(i, true);
}
@@ -1358,10 +1358,10 @@ public abstract class PagedView extends ViewGroup {
ArrayList<Checkable> checked = new ArrayList<Checkable>();
final int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
final ViewGroup layout = (ViewGroup) getChildAt(i);
final int grandChildCount = layout.getChildCount();
Page layout = (Page) getChildAt(i);
final int grandChildCount = layout.getPageChildCount();
for (int j = 0; j < grandChildCount; ++j) {
final View v = layout.getChildAt(j);
final View v = layout.getChildOnPageAt(j);
if (v instanceof Checkable && ((Checkable) v).isChecked()) {
checked.add((Checkable) v);
}
@@ -1378,10 +1378,10 @@ public abstract class PagedView extends ViewGroup {
if (mChoiceMode == CHOICE_MODE_SINGLE) {
final int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
final ViewGroup layout = (ViewGroup) getChildAt(i);
final int grandChildCount = layout.getChildCount();
Page layout = (Page) getChildAt(i);
final int grandChildCount = layout.getPageChildCount();
for (int j = 0; j < grandChildCount; ++j) {
final View v = layout.getChildAt(j);
final View v = layout.getChildOnPageAt(j);
if (v instanceof Checkable && ((Checkable) v).isChecked()) {
return (Checkable) v;
}
@@ -17,7 +17,6 @@
package com.android.launcher2;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -29,13 +28,9 @@ import android.view.ViewGroup;
* which span multiple cells into a grid-like layout. Also supports dimming
* to give a preview of its contents.
*/
public class PagedViewCellLayout extends ViewGroup {
public class PagedViewCellLayout extends ViewGroup implements Page {
static final String TAG = "PagedViewCellLayout";
private float mHolographicAlpha;
private boolean mCenterContent;
private int mCellCountX;
private int mCellCountY;
private int mCellWidth;
@@ -43,6 +38,8 @@ public class PagedViewCellLayout extends ViewGroup {
private int mWidthGap;
private int mHeightGap;
private static int sDefaultCellDimensions = 96;
protected PagedViewCellLayoutChildren mChildren;
private PagedViewCellLayoutChildren mHolographicChildren;
public PagedViewCellLayout(Context context) {
this(context, null);
@@ -61,20 +58,25 @@ public class PagedViewCellLayout extends ViewGroup {
mCellWidth = mCellHeight = sDefaultCellDimensions;
mCellCountX = LauncherModel.getCellCountX();
mCellCountY = LauncherModel.getCellCountY();
mHolographicAlpha = 0.0f;
mWidthGap = mHeightGap = -1;
}
@Override
protected boolean onSetAlpha(int alpha) {
return true;
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);
}
@Override
public void setAlpha(float alpha) {
mHolographicAlpha = 1.0f - alpha;
setChildrenAlpha(alpha);
super.setAlpha(alpha);
mChildren.setAlpha(alpha);
mHolographicChildren.setAlpha(1.0f - alpha);
}
@Override
@@ -103,28 +105,44 @@ public class PagedViewCellLayout extends ViewGroup {
if (lp.cellVSpan < 0) lp.cellVSpan = mCellCountY;
child.setId(childId);
mChildren.addView(child, index, lp);
// We might be in the middle or end of shrinking/fading to a dimmed view
// Make sure this view's alpha is set the same as all the rest of the views
child.setAlpha(1.0f - mHolographicAlpha);
addView(child, index, lp);
if (child instanceof PagedViewIcon) {
PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp);
}
return true;
}
return false;
}
@Override
public void requestChildFocus(View child, View focused) {
super.requestChildFocus(child, focused);
if (child != null) {
Rect r = new Rect();
child.getDrawingRect(r);
requestRectangleOnScreen(r);
}
public void removeAllViewsOnPage() {
mChildren.removeAllViews();
mHolographicChildren.removeAllViews();
}
@Override
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);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO: currently ignoring padding
@@ -154,8 +172,6 @@ public class PagedViewCellLayout extends ViewGroup {
// center it around the min gaps
int minGap = Math.min(widthGap, heightGap);
int paddingLeft = mPaddingLeft;
int paddingTop = mPaddingTop;
/*
if (minGap < heightGap) {
// vertical space has shrunken, so change padding accordingly
@@ -180,16 +196,10 @@ public class PagedViewCellLayout extends ViewGroup {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
lp.setup(cellWidth, cellHeight, widthGap, heightGap,
paddingLeft, paddingTop);
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width,
MeasureSpec.EXACTLY);
int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height,
MeasureSpec.EXACTLY);
int childWidthMeasureSpec =
MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY);
int childheightMeasureSpec =
MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
}
@@ -199,32 +209,9 @@ public class PagedViewCellLayout extends ViewGroup {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
int offsetX = 0;
if (mCenterContent) {
// determine the max width of all the rows and center accordingly
int maxRowWidth = 0;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
maxRowWidth = Math.max(maxRowWidth, lp.x + lp.width);
}
}
offsetX = (getMeasuredWidth() / 2) - (maxRowWidth / 2);
}
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
int childLeft = offsetX + lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
}
child.layout(0, 0, r - l, b - t);
}
}
@@ -234,20 +221,14 @@ public class PagedViewCellLayout extends ViewGroup {
}
public void enableCenteredContent(boolean enabled) {
mCenterContent = enabled;
mChildren.enableCenteredContent(enabled);
mHolographicChildren.enableCenteredContent(enabled);
}
@Override
protected void setChildrenDrawingCacheEnabled(boolean enabled) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View view = getChildAt(i);
view.setDrawingCacheEnabled(enabled);
// Update the drawing caches
if (!view.isHardwareAccelerated()) {
view.buildDrawingCache(true);
}
}
mChildren.setChildrenDrawingCacheEnabled(enabled);
mHolographicChildren.setChildrenDrawingCacheEnabled(enabled);
}
public void setCellCount(int xCount, int yCount) {
@@ -259,25 +240,21 @@ public class PagedViewCellLayout extends ViewGroup {
public void setGap(int widthGap, int heightGap) {
mWidthGap = widthGap;
mHeightGap = heightGap;
mChildren.setGap(widthGap, heightGap);
mHolographicChildren.setGap(widthGap, heightGap);
}
public void setCellDimensions(int width, int height) {
mCellWidth = width;
mCellHeight = height;
requestLayout();
mChildren.setCellDimensions(width, height);
mHolographicChildren.setCellDimensions(width, height);
}
public int getDefaultCellDimensions() {
return sDefaultCellDimensions;
}
private void setChildrenAlpha(float alpha) {
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
getChildAt(i).setAlpha(alpha);
}
}
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
@@ -452,3 +429,11 @@ public class PagedViewCellLayout extends ViewGroup {
}
}
}
interface Page {
public int getPageChildCount();
public View getChildOnPageAt(int i);
public void removeAllViewsOnPage();
public void removeViewOnPageAt(int i);
public int indexOfChildOnPage(View v);
}
@@ -0,0 +1,164 @@
/*
* 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;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
/**
* 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.
*/
public class PagedViewCellLayoutChildren extends ViewGroup {
static final String TAG = "PagedViewCellLayout";
private boolean mCenterContent;
private int mCellWidth;
private int mCellHeight;
private int mWidthGap;
private int mHeightGap;
public PagedViewCellLayoutChildren(Context context) {
super(context);
setLayerType(LAYER_TYPE_HARDWARE, null);
}
@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 void setGap(int widthGap, int heightGap) {
mWidthGap = widthGap;
mHeightGap = heightGap;
requestLayout();
}
public void setCellDimensions(int width, int height) {
mCellWidth = width;
mCellHeight = height;
requestLayout();
}
@Override
public void requestChildFocus(View child, View focused) {
super.requestChildFocus(child, focused);
if (child != null) {
Rect r = new Rect();
child.getDrawingRect(r);
requestRectangleOnScreen(r);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
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 count = getChildCount();
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap,
((ViewGroup)getParent()).getPaddingLeft(),
((ViewGroup)getParent()).getPaddingTop());
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width,
MeasureSpec.EXACTLY);
int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height,
MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
}
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int count = getChildCount();
int offsetX = 0;
if (mCenterContent) {
// determine the max width of all the rows and center accordingly
int maxRowWidth = 0;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
maxRowWidth = Math.max(maxRowWidth, lp.x + lp.width);
}
}
offsetX = (getMeasuredWidth() / 2) - (maxRowWidth / 2);
}
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
PagedViewCellLayout.LayoutParams lp =
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
int childLeft = offsetX + lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event) || true;
}
public void enableCenteredContent(boolean enabled) {
mCenterContent = enabled;
}
@Override
protected void setChildrenDrawingCacheEnabled(boolean enabled) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View view = getChildAt(i);
view.setDrawingCacheEnabled(enabled);
// Update the drawing caches
if (!view.isHardwareAccelerated()) {
view.buildDrawingCache(true);
}
}
}
}
@@ -19,12 +19,13 @@ package com.android.launcher2;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
/**
* The linear layout used strictly for the widget/wallpaper tab of the customization tray
*/
public class PagedViewExtendedLayout extends LinearLayout {
public class PagedViewExtendedLayout extends LinearLayout implements Page {
static final String TAG = "PagedViewWidgetLayout";
public PagedViewExtendedLayout(Context context) {
@@ -68,4 +69,29 @@ public class PagedViewExtendedLayout extends LinearLayout {
getChildAt(i).setAlpha(alpha);
}
}
@Override
public void removeAllViewsOnPage() {
removeAllViews();
}
@Override
public void removeViewOnPageAt(int index) {
removeViewAt(index);
}
@Override
public int getPageChildCount() {
return getChildCount();
}
@Override
public View getChildOnPageAt(int i) {
return getChildAt(i);
}
@Override
public int indexOfChildOnPage(View v) {
return indexOfChild(v);
}
}
+12 -1
View File
@@ -65,6 +65,8 @@ public class PagedViewIcon extends CachedTextView implements Checkable {
private int mHoloBlurColor;
private int mHoloOutlineColor;
HolographicPagedViewIcon mHolographicOutlineView;
private static final HandlerThread sWorkerThread = new HandlerThread("pagedviewicon-helper");
static {
sWorkerThread.start();
@@ -90,7 +92,7 @@ public class PagedViewIcon extends CachedTextView implements Checkable {
public void run() {
icon.mHolographicOutline = holographicOutline;
icon.mIconCache.addOutline(icon.mIconCacheKey, holographicOutline);
icon.invalidate();
icon.getHolographicOutlineView().invalidate();
}
});
}
@@ -127,6 +129,15 @@ public class PagedViewIcon extends CachedTextView implements Checkable {
setFocusable(true);
setBackgroundDrawable(null);
mHolographicOutlineView = new HolographicPagedViewIcon(context, this);
}
protected HolographicPagedViewIcon getHolographicOutlineView() {
return mHolographicOutlineView;
}
protected Bitmap getHolographicOutline() {
return mHolographicOutline;
}
private void queueHolographicOutlineCreation() {