1 /* 2 * Copyright (C) 2007 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.apis.view; 18 19 // Need the following import to get access to the app resources, since this 20 // class is in a sub-package. 21 import com.example.android.apis.R; 22 23 import android.app.Activity; 24 import android.os.Bundle; 25 import android.view.View; 26 import android.view.animation.AnimationUtils; 27 import android.widget.AdapterView; 28 import android.widget.ArrayAdapter; 29 import android.widget.Spinner; 30 import android.widget.ViewFlipper; 31 32 33 public class Animation2 extends Activity implements 34 AdapterView.OnItemSelectedListener { 35 36 @Override onCreate(Bundle savedInstanceState)37 public void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setContentView(R.layout.animation_2); 40 41 mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper)); 42 mFlipper.startFlipping(); 43 44 Spinner s = (Spinner) findViewById(R.id.spinner); 45 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 46 android.R.layout.simple_spinner_item, mStrings); 47 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 48 s.setAdapter(adapter); 49 s.setOnItemSelectedListener(this); 50 } 51 onItemSelected(AdapterView<?> parent, View v, int position, long id)52 public void onItemSelected(AdapterView<?> parent, View v, int position, long id) { 53 switch (position) { 54 55 case 0: 56 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 57 R.anim.push_up_in)); 58 mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 59 R.anim.push_up_out)); 60 break; 61 case 1: 62 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 63 R.anim.push_left_in)); 64 mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 65 R.anim.push_left_out)); 66 break; 67 case 2: 68 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 69 android.R.anim.fade_in)); 70 mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 71 android.R.anim.fade_out)); 72 break; 73 default: 74 mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, 75 R.anim.hyperspace_in)); 76 mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, 77 R.anim.hyperspace_out)); 78 break; 79 } 80 } 81 onNothingSelected(AdapterView<?> parent)82 public void onNothingSelected(AdapterView<?> parent) { 83 } 84 85 private String[] mStrings = { 86 "Push up", "Push left", "Cross fade", "Hyperspace"}; 87 88 private ViewFlipper mFlipper; 89 90 } 91