BaseFragment.java
3.13 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.sunvote.txpad.base;
import android.app.Fragment;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.sunvote.util.LogUtil;
import java.util.Locale;
/**
* Created by Elvis on 2017/9/8.
* Email:Eluis@psunsky.com
* 版权所有:长沙中天电子设计开发有限公司
* Description:平板模块键盘投票功能模块
*/
public abstract class BaseFragment extends Fragment implements BaseFragmentView{
protected View rootView ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try{
int resId = getLayoutId();
if(resId != 0){
rootView = inflater.inflate(resId, container, false);
initView();
initMVP();
initData();
initListener();
}
}catch (Exception ex){
LogUtil.e("BaseFragment",ex);
}
return rootView;
}
/**
* 初始化框架
*/
public void initMVP() {
}
/**
* 获取对应的资源文件
* @return
*/
public int getLayoutId(){
return 0;
}
/**
* 初始化控件
*/
public void initView(){
LogUtil.i("BaseFragment","initView");
}
/**
* 获取对应的View
*/
public <T extends View> T findViewById(int resId){
return (T)rootView.findViewById(resId);
}
/**
* 初始化控件事件
*/
public void initListener(){
LogUtil.i("BaseFragment","initListener");
}
/**
* 初始化数据
*/
public void initData(){
LogUtil.i("BaseFragment","initData");
}
/**
* 获取对应的activity
* @return
*/
public BaseActivity getBaseActivity() {
return (BaseActivity)getActivity();
}
/**
* 显示网络错误
*/
@Override
public void showNetError() {
getBaseActivity().showNetError();
}
/**
* 显示进度条
*/
@Override
public void showProgress() {
getBaseActivity().showProgress();
}
/**
* 隐藏进度条
*/
@Override
public void dismissProgress() {
BaseActivity baseActivity = getBaseActivity();
if(baseActivity != null){
baseActivity.dismissProgress();
}
}
/**
* 显示提示消息
* @param msg
*/
public void showToast(String msg){
getBaseActivity().showToast(msg);
}
/**
* 显示提示消息
* @param resId
*/
public void showToast(int resId){
getBaseActivity().showToast(resId);
}
@Override
public void onDestroy() {
super.onDestroy();
BasePresent basePresent = getBasePresent();
if(basePresent != null){
basePresent.onDestroy();
}
}
public abstract BasePresent getBasePresent();
@Override
public void onResume() {
super.onResume();
LogUtil.i("Page",getClass().getSimpleName());
}
}