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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
package moe.yuuta.flow;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import java.util.Arrays;
// You don't need to use AppCompatActivity and AppCompat styles.
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private FlowFragment mFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
Log.i(TAG, "onCreate()");
if (mFragment == null) {
mFragment = new FlowFragment();
mFragment.setPages(Arrays.asList(new Page1(), new Page2(), new Page3()));
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, mFragment)
.commitAllowingStateLoss();
Log.i(TAG, "done");
}
}
public static class Page1 extends PageFragment {
public Page1() {
mInfo = new FlowInfo(new HeaderConfig("Page 1", "lol", false), null);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView view = new TextView(requireContext());
view.setText("Page 1");
return view;
}
}
public static class Page2 extends PageFragment {
public Page2() {
mInfo = new FlowInfo(new HeaderConfig("Page 2", "built with love", false), null);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView view = new TextView(requireContext());
view.setText("Page 2");
mInfo = new FlowInfo(new HeaderConfig("Page 2 lol", "built with love", false),
new NavigationBarConfig("2", "1", View.VISIBLE, View.VISIBLE, View.VISIBLE, getHostFragment().getGeneralFlowNavListener(),
getHostFragment().getGeneralFlowNavListener()));
getHostFragment().notifyCurrentFlowInfoUpdated();
return view;
}
}
public static class Page3 extends PageFragment {
public Page3() {
mInfo = new FlowInfo(new HeaderConfig("Page 3", "zzz~", true), null);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView view = new TextView(requireContext());
view.setText("Page 3");
return view;
}
@Override
public boolean onBackPressed() {
Vibrator vibrator = (Vibrator) requireContext().getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(new long[]{50L, 30L}, 1);
return true;
}
}
@Override
public void onBackPressed() {
if (mFragment != null && mFragment.onBackPressed()) return;
super.onBackPressed();
}
}
|