4c4b478c07cf9c79f646d43a750db452bde82f4b.svn-base 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package eVVM.apk.common;
  2. import android.content.pm.ActivityInfo;
  3. import android.graphics.drawable.Drawable;
  4. import android.support.annotation.DrawableRes;
  5. import android.support.annotation.Nullable;
  6. import android.support.annotation.StringRes;
  7. import android.util.Log;
  8. import android.view.View;
  9. import com.hjq.bar.OnTitleBarListener;
  10. import com.hjq.bar.TitleBar;
  11. import com.hjq.toast.ToastUtils;
  12. import butterknife.ButterKnife;
  13. import butterknife.Unbinder;
  14. import eVVM.apk.app.MyApplication;
  15. import eVVM.apk.helper.ActivityStackManager;
  16. import eVVM.apk.helper.DebugUtils;
  17. import eVVM.apk.other.EventBusManager;
  18. import eVVM.apk.other.StatusManager;
  19. public abstract class MyActivity extends UIActivity
  20. implements OnTitleBarListener {
  21. @Override
  22. protected void initActivity() {
  23. super.initActivity();
  24. ActivityStackManager.getInstance().onActivityCreated(this);
  25. }
  26. // ButterKnife 注解
  27. private Unbinder mButterKnife;
  28. @Override
  29. protected void initLayout() {
  30. super.initLayout();
  31. // 初始化标题栏的监听
  32. if (getTitleId() > 0) {
  33. if (findViewById(getTitleId()) instanceof TitleBar) {
  34. ((TitleBar) findViewById(getTitleId())).setOnTitleBarListener(this);
  35. }
  36. }
  37. mButterKnife = ButterKnife.bind(this);
  38. EventBusManager.register(this);
  39. initOrientation();
  40. }
  41. /**
  42. * 初始化横竖屏方向,会和 LauncherTheme 主题样式有冲突,注意不要同时使用
  43. */
  44. protected void initOrientation() {
  45. // 当前 Activity 不能是透明的并且没有指定屏幕方向,默认设置为竖屏
  46. if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
  47. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  48. }
  49. }
  50. /**
  51. * 设置标题栏的标题
  52. */
  53. @Override
  54. public void setTitle(int titleId) {
  55. setTitle(getText(titleId));
  56. }
  57. /**
  58. * 设置标题栏的标题
  59. */
  60. @Override
  61. public void setTitle(CharSequence title) {
  62. super.setTitle(title);
  63. TitleBar titleBar = getTitleBar();
  64. if (titleBar != null) {
  65. titleBar.setTitle(title);
  66. }
  67. }
  68. @Nullable
  69. public TitleBar getTitleBar() {
  70. if (getTitleId() > 0 && findViewById(getTitleId()) instanceof TitleBar) {
  71. return findViewById(getTitleId());
  72. }
  73. return null;
  74. }
  75. @Override
  76. public boolean statusBarDarkFont() {
  77. //返回true表示黑色字体
  78. return true;
  79. }
  80. /**
  81. * {@link OnTitleBarListener}
  82. */
  83. // TitleBar 左边的View被点击了
  84. @Override
  85. public void onLeftClick(View v) {
  86. onBackPressed();
  87. }
  88. // TitleBar 中间的View被点击了
  89. @Override
  90. public void onTitleClick(View v) {}
  91. // TitleBar 右边的View被点击了
  92. @Override
  93. public void onRightClick(View v) {}
  94. @Override
  95. protected void onResume() {
  96. super.onResume();
  97. // UmengClient.onResume(this);
  98. }
  99. @Override
  100. protected void onPause() {
  101. // UmengClient.onPause(this);
  102. super.onPause();
  103. }
  104. @Override
  105. protected void onDestroy() {
  106. super.onDestroy();
  107. if (mButterKnife != null) mButterKnife.unbind();
  108. EventBusManager.unregister(this);
  109. ActivityStackManager.getInstance().onActivityDestroyed(this);
  110. }
  111. /**
  112. * 显示吐司
  113. */
  114. public void toast(CharSequence s) {
  115. ToastUtils.show(s);
  116. }
  117. public void toast(@StringRes int id) {
  118. ToastUtils.show(getString(id));
  119. }
  120. public void toast(Object object) {
  121. ToastUtils.show(object);
  122. }
  123. /**
  124. * 打印日志
  125. */
  126. public void log(Object object) {
  127. if (DebugUtils.isDebug(this)) {
  128. Log.v(getClass().getSimpleName(), object != null ? object.toString() : "null");
  129. }
  130. }
  131. /**
  132. * 获取当前的 Application 对象
  133. */
  134. public final MyApplication getMyApplication() {
  135. return (MyApplication) getApplication();
  136. }
  137. private final StatusManager mStatusManager = new StatusManager();
  138. /**
  139. * 显示加载中
  140. */
  141. public void showLoading() {
  142. mStatusManager.showLoading(this);
  143. }
  144. /**
  145. * 显示加载完成
  146. */
  147. public void showComplete() {
  148. mStatusManager.showComplete();
  149. }
  150. /**
  151. * 显示空提示
  152. */
  153. public void showEmpty() {
  154. mStatusManager.showEmpty(getContentView());
  155. }
  156. /**
  157. * 显示错误提示
  158. */
  159. public void showError() {
  160. mStatusManager.showError(getContentView());
  161. }
  162. /**
  163. * 显示自定义提示
  164. */
  165. public void showLayout(@DrawableRes int iconId, @StringRes int textId) {
  166. mStatusManager.showLayout(getContentView(), iconId, textId);
  167. }
  168. public void showLayout(Drawable drawable, CharSequence hint) {
  169. mStatusManager.showLayout(getContentView(), drawable, hint);
  170. }
  171. }