陈奇
2018-11-01 cdbaf79d124d46b69dc62b653fde55f9d40b5534
app/src/main/java/com/moral/yunfushao/MainActivity.java
@@ -9,6 +9,7 @@
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Looper;
@@ -63,13 +64,14 @@
    //定义fragments
    private Class fragments[] = {FragmentMonitor.class, FragmentShoppongMall.class, FragmentSettings.class};
    //定义底部按钮图标数组
    private int mIcons[] = {R.drawable.menu1, R.drawable.menu2,R.drawable.menu3};
    private int mIcons[] = {R.drawable.menu1, R.drawable.menu2, R.drawable.menu3};
    //Tab选项卡文字
    private String mTextArray[] = {"辐射监测", "商城","设置"};
    private String mTextArray[] = {"辐射监测", "商城", "设置"};
    private int index = 0;
    private boolean islogin = false;
    private BluetoothService mBluetoothService;
    @Override
    protected void getBundleExtras(Bundle extras) {
        islogin = extras.getBoolean("islogin", false);
@@ -133,13 +135,13 @@
    @Override
    protected void initData() {
        prepare();
        if(MainApp.theApp.bleManager!=null){
            if(MainApp.theApp.bleManager.isSupportBle()){
        if (MainApp.theApp.bleManager != null) {
            if (MainApp.theApp.bleManager.isSupportBle()) {
                MainApp.theApp.bleManager.enableBluetooth();
            }else{
            } else {
                mToatUtils.showSingletonToast("对不起,您的手机不支持BLE!");
            }
        }else{
        } else {
            mToatUtils.showSingletonToast("对不起,您的手机不支持BLE!");
        }
        getAd();
@@ -218,7 +220,7 @@
        protected String doInBackground(String... params) {
            Looper.prepare();
            // 检查软件更新
            manager.checkUpdate();
            manager.checkUpdateJson();
            Looper.loop();
            return null;
        }
@@ -244,16 +246,16 @@
            /**
             * 版本更新
             */
//            if (Build.VERSION.SDK_INT >= 11) {
//                new checkUpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//            } else {
//                new checkUpdateTask().execute();
//            }
            if (Build.VERSION.SDK_INT >= 11) {
                new checkUpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                new checkUpdateTask().execute();
            }
            if (islogin)
                return;
            String url = API.GET_INFO;
            Map<String, String> params = new HashMap<>();
            params.put("phone",MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone());
            params.put("phone", MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone());
            HttpUtils.doPost(url, params, CacheMode.DEFAULT, false, new HttpCallBack() {
                @Override
                public void onSuccess(String res, String msg) {
@@ -270,12 +272,13 @@
                }
                @Override
                public void onFail(int errno,String s) {
                public void onFail(int errno, String s) {
                }
            });
        }
    }
    public BluetoothService getBluetoothService() {
        return mBluetoothService;
    }
@@ -295,7 +298,7 @@
            mBluetoothService = ((BluetoothService.BluetoothBinder) service).getService();
            mBluetoothService.setScanCallback(callback);
            String mac = MainApp.theApp.sharedPreferencesUtil.getBLE();
            if(!TextUtils.isEmpty(mac)){
            if (!TextUtils.isEmpty(mac)) {
                mBluetoothService.scanAndConnect5(mac);
            }
        }
@@ -334,7 +337,9 @@
        public void onConnectFail() {
            progressDialog.dismiss();
            mToatUtils.showSingletonToast("连接失败");
            EventMessage msg = new EventMessage();
            msg.setType(AppConfig.GET_BLE_DISCONNECT);
            EventBus.getDefault().postSticky(msg);
        }
        @Override
@@ -357,11 +362,12 @@
    private AlertDialog adDialog;
    private View adView;
    private TextView tv_content,tv_name;
    private TextView tv_content, tv_name;
    private ImageView iv_logo;
    private Button bt_cancel,bt_ok;
    private void showAd(String content,String logo,String name){
        adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout,null);
    private Button bt_cancel, bt_ok;
    private void showAd(String content, String logo, String name) {
        adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout, null);
        tv_content = (TextView) adView.findViewById(R.id.tv_content);
        tv_name = (TextView) adView.findViewById(R.id.tv_name);
        bt_cancel = (Button) adView.findViewById(R.id.bt_cancel);
@@ -369,7 +375,7 @@
        iv_logo = (ImageView) adView.findViewById(R.id.iv_logo);
        tv_content.setText(content);
        tv_name.setText(name);
        ImageLoader.setCircleImageView(this,logo,iv_logo,R.mipmap.circle);
        ImageLoader.setCircleImageView(this, logo, iv_logo, R.mipmap.circle);
        bt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
@@ -377,30 +383,30 @@
            }
        });
        adDialog = new AlertDialog.Builder(this).setView(adView).create();
        Window window=adDialog.getWindow();
        Window window = adDialog.getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        adDialog.show();
    }
    private void getAd(){
    private void getAd() {
        HttpUtils.doPost(API.GETAD, null, CacheMode.DEFAULT, false, new HttpCallBack() {
            @Override
            public void onSuccess(String res, String msg) {
                if(TextUtils.isEmpty(res)){
                if (TextUtils.isEmpty(res)) {
                    return;
                }
                try {
                    JSONObject json = new JSONObject(res);
                    String time  = MainApp.theApp.sharedPreferencesUtil.getShowAd();
                    if(TextUtils.isEmpty(time)){
                        showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
                    String time = MainApp.theApp.sharedPreferencesUtil.getShowAd();
                    if (TextUtils.isEmpty(time)) {
                        showAd(json.optString("content"), json.optString("logo"), json.optString("name"));
                        MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
                    }else{
                        if(time.equals(TimeUtil.getCurrentDate("yyyy-MM-dd"))){
                    } else {
                        if (time.equals(TimeUtil.getCurrentDate("yyyy-MM-dd"))) {
                            return;
                        }else{
                            showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
                        } else {
                            showAd(json.optString("content"), json.optString("logo"), json.optString("name"));
                            MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
                        }
                    }
@@ -422,9 +428,10 @@
        });
    }
    public void resetBLECallBack(){
        if(mBluetoothService!=null){
    public void resetBLECallBack() {
        if (mBluetoothService != null) {
            mBluetoothService.setScanCallback(callback);
        }
    }
}