Home | History | Annotate | Download | only in animationsdemo
      1 /*
      2  * Copyright 2012 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.example.android.animationsdemo;
     18 
     19 import android.app.Activity;
     20 import android.app.ListActivity;
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.view.View;
     24 import android.widget.ArrayAdapter;
     25 import android.widget.ListView;
     26 
     27 /**
     28  * The launchpad activity for this sample project. This activity launches other activities that
     29  * demonstrate implementations of common animations.
     30  */
     31 public class MainActivity extends ListActivity {
     32     /**
     33      * This class describes an individual sample (the sample title, and the activity class that
     34      * demonstrates this sample).
     35      */
     36     private class Sample {
     37         private CharSequence title;
     38         private Class<? extends Activity> activityClass;
     39 
     40         public Sample(int titleResId, Class<? extends Activity> activityClass) {
     41             this.activityClass = activityClass;
     42             this.title = getResources().getString(titleResId);
     43         }
     44 
     45         @Override
     46         public String toString() {
     47             return title.toString();
     48         }
     49     }
     50 
     51     /**
     52      * The collection of all samples in the app. This gets instantiated in {@link
     53      * #onCreate(android.os.Bundle)} because the {@link Sample} constructor needs access to {@link
     54      * android.content.res.Resources}.
     55      */
     56     private static Sample[] mSamples;
     57 
     58     public void onCreate(Bundle savedInstanceState) {
     59         super.onCreate(savedInstanceState);
     60         setContentView(R.layout.activity_main);
     61 
     62         // Instantiate the list of samples.
     63         mSamples = new Sample[]{
     64                 new Sample(R.string.title_crossfade, CrossfadeActivity.class),
     65                 new Sample(R.string.title_card_flip, CardFlipActivity.class),
     66                 new Sample(R.string.title_screen_slide, ScreenSlideActivity.class),
     67                 new Sample(R.string.title_zoom, ZoomActivity.class),
     68                 new Sample(R.string.title_layout_changes, LayoutChangesActivity.class),
     69         };
     70 
     71         setListAdapter(new ArrayAdapter<Sample>(this,
     72                 android.R.layout.simple_list_item_1,
     73                 android.R.id.text1,
     74                 mSamples));
     75     }
     76 
     77     @Override
     78     protected void onListItemClick(ListView listView, View view, int position, long id) {
     79         // Launch the sample associated with this list position.
     80         startActivity(new Intent(MainActivity.this, mSamples[position].activityClass));
     81     }
     82 }
     83