1a876ecadb597a22ac0bdab78b254bed68019e5c.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package eVVM.apk.common;
  2. import android.graphics.drawable.Drawable;
  3. import android.os.Bundle;
  4. import android.support.annotation.DrawableRes;
  5. import android.support.annotation.NonNull;
  6. import android.support.annotation.Nullable;
  7. import android.support.annotation.StringRes;
  8. import android.util.Log;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import com.hjq.bar.TitleBar;
  13. import com.hjq.toast.ToastUtils;
  14. import butterknife.ButterKnife;
  15. import butterknife.Unbinder;
  16. import eVVM.apk.helper.DebugUtils;
  17. import eVVM.apk.other.EventBusManager;
  18. import eVVM.apk.other.StatusManager;
  19. public abstract class MyLazyFragment<A extends MyActivity> extends UILazyFragment<A> {
  20. private Unbinder mButterKnife; // View注解
  21. @Override
  22. public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  23. View view = super.onCreateView(inflater, container, savedInstanceState);
  24. mButterKnife = ButterKnife.bind(this, view);
  25. return view;
  26. }
  27. @Override
  28. protected void initFragment() {
  29. super.initFragment();
  30. EventBusManager.register(this);
  31. }
  32. @Override
  33. public void onDestroy() {
  34. super.onDestroy();
  35. if (mButterKnife != null) {
  36. mButterKnife.unbind();
  37. }
  38. EventBusManager.unregister(this);
  39. }
  40. @Nullable
  41. public TitleBar getTitleBar() {
  42. if (getTitleId() > 0 && findViewById(getTitleId()) instanceof TitleBar) {
  43. return findViewById(getTitleId());
  44. }
  45. return null;
  46. }
  47. /**
  48. * 显示吐司
  49. */
  50. public void toast(CharSequence s) {
  51. ToastUtils.show(s);
  52. }
  53. public void toast(int id) {
  54. ToastUtils.show(id);
  55. }
  56. public void toast(Object object) {
  57. ToastUtils.show(object);
  58. }
  59. /**
  60. * 打印日志
  61. */
  62. public void log(Object object) {
  63. if (DebugUtils.isDebug(getBindingActivity())) {
  64. Log.v(getClass().getSimpleName(), object != null ? object.toString() : "null");
  65. }
  66. }
  67. @Override
  68. public void onResume() {
  69. super.onResume();
  70. //UmengClient.onResume(this);
  71. }
  72. @Override
  73. public void onPause() {
  74. // UmengClient.onPause(this);
  75. super.onPause();
  76. }
  77. private final StatusManager mStatusManager = new StatusManager();
  78. /**
  79. * 显示加载中
  80. */
  81. public void showLoading() {
  82. mStatusManager.showLoading(getBindingActivity());
  83. }
  84. /**
  85. * 显示加载完成
  86. */
  87. public void showComplete() {
  88. mStatusManager.showComplete();
  89. }
  90. /**
  91. * 显示空提示
  92. */
  93. public void showEmpty() {
  94. mStatusManager.showEmpty(getView());
  95. }
  96. /**
  97. * 显示错误提示
  98. */
  99. public void showError() {
  100. mStatusManager.showError(getView());
  101. }
  102. /**
  103. * 显示自定义提示
  104. */
  105. public void showLayout(@DrawableRes int iconId, @StringRes int textId) {
  106. mStatusManager.showLayout(getView(), iconId, textId);
  107. }
  108. public void showLayout(Drawable drawable, CharSequence hint) {
  109. mStatusManager.showLayout(getView(), drawable, hint);
  110. }
  111. }