• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import com.example.android.apis.R;
20 
21 import android.app.Activity;
22 import android.os.Bundle;
23 import android.view.Gravity;
24 import android.view.View;
25 import android.view.animation.Animation;
26 import android.view.animation.AnimationUtils;
27 import android.widget.Button;
28 import android.widget.TextSwitcher;
29 import android.widget.TextView;
30 import android.widget.ViewSwitcher;
31 
32 /**
33  * Uses a TextSwitcher.
34  */
35 public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
36         View.OnClickListener {
37 
38     private TextSwitcher mSwitcher;
39 
40     private int mCounter = 0;
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45 
46         setContentView(R.layout.text_switcher_1);
47 
48         mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
49         mSwitcher.setFactory(this);
50 
51         Animation in = AnimationUtils.loadAnimation(this,
52                 android.R.anim.fade_in);
53         Animation out = AnimationUtils.loadAnimation(this,
54                 android.R.anim.fade_out);
55         mSwitcher.setInAnimation(in);
56         mSwitcher.setOutAnimation(out);
57 
58         Button nextButton = (Button) findViewById(R.id.next);
59         nextButton.setOnClickListener(this);
60 
61         updateCounter();
62     }
63 
onClick(View v)64     public void onClick(View v) {
65         mCounter++;
66         updateCounter();
67     }
68 
updateCounter()69     private void updateCounter() {
70         mSwitcher.setText(String.valueOf(mCounter));
71     }
72 
makeView()73     public View makeView() {
74         TextView t = new TextView(this);
75         t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
76         t.setTextSize(36);
77         return t;
78     }
79 }
80