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 | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 62 | private static final String TAG = "Launcher.AllAppsView"; |
| 63 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 64 | private RenderScript mRS; |
| 65 | private RolloRS mRollo; |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 66 | private ArrayList<ApplicationInfo> mAllAppsList; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 67 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 68 | private ViewConfiguration mConfig; |
| 69 | private VelocityTracker mVelocity; |
| 70 | private int mLastScrollX; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 71 | private int mLastMotionX; |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 72 | private ApplicationsAdapter mAdapter; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 73 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 74 | |
| 75 | public AllAppsView(Context context, AttributeSet attrs) { |
| 76 | super(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 77 | setFocusable(true); |
| 78 | getHolder().setFormat(PixelFormat.TRANSLUCENT); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 79 | mConfig = ViewConfiguration.get(context); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 82 | public AllAppsView(Context context, AttributeSet attrs, int defStyle) { |
| 83 | this(context, attrs); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 86 | void setAdapter(ApplicationsAdapter adapter) { |
| 87 | if (mAdapter != null) { |
| 88 | mAdapter.unregisterDataSetObserver(mIconObserver); |
| 89 | } |
| 90 | mAdapter = adapter; |
| 91 | if (adapter != null) { |
| 92 | adapter.registerDataSetObserver(mIconObserver); |
| 93 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 96 | @Override |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 97 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 98 | super.surfaceChanged(holder, format, w, h); |
| 99 | |
Jason Sams | b58cbdc | 2009-08-21 16:56:58 -0700 | [diff] [blame] | 100 | mRS = createRenderScript(true); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 101 | mRollo = new RolloRS(); |
| 102 | mRollo.init(getResources(), w, h); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 103 | if (mAllAppsList != null) { |
| 104 | mRollo.setApps(mAllAppsList); |
| 105 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public boolean onKeyDown(int keyCode, KeyEvent event) |
| 110 | { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 111 | // this method doesn't work when 'extends View' include 'extends ScrollView'. |
| 112 | return super.onKeyDown(keyCode, event); |
| 113 | } |
| 114 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 115 | @Override |
| 116 | public boolean onTouchEvent(MotionEvent ev) |
| 117 | { |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 118 | int x = (int)ev.getX(); |
| 119 | int deltaX; |
| 120 | switch (ev.getAction()) { |
| 121 | case MotionEvent.ACTION_DOWN: |
| 122 | mLastMotionX = x; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 123 | mRollo.mState.read(); |
| 124 | mRollo.mState.scrollX = mLastScrollX = mRollo.mState.currentScrollX; |
| 125 | mRollo.mState.flingVelocityX = 0; |
| 126 | mRollo.mState.adjustedDeceleration = 0; |
| 127 | mRollo.mState.save(); |
| 128 | mVelocity = VelocityTracker.obtain(); |
| 129 | mVelocity.addMovement(ev); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 130 | break; |
| 131 | case MotionEvent.ACTION_MOVE: |
| 132 | case MotionEvent.ACTION_OUTSIDE: |
| 133 | deltaX = x - mLastMotionX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 134 | mVelocity.addMovement(ev); |
| 135 | mRollo.mState.currentScrollX = mLastScrollX; |
| 136 | mLastScrollX += deltaX; |
| 137 | mRollo.mState.scrollX = mLastScrollX; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 138 | mRollo.mState.save(); |
| 139 | mLastMotionX = x; |
| 140 | break; |
| 141 | case MotionEvent.ACTION_UP: |
| 142 | case MotionEvent.ACTION_CANCEL: |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 143 | mVelocity.computeCurrentVelocity(1000 /* px/sec */, |
| 144 | mConfig.getScaledMaximumFlingVelocity()); |
| 145 | mRollo.mState.flingTimeMs = (int)SystemClock.uptimeMillis(); // TODO: use long |
| 146 | mRollo.mState.flingVelocityX = (int)mVelocity.getXVelocity(); |
| 147 | mRollo.mState.save(); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 148 | mLastMotionX = -10000; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 149 | mVelocity.recycle(); |
| 150 | mVelocity = null; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 151 | break; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 152 | } |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 153 | return true; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public boolean onTrackballEvent(MotionEvent ev) |
| 158 | { |
| 159 | float x = ev.getX(); |
| 160 | float y = ev.getY(); |
| 161 | //Float tx = new Float(x); |
| 162 | //Float ty = new Float(y); |
| 163 | //Log.e("rs", "tbe " + tx.toString() + ", " + ty.toString()); |
| 164 | |
| 165 | |
| 166 | return true; |
| 167 | } |
| 168 | |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 169 | DataSetObserver mIconObserver = new DataSetObserver() { |
| 170 | public void onChanged() { |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 171 | Log.d(TAG, "new icons arrived! now have " + mAdapter.getCount()); |
Joe Onorato | 7c312c1 | 2009-08-13 21:36:53 -0700 | [diff] [blame] | 172 | } |
| 173 | }; |
| 174 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 175 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 176 | mAllAppsList = list; |
| 177 | if (mRollo != null) { |
| 178 | mRollo.setApps(list); |
| 179 | } |
| 180 | } |
| 181 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 182 | public class RolloRS { |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 183 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 184 | // Allocations ====== |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 185 | |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 186 | private int mWidth; |
| 187 | private int mHeight; |
| 188 | |
| 189 | private Resources mRes; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 190 | private Script mScript; |
| 191 | private Sampler mSampler; |
| 192 | private Sampler mSamplerText; |
| 193 | private ProgramStore mPSBackground; |
| 194 | private ProgramStore mPSText; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 195 | private ProgramFragment mPFDebug; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 196 | private ProgramFragment mPFImages; |
| 197 | private ProgramFragment mPFText; |
| 198 | private ProgramVertex mPV; |
| 199 | private ProgramVertex.MatrixAllocation mPVAlloc; |
| 200 | private ProgramVertex mPVOrtho; |
| 201 | private ProgramVertex.MatrixAllocation mPVOrthoAlloc; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 202 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 203 | private Allocation[] mIcons; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 204 | private int[] mAllocIconIDBuf; |
| 205 | private Allocation mAllocIconID; |
| 206 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 207 | private Allocation[] mLabels; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 208 | private int[] mAllocLabelIDBuf; |
| 209 | private Allocation mAllocLabelID; |
| 210 | |
| 211 | private int[] mAllocScratchBuf; |
| 212 | private Allocation mAllocScratch; |
| 213 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 214 | Params mParams; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 215 | State mState; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 216 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 217 | class Defines { |
| 218 | public static final int ALLOC_PARAMS = 0; |
| 219 | public static final int ALLOC_STATE = 1; |
| 220 | public static final int ALLOC_SCRATCH = 2; |
| 221 | public static final int ALLOC_ICON_IDS = 3; |
| 222 | public static final int ALLOC_LABEL_IDS = 4; |
| 223 | } |
| 224 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 225 | class Params extends IntAllocation { |
| 226 | Params(RenderScript rs) { |
| 227 | super(rs); |
| 228 | } |
| 229 | @AllocationIndex(0) public int bubbleWidth; |
| 230 | @AllocationIndex(1) public int bubbleHeight; |
| 231 | @AllocationIndex(2) public int bubbleBitmapWidth; |
| 232 | @AllocationIndex(3) public int bubbleBitmapHeight; |
| 233 | } |
| 234 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 235 | class State extends IntAllocation { |
| 236 | State(RenderScript rs) { |
| 237 | super(rs); |
| 238 | } |
| 239 | @AllocationIndex(0) public int iconCount; |
| 240 | @AllocationIndex(1) public int scrollX; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 241 | @AllocationIndex(2) public int flingTimeMs; |
| 242 | @AllocationIndex(3) public int flingVelocityX; |
| 243 | @AllocationIndex(4) public int adjustedDeceleration; |
| 244 | @AllocationIndex(5) public int currentScrollX; |
Joe Onorato | eb2c02e | 2009-08-12 21:40:52 -0700 | [diff] [blame] | 245 | @AllocationIndex(6) public int flingDuration; |
| 246 | @AllocationIndex(7) public int flingEndPos; |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | public RolloRS() { |
| 250 | } |
| 251 | |
| 252 | public void init(Resources res, int width, int height) { |
| 253 | mRes = res; |
| 254 | mWidth = width; |
| 255 | mHeight = height; |
| 256 | initGl(); |
| 257 | initData(); |
| 258 | initRs(); |
| 259 | } |
| 260 | |
| 261 | private void initGl() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 262 | Sampler.Builder sb = new Sampler.Builder(mRS); |
| 263 | sb.setMin(Sampler.Value.LINEAR);//_MIP_LINEAR); |
| 264 | sb.setMag(Sampler.Value.LINEAR); |
| 265 | sb.setWrapS(Sampler.Value.CLAMP); |
| 266 | sb.setWrapT(Sampler.Value.CLAMP); |
| 267 | mSampler = sb.create(); |
| 268 | |
| 269 | sb.setMin(Sampler.Value.NEAREST); |
| 270 | sb.setMag(Sampler.Value.NEAREST); |
| 271 | mSamplerText = sb.create(); |
| 272 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 273 | ProgramFragment.Builder dbg = new ProgramFragment.Builder(mRS, null, null); |
| 274 | mPFDebug = dbg.create(); |
| 275 | mPFDebug.setName("PFDebug"); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 276 | |
| 277 | ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); |
| 278 | bf.setTexEnable(true, 0); |
| 279 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 280 | mPFImages = bf.create(); |
| 281 | mPFImages.setName("PF"); |
| 282 | mPFImages.bindSampler(mSampler, 0); |
| 283 | |
| 284 | bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); |
| 285 | mPFText = bf.create(); |
| 286 | mPFText.setName("PFText"); |
| 287 | mPFText.bindSampler(mSamplerText, 0); |
| 288 | |
| 289 | ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null); |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame^] | 290 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 291 | bs.setDitherEnable(false); |
| 292 | bs.setDepthMask(true); |
| 293 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 294 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 295 | mPSBackground = bs.create(); |
| 296 | mPSBackground.setName("PFS"); |
| 297 | |
| 298 | bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS); |
| 299 | bs.setDepthMask(false); |
| 300 | bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA, |
| 301 | ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA); |
| 302 | mPSText = bs.create(); |
| 303 | mPSText.setName("PFSText"); |
| 304 | |
| 305 | mPVAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 306 | mPVAlloc.setupProjectionNormalized(mWidth, mHeight); |
| 307 | |
| 308 | ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null); |
| 309 | mPV = pvb.create(); |
| 310 | mPV.setName("PV"); |
| 311 | mPV.bindAllocation(mPVAlloc); |
| 312 | |
| 313 | mPVOrthoAlloc = new ProgramVertex.MatrixAllocation(mRS); |
| 314 | mPVOrthoAlloc.setupOrthoWindow(mWidth, mHeight); |
| 315 | |
| 316 | pvb.setTextureMatrixEnable(true); |
| 317 | mPVOrtho = pvb.create(); |
| 318 | mPVOrtho.setName("PVOrtho"); |
| 319 | mPVOrtho.bindAllocation(mPVOrthoAlloc); |
| 320 | |
| 321 | mRS.contextBindProgramVertex(mPV); |
| 322 | |
| 323 | mAllocScratchBuf = new int[32]; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 324 | mAllocScratch = Allocation.createSized(mRS, Element.USER_I32, mAllocScratchBuf.length); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 325 | mAllocScratch.data(mAllocScratchBuf); |
| 326 | |
| 327 | Log.e("rs", "Done loading named"); |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 330 | private void initData() { |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 331 | mParams = new Params(mRS); |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 332 | mState = new State(mRS); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 333 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 334 | final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 335 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 336 | mParams.bubbleWidth = bubble.getBubbleWidth(); |
| 337 | mParams.bubbleHeight = bubble.getMaxBubbleHeight(); |
| 338 | mParams.bubbleBitmapWidth = bubble.getBitmapWidth(); |
| 339 | mParams.bubbleBitmapHeight = bubble.getBitmapHeight(); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 340 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 341 | mParams.save(); |
| 342 | mState.save(); |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 343 | |
| 344 | setApps(null); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Joe Onorato | bf15cb4 | 2009-08-07 14:33:40 -0700 | [diff] [blame] | 347 | Allocation makeTextBitmap(Utilities.BubbleText bubble, String label) { |
| 348 | Bitmap b = bubble.createTextBitmap(label); |
| 349 | Allocation a = Allocation.createFromBitmap(mRS, b, Element.RGBA_8888, true); |
| 350 | b.recycle(); |
| 351 | return a; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Joe Onorato | 1feb3a8 | 2009-08-08 22:32:00 -0700 | [diff] [blame] | 354 | private void initRs() { |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 355 | ScriptC.Builder sb = new ScriptC.Builder(mRS); |
| 356 | sb.setScript(mRes, R.raw.rollo); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 357 | sb.setRoot(true); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 358 | sb.addDefines(Defines.class); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 359 | mScript = sb.create(); |
| 360 | mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 361 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 362 | mScript.bindAllocation(mParams.getAllocation(), Defines.ALLOC_PARAMS); |
| 363 | mScript.bindAllocation(mState.getAllocation(), Defines.ALLOC_STATE); |
| 364 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 365 | mScript.bindAllocation(mAllocScratch, Defines.ALLOC_SCRATCH); |
| 366 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 367 | |
| 368 | mRS.contextBindRootScript(mScript); |
| 369 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 370 | |
Joe Onorato | 9c1289c | 2009-08-17 11:03:03 -0400 | [diff] [blame] | 371 | private void setApps(ArrayList<ApplicationInfo> list) { |
| 372 | final int count = list != null ? list.size() : 0; |
| 373 | mIcons = new Allocation[count]; |
| 374 | mAllocIconIDBuf = new int[count]; |
| 375 | mAllocIconID = Allocation.createSized(mRS, Element.USER_I32, count); |
| 376 | |
| 377 | mLabels = new Allocation[count]; |
| 378 | mAllocLabelIDBuf = new int[count]; |
| 379 | mAllocLabelID = Allocation.createSized(mRS, Element.USER_I32, count); |
| 380 | |
| 381 | Element ie8888 = Element.RGBA_8888; |
| 382 | |
| 383 | Utilities.BubbleText bubble = new Utilities.BubbleText(getContext()); |
| 384 | |
| 385 | for (int i=0; i<count; i++) { |
| 386 | final ApplicationInfo item = list.get(i); |
| 387 | |
| 388 | mIcons[i] = Allocation.createFromBitmap(mRS, item.iconBitmap, |
| 389 | Element.RGBA_8888, true); |
| 390 | mLabels[i] = Allocation.createFromBitmap(mRS, item.titleBitmap, |
| 391 | Element.RGBA_8888, true); |
| 392 | |
| 393 | mIcons[i].uploadToTexture(0); |
| 394 | mLabels[i].uploadToTexture(0); |
| 395 | |
| 396 | mAllocIconIDBuf[i] = mIcons[i].getID(); |
| 397 | mAllocLabelIDBuf[i] = mLabels[i].getID(); |
| 398 | } |
| 399 | |
| 400 | mAllocIconID.data(mAllocIconIDBuf); |
| 401 | mAllocLabelID.data(mAllocLabelIDBuf); |
| 402 | |
| 403 | mState.iconCount = count; |
| 404 | |
| 405 | Log.d("AllAppsView", "mScript=" + mScript + " mAllocIconID=" + mAllocIconID); |
| 406 | |
| 407 | if (mScript != null) { // wtf |
| 408 | mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS); |
| 409 | mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); |
| 410 | } |
| 411 | |
| 412 | mState.save(); |
| 413 | } |
| 414 | } |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | |
| 418 | |