1.添加显示二维码的activity
authorkfl_614 <kfl_614@163.com>
Wed, 25 Mar 2020 11:00:16 +0000 (19:00 +0800)
committerkfl_614 <kfl_614@163.com>
Wed, 25 Mar 2020 11:00:16 +0000 (19:00 +0800)
2.修改监听电源广播。
3.修改更新信号量的方式。
4.修改Presenter类不在Application中初始化。因发现在重启后。偶现会出现空指针异常。

Signed-off-by: kfl_614 <kfl_614@163.com>
22 files changed:
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/ic/launcher/IcLauncherApplication.java
app/src/main/java/com/ic/launcher/MainActivity.java
app/src/main/java/com/ic/launcher/QrCodeActivity.java [new file with mode: 0644]
app/src/main/java/com/ic/launcher/fragment/AppListFragment.java
app/src/main/java/com/ic/launcher/fragment/L02MainFragment.java
app/src/main/java/com/ic/launcher/mode/AppListModel.java
app/src/main/java/com/ic/launcher/mode/L02MainModel.java
app/src/main/java/com/ic/launcher/presenter/BatteryPresenter.java
app/src/main/java/com/ic/launcher/presenter/HardwarePresenter.java
app/src/main/java/com/ic/launcher/presenter/PhoneStatePresenter.java
app/src/main/java/com/ic/launcher/presenter/QueryPhoneState.java [new file with mode: 0644]
app/src/main/java/com/ic/launcher/presenter/QuerySimCardState.java [deleted file]
app/src/main/java/com/ic/launcher/presenter/QueryTrafficPooler.java [deleted file]
app/src/main/java/com/ic/launcher/presenter/TimeDatePresenter.java
app/src/main/java/com/ic/launcher/util/IcLog.java
app/src/main/java/com/ic/launcher/util/QRCodeUtil.java [new file with mode: 0644]
app/src/main/res/drawable/ic_qr_code_imei.xml [new file with mode: 0644]
app/src/main/res/layout/activity_qr_code.xml [new file with mode: 0644]
app/src/main/res/values/styles.xml
app/version_code.properties

index e7d619a..61fd4a8 100644 (file)
@@ -129,4 +129,6 @@ dependencies {
 
     //1.2.0-alpha05
     implementation "com.google.android.material:material:1.2.0-alpha05"
+
+    compile 'com.google.zxing:core:3.4.0'
 }
index bafab39..0bb3561 100644 (file)
@@ -8,6 +8,8 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
 
+    <permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+
     <application
         android:name=".IcLauncherApplication"
         android:allowBackup="true"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/AppTheme">
+        <activity android:name=".QrCodeActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <action android:name="android.intent.action.VIEW" />
+                <category android:name="android.intent.category.LAUNCHER"/>
+            </intent-filter>
+        </activity>
+
 
         <activity android:name=".MainActivity">
             <intent-filter>
index 24b1c8f..6a3005c 100644 (file)
@@ -2,51 +2,18 @@ package com.ic.launcher;
 
 import android.app.Application;
 
-import com.ic.launcher.presenter.AppListPresenter;
-import com.ic.launcher.presenter.BatteryPresenter;
-import com.ic.launcher.presenter.HardwarePresenter;
-import com.ic.launcher.presenter.PhoneStatePresenter;
-import com.ic.launcher.presenter.TimeDatePresenter;
 import com.ic.launcher.util.CrashHandler;
 import com.ic.launcher.util.IcLog;
 
 public class IcLauncherApplication extends Application {
 
-    private PhoneStatePresenter mPhoneState;
-    private BatteryPresenter  mBatteryPresenter;
-    private TimeDatePresenter timeDatePresenter;
-    private AppListPresenter appListPresenter;
-    private HardwarePresenter mHardwarePresenter;
-
     @Override
     public void onCreate() {
         super.onCreate();
 
         IcLog.setLogHead("IcLauncher");
 
-        mPhoneState = new PhoneStatePresenter(this);
-        mBatteryPresenter = new BatteryPresenter(this);
-        timeDatePresenter = new TimeDatePresenter(this);
-        appListPresenter = new AppListPresenter(this);
-        mHardwarePresenter = new HardwarePresenter(this);
-
         CrashHandler crashHandler = CrashHandler.getInstance();
         crashHandler.init(getApplicationContext());
     }
-
-    public PhoneStatePresenter getPhoneStatePresenter() {
-        return mPhoneState;
-    }
-    public BatteryPresenter getBatterPresenter() {
-        return mBatteryPresenter;
-    }
-    public TimeDatePresenter getTimeDatePresenter() {
-        return timeDatePresenter;
-    }
-    public AppListPresenter getAppListPresenter() {
-        return appListPresenter;
-    }
-    public HardwarePresenter getHardwarePresenter() {
-        return mHardwarePresenter;
-    }
 }
index dea0c91..cb440f9 100644 (file)
@@ -105,7 +105,7 @@ public class MainActivity extends AppCompatActivity implements
             fragmentTransaction.hide(mAddFt.get(i));
         }
 
-        fragmentTransaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
+        fragmentTransaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
 
         if (fragment.isAdded()) {
             fragmentTransaction.show(fragment);
@@ -126,6 +126,11 @@ public class MainActivity extends AppCompatActivity implements
             if (mAddFt.get(0).isVisible()) {
                 return true;
             }
+
+            if(mAddFt.get(1).isVisible()){
+                commitFragment(l02MainFt);
+                return true;
+            }
         }
         return super.onKeyDown(keyCode, event);
     }
