-
Notifications
You must be signed in to change notification settings - Fork 12
/
MainActivity.java
80 lines (65 loc) · 2.85 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Implement the Animation logic inside a native fragment subclass.
* Just like App1.13.4 , the animations are in /res/animator and wrapped in ObjectAnimator objects
*
*/
package com.blikoon.app1135;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button1;
private Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.go_to_1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NativeFragment fragment = new NativeFragment();
Bundle bundleArgs = new Bundle();
bundleArgs.putString("fragment_name","Second");
fragment.setArguments(bundleArgs);
FragmentTransaction ft = getFragmentManager().beginTransaction();
//Set the transition value to trigger the correct animations
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.add(R.id.fragment_container, fragment);
ft.addToBackStack(null);
ft.commit();
}
});
button2 = (Button) findViewById(R.id.go_to_2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NativeFragment fragment = new NativeFragment();
Bundle bundleArgs = new Bundle();
bundleArgs.putString("fragment_name","SecondAire");
fragment.setArguments(bundleArgs);
FragmentTransaction ft = getFragmentManager().beginTransaction();
//Set the transition value to trigger the correct animations
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.add(R.id.fragment_container, fragment);
ft.addToBackStack(null);
ft.commit();
}
});
NativeFragment fragment = new NativeFragment();
Bundle bundleArgs = new Bundle();
bundleArgs.putString("fragment_name","First");
fragment.setArguments(bundleArgs);
if ( findViewById(R.id.fragment_container) != null)
{
FragmentTransaction ft = getFragmentManager().beginTransaction();
//Set the transition value to trigger the correct animations
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.add(R.id.fragment_container, fragment);
ft.addToBackStack(null);
ft.commit();
}
}
}