Skip to content

Commit e1a1d47

Browse files
committed
updates
1 parent 9ccf2a1 commit e1a1d47

7 files changed

Lines changed: 216 additions & 46 deletions

File tree

‎de.vogella.android.animation/res/anim/myanimation.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<set xmlns:android="http://schemas.android.com/apk/res/android"
33
android:shareInterpolator="true">
44
<rotate android:fromDegrees="0" android:toDegrees="360"
5-
android:duration="2000" android:pivotX="50%" android:pivotY="90%"
5+
android:duration="5000" android:pivotX="50%" android:pivotY="90%"
66
android:startOffset="0">
77
</rotate>
88
</set>
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical" android:layout_width="fill_parent"
3+
android:id="@+id/layout" android:orientation="vertical" android:layout_width="fill_parent"
44
android:layout_height="fill_parent">
55
<TextView android:id="@+id/rotatetext" android:layout_width="fill_parent"
6-
android:layout_height="wrap_content" android:text="@string/hello" />
6+
android:layout_height="wrap_content" android:text="Will be rotated." />
77
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
8-
android:layout_height="wrap_content" android:text="Animate"
8+
android:layout_height="wrap_content" android:text="Rotate"
99
android:onClick="startAnimation"></Button>
1010
<TextView android:id="@+id/scrolltext" android:layout_width="fill_parent"
1111
android:layout_height="wrap_content" android:lines="1"
12-
android:text="This is a long text, working in the train, yeah you yeah."
13-
android:scrollHorizontally="true"/>
12+
android:text="Will be scrolled to the left."
13+
android:scrollHorizontally="true" />
1414
<Button android:id="@+id/Button02" android:layout_width="wrap_content"
15-
android:layout_height="wrap_content" android:text="Animate"
15+
android:layout_height="wrap_content" android:text="Animate to left + bounce"
16+
android:onClick="startAnimation"></Button>
17+
<TextView android:id="@+id/fadeout" android:layout_width="fill_parent"
18+
android:layout_height="wrap_content" android:lines="1"
19+
android:text="Will be faded out / in" android:scrollHorizontally="true" />
20+
<Button android:id="@+id/Button03" android:layout_width="wrap_content"
21+
android:layout_height="wrap_content" android:text="Fade"
22+
android:onClick="startAnimation"></Button>
23+
<Button android:id="@+id/Button04" android:layout_width="wrap_content"
24+
android:layout_height="wrap_content" android:text="Add / Remove component"
1625
android:onClick="startAnimation"></Button>
1726
</LinearLayout>

‎de.vogella.android.animation/src/de/vogella/android/animation/AnimationExample.java‎

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
import android.graphics.Paint;
55
import android.os.Bundle;
66
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.view.animation.AlphaAnimation;
79
import android.view.animation.Animation;
810
import android.view.animation.Animation.AnimationListener;
911
import android.view.animation.AnimationUtils;
12+
import android.view.animation.BounceInterpolator;
13+
import android.view.animation.LayoutAnimationController;
1014
import android.view.animation.TranslateAnimation;
11-
import android.widget.Button;
1215
import android.widget.TextView;
16+
import android.widget.Toast;
1317

