add charge remove and connected voice.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 12 Aug 2021 12:14:28 +0000 (20:14 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 12 Aug 2021 12:14:28 +0000 (20:14 +0800)
20 files changed:
app/release/ICLoopPageLauncher_V29_202108031427_release.apk [deleted file]
app/release/ICLoopPageLauncher_V31_202108091801_release.apk [new file with mode: 0644]
app/release/output-metadata.json
app/src/main/java/com/ic/launcher/presenter/LauncherPresenter.java
app/src/main/java/com/ic/launcher/presenter/StatusBarBasePresenter.java
app/src/main/java/com/ic/launcher/utils/SoundPlayUtils.java [new file with mode: 0644]
app/src/main/java/com/ic/launcher/utils/VibrateUtil.java [new file with mode: 0644]
app/src/main/res/drawable/ic_app_ai_voice.png [new file with mode: 0644]
app/src/main/res/raw/chrg_complete.mp3 [new file with mode: 0644]
app/src/main/res/raw/chrg_connect.mp3 [new file with mode: 0644]
app/src/main/res/raw/chrg_remove.mp3 [new file with mode: 0644]
app/src/main/res/raw/do_not_enter.mp3 [new file with mode: 0644]
app/src/main/res/raw/goto_see_doctor.mp3 [new file with mode: 0644]
app/src/main/res/raw/please_go_back_home.mp3 [new file with mode: 0644]
app/src/main/res/values-en/strings.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values-night/strings.xml
app/src/main/res/values-zh-rCN/strings.xml
app/src/main/res/values/strings.xml
app/version_code.properties

diff --git a/app/release/ICLoopPageLauncher_V29_202108031427_release.apk b/app/release/ICLoopPageLauncher_V29_202108031427_release.apk
deleted file mode 100644 (file)
index ca0cf7c..0000000
Binary files a/app/release/ICLoopPageLauncher_V29_202108031427_release.apk and /dev/null differ
diff --git a/app/release/ICLoopPageLauncher_V31_202108091801_release.apk b/app/release/ICLoopPageLauncher_V31_202108091801_release.apk
new file mode 100644 (file)
index 0000000..a282682
Binary files /dev/null and b/app/release/ICLoopPageLauncher_V31_202108091801_release.apk differ
index f8c8c74..9538dcd 100644 (file)
@@ -12,7 +12,7 @@
       "filters": [],
       "versionCode": 1,
       "versionName": "1.0",
-      "outputFile": "ICLoopPageLauncher_V29_202108031427_release.apk"
+      "outputFile": "ICLoopPageLauncher_V31_202108091801_release.apk"
     }
   ]
 }
\ No newline at end of file
index d3a3e67..002b95d 100644 (file)
@@ -1,12 +1,17 @@
 package com.ic.launcher.presenter;
 
+import android.content.ContentResolver;
+import android.content.ContentValues;
 import android.content.Context;
+import android.net.Uri;
 
 import androidx.lifecycle.MutableLiveData;
 
+import com.ic.iclooger.ICLogger;
 import com.ic.launcher.data.AppItem;
 import com.ic.launcher.data.HardCodeAppListRepository;
 import com.ic.launcher.data.IAppListRepository;
+import com.ic.launcher.utils.SystemUtils;
 
 import java.util.List;
 import java.util.concurrent.ExecutorService;
