CarouselTestActivity.java revision 420b44b8b11ec1c309ea130e69a6876325dbfef9
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.PixelFormat; 35import android.graphics.Rect; 36import android.os.Bundle; 37import android.util.Log; 38import android.view.WindowManager; 39 40public class CarouselTestActivity extends Activity { 41 private static final String TAG = "CarouselTestActivity"; 42 private static final int CARD_SLOTS = 56; 43 private static final int TOTAL_CARDS = 1000; 44 private static final int TEXTURE_HEIGHT = 256; 45 private static final int TEXTURE_WIDTH = 256; 46 private static final int SLOTS_VISIBLE = 7; 47 48 protected static final boolean DBG = false; 49 private static final int DETAIL_TEXTURE_WIDTH = 200; 50 private static final int DETAIL_TEXTURE_HEIGHT = 80; 51 private CarouselView mView; 52 private Paint mPaint = new Paint(); 53 private CarouselViewHelper mHelper; 54 private Bitmap mGlossyOverlay; 55 private Bitmap mBorder; 56 57 class LocalCarouselViewHelper extends CarouselViewHelper { 58 private static final int PIXEL_BORDER = 3; 59 private DetailTextureParameters mDetailTextureParameters 60 = new DetailTextureParameters(5.0f, 5.0f); 61 62 LocalCarouselViewHelper(Context context) { 63 super(context); 64 } 65 66 @Override 67 public void onCardSelected(int id) { 68 Log.v(TAG, "Yay, card " + id + " was selected!"); 69 } 70 71 @Override 72 public DetailTextureParameters getDetailTextureParameters(int id) { 73 return mDetailTextureParameters; 74 } 75 76 @Override 77 public Bitmap getTexture(int n) { 78 Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, 79 Bitmap.Config.ARGB_8888); 80 Canvas canvas = new Canvas(bitmap); 81 canvas.drawARGB(0, 0, 0, 0); 82 mPaint.setColor(0x40808080); 83 canvas.drawRect(2, 2, TEXTURE_WIDTH-2, TEXTURE_HEIGHT-2, mPaint); 84 mPaint.setTextSize(100.0f); 85 mPaint.setAntiAlias(true); 86 mPaint.setColor(0xffffffff); 87 canvas.drawText("" + n, 2, TEXTURE_HEIGHT-10, mPaint); 88 canvas.drawBitmap(mGlossyOverlay, null, 89 new Rect(PIXEL_BORDER, PIXEL_BORDER, 90 TEXTURE_WIDTH - PIXEL_BORDER, TEXTURE_HEIGHT - PIXEL_BORDER), mPaint); 91 return bitmap; 92 } 93 94 @Override 95 public Bitmap getDetailTexture(int n) { 96 Bitmap bitmap = Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT, 97 Bitmap.Config.ARGB_8888); 98 Canvas canvas = new Canvas(bitmap); 99 canvas.drawARGB(32, 10, 10, 10); 100 mPaint.setTextSize(15.0f); 101 mPaint.setAntiAlias(true); 102 canvas.drawText("Detail text for card " + n, 0, DETAIL_TEXTURE_HEIGHT/2, mPaint); 103 return bitmap; 104 } 105 }; 106 107 @Override 108 public CharSequence onCreateDescription() { 109 return getText(R.string.carousel_test_activity_description); 110 } 111 112 @Override 113 protected void onCreate(Bundle savedInstanceState) { 114 super.onCreate(savedInstanceState); 115 116 mView = new MyCarouselView(this); 117 mView.getHolder().setFormat(PixelFormat.TRANSLUCENT); 118 mPaint.setColor(0xffffffff); 119 final Resources res = getResources(); 120 121 mHelper = new LocalCarouselViewHelper(this); 122 mHelper.setCarouselView(mView); 123 mView.setSlotCount(CARD_SLOTS); 124 mView.createCards(TOTAL_CARDS); 125 mView.setVisibleSlots(SLOTS_VISIBLE); 126 mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS)); 127 mBorder = BitmapFactory.decodeResource(res, R.drawable.border); 128 mView.setDefaultBitmap(mBorder); 129 mView.setLoadingBitmap(mBorder); 130 mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 0.5f); 131 mView.setRezInCardCount(3.0f); 132 mView.setFadeInDuration(250); 133 134 mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay); 135 136 /* 137 mView.setBackgroundColor(0x80ffffff); 138 int flags = WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; 139 WindowManager.LayoutParams lp = new WindowManager.LayoutParams( 140 mView.getWidth(), mView.getHeight(), 141 WindowManager.LayoutParams.TYPE_APPLICATION, 142 flags, PixelFormat.TRANSLUCENT); 143 getWindow().setAttributes(lp); 144 */ 145 146 setContentView(mView); 147 } 148 149 @Override 150 protected void onResume() { 151 super.onResume(); 152 mHelper.onResume(); 153 } 154 155 @Override 156 protected void onPause() { 157 super.onPause(); 158 mHelper.onPause(); 159 } 160 161} 162