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