@@ -17,6 +22,7 @@ import java.util.concurrent.Executors;
  */
 public class LauncherPresenter extends BasePresenter {
 
+    private final Context mContext;
     //关心的数据:
     //应用列表
     public MutableLiveData<List<AppItem>> appListValues = new MutableLiveData<>();
@@ -25,6 +31,7 @@ public class LauncherPresenter extends BasePresenter {
     private final IAppListRepository appListRepository;
 
     private LauncherPresenter(Context context) {
+        this.mContext = context;
         executorService = Executors.newSingleThreadExecutor();
         appListRepository = HardCodeAppListRepository.getInstance(context);
         //去获取应用列表内容
@@ -36,10 +43,40 @@ public class LauncherPresenter extends BasePresenter {
         executorService.execute(() -> {
             //获取应用列表
             List<AppItem> appList = appListRepository.getAppList();
+            updateDbForAi(appList);
             appListValues.postValue(appList);
         });
     }
 
+
+    //添加规则
+    public static final String AUTHORITY = "com.ic.ai.info";
+    public static final String PATH = "apps";
+    public static final String APPS = "content://" + AUTHORITY + "/" + PATH;
+
+
+    private void updateDbForAi(List<AppItem> appList) {
+        ICLogger.d("updateLanguageSystemApp...");
+        Executors.newSingleThreadExecutor().submit(() -> {
+            ContentResolver contentResolver = mContext.getContentResolver();
+            //干掉全部内容
+            ICLogger.d("app info.. save into db");
+            contentResolver.delete(Uri.parse(APPS), null, null);
+            //清空数据库
+            for (AppItem appInfoEntity : appList) {
+                //添加内容进去
+                ContentValues contentValues = new ContentValues();
+                contentValues.put("package_name", mContext.getString(appInfoEntity.getPackageNameResId()));
+                contentValues.put("app_name", mContext.getString(appInfoEntity.getTitleResId()));
+                contentValues.put("brand_name", SystemUtils.getLauncherName());
+                contentValues.put("create_time", System.currentTimeMillis());
+                contentValues.put("update_time", System.currentTimeMillis());
+                //保存一份到数据库中
+                contentResolver.insert(Uri.parse(APPS), contentValues);
+            }
+        });
+    }
+
     private static LauncherPresenter sInstance = null;
 
     public static LauncherPresenter getInstance(Context context) {
index 04a7db8..d94deb5 100644 (file)
@@ -17,13 +17,16 @@ import android.telephony.TelephonyManager;
 import androidx.lifecycle.MutableLiveData;
 
 import com.ic.iclooger.ICLogger;
+import com.ic.launcher.utils.SoundPlayUtils;
 import com.ic.launcher.utils.SystemUtils;
+import com.ic.launcher.utils.VibrateUtil;
 
 import java.util.List;
 
 public class StatusBarBasePresenter extends BasePresenter {
 
     protected final Context mContext;
+    private final SoundPlayUtils playUtils;
     //电量状态
     public MutableLiveData<Boolean> isChargingValue = new MutableLiveData<>();
     //电量
@@ -44,6 +47,8 @@ public class StatusBarBasePresenter extends BasePresenter {
 
     public StatusBarBasePresenter(Context context) {
         this.mContext = context;
+        playUtils = new SoundPlayUtils();
+        playUtils.init();
         //获取电量和充电状态
         getBatteryLevAndChargeState();
         getSignalLev();
@@ -52,26 +57,41 @@ public class StatusBarBasePresenter extends BasePresenter {
     private void getBatteryLevAndChargeState() {
         //充电状态
         IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+        batteryFilter.addAction(Intent.ACTION_POWER_CONNECTED);
+        batteryFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
         mContext.registerReceiver(batteryLevReceiver, batteryFilter);
     }
 
     private final BroadcastReceiver batteryLevReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent batteryStatus) {
-            int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
-            int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
-            float batteryPct = level * 100 / (float) scale;
-            //ICLogger.d("batteryPct == > " + batteryPct);
-            batteryLev.postValue((int) batteryPct);
-            // Are we charging / charged?
-            int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
-            boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
-                    status == BatteryManager.BATTERY_STATUS_FULL;
-            // ICLogger.d("isCharging == > " + isCharging);
-            isChargingValue.postValue(isCharging);
+            String action = batteryStatus.getAction();
+            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
+
+                int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
+                int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
+                float batteryPct = level * 100 / (float) scale;
+                //ICLogger.d("batteryPct == > " + batteryPct);
+                batteryLev.postValue((int) batteryPct);
+                // Are we charging / charged?
+                int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+                boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
+                        status == BatteryManager.BATTERY_STATUS_FULL;
+                // ICLogger.d("isCharging == > " + isCharging);
+                isChargingValue.postValue(isCharging);
+            } else if (Intent.ACTION_POWER_CONNECTED.equals(action)) {
+                showShockAndAudio(0);
+            } else if (Intent.ACTION_POWER_DISCONNECTED.equals(action)) {
+                showShockAndAudio(1);
+            }
         }
     };
 
+    private void showShockAndAudio(int index) {
+        VibrateUtil.getInstance(mContext).vibrateOn(true);
+        playUtils.playKeyboardSound(mContext, index);
+    }
+
 
     private void queryPhoneNetworkTypeResId(TelephonyManager tm) {
         int networkType = tm.getNetworkType();
diff --git a/app/src/main/java/com/ic/launcher/utils/SoundPlayUtils.java b/app/src/main/java/com/ic/launcher/utils/SoundPlayUtils.java
new file mode 100644 (file)
index 0000000..bda78ec
--- /dev/null
@@ -0,0 +1,61 @@
+package com.ic.launcher.utils;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.SoundPool;
+import android.util.SparseArray;
+
+import com.ic.iclooger.ICLogger;
+import com.ic.launcher.R;
+
+
+public class SoundPlayUtils {
+
+    private int nowSoundNum;
+    private SoundPool mSoundPlayer;
+    private SoundPool.OnLoadCompleteListener SoundLoadListener;
+    private SparseArray soundID;
+
+    private static final int[] NUM_RAW = new int[]{
+            R.raw.chrg_connect,
+            R.raw.chrg_remove,
+            R.raw.chrg_complete,
+            R.raw.do_not_enter,
+            R.raw.goto_see_doctor,
+            R.raw.please_go_back_home};
+
+
+    public void init() {
+        if (mSoundPlayer == null) {
+            mSoundPlayer = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
+        }
+        soundID = new SparseArray();
+    }
+
+    public void releaseSoundPlayer() {
+        if (mSoundPlayer != null) {
+            mSoundPlayer.release();
+        }
+        mSoundPlayer = null;
+    }
+
+    public void playKeyboardSound(Context context, int key) {
+        nowSoundNum = key;
+        if (soundID.get(key) == null) {
+            if (SoundLoadListener == null) {
+                SoundLoadListener = (soundPool, sampleId, status) -> SaveSoundIDandPlay(sampleId);
+                mSoundPlayer.setOnLoadCompleteListener(SoundLoadListener);
+            }
+            mSoundPlayer.load(context, NUM_RAW[key], 1);
+        } else {
+            ICLogger.d("play..." + key);
+            mSoundPlayer.play((Integer) soundID.get(key), 1, 1, 0, 0, 1);
+        }
+    }
+
+    private synchronized void SaveSoundIDandPlay(int sampleId) {
+        mSoundPlayer.play(sampleId, 1, 1, 1, 0, 1);
+        ICLogger.d("play--->" + sampleId);
+        soundID.put(nowSoundNum, sampleId);
+    }
+}
diff --git a/app/src/main/java/com/ic/launcher/utils/VibrateUtil.java b/app/src/main/java/com/ic/launcher/utils/VibrateUtil.java
new file mode 100644 (file)
index 0000000..e29d7d0
--- /dev/null
@@ -0,0 +1,33 @@
+package com.ic.launcher.utils;
+
+import android.content.Context;
+import android.os.Vibrator;
+
+import static android.content.Context.VIBRATOR_SERVICE;
+
+public class VibrateUtil {
+
+    private static Context mContext=null;
+    public static VibrateUtil getInstance(Context context){
+        if (mContext==null)
+            mContext=context;
+        if (vibrator==null)
+            vibrator=(Vibrator)mContext.getSystemService(VIBRATOR_SERVICE);
+        vibrateUtil=new VibrateUtil();
+        return vibrateUtil;
+    }
+    private  static Vibrator vibrator = null;
+    private static VibrateUtil vibrateUtil=null;
+
+    private final  long[] patter = {1000, 1000, 1000, 1000}; //1秒开,1秒关,2秒开,50ms关
+
+    public void vibrateOn(boolean on){
+        if(vibrator!=null) {
+            if (on)
+                vibrator.vibrate(100);//不循环
+            else
+                vibrator.cancel();
+        }
+    }
+
+}
diff --git a/app/src/main/res/drawable/ic_app_ai_voice.png b/app/src/main/res/drawable/ic_app_ai_voice.png
new file mode 100644 (file)
index 0000000..4982eca
Binary files /dev/null and b/app/src/main/res/drawable/ic_app_ai_voice.png differ
diff --git a/app/src/main/res/raw/chrg_complete.mp3 b/app/src/main/res/raw/chrg_complete.mp3
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/app/src/main/res/raw/chrg_connect.mp3 b/app/src/main/res/raw/chrg_connect.mp3
new file mode 100644 (file)
index 0000000..d484792
Binary files /dev/null and b/app/src/main/res/raw/chrg_connect.mp3 differ
diff --git a/app/src/main/res/raw/chrg_remove.mp3 b/app/src/main/res/raw/chrg_remove.mp3
new file mode 100644 (file)
index 0000000..b03acac
Binary files /dev/null and b/app/src/main/res/raw/chrg_remove.mp3 differ
diff --git a/app/src/main/res/raw/do_not_enter.mp3 b/app/src/main/res/raw/do_not_enter.mp3
new file mode 100644 (file)
index 0000000..d01b8d9
Binary files /dev/null and b/app/src/main/res/raw/do_not_enter.mp3 differ
diff --git a/app/src/main/res/raw/goto_see_doctor.mp3 b/app/src/main/res/raw/goto_see_doctor.mp3
new file mode 100644 (file)
index 0000000..c0703cd
Binary files /dev/null and b/app/src/main/res/raw/goto_see_doctor.mp3 differ
diff --git a/app/src/main/res/raw/please_go_back_home.mp3 b/app/src/main/res/raw/please_go_back_home.mp3
new file mode 100644 (file)
index 0000000..2be8ae7
Binary files /dev/null and b/app/src/main/res/raw/please_go_back_home.mp3 differ
index 145cfd7..fff8e27 100644 (file)
@@ -25,4 +25,5 @@
     <string name="no_sim_service">no service</string>
     <string name="no_application_tips_text">no such app</string>
     <string name="checking_sim_text_tips">检测sim卡</string>
+    <string name="ai_voice_text">AI语助</string>
 </resources>
\ No newline at end of file
index a69b4c2..68db37b 100644 (file)
@@ -25,4 +25,5 @@
     <string name="no_sim_service">サービスなし</string>
     <string name="no_application_tips_text">应用未装着</string>
     <string name="checking_sim_text_tips">检测sim卡</string>
+    <string name="ai_voice_text">AI语助</string>
 </resources>
\ No newline at end of file
index 5018f07..9f09dca 100644 (file)
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <string name="checking_sim_text_tips">检测sim卡</string>
+    <string name="ai_voice_text">AI语助</string>
 </resources>
\ No newline at end of file
index 773755e..33db44f 100644 (file)
@@ -28,5 +28,6 @@
     <string name="no_sim_car">没有sim卡</string>
     <string name="no_sim_service">没有服务</string>
     <string name="checking_sim_text_tips">检测sim卡</string>
+    <string name="ai_voice_text">AI语助</string>
 
 </resources>
\ No newline at end of file
index 3093cba..10e2213 100644 (file)
@@ -16,6 +16,7 @@
     <string name="app_title_settings">设置</string>
     <!--Package name-->
     <string name="app_package_name_temperature" translatable="false">com.ic.temperature</string>
+    <string name="app_package_name_ai" translatable="false">com.ic.ai</string>
     <string name="app_package_name_health" translatable="false">com.ic.blood</string>
     <string name="app_package_name_sport" translatable="false">com.ic.sport</string>
     <string name="app_package_name_weather" translatable="false">com.ic.weather</string>
@@ -41,5 +42,6 @@
     <string name="no_sim_car">没有sim卡</string>
     <string name="no_sim_service">没有服务</string>
     <string name="checking_sim_text_tips">检测sim卡</string>
+    <string name="ai_voice_text">AI语助</string>
 
 </resources>
\ No newline at end of file
index 4239a87..d8290ef 100644 (file)
@@ -1,2 +1,2 @@
-#Tue Aug 03 14:27:38 CST 2021
-VERSION_CODE=29
+#Mon Aug 09 18:01:37 CST 2021
+VERSION_CODE=31