diff --git a/app/src/main/java/com/ic/launcher/QrCodeActivity.java b/app/src/main/java/com/ic/launcher/QrCodeActivity.java
new file mode 100644 (file)
index 0000000..c55072d
--- /dev/null
@@ -0,0 +1,65 @@
+package com.ic.launcher;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.os.Bundle;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.TypedValue;
+
+import com.ic.launcher.databinding.ActivityQrCodeBinding;
+import com.ic.launcher.util.QRCodeUtil;
+
+public class QrCodeActivity extends AppCompatActivity {
+
+    final static String KeyIMEI = "IMEI";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        ActivityQrCodeBinding qrCodeBinding = ActivityQrCodeBinding.inflate(getLayoutInflater());
+        setContentView(qrCodeBinding.getRoot());
+
+        String imei = getPrefStringPublic(this,KeyIMEI,null);
+        if(TextUtils.isEmpty(imei)){
+            imei=GetIMEI();
+        }
+        if(TextUtils.isEmpty(imei)){
+            qrCodeBinding.setQrCodeDrawable(ContextCompat.getDrawable(this,R.drawable.ic_qr_code_imei));
+            qrCodeBinding.setQrCodeText("未查询到IEMI");
+        }else{
+            Bitmap mBitmap = QRCodeUtil.createQRCodeBitmap(imei, (int) dpToPx(200), (int) dpToPx(200));
+            qrCodeBinding.setQrCodeDrawable(new BitmapDrawable(getResources(), mBitmap));
+            qrCodeBinding.setQrCodeText(imei);
+        }
+    }
+
+    @SuppressLint("WorldReadableFiles")
+    public static String getPrefStringPublic(Context context, String key, String value) {
+        SharedPreferences sp = context.getSharedPreferences("icprotocolconfig", Context.MODE_WORLD_READABLE);
+        return sp.getString(key, value);
+    }
+
+    public String GetIMEI() {
+        TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
+        if (tm == null) return null;
+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
+            return "";
+        }
+        return tm.getDeviceId();
+    }
+
+    private float dpToPx(float dp) {
+        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
+    }
+
+}
index 29ba6b7..904b576 100644 (file)
@@ -129,7 +129,7 @@ public class AppListFragment extends Fragment {
     }
 
     private void initAppListModel() {
-        AppListModel.Factory factory = new AppListModel.Factory(mApp, mApp.getAppListPresenter());
+        AppListModel.Factory factory = new AppListModel.Factory(mApp);
         appListModel = new ViewModelProvider(this, factory).get(AppListModel.class);
 
         appListModel.getObsAppInfoList().observe(getViewLifecycleOwner(), appList -> {
index 3d32341..6776112 100644 (file)
@@ -60,6 +60,7 @@ public class L02MainFragment extends Fragment {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mApp = (IcLauncherApplication) mContext.getApplicationContext();
+
     }
 
     @Override
@@ -68,8 +69,8 @@ public class L02MainFragment extends Fragment {
         View view = inflater.inflate(R.layout.fragment_l02_main, container, false);
         statusBarFt = (L02StatusBarFragment) getChildFragmentManager().findFragmentById(R.id.l02_status_fl);
         watchFt = (L02WatchFragment) getChildFragmentManager().findFragmentById(R.id.l02_watch_fl);
-        initL02MainModel();
         //监听事件
+        initL02MainModel();
         initOnTouchListener(view);
         return view;
     }
@@ -104,26 +105,20 @@ public class L02MainFragment extends Fragment {
     }
 
     @Override
-    public void onDestroy() {
-        super.onDestroy();
+    public void onDestroyView() {
+        super.onDestroyView();
+        IcLog.i(TAG, "onDestroyView");
         if(watchMainModel != null){
             watchMainModel.onFragmentDestroy();
         }
-
-        IcLog.i(TAG, "onDestroy");
     }
 
     private void initL02MainModel() {
-        L02MainModel.Factory factory = new L02MainModel.Factory(mApp,
-                mApp.getPhoneStatePresenter(),
-                mApp.getBatterPresenter(),
-                mApp.getTimeDatePresenter(),
-                mApp.getHardwarePresenter());
+        L02MainModel.Factory factory = new L02MainModel.Factory(mApp);
 
         watchMainModel = new ViewModelProvider(this, factory).get(L02MainModel.class);
         observeStateBarValue(watchMainModel);
         observeWatchValue(watchMainModel);
-        watchMainModel.onFragmentCreate();
     }
 
     private void observeStateBarValue(L02MainModel model) {
index 09693b5..f5e4d14 100644 (file)
@@ -22,10 +22,9 @@ public class AppListModel extends AndroidViewModel {
     private final LiveData<boolean[]> mObsAppState;
     private final LiveData<String> mObsActivityError;
 
-    public AppListModel(@NonNull Application application,
-                        @NonNull AppListPresenter appListPresenter) {
+    public AppListModel(@NonNull Application application) {
         super(application);
-        this.appListPresenter = appListPresenter;
+        this.appListPresenter = new AppListPresenter(application);
         mObsAppInfoList = appListPresenter.getObsAppInfoList();
 
         mObsAppState = appListPresenter.getObsAppState();
@@ -57,22 +56,15 @@ public class AppListModel extends AndroidViewModel {
         @NonNull
         private final Application mApplication;
 
-        @NonNull
-        private final AppListPresenter appListPresenter;
-
-
-        public Factory(@NonNull Application application,
-                       @NonNull AppListPresenter appListPresenter) {
+        public Factory(@NonNull Application application) {
             mApplication = application;
-            this.appListPresenter = appListPresenter;
-
         }
 
         @SuppressWarnings("unchecked")
         @Override
         @NonNull
         public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
-            return (T) new AppListModel(mApplication, appListPresenter);
+            return (T) new AppListModel(mApplication);
         }
     }
 }
index d639e25..c5534ab 100644 (file)
@@ -20,7 +20,6 @@ public class L02MainModel extends AndroidViewModel {
 
     private static final String TAG = "L02MainModel";
 
-    private final Application application;
     private final PhoneStatePresenter phonePresenter;
     private final BatteryPresenter batteryPresenter;
     private final TimeDatePresenter timeDatePresenter;
@@ -41,17 +40,12 @@ public class L02MainModel extends AndroidViewModel {
     private final LiveData<String> mObsHardwareHeart;
     private final LiveData<String> mObsHardwarePed;
 
-    public L02MainModel(@NonNull Application application,
-                        @NonNull PhoneStatePresenter phonePresenter,
-                        @NonNull BatteryPresenter batteryPresenter,
-                        @NonNull TimeDatePresenter timeDatePresenter,
-                        @NonNull HardwarePresenter hardwarePresenter) {
+    public L02MainModel(@NonNull Application application) {
         super(application);
-        this.application = application;
-        this.phonePresenter = phonePresenter;
-        this.batteryPresenter = batteryPresenter;
-        this.timeDatePresenter = timeDatePresenter;
-        this.hardwarePresenter = hardwarePresenter;
+        this.phonePresenter = new PhoneStatePresenter(application.getApplicationContext());
+        this.batteryPresenter = new BatteryPresenter(application.getApplicationContext());
+        this.timeDatePresenter = new TimeDatePresenter(application.getApplicationContext());
+        this.hardwarePresenter = new HardwarePresenter(application.getApplicationContext());
 
         mObsPhoneSignalID = phonePresenter.getPhoneSignalObservable();
         mObsPhoneTypeID = phonePresenter.getPhoneTypeObservable();
@@ -71,9 +65,6 @@ public class L02MainModel extends AndroidViewModel {
 
     public void onFragmentCreate(){
         IcLog.i(TAG,"onFragmentCreate");
-        hardwarePresenter.registerHardwareBroadcast();
-        phonePresenter.onStartQuery();
-        timeDatePresenter.registerTimeDateReceiver();
     }
 
     public void onFragmentResume(){
@@ -102,40 +93,16 @@ public class L02MainModel extends AndroidViewModel {
         @NonNull
         private final Application mApplication;
 
-        @NonNull
-        private final PhoneStatePresenter phonePresenter;
-
-        @NonNull
-        private final BatteryPresenter batteryPresenter;
-
-        @NonNull
-        private final TimeDatePresenter timeDatePresenter;
-
-        @NonNull
-        private final HardwarePresenter hardwarePresenter;
 
-        public Factory(@NonNull Application application,
-                       @NonNull PhoneStatePresenter phonePresenter,
-                       @NonNull BatteryPresenter batteryPresenter,
-                       @NonNull TimeDatePresenter timeDatePresenter,
-                       @NonNull HardwarePresenter hardwarePresenter) {
+        public Factory(@NonNull Application application) {
             mApplication = application;
-            this.phonePresenter = phonePresenter;
-            this.batteryPresenter = batteryPresenter;
-            this.timeDatePresenter = timeDatePresenter;
-            this.hardwarePresenter = hardwarePresenter;
-
         }
 
         @SuppressWarnings("unchecked")
         @Override
         @NonNull
         public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
-            return (T) new L02MainModel(mApplication,
-                    phonePresenter,
-                    batteryPresenter,
-                    timeDatePresenter,
-                    hardwarePresenter);
+            return (T) new L02MainModel(mApplication);
         }
     }
 
index 46ad639..4d16b68 100644 (file)
@@ -12,6 +12,7 @@ import androidx.lifecycle.MediatorLiveData;
 import com.ic.launcher.configure.l02.L02Icon;
 import com.ic.launcher.util.IcLog;
 
+
 public class BatteryPresenter {
     private static final String TAG = "BatteryPresenter";
     private Context mContext;
@@ -45,16 +46,19 @@ public class BatteryPresenter {
     private void registerBatteryReceiver() {
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+        filter.addAction(Intent.ACTION_BATTERY_LOW);
+        filter.addAction(Intent.ACTION_BATTERY_OKAY);
+        filter.addAction(Intent.ACTION_POWER_CONNECTED);
+        filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
         mContext.registerReceiver(mIntentReceiver, filter);
     }
 
     public void unRegisterBatteryReceiver() {
         try {
             mContext.unregisterReceiver(mIntentReceiver);
-        }catch (Exception e){
-            IcLog.e("BatteryPresenter",e.getMessage());
+        } catch (Exception e) {
+            IcLog.e(TAG, "BatteryPresenter", e);
         }
-
     }
 
     private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@@ -68,15 +72,28 @@ public class BatteryPresenter {
                     return;
                 }
 
-                if (Intent.ACTION_BATTERY_CHANGED.equals(acyion)) {
-                    int status = intent.getIntExtra("status", -1);
-                    int rawlevel = intent.getIntExtra("level", -1);
-                    int scale = intent.getIntExtra("scale", -1);
-
-                    IcLog.i(TAG,"Battery Statu:"+acyion);
-
-                    updateBatteryValue(rawlevel, scale);
-                    updateBatteryCharging(status);
+                IcLog.i(TAG, "Battery Statu:" + acyion);
+
+                switch (acyion) {
+                    case Intent.ACTION_BATTERY_CHANGED:
+                        int status = intent.getIntExtra("status", -1);
+                        int rawlevel = intent.getIntExtra("level", -1);
+                        int scale = intent.getIntExtra("scale", -1);
+                        updateBatteryValue(rawlevel, scale);
+                        updateBatteryCharging(status);
+                        break;
+                    case Intent.ACTION_BATTERY_OKAY:
+                        mObsBatteryCharging.setValue(false);
+                        IcLog.i(TAG, "POWER ACTION_BATTERY_OKAY");
+                        break;
+                    case Intent.ACTION_POWER_DISCONNECTED:
+                        //电量满了,或者 没有接电源
+                        mObsBatteryCharging.setValue(false);
+                        IcLog.i(TAG, "POWER ACTION_POWER_DISCONNECTED");
+                        break;
+                    case Intent.ACTION_POWER_CONNECTED:
+                        IcLog.i(TAG, "POWER CONNECTED");
+                        break;
                 }
             }
         }
@@ -87,6 +104,8 @@ public class BatteryPresenter {
         if (rawlevel >= 0 && scale > 0) {
             level = (rawlevel * 100) / scale;
         }
+
+
         mObsBatteryResID.setValue(L02Icon.l02BatteryResId[getBatteryLevel(level)]);
         mObsBatteryValue.setValue(level + "%");
     }
@@ -94,7 +113,7 @@ public class BatteryPresenter {
     private void updateBatteryCharging(int state) {
         if (BatteryManager.BATTERY_STATUS_CHARGING == state) {
             mObsBatteryCharging.setValue(true);
-        }else {
+        }else{
             mObsBatteryCharging.setValue(false);
         }
     }
index 769049e..d1441b0 100644 (file)
@@ -8,9 +8,11 @@ import android.text.TextUtils;
 
 import androidx.lifecycle.MediatorLiveData;
 
+import com.ic.launcher.util.IcLog;
 import com.ic.launcher.util.SPUtils;
 
 public class HardwarePresenter {
+    private static final String TAG = "HardwarePresenter";
 
     private static final String HEART_ACTION = "com.ic.action.BLOOD_HEART";
     private static final String PED_ACTION = "com.ic.action.PED_COUNT";
@@ -27,6 +29,8 @@ public class HardwarePresenter {
 
         mObsHardwareHeart = new MediatorLiveData<>();
         mObsHardwarePed = new MediatorLiveData<>();
+
+        registerHardwareBroadcast();
     }
 
     public MediatorLiveData<String> getObsHardwareHeart() {
@@ -37,7 +41,7 @@ public class HardwarePresenter {
         return mObsHardwarePed;
     }
 
-    public void registerHardwareBroadcast() {
+    private void registerHardwareBroadcast() {
         IntentFilter filter = new IntentFilter();
         filter.addAction(PED_ACTION);
         filter.addAction(HEART_ACTION);
@@ -45,7 +49,11 @@ public class HardwarePresenter {
     }
 
     public void unRegisterHardwareReceiver() {
-        mContext.unregisterReceiver(mIntentReceiver);
+        try {
+            mContext.unregisterReceiver(mIntentReceiver);
+        }catch (Exception e){
+            IcLog.e(TAG,"HardwareReceiver",e);
+        }
     }
 
     public void sendGetPedBroadcast(){
index 71d5afe..8d854d7 100644 (file)
@@ -1,42 +1,28 @@
 package com.ic.launcher.presenter;
 
 import android.content.Context;
-import android.telephony.PhoneStateListener;
-import android.telephony.SignalStrength;
-import android.telephony.TelephonyManager;
 
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MediatorLiveData;
 
-import com.ic.launcher.util.IcLog;
-
-
-import static com.ic.launcher.configure.l02.L02Icon.l02PhoneTypeResId;
-import static com.ic.launcher.configure.l02.L02Icon.l02SignalResId;
 
 public class PhoneStatePresenter {
     private static final String TAG = "PhoneStatePresenter";
 
-    private MediatorLiveData<Integer> mObsPhoneTypeID;
-    private MediatorLiveData<Integer> mObsPhoneSignalID;
-    private MediatorLiveData<Integer> mObsPhoneTransportID;
-
-    private QuerySimCardState simCardState;
-    private QueryTrafficPooler trafficPooler;
+    private QueryPhoneState queryState;
+    private Thread mQueryThread;
 
-    private TelephonyManager mTM;
 
-    private Thread mThread;
-    private Thread mQueryThread;
+    private MediatorLiveData<Integer> mObsPhoneTransportID;
+    private MediatorLiveData<Integer> mObsPhoneTypeID;
+    private MediatorLiveData<Integer> mObsPhoneSignalID;
 
     public PhoneStatePresenter(Context context) {
-        mTM = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
         mObsPhoneTypeID = new MediatorLiveData<>();
         mObsPhoneSignalID = new MediatorLiveData<>();
         mObsPhoneTransportID = new MediatorLiveData<>();
 
-        trafficPooler = new QueryTrafficPooler(mObsPhoneTransportID);
-        simCardState = new QuerySimCardState(mTM,mObsPhoneTypeID,mObsPhoneSignalID);
+        queryState = new QueryPhoneState(context,mObsPhoneTypeID,mObsPhoneSignalID,mObsPhoneTransportID);
     }
 
     public LiveData<Integer> getPhoneTypeObservable() {
@@ -51,114 +37,29 @@ public class PhoneStatePresenter {
         return mObsPhoneTransportID;
     }
 
-    public void onStartQuery(){
-        mQueryThread = new Thread(simCardState);
-        mQueryThread.start();
-        startQueryTraffic();
-    }
-
     public void onResumePresenter() {
-        resumeQuerySimCard();
-        resumeQueryTraffic();
-        listenPhoneState();
-    }
-
-    public void onPausePresenter() {
-        pauseQuerySimCard();
-        pauseQueryTraffic();
-        stopListenPhoneState();
-    }
-
-    public void onDestroyPresenter() {
-        stopQueryTraffic();
-        stopQuerySimCard();
-        mTM=null;
-    }
-
-    private void startQueryTraffic() {
-        mThread = new Thread(trafficPooler);
-        mThread.start();
-    }
-
-    private void stopQueryTraffic() {
-        if (mThread != null) {
-            mThread.interrupt();
+        if(mQueryThread == null){
+            mQueryThread = new Thread(queryState);
+            mQueryThread.start();
+        }else if(queryState != null){
+            queryState.resumeQueryThread();
         }
-
-        mThread = null;
     }
 
-    public void resumeQuerySimCard() {
-        if (mQueryThread != null && simCardState != null) {
-            simCardState.resumeQueryThread();
-        }
-    }
-
-    public void pauseQuerySimCard() {
-        if (mQueryThread != null && simCardState != null) {
-            simCardState.pauseQueryThread();
+    public void onPausePresenter() {
+        if (mQueryThread != null && queryState != null) {
+            queryState.pauseQueryThread();
         }
     }
 
-    private void stopQuerySimCard() {
+    public void onDestroyPresenter() {
         if (mQueryThread != null) {
             mQueryThread.interrupt();
         }
 
         mQueryThread = null;
-    }
-
-    public void resumeQueryTraffic() {
-        if (mThread != null && trafficPooler != null) {
-            trafficPooler.resumeQueryThread();
-        }
-    }
-
-    public void pauseQueryTraffic() {
-        if (mThread != null && trafficPooler != null) {
-            trafficPooler.pauseQueryThread();
-        }
-    }
 
-    private void listenPhoneState() {
-        if (mTM != null) {
-            mTM.listen(mPhoneListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
-        }
-    }
-
-    private void stopListenPhoneState() {
-        if (mTM != null) {
-            mTM.listen(mPhoneListener, PhoneStateListener.LISTEN_NONE);
-        }
-    }
-
-    private PhoneStateListener mPhoneListener = new PhoneStateListener() {
-        private int lastSignal = 0;
-
-        @Override
-        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
-            String ssignal = signalStrength.toString();
-            String[] parts = ssignal.split(" ");
-            lastSignal = Integer.parseInt(parts[8])-140;
-            IcLog.i(TAG, "Signal:" + lastSignal);
-            mObsPhoneSignalID.postValue(l02SignalResId[checkSignalLevel(lastSignal)]);
-            super.onSignalStrengthsChanged(signalStrength);
-        }
-    };
-
-
-
-    private int checkSignalLevel(int dbm){
-        int index=6;
-        if(dbm <= -120){
-            index=2;
-        }else if(dbm <= -111){
-            index =3;
-        }else if(dbm <= -106){
-            index =4;
-        }else if(dbm <= -91){
-            index=5;
-        }
-        return index;
+        queryState.destroyPhoneState();
+        queryState=null;
     }
 }
diff --git a/app/src/main/java/com/ic/launcher/presenter/QueryPhoneState.java b/app/src/main/java/com/ic/launcher/presenter/QueryPhoneState.java
new file mode 100644 (file)
index 0000000..c5e8320
--- /dev/null
@@ -0,0 +1,146 @@
+package com.ic.launcher.presenter;
+
+import android.content.Context;
+import android.net.TrafficStats;
+import android.os.Message;
+import android.telephony.CellInfo;
+import android.telephony.CellInfoLte;
+import android.telephony.TelephonyManager;
+
+import androidx.lifecycle.MediatorLiveData;
+
+import com.ic.launcher.util.IcLog;
+
+import java.util.List;
+
+import static com.ic.launcher.configure.l02.L02Icon.l02PhoneTypeResId;
+import static com.ic.launcher.configure.l02.L02Icon.l02SignalResId;
+import static com.ic.launcher.configure.l02.L02Icon.l02TransportResId;
+
+public class QueryPhoneState extends QueryThread {
+
+    private static final String TAG = "QueryPhoneState";
+
+
+
+    private TelephonyManager mTelephony;
+    private MediatorLiveData<Integer> mObsPhoneTypeID;
+    private MediatorLiveData<Integer> mObsPhoneSignalID;
+    private MediatorLiveData<Integer> mObsPhoneTransportID;
+
+    private long receivedWork;
+    private long sendNetWork;
+
+    private int mOldSimCardState = -1;
+    private int oldSignalLevel = -1;
+
+    public QueryPhoneState(Context context,
+                           MediatorLiveData<Integer> mObsPhoneTypeID,
+                           MediatorLiveData<Integer> mObsPhoneSignalID,
+                           MediatorLiveData<Integer> mObsPhoneTransportID) {
+        mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+        this.mObsPhoneTypeID = mObsPhoneTypeID;
+        this.mObsPhoneSignalID = mObsPhoneSignalID;
+        this.mObsPhoneTransportID = mObsPhoneTransportID;
+    }
+
+    public void destroyPhoneState() {
+        mTelephony = null;
+        mObsPhoneTypeID = null;
+        mObsPhoneSignalID = null;
+        mObsPhoneTransportID = null;
+    }
+
+    @Override
+    void onThreadExecute() {
+        if (querySimCardState()) {
+            getSignalStrength();
+            getTrafficPollerValue();
+        }
+    }
+
+    private void getTrafficPollerValue() {
+        long rw = TrafficStats.getMobileRxPackets();
+        long sw = TrafficStats.getMobileTxPackets();
+        int index = 0;
+        if (rw > receivedWork && sw > sendNetWork) {
+            index = 3;
+        } else {
+            if (rw > receivedWork) {
+                index = 1;
+            }
+            if (sw > sendNetWork) {
+                index = 2;
+            }
+        }
+        IcLog.i(TAG, "receivedWork:" + receivedWork + "sendNetWork:" + sendNetWork);
+        receivedWork = rw;
+        sendNetWork = sw;
+        mObsPhoneTransportID.postValue(l02TransportResId[index]);
+    }
+
+    private boolean querySimCardState() {
+
+        if (mTelephony == null) {
+            return false;
+        }
+
+        int simState = mTelephony.getSimState();
+        if (simState == mOldSimCardState && simState == TelephonyManager.SIM_STATE_READY) {
+            return true;
+        }
+
+        boolean flag = false;
+        mOldSimCardState = simState;
+
+        IcLog.i(TAG, "simState:" + simState);
+
+        switch (simState) {
+            case TelephonyManager.SIM_STATE_READY:
+                mObsPhoneTypeID.postValue(l02PhoneTypeResId[0]);
+                mObsPhoneSignalID.postValue(l02SignalResId[6]);
+                flag = true;
+                break;
+            case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
+            case TelephonyManager.SIM_STATE_PUK_REQUIRED:
+            case TelephonyManager.SIM_STATE_PIN_REQUIRED:
+                mObsPhoneSignalID.postValue(l02SignalResId[1]);
+                break;
+            default:
+                mObsPhoneSignalID.postValue(l02SignalResId[0]);
+                break;
+        }
+
+        return flag;
+    }
+
+    public void getSignalStrength() {
+        if (mTelephony == null) {
+            return;
+        }
+
+        List<CellInfo> cellInfoList = mTelephony.getAllCellInfo();
+        if (cellInfoList == null || cellInfoList.size() == 0) {
+            return;
+        }
+        for (CellInfo cellInfo : cellInfoList) {
+            if (cellInfo instanceof CellInfoLte) {
+                // cast to CellInfoLte and call all the CellInfoLte methods you need
+                int level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel() + 1;
+                IcLog.i(TAG, "Signal Strength level:" + level);
+                if (level != oldSignalLevel) {
+                    oldSignalLevel = level;
+                    mObsPhoneSignalID.postValue(l02SignalResId[level + 1]);
+                }
+
+            }
+        }
+    }
+
+    private int queryPhoneNetworkTypeResId(TelephonyManager tm) {
+        if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE) {
+            return l02PhoneTypeResId[0];
+        }
+        return -1;
+    }
+}
diff --git a/app/src/main/java/com/ic/launcher/presenter/QuerySimCardState.java b/app/src/main/java/com/ic/launcher/presenter/QuerySimCardState.java
deleted file mode 100644 (file)
index 0bc3808..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.ic.launcher.presenter;
-
-import android.telephony.TelephonyManager;
-
-import androidx.lifecycle.MediatorLiveData;
-
-import com.ic.launcher.util.IcLog;
-
-import static com.ic.launcher.configure.l02.L02Icon.l02PhoneTypeResId;
-import static com.ic.launcher.configure.l02.L02Icon.l02SignalResId;
-
-public class QuerySimCardState extends QueryThread {
-
-    private static final String TAG = "QuerySimCardState";
-
-    private TelephonyManager mTM;
-    private MediatorLiveData<Integer> mObsPhoneTypeID;
-    private MediatorLiveData<Integer> mObsPhoneSignalID;
-
-    public QuerySimCardState(TelephonyManager mTM,
-                             MediatorLiveData<Integer> mObsPhoneTypeID,
-                             MediatorLiveData<Integer> mObsPhoneSignalID) {
-        this.mTM=mTM;
-        this.mObsPhoneTypeID=mObsPhoneTypeID;
-        this.mObsPhoneSignalID=mObsPhoneSignalID;
-    }
-
-    @Override
-    void onThreadExecute() {
-        querySimCardState();
-    }
-
-    private void querySimCardState() {
-        int resIdIndex = 0;
-        if (mTM == null) {
-            return;
-        }
-
-        int simState = mTM.getSimState();
-
-        IcLog.i(TAG,"simState:"+simState);
-
-        switch (simState) {
-            case TelephonyManager.SIM_STATE_READY:
-                resIdIndex = 2;
-                break;
-            case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
-            case TelephonyManager.SIM_STATE_PUK_REQUIRED:
-            case TelephonyManager.SIM_STATE_PIN_REQUIRED:
-                resIdIndex = 1;
-                break;
-        }
-
-        if (resIdIndex == 2) {
-            mObsPhoneTypeID.postValue(l02PhoneTypeResId[0]);
-            mObsPhoneSignalID.postValue(l02SignalResId[6]);
-        } else if (resIdIndex == 1) {
-            mObsPhoneSignalID.postValue(l02SignalResId[1]);
-        } else {
-            mObsPhoneSignalID.postValue(l02SignalResId[0]);
-        }
-    }
-
-    private int queryPhoneNetworkTypeResId(TelephonyManager tm) {
-        if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE) {
-            return l02PhoneTypeResId[0];
-        }
-        return -1;
-    }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/ic/launcher/presenter/QueryTrafficPooler.java b/app/src/main/java/com/ic/launcher/presenter/QueryTrafficPooler.java
deleted file mode 100644 (file)
index 0eda9b0..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.ic.launcher.presenter;
-
-import android.net.TrafficStats;
-
-import androidx.lifecycle.MediatorLiveData;
-
-import com.ic.launcher.util.IcLog;
-
-import static com.ic.launcher.configure.l02.L02Icon.l02TransportResId;
-
-public class QueryTrafficPooler extends QueryThread {
-
-    private static final String TAG = "QueryTrafficPooler";
-
-    private long receivedWork;
-    private long sendNetWork;
-
-    private MediatorLiveData<Integer> mObsPhoneTransportID;
-
-    public QueryTrafficPooler(MediatorLiveData<Integer> transportID) {
-        mObsPhoneTransportID = transportID;
-    }
-
-    @Override
-    void onThreadExecute() {
-        getTrafficPollerValue();
-    }
-
-    private void getTrafficPollerValue() {
-        long rw = TrafficStats.getMobileRxPackets();
-        long sw = TrafficStats.getMobileTxPackets();
-        int index = 0;
-        if (rw > receivedWork && sw > sendNetWork) {
-            index = 3;
-        } else {
-            if (rw > receivedWork) {
-                index = 1;
-            }
-            if (sw > sendNetWork) {
-                index = 2;
-            }
-        }
-        IcLog.i(TAG, "receivedWork:" + receivedWork + "sendNetWork:" + sendNetWork);
-        receivedWork = rw;
-        sendNetWork = sw;
-        mObsPhoneTransportID.postValue(l02TransportResId[index]);
-    }
-}
index 28c24b0..f44de06 100644 (file)
@@ -17,6 +17,7 @@ import java.util.TimeZone;
 
 import static com.ic.launcher.configure.l02.L02Icon.l02TimeHourImage;
 import static com.ic.launcher.configure.l02.L02Icon.l02TimeMinutesImage;
+
 public class TimeDatePresenter {
 
     private static final String TAG = "TimeDatePresenter";
@@ -44,6 +45,8 @@ public class TimeDatePresenter {
         mObsTime = new MediatorLiveData<>();
         mObsYear = new MediatorLiveData<>();
         mObsWeek = new MediatorLiveData<>();
+
+        registerTimeDateReceiver();
     }
 
     public MediatorLiveData<ArrayList<Integer>> getObsTime() {
@@ -67,7 +70,7 @@ public class TimeDatePresenter {
         mShouldRunTicker = false;
     }
 
-    public void registerTimeDateReceiver() {
+    private void registerTimeDateReceiver() {
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_TIME_TICK);
         filter.addAction(Intent.ACTION_TIME_CHANGED);
@@ -78,12 +81,12 @@ public class TimeDatePresenter {
     public void unRegisterTimeDateReceiver() {
         try {
             mContext.unregisterReceiver(mIntentReceiver);
-        }catch (Exception e){
-            IcLog.e(TAG,e.getMessage());
+        } catch (Exception e) {
+            IcLog.e(TAG, "unRegisterTimeDateReceiver", e);
         }
     }
 
-    private  BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
             if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
@@ -114,17 +117,17 @@ public class TimeDatePresenter {
 
         timeList.clear();
 
-        boolean isHour=true;
+        boolean isHour = true;
 
-        for(int i=0; i<time.length(); i++){
-            if(time.charAt(i) == ':'){
-                isHour=false;
+        for (int i = 0; i < time.length(); i++) {
+            if (time.charAt(i) == ':') {
+                isHour = false;
                 continue;
             }
 
-            if(isHour){
+            if (isHour) {
                 timeList.add(l02TimeHourImage[Character.getNumericValue(time.charAt(i))]);
-            }else{
+            } else {
                 timeList.add(l02TimeMinutesImage[Character.getNumericValue(time.charAt(i))]);
             }
         }
index 0acad7c..0ed43b9 100644 (file)
@@ -39,9 +39,9 @@ public class IcLog {
         }
     }
 
-    public static void e(String tag, String msg) {
+    public static void e(String tag, String msg,Throwable e) {
         if (isDebug) {
-            Log.e(mergeHeadTag(tag), msg);
+            Log.e(mergeHeadTag(tag), msg,e);
         }
     }
 
diff --git a/app/src/main/java/com/ic/launcher/util/QRCodeUtil.java b/app/src/main/java/com/ic/launcher/util/QRCodeUtil.java
new file mode 100644 (file)
index 0000000..1eccf8e
--- /dev/null
@@ -0,0 +1,100 @@
+package com.ic.launcher.util;
+
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.text.TextUtils;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.Nullable;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.CharacterSetECI;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+import java.util.Hashtable;
+
+public class QRCodeUtil {
+    /**
+     * 创建二维码位图
+     *
+     * @param content 字符串内容(支持中文)
+     * @param width 位图宽度(单位:px)
+     * @param height 位图高度(单位:px)
+     * @return
+     */
+    @Nullable
+    public static Bitmap createQRCodeBitmap(String content, int width, int height){
+        return createQRCodeBitmap(content, width, height, "UTF-8", "H", "2", Color.BLACK, Color.WHITE);
+    }
+
+    /**
+     * 创建二维码位图 (支持自定义配置和自定义样式)
+     *
+     * @param content 字符串内容
+     * @param width 位图宽度,要求>=0(单位:px)
+     * @param height 位图高度,要求>=0(单位:px)
+     * @param character_set 字符集/字符转码格式 (支持格式:{@link CharacterSetECI })。传null时,zxing源码默认使用 "ISO-8859-1"
+     * @param error_correction 容错级别 (支持级别:{@link ErrorCorrectionLevel })。传null时,zxing源码默认使用 "L"
+     * @param margin 空白边距 (可修改,要求:整型且>=0), 传null时,zxing源码默认使用"4"。
+     * @param color_black 黑色色块的自定义颜色值
+     * @param color_white 白色色块的自定义颜色值
+     * @return
+     */
+    @Nullable
+    public static Bitmap createQRCodeBitmap(String content, int width, int height,
+                                            @Nullable String character_set, @Nullable String error_correction, @Nullable String margin,
+                                            @ColorInt int color_black, @ColorInt int color_white){
+
+        /** 1.参数合法性判断 */
+        if(TextUtils.isEmpty(content)){ // 字符串内容判空
+            return null;
+        }
+
+        if(width < 0 || height < 0){ // 宽和高都需要>=0
+            return null;
+        }
+
+        try {
+            /** 2.设置二维码相关配置,生成BitMatrix(位矩阵)对象 */
+            Hashtable<EncodeHintType, String> hints = new Hashtable<>();
+
+            if(!TextUtils.isEmpty(character_set)) {
+                hints.put(EncodeHintType.CHARACTER_SET, character_set); // 字符转码格式设置
+            }
+
+            if(!TextUtils.isEmpty(error_correction)){
+                hints.put(EncodeHintType.ERROR_CORRECTION, error_correction); // 容错级别设置
+            }
+
+            if(!TextUtils.isEmpty(margin)){
+                hints.put(EncodeHintType.MARGIN, margin); // 空白边距设置
+            }
+            BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
+
+            /** 3.创建像素数组,并根据BitMatrix(位矩阵)对象为数组元素赋颜色值 */
+            int[] pixels = new int[width * height];
+            for(int y = 0; y < height; y++){
+                for(int x = 0; x < width; x++){
+                    if(bitMatrix.get(x, y)){
+                        pixels[y * width + x] = color_black; // 黑色色块像素设置
+                    } else {
+                        pixels[y * width + x] = color_white; // 白色色块像素设置
+                    }
+                }
+            }
+
+            /** 4.创建Bitmap对象,根据像素数组设置Bitmap每个像素点的颜色值,之后返回Bitmap对象 */
+            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+            bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
+            return bitmap;
+        } catch (WriterException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+}
diff --git a/app/src/main/res/drawable/ic_qr_code_imei.xml b/app/src/main/res/drawable/ic_qr_code_imei.xml
new file mode 100644 (file)
index 0000000..cd4d445
--- /dev/null
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="200dp"
+    android:height="64dp"
+    android:viewportWidth="2557"
+    android:viewportHeight="1024">
+  <path
+      android:fillColor="#FFFFFF"
+      android:pathData="M1572.58,916.96v-783.73c0,-81.44 35.29,-122.1 105.73,-122.1h355.43c63.03,3.84 96.4,35.16 100.11,94.35 -3.71,63.16 -37.08,96.53 -99.98,100.24h-249.95v205.46h233.33c62.9,3.84 98.06,37.08 105.61,100.11 -7.54,63.03 -42.7,96.27 -105.61,99.98h-233.33v216.71h261.07c63.03,0 96.4,31.45 100.11,94.61 -3.84,62.78 -37.08,96.27 -100.11,99.85h-366.68c-66.74,-3.58 -102.03,-38.87 -105.73,-105.48zM305.57,905.83L439.04,111.23C461.29,40.91 507.57,3.84 577.89,0c70.32,3.84 118.65,38.87 144.47,105.61l166.85,561.27h5.5L1061.43,105.48C1087.25,38.87 1133.67,3.71 1200.53,0c73.9,3.84 122.23,40.91 144.47,111.23l127.85,794.6a50.89,50.89 0,0 1,5.37 22.25c-3.71,62.9 -38.87,94.48 -105.48,94.48 -66.74,3.58 -103.82,-26.08 -111.1,-88.86l-83.49,-583.65 -172.34,600.14c-18.54,48.2 -57.28,72.36 -116.47,72.36 -55.62,0 -92.69,-24.16 -111.23,-72.36L605.76,350.06l-83.49,583.65c-7.29,62.78 -44.36,92.44 -111.1,88.86 -66.48,0 -101.9,-31.58 -105.61,-94.61v-22.12zM2228.46,922.45L2228.46,111.23c3.58,-70.32 38.74,-107.4 105.61,-111.1 66.61,3.84 101.77,40.91 105.48,111.1v811.48c-3.71,66.61 -38.87,99.98 -105.48,99.98 -66.87,0 -102.03,-33.37 -105.61,-99.98zM0,922.58L0,111.23C3.58,40.78 38.87,3.71 105.48,0c66.74,3.84 101.9,40.91 105.61,111.1v811.48c-3.71,66.61 -38.87,99.98 -105.61,99.98 -66.61,0 -101.9,-33.37 -105.48,-99.98z"/>
+</vector>
diff --git a/app/src/main/res/layout/activity_qr_code.xml b/app/src/main/res/layout/activity_qr_code.xml
new file mode 100644 (file)
index 0000000..93961ce
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:context=".QrCodeActivity">
+
+    <data>
+
+        <variable
+            name="qrCodeDrawable"
+            type="android.graphics.drawable.Drawable" />
+
+        <variable
+            name="qrCodeText"
+            type="String" />
+    </data>
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="@mipmap/qs_background">
+
+        <ImageView
+            android:id="@+id/qr_code_iv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerHorizontal="true"
+            android:layout_marginTop="30dp"
+            android:scaleType="centerInside"
+            android:src="@{qrCodeDrawable}" />
+
+        <TextView
+            style="@style/QcCordTextStyle"
+            android:layout_below="@id/qr_code_iv"
+            android:layout_centerHorizontal="true"
+            android:layout_marginTop="20dp"
+            android:text="@{qrCodeText}" />
+
+    </RelativeLayout>
+</layout>
+
index 478b537..8d80872 100644 (file)
         <item name="android:includeFontPadding">false</item>
         <item name="android:layout_marginBottom">25dp</item>
     </style>
+
+    <style name="QcCordTextStyle">
+        <item name="android:layout_width">wrap_content</item>
+        <item name="android:layout_height">wrap_content</item>
+        <item name="android:textSize">36sp</item>
+        <item name="android:textColor">#FFFFFF</item>
+        <item name="android:includeFontPadding">false</item>
+        <item name="android:background">@android:color/transparent</item>
+    </style>
 </resources>
index 61818d9..b531d14 100644 (file)
@@ -1,2 +1,2 @@
-#Tue Mar 24 16:41:40 CST 2020
-VERSION_CODE=14
+#Tue Mar 24 19:16:13 CST 2020
+VERSION_CODE=15