7147f84d12d84fbaebb42e0fca586a77854d1ec4.svn-base 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 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. * 判断是否支持GPS和NFC功能
  114. */
  115. protected boolean checkGpsAndNfc(){
  116. switch (NfcUtil.isOPen(MyActivity.this)){
  117. case 0 :
  118. toast("设备不支持NFC功能");
  119. return false;
  120. case 1 :
  121. toast("NFC功能未开启");
  122. return false;
  123. }
  124. if(!GpsUtil.isOPen(MyActivity.this)){
  125. toast("GPS功能未开启");
  126. return false;
  127. }
  128. return true;
  129. }
  130. /**
  131. * 显示吐司
  132. */
  133. public void toast(CharSequence s) {
  134. ToastUtils.show(s);
  135. }
  136. public void toast(@StringRes int id) {
  137. ToastUtils.show(getString(id));
  138. }
  139. public void toast(Object object) {
  140. ToastUtils.show(object);
  141. }
  142. /**
  143. * 打印日志
  144. */
  145. public void log(Object object) {
  146. if (DebugUtils.isDebug(this)) {
  147. Log.v(getClass().getSimpleName(), object != null ? object.toString() : "null");
  148. }
  149. }
  150. /**
  151. * 获取当前的 Application 对象
  152. */
  153. public final MyApplication getMyApplication() {
  154. return (MyApplication) getApplication();
  155. }
  156. private final StatusManager mStatusManager = new StatusManager();
  157. /**
  158. * 显示加载中
  159. */
  160. public void showLoading() {
  161. mStatusManager.showLoading(this);
  162. }
  163. /**
  164. * 显示加载完成
  165. */
  166. public void showComplete() {
  167. mStatusManager.showComplete();
  168. }
  169. /**
  170. * 显示空提示
  171. */
  172. public void showEmpty() {
  173. mStatusManager.showEmpty(getContentView());
  174. }
  175. /**
  176. * 显示错误提示
  177. */
  178. public void showError() {
  179. mStatusManager.showError(getContentView());
  180. }
  181. /**
  182. * 显示自定义提示
  183. */
  184. public void showLayout(@DrawableRes int iconId, @StringRes int textId) {
  185. mStatusManager.showLayout(getContentView(), iconId, textId);
  186. }
  187. public void showLayout(Drawable drawable, CharSequence hint) {
  188. mStatusManager.showLayout(getContentView(), drawable, hint);
  189. }
  190. }