Created
March 17, 2019 12:58
-
-
Save mikeyang01/dd21b35d0979845f4f058c901dd07966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//链接:https://www.zhihu.com/question/47045239/answer/105086885 | |
public abstract class BaseFragment extends Fragment implements OnClickListener { | |
private boolean isDebug; | |
private String APP_NAME; | |
protected final String TAG = this.getClass().getSimpleName(); | |
private View mContextView = null; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
isDebug = MApplication.isDebug; | |
APP_NAME = MApplication.APP_NAME; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
mContextView = inflater.inflate(bindLayout(), container, false); | |
initView(mContextView); | |
doBusiness(getActivity()); | |
return mContextView; | |
} | |
/** | |
* [绑定布局] | |
* | |
* @return | |
*/ | |
public abstract int bindLayout(); | |
/** | |
* [初始化控件] | |
* | |
* @param view | |
*/ | |
public abstract void initView(final View view); | |
/** | |
* [业务操作] | |
* | |
* @param mContext | |
*/ | |
public abstract void doBusiness(Context mContext); | |
/** View点击 **/ | |
public abstract void widgetClick(View v); | |
@Override | |
public void onClick(View v) { | |
if (fastClick()) | |
widgetClick(v); | |
} | |
@SuppressWarnings("unchecked") | |
public <T extends View> T $(View view, int resId) { | |
return (T) view.findViewById(resId); | |
} | |
/** | |
* [日志输出] | |
* | |
* @param msg | |
*/ | |
protected void $Log(String msg) { | |
if (isDebug) { | |
Log.d(APP_NAME, msg); | |
} | |
} | |
/** | |
* [防止快速点击] | |
* | |
* @return | |
*/ | |
private boolean fastClick() { | |
long lastClick = 0; | |
if (System.currentTimeMillis() - lastClick <= 1000) { | |
return false; | |
} | |
lastClick = System.currentTimeMillis(); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment