CarouselTestActivity.java revision a3cb716626b477c98ba912698c765eab20f27286
1/* 2 * Copyright (C) 2010 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 17package com.android.carouseltest; 18 19import com.android.carouseltest.MyCarouselView; 20import com.android.carouseltest.TaskSwitcherActivity.ActivityDescription; 21import com.android.ex.carousel.CarouselView; 22import com.android.ex.carousel.CarouselViewHelper; 23import com.android.ex.carousel.CarouselViewHelper.DetailTextureParameters; 24 25import android.app.Activity; 26import android.content.ActivityNotFoundException; 27import android.content.Context; 28import android.content.Intent; 29import android.content.res.Resources; 30import android.graphics.Bitmap; 31import android.graphics.BitmapFactory; 32import android.graphics.Canvas; 33import android.graphics.Paint; 34import android.graphics.Rect; 35import android.os.Bundle; 36import android.util.Log; 37 38public class CarouselTestActivity extends Activity { 39 private static final String TAG = "CarouselTestActivity"; 40 private static final int CARD_SLOTS = 56; 41 private static final int TOTAL_CARDS = 1000; 42 private static final int TEXTURE_HEIGHT = 512; 43 private static final int TEXTURE_WIDTH = 512; 44 private static final int SLOTS_VISIBLE = 7; 45 46 protected static final boolean DBG = false; 47 private static final int DETAIL_TEXTURE_WIDTH = 200; 48 private static final int DETAIL_TEXTURE_HEIGHT = 80; 49 private CarouselView mView; 50 private Paint mPaint = new Paint(); 51 private CarouselViewHelper mHelper; 52 private Bitmap mGlossyOverlay; 53 private Bitmap mBorder; 54 55 class LocalCarouselViewHelper extends CarouselViewHelper { 56 private static final int PIXEL_BORDER = 3; 57 private DetailTextureParameters mDetailTextureParameters 58 = new DetailTextureParameters(5.0f, 5.0f); 59 60 LocalCarouselViewHelper(Context context) { 61 super(context); 62 } 63 64 @Override 65 public void onCardSelected(int id) { 66 Log.v(TAG, "Yay, card " + id + " was selected!"); 67 } 68 69 @Override 70 public DetailTextureParameters getDetailTextureParameters(int id) { 71 return mDetailTextureParameters; 72 } 73 74 @Override 75 public Bitmap getTexture(int n) { 76 Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 77 Bitmap.Config.ARGB_8888); 78 Canvas canvas = new Canvas(bitmap); 79 canvas.drawARGB(0, 0, 0, 0); 80 mPaint.setTextSize(100.0f); 81 mPaint.setAntiAlias(true); 82 mPaint.setColor(0xffffffff); 83 canvas.drawText(""+n, 0, TEXTURE_HEIGHT-10, mPaint); 84 canvas.drawBitmap(mGlossyOverlay, null, 85 new Rect(PIXEL_BORDER, PIXEL_BORDER, 86 TEXTURE_WIDTH - PIXEL_BORDER, TEXTURE_HEIGHT - PIXEL_BORDER), mPaint); 87 return bitmap; 88 } 89 90 @Override 91 public Bitmap getDetailTexture(int n) { 92 Bitmap bitmap = Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT, 93 Bitmap.Config.ARGB_8888); 94 Canvas canvas = new Canvas(bitmap); 95 canvas.drawARGB(200, 200, 200, 255); 96 mPaint.setTextSize(15.0f); 97 mPaint.setAntiAlias(true); 98 canvas.drawText("Detail text for card " + n, 0, DETAIL_TEXTURE_HEIGHT/2, mPaint); 99 return bitmap; 100 } 101 }; 102 103 @Override 104 protected void onCreate(Bundle savedInstanceState) { 105 super.onCreate(savedInstanceState); 106 107 mView = new MyCarouselView(this); 108 mPaint.setColor(0xffffffff); 109 final Resources res = getResources(); 110 111 mHelper = new LocalCarouselViewHelper(this); 112 mHelper.setCarouselView(mView); 113 mView.setSlotCount(CARD_SLOTS); 114 mView.createCards(TOTAL_CARDS); 115 mView.setVisibleSlots(SLOTS_VISIBLE); 116 mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS)); 117 mBorder = BitmapFactory.decodeResource(res, R.drawable.border); 118 mView.setDefaultBitmap(mBorder); 119 mView.setLoadingBitmap(mBorder); 120 mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 1.0f); 121 122 mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay); 123 setContentView(mView); 124 } 125 126 @Override 127 protected void onResume() { 128 super.onResume(); 129 mHelper.onResume(); 130 } 131 132 @Override 133 protected void onPause() { 134 super.onPause(); 135 mHelper.onPause(); 136 } 137 138} 139