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