1418
public class AnimationExample extends Activity implements AnimationListener {
19+
private TextView animatedView3;
20+
1521
/** Called when the activity is first created. */
1622
@Override
1723
public void onCreate(Bundle savedInstanceState) {
@@ -23,6 +29,7 @@ public void onCreate(Bundle savedInstanceState) {
2329
public void startAnimation(View view) {
2430
switch (view.getId()) {
2531
case R.id.Button01:
32+
// Show how to load an animation from XML
2633
Animation animation1 = AnimationUtils.loadAnimation(this,
2734
R.anim.myanimation);
2835
animation1.setAnimationListener(this);
@@ -31,16 +38,52 @@ public void startAnimation(View view) {
3138
break;
3239

3340
case R.id.Button02:
34-
// Get the window manager
35-
// Display display = getWindowManager().getDefaultDisplay();
36-
// int width = display.getWidth();
37-
Paint paint = new Paint();
38-
TextView animatedView2 = (TextView) findViewById(R.id.scrolltext);
39-
float measureTextCenter = paint.measureText(animatedView2.getText().toString());
40-
Animation animation2 = new TranslateAnimation(0f, -measureTextCenter, 0.0f, 0.0f);
41-
animation2.setDuration(2000);
42-
// animatedView.setAnimation(animation2);
43-
animatedView2.startAnimation(animation2);
41+
// Shows how to define a animation via code
42+
// Also use an Interpolator (BounceInterpolator)
43+
Paint paint = new Paint();
44+
TextView animatedView2 = (TextView) findViewById(R.id.scrolltext);
45+
float measureTextCenter = paint.measureText(animatedView2.getText()
46+
.toString());
47+
Animation animation2 = new TranslateAnimation(0f,
48+
-measureTextCenter, 0.0f, 0.0f);
49+
animation2.setDuration(5000);
50+
animation2.setInterpolator(new BounceInterpolator());
51+
animatedView2.startAnimation(animation2);
52+
break;
53+
54+
case R.id.Button03:
55+
// Demonstrate fading and adding an AnimationListener
56+
animatedView3 = (TextView) findViewById(R.id.fadeout);
57+
float from = 1.0f;
58+
float to = 0.0f;
59+
60+
if (animatedView3.getVisibility() == View.INVISIBLE) {
61+
from = to;
62+
to = 1.0f;
63+
}
64+
65+
Animation animation3 = new AlphaAnimation(from, to);
66+
animation3.setDuration(5000);
67+
animation3.setAnimationListener(this);
68+
animatedView3.startAnimation(animation3);
69+
70+
break;
71+
72+
case R.id.Button04:
73+
// Demonstrate LayoutAnimation
74+
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
75+
Animation animation4 = new AlphaAnimation(0.0f, 1.0f);
76+
animation4.setDuration(5000);
77+
LayoutAnimationController controller = new LayoutAnimationController(
78+
animation4, 0);
79+
layout.setLayoutAnimation(controller);
80+
81+
View button = findViewById(R.id.Button03);
82+
if (button == null) {
83+
layout.addView(button);
84+
} else {
85+
layout.removeView(button);
86+
}
4487
break;
4588

4689
default:
@@ -51,20 +94,22 @@ public void startAnimation(View view) {
5194

5295
@Override
5396
public void onAnimationStart(Animation animation) {
54-
97+
Toast.makeText(this, "Animation started", Toast.LENGTH_SHORT).show();
5598
}
5699

57100
@Override
58101
public void onAnimationEnd(Animation animation) {
59-
Animation inAnimation = AnimationUtils.makeInAnimation(this, false);
60-
Button button = new Button(this);
61-
button.setText("This is the new view");
62-
button.setAnimation(inAnimation);
102+
Toast.makeText(this, "Animation ended", Toast.LENGTH_SHORT).show();
103+
if (animatedView3.getVisibility() == View.VISIBLE) {
104+
animatedView3.setVisibility(View.INVISIBLE);
105+
} else {
106+
animatedView3.setVisibility(View.VISIBLE);
107+
}
63108
}
64109

65110
@Override
66111
public void onAnimationRepeat(Animation animation) {
67-
// TODO Auto-generated method stub
112+
Toast.makeText(this, "Animation rep", Toast.LENGTH_SHORT).show();
68113

69114
}
70115
}

‎de.vogella.android.listactivity/src/de/vogella/android/listactivity/MyList.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.app.ListActivity;
77
import android.os.Bundle;
88
import android.view.View;
9-
import android.widget.ArrayAdapter;
109
import android.widget.ListView;
1110
import android.widget.Toast;
1211

@@ -15,11 +14,9 @@ public class MyList extends ListActivity {
1514
/** Called when the activity is first created. */
1615
public void onCreate(Bundle icicle) {
1716
super.onCreate(icicle);
18-
// Create an array of Strings, that will be put to our ListActivity
19-
// ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,
20-
// getModel());
21-
ArrayAdapter<Model> adapter = new ArrayAdapter<Model>(this,
22-
android.R.layout.simple_list_item_1, getModel());
17+
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
18+
"Ubuntu", "Solaris", "Android", "iPhone" };
19+
MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, names);
2320
setListAdapter(adapter);
2421
}
2522

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package de.vogella.android.listactivity;
2+
3+
import android.app.Activity;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
7+
import android.widget.ArrayAdapter;
8+
import android.widget.ImageView;
9+
import android.widget.TextView;
10+
11+
public class MySimpleArrayAdapter extends ArrayAdapter<String> {
12+
private final Activity context;
13+
private final String[] names;
14+
15+
public MySimpleArrayAdapter(Activity context, String[] names) {
16+
super(context, R.layout.rowlayout, names);
17+
this.context = context;
18+
this.names = names;
19+
}
20+
21+
@Override
22+
public View getView(int position, View convertView, ViewGroup parent) {
23+
LayoutInflater inflater = context.getLayoutInflater();
24+
View rowView = inflater.inflate(R.layout.rowlayout, null, true);
25+
TextView textView = (TextView) rowView.findViewById(R.id.label);
26+
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
27+
textView.setText(names[position]);
28+
// Change the icon for Windows and iPhone
29+
String s = names[position];
30+
if (s.startsWith("Windows7") || s.startsWith("iPhone")
31+
|| s.startsWith("Solaris")) {
32+
33+
imageView.setImageResource(R.drawable.no);
34+
} else {
35+
imageView.setImageResource(R.drawable.ok);
36+
}
37+
38+
return rowView;
39+
}
40+
}

‎de.vogella.android.temperature/src/de/vogella/android/temperature/Convert.java‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package de.vogella.android.temperature;
32

43
import android.app.Activity;
@@ -36,17 +35,13 @@ public void myClickHandler(View view) {
3635
if (celsiusButton.isChecked()) {
3736
text.setText(String
3837
.valueOf(convertFahrenheitToCelsius(inputValue)));
38+
celsiusButton.setChecked(false);
39+
fahrenheitButton.setChecked(true);
3940
} else {
4041
text.setText(String
4142
.valueOf(convertCelsiusToFahrenheit(inputValue)));
42-
}
43-
// Switch to the other button
44-
if (fahrenheitButton.isChecked()) {
4543
fahrenheitButton.setChecked(false);
4644
celsiusButton.setChecked(true);
47-
} else {
48-
fahrenheitButton.setChecked(true);
49-
celsiusButton.setChecked(false);
5045
}
5146
break;
5247
}

0 commit comments

Comments
 (0)