实例介绍
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | package com.android.graphic.iroom; import java.util.List; import com.android.graphic.iroom.R; import gocom.android.GoStyle.GOSTYLE; import gocom.android.GoStyle.Group; import gocom.android.GoStyle.Mesh; import gocom.android.GoStyle.OpenGLRenderer; import gocom.android.GoStyle.SimplePlane; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.net.Uri; import android.opengl.GLSurfaceView; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.text.StaticLayout; import android.text.TextPaint; import android.text.Layout.Alignment; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.MotionEvent; import android.view.Surface; import android.view.SurfaceHolder; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.Toast; public class IroomMenuAppListView extends GLSurfaceView{ private static final String TAG = "IroomAppView" ; public final int PageNUM = 10 ; // 最大支持十页 public int PAGE_LINE_NUM = 4 ; // 行 public int PAGE_ROW_NUM = 4 ; // 列 public int PAGE_ITEM_NUM = PAGE_LINE_NUM * PAGE_ROW_NUM; // 每页ITEM的数目 public final int CHILDNUM = 17 ; // 每页算法需要的元素的数目,包含背景等 public final int SPREADFRAME = 10 ; // 展开的帧数 public final int ICON_SIZE = 72 ; public final int BITMAP_SIZE = 128 ; public final int TEXT_HEIGHT = 56 ; public final int TEXT_START = 8 ; private final float START_TOUCH_MOVE_PIX = 5 ; private static final int SNAP_VELOCITY = 200 ; private final int WHOLEPASSFRAME = 20 ; private final int GO_MENU_STYLE_MAX_NUM = 15 ; private final int VIEW_UP_MAGIN = 30 ; private final int VIEW_LEFT_MAGIN = - 8 ; private final int VIEW_BOTTOM_MAGIN = 30 ; private int BOTTOM_BAR_HEIGHT; // public Group[] muPages = null ; public SimplePlane[][] iconcollection; public SimplePlane[][] textcollection; public boolean isinit = false ; public int mCurEffect = 0 ; public static final int PANEL_NUM = 4 ; public final SimplePlane panel[] = new SimplePlane[PANEL_NUM]; public Bitmap panelframe; private OpenGLRenderer renderer; private IRoomActivity mHome; private int mCurscreen = 0 ; private int mViewWidth = 480 ; private int mViewHeight = 762 ; private GOSTYLE mCurStyle = GOSTYLE.GO_CLASSIC; private int cFrame = 0 ; private int tFrame = 20 ; private float xFrame = 0 ; private float mXoffset = 0 ; private float mXstart = 0 ; private boolean mIsGoRight = false ; private boolean mIsMove = false ; private VelocityTracker mVelocityTracker; private int mTouchSlop; private int mMaximumVelocity; private Thread menuThread; private boolean ischangepage = false ; private boolean isoneframe = true ; private boolean isinanim = false ; private float scale; private List<ResolveInfo> mApps; private int mAppTotalNum = - 1 ; private Context mContext; public IroomMenuAppListView(Context context, AttributeSet attrs) { super (context, attrs); // TODO Auto-generated constructor stub Log.d(TAG, "construct" ); // We want an 8888 pixel format because that's required for // a translucent window. // And we want a depth buffer. setEGLConfigChooser( 8 , 8 , 8 , 8 , 16 , 0 ); // 这个要放在set renderer前 mContext = context; renderer = new OpenGLRenderer(mContext); this .setRenderer(renderer); // 按需渲染 setRenderMode(RENDERMODE_WHEN_DIRTY); // setZOrderOnTop(true); // 设置透明 getHolder().setFormat(PixelFormat.TRANSLUCENT); BOTTOM_BAR_HEIGHT = ( int ) (context.getResources() .getDimension(R.dimen.button_bar_height)); final ViewConfiguration configuration = ViewConfiguration .get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); Log.d(TAG, "mTouchSlop :" mTouchSlop); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mCurscreen = 0 ; } @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { // TODO Auto-generated method stub Log.d(TAG, "surfaceChanged" w); super .surfaceChanged(holder, format, w, h); mViewWidth = w; mViewHeight = h; if (mViewWidth>mViewHeight){ PAGE_LINE_NUM = 3 ; // 行 PAGE_ROW_NUM = 5 ; // 列 PAGE_ITEM_NUM = PAGE_LINE_NUM * PAGE_ROW_NUM; // 每页ITEM的数目 } else { PAGE_LINE_NUM = 4 ; // 行 PAGE_ROW_NUM = 4 ; // 列 PAGE_ITEM_NUM = PAGE_LINE_NUM * PAGE_ROW_NUM; // 每页ITEM的数目 } resetParams(); initRender(mViewWidth,mViewHeight); startRender( true ); } private void resetParams(){ ischangepage = false ; isoneframe = true ; isinanim = false ; cFrame = 0 ; tFrame = 20 ; xFrame = 0 ; mXoffset = 0 ; mXstart = 0 ; mIsGoRight = false ; mIsMove = false ; } @Override public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub Log.d(TAG, "surfaceCreated" ); super .surfaceCreated(holder); resetParams(); if (mHome.mAppNumView != null ){ mHome.mAppNumView.updateScreen(mCurscreen, getAppAllPageNum()); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub Log.d(TAG, "surfaceDestroyed" ); super .surfaceDestroyed(holder); } @Override protected void onVisibilityChanged(View changedView, int visibility) { // TODO Auto-generated method stub super .onVisibilityChanged(changedView, visibility); if (changedView == this ){ if (mHome.mAppNumView != null ){ if (visibility == View.VISIBLE){ mHome.mAppNumView.setVisibility(View.VISIBLE); } else { mHome.mAppNumView.setVisibility(View.GONE); } } } } @Override public boolean onTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub final int action = ev.getAction(); float x, y; Log.d(TAG, "onTouchEvent action :" action); if (mVelocityTracker == null ) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: x = ev.getX(); y = ev.getY(); if (!isinanim) { mcurX = mXstart = x; istpdown = true ; isSpreadAnim = - 1 ; } break ; case MotionEvent.ACTION_MOVE: x = ev.getX(); y = ev.getY(); if ((Math.abs(x - mXstart) > START_TOUCH_MOVE_PIX&&istpdown == true )|| mIsMove) { mcurX = x; mIsMove = true ; mIsGoRight = (x - mXstart) > 0 ? false : true ; mXoffset = Math.abs(x - mXstart); startRender( false ); } break ; case MotionEvent.ACTION_UP: x = ev.getX(); y = ev.getY(); if (istpdown){ istpdown = false ; if (mIsMove) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity( 1000 , mMaximumVelocity); final int velocityX = ( int ) velocityTracker.getXVelocity(); mXoffset = Math.abs(x - mXstart); upVecX = velocityX; mcurX = x; cFrame = 0 ; if (mXoffset > mViewWidth / 2 || Math.abs(velocityX) > SNAP_VELOCITY) { tFrame = ( int ) (WHOLEPASSFRAME * ( 1 - (mXoffset / mViewWidth))); if (tFrame == 0 ) { tFrame = 1 ; } ischangepage = true ; InitSlideInfo(); } else { ischangepage = false ; tFrame = 10 ; //(int)(WHOLEPASSFRAME *((Math.abs(mcurX-mstartX)/mViewWidth))); } startMenuAppRunnable(); mIsMove = false ; } else { int position = getTpSelectItemPosition(x, y); startSelectItem(position); } if (mVelocityTracker != null ) { mVelocityTracker.recycle(); mVelocityTracker = null ; } break ; } } return true ; } private int upVecX = 0 ; private float oneX = 0 ; private float mcurX = 0 ; private int isSpreadAnim = - 1 ; //-1代表正常状态,0代表收缩,1代表动画稳定态,2代表展开 private boolean istpdown = false ; private void InitSlideInfo() { Log.d(TAG, "upVecX :" upVecX); // mslideInfo.cosWdata =upVecX/MAXVECX; mslideInfo.cosWdata = upVecX / mMaximumVelocity; mslideInfo.sinWdata = ( float ) Math.sin(-Math.acos(mslideInfo.cosWdata)); if ( 1 != mslideInfo.sinWdata) { mslideInfo.a = ((Math.abs(mcurX - mXstart)) - mViewWidth) / (mslideInfo.sinWdata - 1 ); } mslideInfo.b = mViewWidth - mslideInfo.a; mslideInfo.w = mMaximumVelocity / mslideInfo.a; mslideInfo.xPlusdx = ( float ) -Math.acos((mslideInfo.cosWdata)); } private float loop_fuction_veccontinue() { float d_angle = 0 ; d_angle = ( float ) (Math.PI / 2 - mslideInfo.xPlusdx); oneX = ( float ) (mslideInfo.a * Math.sin(mslideInfo.xPlusdx d_angle * cFrame / tFrame) mslideInfo.b); return oneX; } private float loop_fuction() { oneX = ( float ) ((mcurX - mXstart) * Math .sin(( double ) (Math.PI / 2 Math.PI / 2 * cFrame / tFrame))); Log.d(TAG, "cFrame :" cFrame); Log.d(TAG, "tFrame :" tFrame); Log.d(TAG, "oneX :" oneX); return Math.abs(oneX); } private slideifo mslideInfo = new slideifo(); private class slideifo { public float a; public float w; public float b; public float sinWdata; public float cosWdata; public float xPlusdx; public slideifo() { } } private void computeScrollEX() { Log.d(TAG, "cFrame:" cFrame); Log.d(TAG, "tFrame:" tFrame); Log.d(TAG, "istpdown:" istpdown); Log.d(TAG, "ischangepage:" ischangepage); if (!istpdown) { if (isSpreadAnim == - 1 ) { mXoffset = 0 ; } else if (isSpreadAnim == 1 ||isSpreadAnim == 0 ) { if (cFrame == tFrame) { return ; } cFrame ; if (ischangepage) { mXoffset = loop_fuction_veccontinue(); if (mXoffset>=mViewWidth||cFrame == tFrame) { mXoffset = mViewWidth; mcurX = mViewWidth; } } else { mXoffset = loop_fuction(); if (mXoffset <= 0 ||cFrame == tFrame) { mXoffset = 0 ; mcurX = 0 ; } } } } } public void sendMsgToUpdateNumView(){ int what = 0 ; mHandler.sendEmptyMessage(what); } private void setCurScreen( int index) { if (index > 0 ) { mCurscreen = index % getAppAllPageNum(); } else { mCurscreen = (getAppAllPageNum() - Math.abs(index)) % getAppAllPageNum(); } sendMsgToUpdateNumView(); } public int getTpSelectItemPosition( float x, float y) { int position = 0 ; int curScreenPosition = 0 ; int gridW = mViewWidth / PAGE_ROW_NUM; int gridH = (mViewHeight - BOTTOM_BAR_HEIGHT - VIEW_UP_MAGIN - VIEW_BOTTOM_MAGIN) / PAGE_LINE_NUM; Log.d(TAG, "getTpSelectItemPosition x = " x "y= :" y); curScreenPosition = (( int ) (y - VIEW_UP_MAGIN)/ gridH) * PAGE_ROW_NUM ( int ) x / gridW; Log.d(TAG, "getTpSelectItemPosition curScreenPosition " curScreenPosition); if (curScreenPosition< 0 ||curScreenPosition>=PAGE_ITEM_NUM){ return - 1 ; } position = curScreenPosition mCurscreen * PAGE_ITEM_NUM; return position; } void startActivitySafely(Intent intent) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { mHome.StartActivityWithAnimation(intent); } catch (ActivityNotFoundException e) { Toast.makeText(mHome, "activity not found" , Toast.LENGTH_SHORT).show(); Log.e(TAG, "Unable to launch " " intent=" intent, e); } catch (SecurityException e) { Toast.makeText(mHome, "activity not found" , Toast.LENGTH_SHORT).show(); Log.e(TAG, "Launcher does not have the permission to launch " intent ". Make sure to create a MAIN intent-filter for the corresponding activity " "or use the exported attribute for this activity. " " intent=" intent, e); } } public void startSelectItem( int position) { Log.d(TAG, "startSelectItem position " position); if (position< 0 ||position>=getAppItemNum()){ return ; } Intent i = mHome.mIroomLoadApp.getItemInfo(position).intent; startActivitySafely(i); } public GOSTYLE getMenuStyle( int index) { GOSTYLE style = GOSTYLE.GO_CLASSIC; switch (index) { case 0 : // 随机 style = GOSTYLE.GO_RANDOM; break ; case 1 : style = GOSTYLE.GO_CLASSIC; break ; case 2 : style = GOSTYLE.GO_BALL; break ; case 3 : style = GOSTYLE.GO_CUBE; break ; case 4 : style = GOSTYLE.GO_CYLINDER; break ; case 5 : style = GOSTYLE.GO_MIDROTATE; break ; case 6 : style = GOSTYLE.GO_MIDS; break ; case 7 : style = GOSTYLE.GO_PUSH; break ; case 8 : style = GOSTYLE.GO_ROLL; break ; case 9 : style = GOSTYLE.GO_SHUTTER; break ; case 10 : style = GOSTYLE.GO_SMALLINOUT; break ; case 11 : style = GOSTYLE.GO_BINARY; break ; case 12 : style = GOSTYLE.GO_BAR; break ; case 13 : style = GOSTYLE.GO_BOXIN; break ; case 14 : style = GOSTYLE.GO_CIRCLE; break ; case 15 : style = GOSTYLE.GO_SMALLBOX; break ; default : style = GOSTYLE.GO_CLASSIC; break ; } return style; } public void setAppHome(IRoomActivity home) { mHome = home; final Resources resources = mHome.getResources(); final DisplayMetrics metrics = resources.getDisplayMetrics(); scale = metrics.density; } private void initRender( final int totalwidth, final int totalheight) { Log.d(TAG, "initRender" ); queueEvent( new Runnable() { //@Override public void run() { // TODO Auto-generated method stub Log.d(TAG, "initRender run!" ); int pageIndex = 0 ; muPages = new Group[PageNUM]; iconcollection = new SimplePlane[PageNUM][]; renderer.Pages = muPages; renderer.iconArr = iconcollection; for (pageIndex = 0 ; pageIndex < PageNUM; pageIndex ) { muPages[pageIndex] = new Group(); iconcollection[pageIndex] = new SimplePlane[CHILDNUM]; for ( int i = 0 ; i < CHILDNUM; i ) { iconcollection[pageIndex][i] = new SimplePlane(); } } panelframe = BitmapFactory.decodeResource(getResources(), R.drawable.panel_frame_big); for ( int i = 0 ; i < PANEL_NUM; i ) { panel[i] = new SimplePlane(); } renderer.InitGoRender(CHILDNUM, CHILDNUM, SPREADFRAME, false , panel); initCalcData(); isinit = true ; } }); } public int getAppAllPageNum() { int pagenum = 0 ; int ret = 2 ; pagenum = getAppItemNum() / PAGE_ITEM_NUM; ret = (getAppItemNum() % PAGE_ITEM_NUM == 0 ) ? pagenum : pagenum 1 ; if (ret == 0 ) { ret = 2 ; } Log.d(TAG, "getAppAllPageNum = " ret); return ret; } public int getAppItemPageNum( int position) { return position / PAGE_ITEM_NUM; } public int getPageItemNum( int page_index) { int item_num = 0 ; if (page_index == getAppAllPageNum() - 1 ) { if (getAppItemNum() == getAppAllPageNum()*PAGE_ITEM_NUM){ item_num = PAGE_ITEM_NUM; } else { item_num = getAppItemNum() % PAGE_ITEM_NUM; } } else { item_num = PAGE_ITEM_NUM; } return item_num; } public Bitmap getAppItemBmp( int position) { final ContentResolver cr = mContext.getContentResolver(); Bitmap iconbmp = null ; String icontext = null ; IRoomApplicationInfo info = mHome.mIroomLoadApp.getItemInfo(position); iconbmp = info.iconBitmap; icontext = (String)info.title; // include icon and name Bitmap tempbmp = Bitmap.createBitmap(BITMAP_SIZE, BITMAP_SIZE, Config.RGB_565); Canvas c = new Canvas(tempbmp); Log.d(TAG, "creat tempbmp = " tempbmp); if (iconbmp != null &&!iconbmp.isRecycled()) { int iconW = iconbmp.getWidth(); int iconH = iconbmp.getHeight(); c.drawBitmap(iconbmp, new Rect( 0 , 0 , iconW, iconH), new Rect( (BITMAP_SIZE - ICON_SIZE) / 2 , 0 , (BITMAP_SIZE ICON_SIZE) / 2 , ICON_SIZE), null ); } else { Log.d(TAG, "iconbmp is null" ); } if (icontext != null ) { TextPaint textPaint = new TextPaint(); textPaint.setTypeface(Typeface.DEFAULT); textPaint.setTextSize( 13 *scale); textPaint.setColor( 0xffffffff ); textPaint.setAntiAlias( true ); StaticLayout layout = new StaticLayout(icontext, textPaint, ( int )BITMAP_SIZE - 2 * TEXT_START, Alignment.ALIGN_CENTER, 1 , 0 , true ); c.translate(TEXT_START, ICON_SIZE); layout.draw(c); } return tempbmp; } static Bitmap getIconFromCursor(Cursor c, int iconIndex) { byte [] data = c.getBlob(iconIndex); try { return BitmapFactory.decodeByteArray(data, 0 , data.length); } catch (Exception e) { return null ; } } public void addMesh(Mesh mesh, int PageIndex) { muPages[PageIndex].add(mesh); } public void initCalcData() { int item_index = 0 ; int page_index = 0 ; int pagenum = getAppAllPageNum(); int pageitemnum = 0 ; int x = 0 , y = 0 ; int position = 0 ; int gridW = 0 ; int gridH = 0 ; Log.d(TAG, "initCalcData start !" ); gridW = (mViewWidth) / PAGE_ROW_NUM; gridH = (mViewHeight - BOTTOM_BAR_HEIGHT - VIEW_UP_MAGIN - VIEW_BOTTOM_MAGIN) / PAGE_LINE_NUM; Log.d(TAG, "totalheight" mViewHeight); for (page_index = 0 ; page_index < pagenum; page_index ) { pageitemnum = getPageItemNum(page_index); for (item_index = 0 ; item_index < pageitemnum; item_index ) { position = page_index * PAGE_ITEM_NUM item_index; Log.d(TAG, "position = " position); Bitmap tempbmp = getAppItemBmp(position); Log.d(TAG, "init calc Data = " tempbmp); x = (item_index % PAGE_ROW_NUM) * gridW VIEW_LEFT_MAGIN; y = (item_index / PAGE_ROW_NUM) * gridH VIEW_UP_MAGIN; iconcollection[page_index][item_index].Set(x, y, BITMAP_SIZE, BITMAP_SIZE, false , tempbmp); iconcollection[page_index][item_index].setVerticesLocation(x, y, BITMAP_SIZE, BITMAP_SIZE, mViewWidth, mViewHeight); addMesh(iconcollection[page_index][item_index], page_index); } } } public void startRender( boolean isUpdateOnly) { int curscreen = 0 ; int nextscreen = 0 ; int count = 0 ; int num1 = 0 ; int num2 = 0 ; count = getAppAllPageNum(); if (mIsGoRight) { curscreen = mCurscreen; nextscreen = (curscreen 1 )%count; } else { curscreen = mCurscreen; nextscreen = (curscreen count - 1 )%count; } num1 = getPageItemNum(curscreen); num2 = getPageItemNum(nextscreen); Log.d(TAG, "curscreen num:" num1); Log.d(TAG, "nextscreen num:" num2); Log.d(TAG, "curscreen :" curscreen); Log.d(TAG, "nextscreen :" nextscreen); updateumenusetparam(); Log.d(TAG, "isoneframe:" isoneframe); if (isSpreadAnim != - 1 ||isoneframe||isUpdateOnly){ setMenuRender(mCurStyle, xFrame, mXoffset, 0 , mViewWidth, mIsGoRight, num1, num2, curscreen, nextscreen, mViewWidth, mViewHeight); } else { isinanim = false ; } if (isSpreadAnim == - 1 ) { isoneframe = false ; } } private void setMenuRender( final GOSTYLE style, final float xframe, final float xoffset, final float yoffset, final float total_frame, final boolean isright, final int curnum, final int nextnum, final int curindex, final int nextindex, final int width, final int height) { Log.d(TAG, "setMenuRender" ); queueEvent( new Runnable() { // @Override public void run() { Log.d(TAG, "setMenuRender run !!" ); // TODO Auto-generated method stub Log.d(TAG, "style = " style); Log.d(TAG, "xframe = " xframe); Log.d(TAG, "xoffset = " xoffset); Log.d(TAG, "isright = " isright); Log.d(TAG, "curnum = " curnum); renderer.SetGoRender(style, xframe, xoffset, yoffset, total_frame, isright, curnum, nextnum, curindex, nextindex, width, height); requestRender(); } }); } public void startMenuAppRunnable(){ isinanim = true ; menuThread = new Thread( new menuAppRunnable()); menuThread.start(); } class menuAppRunnable implements Runnable { // @Override public void run() { while (isinanim) { startRender( false ); try { Thread.sleep( 17 ); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } private void updateumenusetparam() { int count = 0 ; count = getAppAllPageNum(); computeScrollEX(); //如果是球或者圆柱,需要播放收缩展开的帧数 if (mCurStyle == GOSTYLE.GO_CYLINDER||mCurStyle == GOSTYLE.GO_BALL) { if (isSpreadAnim == - 1 &&istpdown) //开始收缩 { isSpreadAnim = 0 ; xFrame = 0 ; } else if (isSpreadAnim == 0 &&!istpdown&&xFrame == 0 ) //收缩到正常 { isSpreadAnim = - 1 ; mXoffset = 0 ; isoneframe = true ; } else if (isSpreadAnim == 0 &&xFrame == SPREADFRAME) //收缩到稳定态 { isSpreadAnim = 1 ; } else if (mXoffset%mViewWidth== 0 &&(isSpreadAnim== 1 ) &&!istpdown ) //开始展开,没有必要达到稳定状态才展开 { isSpreadAnim = 2 ; if (ischangepage) { xFrame = SPREADFRAME 1 ; } else { xFrame = SPREADFRAME; } } else if (isSpreadAnim == 2 &&(xFrame == 2 *SPREADFRAME||xFrame == 0 )) //展开到正常态 { isSpreadAnim = - 1 ; isoneframe = true ; if (ischangepage) { if (mIsGoRight) { mCurscreen ; } else { mCurscreen = count; mCurscreen--; } mCurscreen = mCurscreen%count; setCurScreen(mCurscreen); ischangepage = false ; } } if (isSpreadAnim == 0 ) { if (istpdown) { xFrame ; } else { if (ischangepage) { xFrame ; } else { xFrame --; } } } else if (isSpreadAnim == 2 ) { if (ischangepage) { xFrame ; } else { xFrame --; } } } else { xFrame = 0 ; if (isSpreadAnim == - 1 &&istpdown) // { isSpreadAnim = 1 ; } else if (mXoffset%mViewWidth== 0 && isSpreadAnim == 1 && !istpdown ) { isSpreadAnim = - 1 ; isoneframe = true ; if (ischangepage) { if (mIsGoRight) { mCurscreen ; } else { mCurscreen = count; mCurscreen--; } mCurscreen = mCurscreen%count; setCurScreen(mCurscreen); ischangepage = false ; } } } Log.d(TAG, "isSpreadAnim :" isSpreadAnim); } private void updateNumView(){ if (mHome.mAppNumView != null ){ mHome.mAppNumView.updateScreen(mCurscreen, getAppAllPageNum()); } } private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { updateNumView(); } }; public int getAppItemNum() { mAppTotalNum = mHome.mIroomLoadApp.getAppItemNum(); Log.d(TAG, "getAppItemNum = " mAppTotalNum); return mAppTotalNum; } } |
标签: Android
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论