From: kfl_614 Date: Tue, 7 Apr 2020 09:40:59 +0000 (+0800) Subject: 1.加入电量拔插震动和声音。暂时没有加充满和低电量的提示。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=80dc2b4ac3907d9ef69148ae992ea3d6277aef71;p=launcher4.git 1.加入电量拔插震动和声音。暂时没有加充满和低电量的提示。 2.修复二维码不能退出的BUG。 Signed-off-by: kfl_614 --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4bacd10..73eed28 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,8 @@ + + mObsBatteryValue; private MediatorLiveData mObsBatteryCharging; @@ -59,6 +65,11 @@ public class BatteryPresenter extends PresenterCycle { mObsLowPower = new MediatorLiveData<>(); mObsLowPowerValue = new MediatorLiveData<>(); + + playUtils = new SoundPlayUtils(); + playUtils.init(); + + isPlaySound=false; } /** @@ -67,6 +78,7 @@ public class BatteryPresenter extends PresenterCycle { public void registerBatteryReceiver() { IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); + filter.addAction(Intent.ACTION_POWER_CONNECTED); filter.addAction(Intent.ACTION_POWER_DISCONNECTED); mContext.registerReceiver(mIntentReceiver, filter); } @@ -95,7 +107,6 @@ public class BatteryPresenter extends PresenterCycle { switch (acyion) { case Intent.ACTION_BATTERY_CHANGED: - IcLog.i(TAG, "Battery Statu: ACTION_BATTERY_CHANGED"); int status = intent.getIntExtra("status", -1); int rawlevel = intent.getIntExtra("level", -1); int scale = intent.getIntExtra("scale", -1); @@ -104,8 +115,14 @@ public class BatteryPresenter extends PresenterCycle { case Intent.ACTION_POWER_DISCONNECTED: // 没有接电源 mObsBatteryCharging.setValue(false); + showShockAndAudio(1); IcLog.i(TAG, "POWER ACTION_POWER_DISCONNECTED"); break; + case Intent.ACTION_POWER_CONNECTED: + //接电源 + IcLog.i(TAG, "POWER ACTION_POWER_CONNECTED"); + showShockAndAudio(0); + break; } } } @@ -126,8 +143,8 @@ public class BatteryPresenter extends PresenterCycle { shutDown(); } else if (level <= LOW_LEVEL) { //进入低电量 - if(!gotoLowPowerMode(level)){ - updateBatteryObserveValue(level,status); + if (!gotoLowPowerMode(level)) { + updateBatteryObserveValue(level, status); } } else { //退出低电量模式 @@ -135,18 +152,32 @@ public class BatteryPresenter extends PresenterCycle { mObsLowPower.setValue(false); isLowPowerState = false; } - updateBatteryObserveValue(level,status); + updateBatteryObserveValue(level, status); } } - private void updateBatteryObserveValue(int level,int status){ + private void updateBatteryObserveValue(int level, int status) { mObsBatteryResID.setValue(L02Icon.l02BatteryResId[getBatteryLevel(level)]); mObsBatteryValue.setValue(level + "%"); - if (BatteryManager.BATTERY_STATUS_CHARGING == status) { - mObsBatteryCharging.setValue(true); - } else { - mObsBatteryCharging.setValue(false); + switch (status){ + case BatteryManager.BATTERY_STATUS_CHARGING: + IcLog.i(TAG, "Battery Statu: BATTERY_STATUS_CHARGING"); + mObsBatteryCharging.setValue(true); + if(!isPlaySound){ + showShockAndAudio(0); + isPlaySound=true; + } + isPlayFullSound=false; + break; + case BatteryManager.BATTERY_STATUS_FULL: + IcLog.i(TAG, "Battery Statu: BATTERY_STATUS_FULL"); + mObsBatteryCharging.setValue(false); + /**if(!isPlayFullSound){ + showShockAndAudio(2); + isPlayFullSound=true; + }**/ + break; } } @@ -211,4 +242,9 @@ public class BatteryPresenter extends PresenterCycle { IcLog.e(TAG, "shutdown", e); } } + + private void showShockAndAudio(int index){ + VibrateUtil.getInstance(mContext).VibrateOn(true); + playUtils.playKeyboardSound(mContext, index); + } } diff --git a/app/src/main/java/com/ic/launcher/util/SoundPlayUtils.java b/app/src/main/java/com/ic/launcher/util/SoundPlayUtils.java new file mode 100644 index 0000000..d890530 --- /dev/null +++ b/app/src/main/java/com/ic/launcher/util/SoundPlayUtils.java @@ -0,0 +1,57 @@ +package com.ic.launcher.util; + +import android.content.Context; +import android.media.AudioManager; +import android.media.SoundPool; +import android.util.SparseArray; + +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}; + + + 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 { + 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); + soundID.put(nowSoundNum, sampleId); + } +} diff --git a/app/src/main/java/com/ic/launcher/util/VibrateUtil.java b/app/src/main/java/com/ic/launcher/util/VibrateUtil.java new file mode 100644 index 0000000..f5b7636 --- /dev/null +++ b/app/src/main/java/com/ic/launcher/util/VibrateUtil.java @@ -0,0 +1,34 @@ +package com.ic.launcher.util; + +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(patter, 0);//一直循环 + vibrator.vibrate(50);//不循环 + else + vibrator.cancel(); + } + } + +} diff --git a/app/src/main/res/raw/chrg_complete.mp3 b/app/src/main/res/raw/chrg_complete.mp3 new file mode 100644 index 0000000..c56ac5a Binary files /dev/null and b/app/src/main/res/raw/chrg_complete.mp3 differ diff --git a/app/src/main/res/raw/chrg_connect.mp3 b/app/src/main/res/raw/chrg_connect.mp3 new file mode 100644 index 0000000..ba5c0ce 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 index 0000000..4a91c17 Binary files /dev/null and b/app/src/main/res/raw/chrg_remove.mp3 differ diff --git a/app/version_code.properties b/app/version_code.properties index 097f2ca..882c2db 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Thu Apr 02 19:06:12 CST 2020 -VERSION_CODE=29 +#Mon Apr 06 10:46:59 CST 2020 +VERSION_CODE=30