MainActivity.java
4.29 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.shunzhi.parent.ui;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import com.share.mvpsdk.base.activity.BaseCompatActivity;
import com.share.mvpsdk.helper.BottomNavigationViewHelper;
import com.share.mvpsdk.utils.PermissionUtils;
import com.shunzhi.parent.AppContext;
import com.shunzhi.parent.R;
import com.shunzhi.parent.ui.fragment.CePingFragment;
import com.shunzhi.parent.ui.fragment.ConsultFragment;
import com.shunzhi.parent.ui.fragment.MineFragment;
import com.shunzhi.parent.ui.fragment.ReportFragment;
import java.util.Calendar;
import java.util.Date;
public class MainActivity extends BaseCompatActivity implements PermissionUtils.PermissionGrant {
BottomNavigationView bottom_navigationView;
CePingFragment cePingFragment = null;
ConsultFragment consultFragment = null;
ReportFragment reportFragment = null;
MineFragment mineFragment = null;
Fragment[] fragments = null;
private int CEPING_INDEX = 0, CONSULT_INDEX = 1, REPORT_INDEX = 2, MINE_INDEX = 3;
FragmentTransaction fragmentTransaction = null;
@Override
protected void initView(Bundle savedInstanceState) {
PermissionUtils.requestMultiPermissions(this, this);
bottom_navigationView = findViewById(R.id.bottom_navigationView);
BottomNavigationViewHelper.disableShiftMode(bottom_navigationView);
bottom_navigationView.setSelectedItemId(R.id.bottom_navigationView);
bottom_navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_index://测评页面
showFragment(CEPING_INDEX);
break;
case R.id.menu_item_consult://咨询频道
showFragment(CONSULT_INDEX);
break;
case R.id.menu_item_report://报告
showFragment(REPORT_INDEX);
break;
case R.id.menu_item_mine://个人中心
showFragment(MINE_INDEX);
break;
}
return true;
}
});
initFragments();
}
private void initFragments() {
fragments = new Fragment[4];
cePingFragment = new CePingFragment();
consultFragment = new ConsultFragment();
reportFragment = new ReportFragment();
mineFragment = new MineFragment();
fragments[CEPING_INDEX] = cePingFragment;
fragments[CONSULT_INDEX] = consultFragment;
fragments[REPORT_INDEX] = reportFragment;
fragments[MINE_INDEX] = mineFragment;
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.frame, cePingFragment)
.add(R.id.frame, consultFragment)
.add(R.id.frame, reportFragment)
.add(R.id.frame, mineFragment)
.show(cePingFragment)
.hide(consultFragment)
.hide(reportFragment)
.hide(mineFragment)
.commit();
}
private void showFragment(int index) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
for (int i = 0; i < fragments.length; i++) {
if (index == i) fragmentTransaction.show(fragments[index]);
else fragmentTransaction.hide(fragments[i]);
}
fragmentTransaction.commit();
}
@Override
protected int getLayoutId() {
return R.layout.activity_main;
}
@Override
protected void onDestroy() {
super.onDestroy();
AppContext.getInstance().destoryLocation();
}
@Override
public void onPermissionGranted(int requestCode) {
}
@Override
protected void onResume() {
super.onResume();
Date l= Calendar.getInstance().getTime();
Log.e("2222--==",l.getTime()+"");
}
}