| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- package eVVM.apk.common;
- import android.content.pm.ActivityInfo;
- import android.graphics.drawable.Drawable;
- import android.support.annotation.DrawableRes;
- import android.support.annotation.Nullable;
- import android.support.annotation.StringRes;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.View;
- import com.hjq.bar.OnTitleBarListener;
- import com.hjq.bar.TitleBar;
- import com.hjq.base.BaseDialog;
- import com.hjq.dialog.MenuDialog;
- import com.hjq.toast.ToastUtils;
- import java.util.ArrayList;
- import java.util.List;
- import butterknife.ButterKnife;
- import butterknife.Unbinder;
- import eVVM.apk.app.MyApplication;
- import eVVM.apk.helper.ActivityStackManager;
- import eVVM.apk.helper.DebugUtils;
- import eVVM.apk.helper.GPS.LocationUtils;
- import eVVM.apk.helper.NfcUtil;
- import eVVM.apk.other.EventBusManager;
- import eVVM.apk.other.StatusManager;
- public abstract class MyActivity extends UIActivity implements OnTitleBarListener {
- @Override
- protected void initActivity() {
- super.initActivity();
- ActivityStackManager.getInstance().onActivityCreated(this);
- }
- // ButterKnife 注解
- private Unbinder mButterKnife;
- @Override
- protected void initLayout() {
- super.initLayout();
- // 初始化标题栏的监听
- if (getTitleId() > 0) {
- if (findViewById(getTitleId()) instanceof TitleBar) {
- ((TitleBar) findViewById(getTitleId())).setOnTitleBarListener(this);
- }
- }
- mButterKnife = ButterKnife.bind(this);
- EventBusManager.register(this);
- initOrientation();
- }
- /**
- * 初始化横竖屏方向,会和 LauncherTheme 主题样式有冲突,注意不要同时使用
- */
- protected void initOrientation() {
- // 当前 Activity 不能是透明的并且没有指定屏幕方向,默认设置为竖屏
- if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- }
- }
- /**
- * 设置标题栏的标题
- */
- @Override
- public void setTitle(int titleId) {
- setTitle(getText(titleId));
- }
- /**
- * 设置标题栏的标题
- */
- @Override
- public void setTitle(CharSequence title) {
- super.setTitle(title);
- TitleBar titleBar = getTitleBar();
- if (titleBar != null) {
- titleBar.setTitle(title);
- }
- }
- @Nullable
- public TitleBar getTitleBar() {
- if (getTitleId() > 0 && findViewById(getTitleId()) instanceof TitleBar) {
- return findViewById(getTitleId());
- }
- return null;
- }
- @Override
- public boolean statusBarDarkFont() {
- //返回true表示黑色字体
- return true;
- }
- /**
- * {@link OnTitleBarListener}
- */
- // TitleBar 左边的View被点击了
- @Override
- public void onLeftClick(View v) {
- onBackPressed();
- }
- // TitleBar 中间的View被点击了
- @Override
- public void onTitleClick(View v) {}
- // TitleBar 右边的View被点击了
- @Override
- public void onRightClick(View v) {}
- @Override
- protected void onResume() {
- super.onResume();
- // UmengClient.onResume(this);
- }
- @Override
- protected void onPause() {
- // UmengClient.onPause(this);
- super.onPause();
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mButterKnife != null) mButterKnife.unbind();
- EventBusManager.unregister(this);
- ActivityStackManager.getInstance().onActivityDestroyed(this);
- }
- private List<String> toastList = new ArrayList<>();
- /**
- * 显示吐司
- */
- public void toast(CharSequence s) {
- // ToastUtils.show(s);
- toastList.clear();
- toastList.add(s.toString());
- final BaseDialog show = new MenuDialog.Builder(this)
- .setCancel(null) // 设置 null 表示不显示取消按钮
- .setAutoDismiss(false) // 设置点击按钮后不关闭对话框
- .setList(toastList)
- .setGravity(Gravity.BOTTOM)
- .setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
- .show();
- postDelayed(new Runnable() {
- @Override
- public void run() {
- show.dismiss();
- }
- }, 2000);
- }
- public void toast(@StringRes int id) {
- ToastUtils.show(getString(id));
- }
- public void toast(Object object) {
- ToastUtils.show(object);
- }
- /**
- * 打印日志
- */
- public void log(Object object) {
- if (DebugUtils.isDebug(this)) {
- Log.v(getClass().getSimpleName(), object != null ? object.toString() : "null");
- }
- }
- /**
- * 获取当前的 Application 对象
- */
- public final MyApplication getMyApplication() {
- return (MyApplication) getApplication();
- }
- private final StatusManager mStatusManager = new StatusManager();
- /**
- * 显示加载中
- */
- public void showLoading() {
- mStatusManager.showLoading(this);
- }
- /**
- * 显示加载完成
- */
- public void showComplete() {
- mStatusManager.showComplete();
- }
- /**
- * 显示空提示
- */
- public void showEmpty() {
- mStatusManager.showEmpty(getContentView());
- }
- /**
- * 显示错误提示
- */
- public void showError() {
- mStatusManager.showError(getContentView());
- }
- /**
- * 显示自定义提示
- */
- public void showLayout(@DrawableRes int iconId, @StringRes int textId) {
- mStatusManager.showLayout(getContentView(), iconId, textId);
- }
- public void showLayout(Drawable drawable, CharSequence hint) {
- mStatusManager.showLayout(getContentView(), drawable, hint);
- }
- /**
- * 判断是否支持GPS和NFC功能
- */
- protected boolean checkGpsAndNfc(){
- switch (NfcUtil.isOPen(MyActivity.this)){
- case 0 :
- toast("您的手机没有NFC功能, 不能使用");
- return false;
- case 1 :
- toast("NFC功能未开启");
- return false;
- }
- if(!LocationUtils.isOPen(MyActivity.this)){
- toast("GPS功能未开启");
- return false;
- }
- return true;
- }
- }
|