diff options
author | Joe Onorato <joeo@android.com> | 2009-08-08 18:53:53 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-08-08 18:53:53 -0700 |
commit | 43e7bcf0ad7b487df9244bc5491695b130d331c7 (patch) | |
tree | a11dd522b36875642ca71f6f9b4694bc4f87a485 /src/com/android/launcher2 | |
parent | bf15cb44cc8e5ea9a19ab8aaee8e02c96bd6130c (diff) | |
download | android_packages_apps_Trebuchet-43e7bcf0ad7b487df9244bc5491695b130d331c7.tar.gz android_packages_apps_Trebuchet-43e7bcf0ad7b487df9244bc5491695b130d331c7.tar.bz2 android_packages_apps_Trebuchet-43e7bcf0ad7b487df9244bc5491695b130d331c7.zip |
start rewriting rollo so it's a little more parameterized.
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r-- | src/com/android/launcher2/AllAppsView.java | 40 | ||||
-rw-r--r-- | src/com/android/launcher2/AllocationIndex.java | 37 | ||||
-rw-r--r-- | src/com/android/launcher2/IntAllocation.java | 67 | ||||
-rw-r--r-- | src/com/android/launcher2/Utilities.java | 35 |
4 files changed, 168 insertions, 11 deletions
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java index 7bf0c7c6b..0a522ae5f 100644 --- a/src/com/android/launcher2/AllAppsView.java +++ b/src/com/android/launcher2/AllAppsView.java @@ -243,6 +243,12 @@ public class AllAppsView extends RSSurfaceView { public static final int STATE_COUNT = 8; public static final int STATE_TOUCH = 9; + static final int ALLOC_PARAMS = 0; + static final int ALLOC_STATE = 1; + static final int ALLOC_SCRATCH = 2; + static final int ALLOC_ICON_IDS = 3; + static final int ALLOC_LABEL_IDS = 4; + public RolloRS() { } @@ -291,6 +297,7 @@ public class AllAppsView extends RSSurfaceView { private Sampler mSamplerText; private ProgramStore mPSBackground; private ProgramStore mPSText; + private ProgramFragment mPFDebug; private ProgramFragment mPFImages; private ProgramFragment mPFText; private ProgramVertex mPV; @@ -312,6 +319,18 @@ public class AllAppsView extends RSSurfaceView { private int[] mAllocScratchBuf; private Allocation mAllocScratch; + Params mParams; + + class Params extends IntAllocation { + Params(RenderScript rs) { + super(rs); + } + @AllocationIndex(0) public int bubbleWidth; + @AllocationIndex(1) public int bubbleHeight; + @AllocationIndex(2) public int bubbleBitmapWidth; + @AllocationIndex(3) public int bubbleBitmapHeight; + } + private void initNamed() { Sampler.Builder sb = new Sampler.Builder(mRS); sb.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR); @@ -324,6 +343,9 @@ public class AllAppsView extends RSSurfaceView { sb.setMag(Sampler.Value.NEAREST); mSamplerText = sb.create(); + ProgramFragment.Builder dbg = new ProgramFragment.Builder(mRS, null, null); + mPFDebug = dbg.create(); + mPFDebug.setName("PFDebug"); ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); bf.setTexEnable(true, 0); @@ -380,6 +402,8 @@ public class AllAppsView extends RSSurfaceView { } private void initIcons(int count) { + mParams = new Params(mRS); + mIcons = new Allocation[count]; mAllocIconIDBuf = new int[count]; mAllocIconID = Allocation.createSized(mRS, @@ -394,6 +418,12 @@ public class AllAppsView extends RSSurfaceView { final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); + mParams.bubbleWidth = bubble.getBubbleWidth(); + mParams.bubbleHeight = bubble.getMaxBubbleHeight(); + mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); + mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); + mParams.save(); + for (int i=0; i<count; i++) { mIcons[i] = Allocation.createFromBitmapResource( mRS, mRes, R.raw.maps, ie8888, true); @@ -430,10 +460,12 @@ public class AllAppsView extends RSSurfaceView { mAllocStateBuf = new int[] {0, 0, 0, 8, 0, 0, -1, 0, mAllocIconIDBuf.length, 0, 0}; mAllocState = Allocation.createSized(mRS, Element.USER_I32, mAllocStateBuf.length); - mScript.bindAllocation(mAllocState, 0); - mScript.bindAllocation(mAllocIconID, 1); - mScript.bindAllocation(mAllocScratch, 2); - mScript.bindAllocation(mAllocLabelID, 3); + + mScript.bindAllocation(mParams.getAllocation(), ALLOC_PARAMS); + mScript.bindAllocation(mAllocState, ALLOC_STATE); + mScript.bindAllocation(mAllocIconID, ALLOC_ICON_IDS); + mScript.bindAllocation(mAllocScratch, ALLOC_SCRATCH); + mScript.bindAllocation(mAllocLabelID, ALLOC_LABEL_IDS); setPosition(0); setZoom(1); diff --git a/src/com/android/launcher2/AllocationIndex.java b/src/com/android/launcher2/AllocationIndex.java new file mode 100644 index 000000000..0202db5c6 --- /dev/null +++ b/src/com/android/launcher2/AllocationIndex.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2009 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 java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Annotate fields of a subclass of {@link IntAllocaiton} or + * FloatAllocation with this, and the save() method on those + * those classes will find the field an save it. + * <p> + * TODO: This would be even better if the allocations were + * named, and renderscript automatically added them into to + * the renderscript namespace. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface AllocationIndex { + /** + * The index in the allocation to use inside renderscript. + */ + int value(); +} diff --git a/src/com/android/launcher2/IntAllocation.java b/src/com/android/launcher2/IntAllocation.java new file mode 100644 index 000000000..3d96c5eee --- /dev/null +++ b/src/com/android/launcher2/IntAllocation.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 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.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; + +import java.lang.reflect.Field; + +public class IntAllocation { + private RenderScript mRS; + private int[] mBuffer; + private Allocation mAlloc; + + public IntAllocation(RenderScript rs) { + mRS = rs; + } + + public void save() { + Field[] fields = this.getClass().getFields(); + if (mBuffer == null) { + int maxIndex = 0; + for (Field f: fields) { + AllocationIndex index = f.getAnnotation(AllocationIndex.class); + if (index != null) { + int value = index.value(); + if (value > maxIndex) { + maxIndex = value; + } + } + } + mBuffer = new int[maxIndex+1]; + mAlloc = Allocation.createSized(mRS, Element.USER_I32, mBuffer.length); + } + int[] buf = mBuffer; + for (Field f: fields) { + AllocationIndex index = f.getAnnotation(AllocationIndex.class); + if (index != null) { + try { + buf[index.value()] = f.getInt(this); + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } + } + mAlloc.data(buf); + } + + Allocation getAllocation() { + return mAlloc; + } +} diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index c7106152e..9e715d1b7 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -234,7 +234,7 @@ final class Utilities { final float paddingRight = 5.0f * scale; final float cellWidth = resources.getDimension(R.dimen.workspace_cell_width); final float bubbleWidth = cellWidth - paddingLeft - paddingRight; - mBubblePadding = 5.0f * scale; + mBubblePadding = 3.0f * scale; RectF bubbleRect = mBubbleRect; bubbleRect.left = 0; @@ -245,27 +245,29 @@ final class Utilities { mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding; Paint rectPaint = mRectPaint = new Paint(); - rectPaint.setColor(0xff000000); + rectPaint.setColor(0xaa000000); + rectPaint.setAntiAlias(true); TextPaint textPaint = mTextPaint = new TextPaint(); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setTextSize(20); textPaint.setColor(0xffffffff); + textPaint.setAntiAlias(true); float ascent = -textPaint.ascent(); float descent = textPaint.descent(); - float leading = (ascent+descent) * 0.1f; + float leading = 0.0f;//(ascent+descent) * 0.1f; mLeading = (int)(leading + 0.5f); mFirstLineY = (int)(leading + ascent + 0.5f); mLineHeight = (int)(leading + ascent + descent + 0.5f); roundToPow2(64); mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f)); - mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + mLeading + 0.5f)); + mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f)); Log.d(Launcher.LOG_TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight=" + mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f)) - + " h=" + ((int)((MAX_LINES * mLineHeight) + mLeading + 0.5f))); + + " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f))); } /** You own the bitmap after this and you must call recycle on it. */ @@ -281,9 +283,8 @@ final class Utilities { } if (lineCount > 0) { RectF bubbleRect = mBubbleRect; - bubbleRect.bottom = (int)((lineCount * mLineHeight) + mLeading + mLeading + 0.0f); + bubbleRect.bottom = height(lineCount); c.drawRoundRect(bubbleRect, mCornerRadius, mCornerRadius, mRectPaint); - Log.d(Launcher.LOG_TAG, "bubbleRect=" + bubbleRect); } for (int i=0; i<lineCount; i++) { int x = (int)((mBubbleRect.width() - layout.getLineMax(i)) / 2.0f); @@ -294,6 +295,26 @@ final class Utilities { return b; } + + private int height(int lineCount) { + return (int)((lineCount * mLineHeight) + mLeading + mLeading + 0.0f); + } + + int getBubbleWidth() { + return (int)(mBubbleRect.width() + 0.5f); + } + + int getMaxBubbleHeight() { + return height(MAX_LINES); + } + + int getBitmapWidth() { + return mBitmapWidth; + } + + int getBitmapHeight() { + return mBitmapHeight; + } } /** Only works for positive numbers. */ |