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