Home | History | Annotate | Download | only in carouseltest
      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 
     17 package com.android.carouseltest;
     18 
     19 import com.android.ex.carousel.CarouselView;
     20 import com.android.ex.carousel.CarouselViewHelper;
     21 
     22 import android.app.Activity;
     23 import android.content.Context;
     24 import android.content.res.Resources;
     25 import android.graphics.Bitmap;
     26 import android.graphics.BitmapFactory;
     27 import android.os.Bundle;
     28 import android.util.Log;
     29 
     30 public class MusicDemoActivity extends Activity {
     31     private static final String TAG = "MusicDemoActivity";
     32     private static final int CD_GEOMETRY = R.raw.book;
     33     private static final int VISIBLE_SLOTS = 7;
     34     private static final int CARD_SLOTS = 56;
     35     private static final int TOTAL_CARDS = 10000;
     36     private CarouselView mView;
     37     private int mImageResources[] = {
     38         R.drawable.emo_im_angel,
     39         R.drawable.emo_im_cool,
     40         R.drawable.emo_im_crying,
     41         R.drawable.emo_im_foot_in_mouth,
     42         R.drawable.emo_im_happy,
     43         R.drawable.emo_im_kissing,
     44         R.drawable.emo_im_laughing,
     45         R.drawable.emo_im_lips_are_sealed,
     46         R.drawable.emo_im_money_mouth,
     47         R.drawable.emo_im_sad,
     48         R.drawable.emo_im_surprised,
     49         R.drawable.emo_im_tongue_sticking_out,
     50         R.drawable.emo_im_undecided,
     51         R.drawable.emo_im_winking,
     52         R.drawable.emo_im_wtf,
     53         R.drawable.emo_im_yelling
     54     };
     55 
     56     private LocalCarouselViewHelper mHelper;
     57 
     58     class LocalCarouselViewHelper extends CarouselViewHelper {
     59 
     60         LocalCarouselViewHelper(Context context) {
     61             super(context);
     62         }
     63 
     64         @Override
     65         public void onCardSelected(int id) {
     66             Log.v(TAG, "Yay, item " + id + " was selected!");
     67         }
     68 
     69         @Override
     70         public Bitmap getTexture(int n) {
     71             return BitmapFactory.decodeResource(getResources(),
     72                     mImageResources[n % mImageResources.length]);
     73         }
     74 
     75         @Override
     76         public Bitmap getDetailTexture(int n) {
     77             return null;
     78         }
     79     };
     80 
     81     @Override
     82     protected void onCreate(Bundle savedInstanceState) {
     83         super.onCreate(savedInstanceState);
     84         final Resources res = getResources();
     85         setContentView(R.layout.music_demo);
     86         mView = (CarouselView) findViewById(R.id.carousel);
     87         mHelper = new LocalCarouselViewHelper(this);
     88         mHelper.setCarouselView(mView);
     89         mView.setSlotCount(CARD_SLOTS);
     90         mView.createCards(TOTAL_CARDS);
     91         mView.setVisibleSlots(VISIBLE_SLOTS);
     92         mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS));
     93         mView.setDefaultBitmap(BitmapFactory.decodeResource(res, R.drawable.wait));
     94         mView.setLoadingBitmap(BitmapFactory.decodeResource(res, R.drawable.blank_album));
     95         mView.setBackgroundBitmap(BitmapFactory.decodeResource(res, R.drawable.background));
     96         mView.setDefaultGeometry(CD_GEOMETRY);
     97         mView.setFadeInDuration(250);
     98         mView.setRezInCardCount(3.0f);
     99         mView.setForceBlendCardsWithZ(false);
    100     }
    101 
    102     @Override
    103     protected void onResume() {
    104         super.onResume();
    105         mHelper.onResume();
    106     }
    107 
    108     @Override
    109     protected void onPause() {
    110         super.onPause();
    111         mHelper.onPause();
    112     }
    113 }
    114