• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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.app;
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 import com.example.android.apis.view.Controls1;
23 
24 import android.app.Activity;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.view.View;
28 import android.view.View.OnClickListener;
29 import android.widget.Button;
30 
31 
32 /**
33  * <p>Example of using a custom animation when transitioning between activities.</p>
34  */
35 public class Animation extends Activity {
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         setContentView(R.layout.activity_animation);
41 
42         // Watch for button clicks.
43         Button button = (Button)findViewById(R.id.fade_animation);
44         button.setOnClickListener(mFadeListener);
45         button = (Button)findViewById(R.id.zoom_animation);
46         button.setOnClickListener(mZoomListener);
47     }
48 
49     private OnClickListener mFadeListener = new OnClickListener() {
50         public void onClick(View v) {
51             // Request the next activity transition (here starting a new one).
52             startActivity(new Intent(Animation.this, Controls1.class));
53             // Supply a custom animation.  This one will just fade the new
54             // activity on top.  Note that we need to also supply an animation
55             // (here just doing nothing for the same amount of time) for the
56             // old activity to prevent it from going away too soon.
57             overridePendingTransition(R.anim.fade, R.anim.hold);
58         }
59     };
60 
61     private OnClickListener mZoomListener = new OnClickListener() {
62         public void onClick(View v) {
63             // Request the next activity transition (here starting a new one).
64             startActivity(new Intent(Animation.this, Controls1.class));
65             // This is a more complicated animation, involving transformations
66             // on both this (exit) and the new (enter) activity.  Note how for
67             // the duration of the animation we force the exiting activity
68             // to be Z-ordered on top (even though it really isn't) to achieve
69             // the effect we want.
70             overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
71         }
72     };
73 }
74 
75