4cc952b59fd89075004a56d0899df0655d6694a6.svn-base 5.5 KB

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