19c78c48e1b847b27034f913ae910ca0842d2c2b.svn-base 5.5 KB

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