Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher2; |
| 18 | |
| 19 | import java.io.Writer; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.concurrent.Semaphore; |
| 22 | import java.lang.Float; |
| 23 | |
| 24 | import android.renderscript.RSSurfaceView; |
| 25 | import android.renderscript.RenderScript; |
| 26 | |
| 27 | import android.renderscript.RenderScript; |
| 28 | import android.renderscript.ProgramVertex; |
| 29 | import android.renderscript.Element; |
| 30 | import android.renderscript.Allocation; |
| 31 | import android.renderscript.Script; |
| 32 | import android.renderscript.ScriptC; |
| 33 | import android.renderscript.ProgramFragment; |
| 34 | import android.renderscript.ProgramStore; |
| 35 | import android.renderscript.Sampler; |
| 36 | |
| 37 | import android.content.Context; |
| 38 | import android.content.res.Resources; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 39 | import android.database.DataSetObserver; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
| 41 | import android.graphics.BitmapFactory; |
| 42 | import android.graphics.Canvas; |
| 43 | import android.graphics.Paint; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 44 | import android.graphics.drawable.BitmapDrawable; |
| 45 | import android.graphics.drawable.Drawable; |
| 46 | import android.os.Handler; |
| 47 | import android.os.Message; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 48 | import android.os.SystemClock; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 49 | import android.util.AttributeSet; |
| 50 | import android.util.Log; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 51 | import android.view.KeyEvent; |
| 52 | import android.view.MotionEvent; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 53 | import android.view.Surface; |
| 54 | import android.view.SurfaceHolder; |
| 55 | import android.view.SurfaceView; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 56 | import android.view.VelocityTracker; |
| 57 | import android.view.ViewConfiguration; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 58 | import android.graphics.PixelFormat; |
| 59 | |
| 60 | |
| 61 | public class AllAppsView extends RSSurfaceView { |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 62 | private RenderScript mRS; |
| 63 | private RolloRS mRollo; |
| 64 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 65 | private ViewConfiguration mConfig; |
| 66 | private VelocityTracker mVelocity; |
| 67 | private int mLastScrollX; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 68 | private int mLastMotionX; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 69 | private ApplicationsAdapter mAdapter; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 70 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 71 | |
| 72 | public AllAppsView(Context context, AttributeSet attrs) { |
| 73 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 74 | setFocusable(true); |
| 75 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 76 | mConfig = ViewConfiguration.get(context); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 79 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 80 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 83 | void setAdapter(ApplicationsAdapter adapter) { |
| 84 | if (mAdapter != null) { |
| 85 | mAdapter.unregisterDataSetObserver(mIconObserver); |
| 86 | } |
| 87 | mAdapter = adapter; |
| 88 | if (adapter != null) { |
| 89 | adapter.registerDataSetObserver(mIconObserver); |
| 90 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 93 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 94 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 95 | super.surfaceChanged(holder, format, w, h); |
| 96 | |
| 97 | mRS = createRenderScript(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 98 | mRollo = new RolloRS(); |
| 99 | mRollo.init(getResources(), w, h); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 104 | { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 105 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 106 | return super.onKeyDown(keyCode, event); |
| 107 | } |
| 108 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 109 | @Override |
| 110 | public boolean onTouchEvent(MotionEvent ev) |
| 111 | { |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 112 | Log.d(Launcher.LOG_TAG, "onTouchEvent " + ev); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 113 | int x = (int)ev.getX(); |
| 114 | int deltaX; |
| 115 | switch (ev.getAction()) { |
| 116 | case MotionEvent.ACTION_DOWN: |
| 117 | mLastMotionX = x; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 118 | mRollo.mState.read(); |
| 119 | mRollo.mState.scrollX = mLastScrollX = mRollo.mState.currentScrollX; |
| 120 | mRollo.mState.flingVelocityX = 0; |
| 121 | mRollo.mState.adjustedDeceleration = 0; |
| 122 | mRollo.mState.save(); |
| 123 | mVelocity = VelocityTracker.obtain(); |
| 124 | mVelocity.addMovement(ev); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 125 | break; |
| 126 | case MotionEvent.ACTION_MOVE: |
| 127 | case MotionEvent.ACTION_OUTSIDE: |
| 128 | deltaX = x - mLastMotionX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 129 | mVelocity.addMovement(ev); |
| 130 | mRollo.mState.currentScrollX = mLastScrollX; |
| 131 | mLastScrollX += deltaX; |
| 132 | mRollo.mState.scrollX = mLastScrollX; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 133 | mRollo.mState.save(); |
| 134 | mLastMotionX = x; |
| 135 | break; |
| 136 | case MotionEvent.ACTION_UP: |
| 137 | case MotionEvent.ACTION_CANCEL: |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 138 | mVelocity.computeCurrentVelocity(1000 /* px/sec */, |
| 139 | mConfig.getScaledMaximumFlingVelocity()); |
| 140 | mRollo.mState.flingTimeMs = (int)SystemClock.uptimeMillis(); // TODO: use long |
| 141 | mRollo.mState.flingVelocityX = (int)mVelocity.getXVelocity(); |
| 142 | mRollo.mState.save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 143 | mLastMotionX = -10000; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 144 | mVelocity.recycle(); |
| 145 | mVelocity = null; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 146 | break; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 147 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 148 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public boolean onTrackballEvent(MotionEvent ev) |
| 153 | { |
| 154 | float x = ev.getX(); |
| 155 | float y = ev.getY(); |
| 156 | //Float tx = new Float(x); |
| 157 | //Float ty = new Float(y); |
| 158 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 159 | |
| 160 | |
| 161 | return true; |
| 162 | } |
| 163 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame^] | 164 | DataSetObserver mIconObserver = new DataSetObserver() { |
| 165 | public void onChanged() { |
| 166 | Log.d(Launcher.LOG_TAG, "new icons arrived! now have " + mAdapter.getCount()); |
| 167 | } |
| 168 | }; |
| 169 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 170 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 171 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 172 | // Allocations ====== |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 173 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 174 | private int mWidth; |
| 175 | private int mHeight; |
| 176 | |
| 177 | private Resources mRes; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 178 | private Script mScript; |
| 179 | private Sampler mSampler; |
| 180 | private Sampler mSamplerText; |
| 181 | private ProgramStore mPSBackground; |
| 182 | private ProgramStore mPSText; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 183 | private ProgramFragment mPFDebug; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 184 | private ProgramFragment mPFImages; |
| 185 | private ProgramFragment mPFText; |
| 186 | private ProgramVertex mPV; |
| 187 | private ProgramVertex.MatrixAllocation mPVAlloc; |
| 188 | private ProgramVertex mPVOrtho; |
| 189 | private ProgramVertex.MatrixAllocation mPVOrthoAlloc; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 190 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 191 | private Allocation[] mIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 192 | private int[] mAllocIconIDBuf; |
| 193 | private Allocation mAllocIconID; |
| 194 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 195 | private Allocation[] mLabels; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 196 | private int[] mAllocLabelIDBuf; |
| 197 | private Allocation mAllocLabelID; |
| 198 | |
| 199 | private int[] mAllocScratchBuf; |
| 200 | private Allocation mAllocScratch; |
| 201 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 202 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 203 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 204 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 205 | class Defines { |
| 206 | public static final int ALLOC_PARAMS = 0; |
| 207 | public static final int ALLOC_STATE = 1; |
| 208 | public static final int ALLOC_SCRATCH = 2; |
| 209 | public static final int ALLOC_ICON_IDS = 3; |
| 210 | public static final int ALLOC_LABEL_IDS = 4; |
| 211 | } |
| 212 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 213 | class Params extends IntAllocation { |
| 214 | Params(RenderScript rs) { |
| 215 | super(rs); |
| 216 | } |
| 217 | @AllocationIndex(0) public int bubbleWidth; |
| 218 | @AllocationIndex(1) public int bubbleHeight; |
| 219 | @AllocationIndex(2) public int bubbleBitmapWidth; |
| 220 | @AllocationIndex(3) public int bubbleBitmapHeight; |
| 221 | } |
| 222 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 223 | class State extends IntAllocation { |
| 224 | State(RenderScript rs) { |
| 225 | super(rs); |
| 226 | } |
| 227 | @AllocationIndex(0) public int iconCount; |
| 228 | @AllocationIndex(1) public int scrollX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 229 | @AllocationIndex(2) public int flingTimeMs; |
| 230 | @AllocationIndex(3) public int flingVelocityX; |
| 231 | @AllocationIndex(4) public int adjustedDeceleration; |
| 232 | @AllocationIndex(5) public int currentScrollX; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 233 | @AllocationIndex(6) public int flingDuration; |
| 234 | @AllocationIndex(7) public int flingEndPos; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | public RolloRS() { |
| 238 | } |
| 239 | |
| 240 | public void init(Resources res, int width, int height) { |
| 241 | mRes = res; |
| 242 | mWidth = width; |
| 243 | mHeight = height; |
| 244 | initGl(); |
| 245 | initData(); |
| 246 | initRs(); |
| 247 | } |
| 248 | |
| 249 | private void initGl() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 250 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 251 | sb.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR); |
| 252 | sb.setMag(Sampler.Value.LINEAR); |
| 253 | sb.setWrapS(Sampler.Value.CLAMP); |
| 254 | sb.setWrapT(Sampler.Value.CLAMP); |
| 255 | mSampler = sb.create(); |
| 256 | |
| 257 | sb.setMin(Sampler.Value.NEAREST); |
| 258 | sb.setMag(Sampler.Value.NEAREST); |
| 259 | mSamplerText = sb.create(); |
| 260 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 261 | ProgramFragment.Builder dbg = new ProgramFragment.Builder(mRS, null, null); |
| 262 | mPFDebug = dbg.create(); |
| 263 | mPFDebug.setName("PFDebug"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 264 | |
| 265 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 266 | bf.setTexEnable(true, 0); |
| 267 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 268 | mPFImages = bf.create(); |
| 269 | mPFImages.setName("PF"); |
| 270 | mPFImages.bindSampler(mSampler, 0); |
| 271 | |
| 272 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 273 | mPFText = bf.create(); |
| 274 | mPFText.setName("PFText"); |
| 275 | mPFText.bindSampler(mSamplerText, 0); |
| 276 | |
| 277 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
| 278 | bs.setDepthFunc(ProgramStore.DepthFunc.LESS); |
| 279 | bs.setDitherEnable(false); |
| 280 | bs.setDepthMask(true); |
| 281 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 282 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 283 | mPSBackground = bs.create(); |
| 284 | mPSBackground.setName("PFS"); |
| 285 | |
| 286 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 287 | bs.setDepthMask(false); |
| 288 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 289 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 290 | mPSText = bs.create(); |
| 291 | mPSText.setName("PFSText"); |
| 292 | |
| 293 | mPVAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 294 | mPVAlloc.setupProjectionNormalized(mWidth, mHeight); |
| 295 | |
| 296 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
| 297 | mPV = pvb.create(); |
| 298 | mPV.setName("PV"); |
| 299 | mPV.bindAllocation(mPVAlloc); |
| 300 | |
| 301 | mPVOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 302 | mPVOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
| 303 | |
| 304 | pvb.setTextureMatrixEnable(true); |
| 305 | mPVOrtho = pvb.create(); |
| 306 | mPVOrtho.setName("PVOrtho"); |
| 307 | mPVOrtho.bindAllocation(mPVOrthoAlloc); |
| 308 | |
| 309 | mRS.contextBindProgramVertex(mPV); |
| 310 | |
| 311 | mAllocScratchBuf = new int[32]; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 312 | mAllocScratch = Allocation.createSized(mRS, Element.USER_I32, mAllocScratchBuf.length); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 313 | mAllocScratch.data(mAllocScratchBuf); |
| 314 | |
| 315 | Log.e("rs", "Done loading named"); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 318 | private void initData() { |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 319 | final int count = 100; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 320 | mParams = new Params(mRS); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 321 | mState = new State(mRS); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 322 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 323 | mIcons = new Allocation[count]; |
| 324 | mAllocIconIDBuf = new int[count]; |
| 325 | mAllocIconID = Allocation.createSized(mRS, |
| 326 | Element.USER_I32, mAllocIconIDBuf.length); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 327 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 328 | mLabels = new Allocation[count]; |
| 329 | mAllocLabelIDBuf = new int[mLabels.length]; |
| 330 | mAllocLabelID = Allocation.createSized(mRS, |
| 331 | Element.USER_I32, mLabels.length); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 332 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 333 | Element ie8888 = Element.RGBA_8888; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 334 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 335 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 336 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 337 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 338 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 339 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 340 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 341 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 342 | for (int i=0; i<count; i++) { |
| 343 | mIcons[i] = Allocation.createFromBitmapResource( |
| 344 | mRS, mRes, R.raw.maps, ie8888, true); |
| 345 | mLabels[i] = makeTextBitmap(bubble, i%9==0 ? "Google Maps" : "Maps"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 348 | for (int i=0; i<count; i++) { |
| 349 | mIcons[i].uploadToTexture(0); |
| 350 | mLabels[i].uploadToTexture(0); |
| 351 | mAllocIconIDBuf[i] = mIcons[i].getID(); |
| 352 | mAllocLabelIDBuf[i] = mLabels[i].getID(); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 353 | } |
| 354 | mAllocIconID.data(mAllocIconIDBuf); |
| 355 | mAllocLabelID.data(mAllocLabelIDBuf); |
| 356 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 357 | mState.iconCount = count; |
| 358 | |
| 359 | mParams.save(); |
| 360 | mState.save(); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 363 | Allocation makeTextBitmap(Utilities.BubbleText bubble, String label) { |
| 364 | Bitmap b = bubble.createTextBitmap(label); |
| 365 | Allocation a = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888, true); |
| 366 | b.recycle(); |
| 367 | return a; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 370 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 371 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
| 372 | sb.setScript(mRes, R.raw.rollo); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 373 | sb.setRoot(true); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 374 | sb.addDefines(Defines.class); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 375 | mScript = sb.create(); |
| 376 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 377 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 378 | mScript.bindAllocation(mParams.getAllocation(), Defines.ALLOC_PARAMS); |
| 379 | mScript.bindAllocation(mState.getAllocation(), Defines.ALLOC_STATE); |
| 380 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 381 | mScript.bindAllocation(mAllocScratch, Defines.ALLOC_SCRATCH); |
| 382 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 383 | |
| 384 | mRS.contextBindRootScript(mScript); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | } |
| 389 | |
| 390 | |
| 391 | |