addOrShowFragment(finish, fragment);
}
+ Fragment getLowPowerFragment() {
+ return getFragmentList(LOW_FRAGMENT_INDEX);
+ }
+
void showAppFragment(boolean finish, int flag) {
Fragment fragment = getFragmentList(APP_FRAGMENT_INDEX);
if (fragment == null) {
}
boolean onBackFragment(boolean finish) {
- if (mAddFt.get(0).isVisible()) {
+
+ if(mAddFt.get(LOW_FRAGMENT_INDEX) != null){
return true;
}
- if (mAddFt.get(1).isVisible()) {
+ if (mAddFt.get(MAIN_FRAGMENT_INDEX) != null && mAddFt.get(MAIN_FRAGMENT_INDEX).isVisible()) {
+ return true;
+ }
+
+ if (mAddFt.get(APP_FRAGMENT_INDEX) != null && mAddFt.get(APP_FRAGMENT_INDEX).isVisible()) {
showCurrMainFragment(finish, 0);
return true;
}
return false;
}
- void gotoLowPowerMode(boolean finish) {
+ void gotoLowPowerMode(boolean finish,String lowBatteryValue) {
Fragment fragment = getFragmentList(LOW_FRAGMENT_INDEX);
return;
}
- fragment = LowPowerModeFragment.newInstance();
-
+ fragment = LowPowerModeFragment.newInstance(lowBatteryValue);
replaceLowFragment(finish, fragment);
}
if (fragment == null) {
return;
}
+ mAddFt.remove(LOW_FRAGMENT_INDEX);
Fragment mainFt = getCurrMainFragment();
package com.ic.launcher;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
+import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.text.TextUtils;
import android.view.KeyEvent;
+import com.ic.launcher.fragment.LowPowerModeFragment;
import com.ic.launcher.listener.IChangeMainFragmentListener;
-import com.ic.launcher.listener.ILowPowerStateListener;
import com.ic.launcher.listener.MainClockGestureDetectorImpl;
+import com.ic.launcher.mode.LowPowerModel;
import com.ic.launcher.util.IcLog;
import com.ic.launcher.util.ServiceUtil;
import com.ic.launcher.util.SystemUtils;
-
public class MainActivity extends AppCompatActivity implements
MainClockGestureDetectorImpl.OnClockGestureFlingListener,
- IChangeMainFragmentListener,
- ILowPowerStateListener {
+ IChangeMainFragmentListener {
private static final String TAG = "MainActivity";
private boolean isLowPower = false;
private FragmentManage ftManage;
- private boolean isChangeClock=false;
+
+ private boolean isChangeClock = false;
+ private String lowBatteryValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- ftManage = new FragmentManage(this,getSupportFragmentManager());
- ftManage.showCurrMainFragment(isFinishing(),0);
+ ftManage = new FragmentManage(this, getSupportFragmentManager());
+ ftManage.showCurrMainFragment(isFinishing(), 0);
- ((IcLauncherApplication)getApplication()).getBatteryPresenter().registerBatteryReceiver();
- ((IcLauncherApplication)getApplication()).getTimeDatePresenter().registerTimeDateReceiver();
+ ((IcLauncherApplication) getApplication()).getBatteryPresenter().registerBatteryReceiver();
+ ((IcLauncherApplication) getApplication()).getTimeDatePresenter().registerTimeDateReceiver();
registerChangeClockReceiver();
+ initLowPowerModel(getApplication());
+
ServiceUtil.startServiceUtil(getApplicationContext(),
- "com.ic.action.WORK_SERVICE", getPackageName());
+ "com.ic.action.WORK_SERVICE", getPackageName());
}
@Override
protected void onResume() {
super.onResume();
- if(isChangeClock){
+ if (isChangeClock) {
ftManage.changeMainClock(isFinishing());
- isChangeClock=false;
+ isChangeClock = false;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
- ((IcLauncherApplication)getApplication()).getBatteryPresenter().unRegisterBatteryReceiver();
- ((IcLauncherApplication)getApplication()).getTimeDatePresenter().unRegisterTimeDateReceiver();
+ ((IcLauncherApplication) getApplication()).getBatteryPresenter().unRegisterBatteryReceiver();
+ ((IcLauncherApplication) getApplication()).getTimeDatePresenter().unRegisterTimeDateReceiver();
unRegisterChangeClockReceiver();
}
@Override
public void onChangeMain(int direction) {
- ftManage.showCurrMainFragment(isFinishing(),direction);
- }
-
- @Override
- public void onLowChange(boolean state) {
- if (state) {
- ftManage.gotoLowPowerMode(isFinishing());
- } else {
- ftManage.quitLowPowerMode(isFinishing());
- }
+ ftManage.showCurrMainFragment(isFinishing(), direction);
}
@Override
}
}
+ private void initLowPowerModel(Application application) {
+ LowPowerModel.Factory factory = new LowPowerModel.Factory(application);
+ LowPowerModel lowPowerModel = new ViewModelProvider(this, factory).get(LowPowerModel.class);
+ onObserveModelValue(lowPowerModel);
+ }
+
+ private void onObserveModelValue(LowPowerModel baseModel) {
+ baseModel.getObservableLowPowerValue().observe(this, this::updateLowPowerValue);
+
+ //退出低电量模式
+ baseModel.getObservableLowPower().observe(this, status -> {
+ IcLog.i(TAG, "getObservableLowPower status:" + status);
+ if (status) {
+ ftManage.gotoLowPowerMode(isFinishing(),lowBatteryValue);
+ } else {
+ ftManage.quitLowPowerMode(isFinishing());
+ }
+ });
+ }
+
+ private void updateLowPowerValue(String value) {
+ Fragment fragment = ftManage.getLowPowerFragment();
+ if (fragment != null) {
+ ((LowPowerModeFragment) fragment).updateLowPowerValue(value);
+ }
+ lowBatteryValue = value;
+ }
+
private void registerChangeClockReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction("com.ic.action.CHANGE_CLOCK");
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("com.ic.action.CHANGE_CLOCK".equals(action)) {
- isChangeClock =true;
+ isChangeClock = true;
}
}
};
indicatorAdapter = new IndicatorAdapter(state);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
indicatorRv.setLayoutManager(mLayoutManager);
- indicatorRv.addItemDecoration(new SpacesItemDecoration(4));
+ indicatorRv.addItemDecoration(new SpacesItemDecoration(6));
indicatorRv.setAdapter(indicatorAdapter);
}
import com.ic.launcher.configure.l02.L02Icon;
import com.ic.launcher.databinding.FragmentL02MainBinding;
-import com.ic.launcher.listener.ILowPowerStateListener;
import com.ic.launcher.mode.BaseModel;
import com.ic.launcher.mode.L02MainModel;
-import com.ic.launcher.util.IcLog;
import com.ic.launcher.util.SPUtils;
private static final String TAG = "L02MainFragment";
private FragmentL02MainBinding mainBinding;
-
- private ILowPowerStateListener lowPower;
+ private boolean chargingState;
public static L02MainFragment newInstance() {
return new L02MainFragment();
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
-
- if (context instanceof ILowPowerStateListener) {
- lowPower = (ILowPowerStateListener) context;
- }
}
@Override
observeBatteryValue(mainModel);
observeDataTimeValue(mainModel);
observeHardwareValue(mainModel);
-
- //进入电量模式
- baseModel.getObservableLowPower().observe(this,status ->{
- IcLog.i(TAG,"getObservableLowPower status"+status);
- if(status){
- lowPower.onLowChange(true);
- }
- });
}
@Override
Bundle savedInstanceState) {
mainBinding = FragmentL02MainBinding.inflate(inflater, container, false);
mainBinding.setHeartValue(String.valueOf(SPUtils.getBloodHeartSP(mContext)));
+ chargingState=false;
mainBinding.setStepValue("0");
//监听事件
initOnTouchListener(mainBinding.getRoot());
return mainBinding.getRoot();
}
+ @Override
+ public void onResume() {
+ super.onResume();
+ if(chargingState){
+ if(mainBinding != null){
+ mainBinding.setBatteryCharge(true);
+ }
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if(chargingState){
+ if(mainBinding != null){
+ mainBinding.setBatteryCharge(false);
+ }
+ }
+ }
+
private void observePhoneValue(L02MainModel model) {
model.getObservablePhoneType().observe(this, resID ->{
if(mainBinding != null){
});
model.getObservableBatteryCharging().observe(this, state -> {
- if(mainBinding != null){
- mainBinding.setBatteryCharge(state);
+ if(chargingState != state){
+ chargingState =state;
+ if(mainBinding != null){
+ mainBinding.setBatteryCharge(chargingState);
+ }
}
});
}
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import com.ic.launcher.IcLauncherApplication;
import com.ic.launcher.configure.l02.L02AppInfo;
import com.ic.launcher.databinding.FragmentLowPowerModeBinding;
import com.ic.launcher.entity.AppInfoEntity;
import com.ic.launcher.listener.ILowPowerCallPhoneListener;
-import com.ic.launcher.listener.ILowPowerStateListener;
-import com.ic.launcher.mode.LowPowerModel;
import com.ic.launcher.util.IcLog;
/**
private Context mContext;
- private LowPowerModel lowPowerModel;
-
private FragmentLowPowerModeBinding mPowerModeBinding;
private String batteryValue;
- private ILowPowerStateListener lowPower;
-
- public static LowPowerModeFragment newInstance() {
- return new LowPowerModeFragment();
+ public static LowPowerModeFragment newInstance(String battery) {
+ LowPowerModeFragment fragment = new LowPowerModeFragment();
+ Bundle args = new Bundle();
+ args.putString("battery", battery);
+ fragment.setArguments(args);
+ return fragment;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
-
mContext = context;
- if (context instanceof ILowPowerStateListener) {
- lowPower = (ILowPowerStateListener) context;
- }
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- IcLauncherApplication mApp = (IcLauncherApplication) mContext.getApplicationContext();
- lowPowerModel = initFragmentModel(mApp);
- onObserveModelValue(lowPowerModel);
- lowPowerModel.OnUiCreate();
+ Bundle bundle = getArguments();
+ if (bundle != null) {
+ batteryValue = bundle.getString("battery");
+ }
}
@Override
public void onDestroy() {
super.onDestroy();
- lowPowerModel.OnUiDestroy();
- lowPowerModel=null;
}
@Override
return mPowerModeBinding.getRoot();
}
- private LowPowerModel initFragmentModel(Application application){
- LowPowerModel.Factory factory = new LowPowerModel.Factory(application);
- return new ViewModelProvider(this, factory).get(LowPowerModel.class);
- }
-
- private void onObserveModelValue(LowPowerModel baseModel) {
- baseModel.getObservableLowPowerValue().observe(this, this::updateLowPowerValue);
-
- //退出低电量模式
- baseModel.getObservableLowPower().observe(this,status ->{
- IcLog.i(TAG,"getObservableLowPower status"+status);
- if(!status){
- lowPower.onLowChange(false);
- }
- });
- }
-
- private void updateLowPowerValue(String value){
- if(mPowerModeBinding != null){
- mPowerModeBinding.setLowPowerValue(value);
+ public void updateLowPowerValue(String batteryValue) {
+ if (mPowerModeBinding != null) {
+ mPowerModeBinding.setLowPowerValue(batteryValue);
}
- batteryValue= value;
+ this.batteryValue = batteryValue;
}
private ILowPowerCallPhoneListener callListener = () -> {
AppInfoEntity entity = L02AppInfo.mL02DefaultAppList.get(1);
- if(entity != null){
+ if (entity != null) {
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(entity.getPackageName(), entity.getActivityName()));
mContext.startActivity(intent);
- }catch (Exception e){
- IcLog.e(TAG,"ILowPowerCallPhoneListener",e);
+ } catch (Exception e) {
+ IcLog.e(TAG, "ILowPowerCallPhoneListener", e);
}
}
};
}
- public void OnUiCreate() {
- if (batteryPresenter != null) {
- batteryPresenter.onPresenterCreate();
- }
- }
-
- public void OnUiDestroy() {
- if (batteryPresenter != null) {
- batteryPresenter.onPresenterDestroy();
- }
- }
-
public LiveData<String> getObservableLowPowerValue() {
if (batteryPresenter != null) {
return batteryPresenter.getObsLowPowerValue();
package com.ic.launcher.presenter;
+import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
+import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import androidx.annotation.RequiresApi;
import androidx.lifecycle.MediatorLiveData;
import com.ic.launcher.configure.l02.L02Icon;
import com.ic.launcher.util.SoundPlayUtils;
import com.ic.launcher.util.VibrateUtil;
+import java.util.ArrayList;
+
public class BatteryPresenter extends PresenterCycle {
private static final String TAG = "BatteryPresenter";
private SoundPlayUtils playUtils;
- private boolean isLowPowerState = false;
private boolean isPlaySound;
- private boolean isPlayFullSound=false;
+ private boolean isPlayFullSound = false;
private MediatorLiveData<String> mObsBatteryValue;
private MediatorLiveData<Boolean> mObsBatteryCharging;
playUtils = new SoundPlayUtils();
playUtils.init();
- isPlaySound=false;
+ isPlaySound = false;
}
/**
int status = intent.getIntExtra("status", -1);
int rawlevel = intent.getIntExtra("level", -1);
int scale = intent.getIntExtra("scale", -1);
+ IcLog.i(TAG, "ACTION_BATTERY_CHANGED,level:" + rawlevel + ",status:" + status);
updateBatteryValue(rawlevel, scale, status);
break;
case Intent.ACTION_POWER_DISCONNECTED:
};
private void updateBatteryValue(int rawlevel, int scale, int status) {
+
int level = -1;
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
- IcLog.i(TAG, "Battery Value:" + level);
-
if (level == -1) return;
+ mObsBatteryValue.setValue(level + "%");
+ mObsLowPowerValue.setValue(level + "%");
+
+ switch (status) {
+ case BatteryManager.BATTERY_STATUS_CHARGING:
+ mObsLowPower.setValue(false);
+ updateBatteryChargingValue();
+ break;
+ case BatteryManager.BATTERY_STATUS_FULL:
+ updateBatteryFullValue();
+ mObsBatteryResID.setValue(L02Icon.l02BatteryResId[getBatteryLevel(level)]);
+ break;
+ default:
+ mObsBatteryResID.setValue(L02Icon.l02BatteryResId[getBatteryLevel(level)]);
+ gotoLowBatteryMode(level);
+ break;
+ }
+ }
+
+ private void gotoLowBatteryMode(int level) {
//低于5 则直接关机
if (level <= SHUT_DOWN_LEVEL) {
shutDown();
} else if (level <= LOW_LEVEL) {
//进入低电量
- if (!gotoLowPowerMode(level)) {
- updateBatteryObserveValue(level, status);
- }
- } else {
- //退出低电量模式
- if (isLowPowerState) {
- mObsLowPower.setValue(false);
- isLowPowerState = false;
- }
- updateBatteryObserveValue(level, status);
+ gotoLowPowerMode(level);
}
}
- private void updateBatteryObserveValue(int level, int status) {
- mObsBatteryResID.setValue(L02Icon.l02BatteryResId[getBatteryLevel(level)]);
- mObsBatteryValue.setValue(level + "%");
+ private void updateBatteryChargingValue() {
+ mObsBatteryCharging.setValue(true);
+ if (!isPlaySound) {
+ showShockAndAudio(0);
+ isPlaySound = true;
+ }
+ isPlayFullSound = 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;
+ private void updateBatteryFullValue() {
+ mObsBatteryCharging.setValue(false);
+ if (!isPlayFullSound) {
+ showShockAndAudio(2);
+ isPlayFullSound = true;
}
+ isPlayFullSound = false;
}
private int getBatteryLevel(int level) {
return index;
}
- private boolean gotoLowPowerMode(int level) {
+ @RequiresApi(api = Build.VERSION_CODES.Q)
+ private void gotoLowPowerMode(int level) {
//判断是否在通话中,如果是 则返回
- if (phoneIsInUse()) return false;
-
- //是否是首次进入到低电量模式
- if (!isLowPowerState) {
- mObsLowPower.setValue(true);
- getHome();
- isLowPowerState = true;
- }
-
+ if (phoneIsInUse()) return;
+ if (isFactoryTestTopActivity(mContext)) return;
+ getHome();
+ mObsLowPower.setValue(true);
//更新低电量的值
mObsLowPowerValue.setValue(level + "%");
-
- return true;
}
private void getHome() {
}
}
- private void showShockAndAudio(int index){
+ private void showShockAndAudio(int index) {
VibrateUtil.getInstance(mContext).VibrateOn(true);
playUtils.playKeyboardSound(mContext, index);
}
+
+ @RequiresApi(api = Build.VERSION_CODES.Q)
+ public static boolean isFactoryTestTopActivity(Context paramContext) {
+ ArrayList<String> arrayList = new ArrayList();
+ arrayList.add("mobile.miki");
+ return arrayList.contains((((ActivityManager) paramContext.getSystemService(Context.ACTIVITY_SERVICE)).getRunningTasks(1).get(0)).topActivity.getPackageName());
+ }
}
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
+import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
if (animationDrawable == null) {
batteryIv.setImageResource(R.drawable.l02_battery_charging_anim);
animationDrawable = (AnimationDrawable) batteryIv.getDrawable();
- animationDrawable.start();
+ batteryIv.getViewTreeObserver().addOnDrawListener(() -> {
+ if (animationDrawable != null) {
+ animationDrawable.start();
+ }
+ }
+ );
}
} else {
if (animationDrawable != null) {
-<vector android:height="18dp" android:tint="#A7A5A5"
+<vector android:height="12dp" android:tint="#A7A5A5"
android:viewportHeight="24.0" android:viewportWidth="24.0"
- android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#A7A5A5" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2z"/>
</vector>
-<vector android:height="18dp" android:tint="#FFFFFF"
+<vector android:height="12dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
- android:width="18dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ android:width="12dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2z"/>
</vector>
<ImageView
android:id="@+id/app_icon_iv"
- android:layout_width="180dp"
- android:layout_height="180dp"
+ android:layout_width="200dp"
+ android:layout_height="200dp"
android:layout_centerHorizontal="true"
- android:layout_marginTop="30dp" />
+ android:layout_marginTop="10dp" />
<TextView
android:id="@+id/app_title_tv"
android:layout_centerHorizontal="true"
android:text="@{appTitle}"
android:textColor="#FFFFFF"
- android:textSize="52sp"
- android:layout_marginTop="15dp"/>
+ android:textSize="62sp"/>
</RelativeLayout>
</layout>
<string name="app_name_motion">运动</string>
<string name="app_name_talk">微聊</string>
<string name="app_name_weather">天气</string>
- <string name="app_name_heart">心率</string>
+ <string name="app_name_heart">爱健康</string>
<string name="app_name_alipay">支付宝</string>
<string name="app_name_camera">照相</string>
<string name="app_name_album">相册</string>
-#Wed Apr 08 10:21:39 CST 2020
-VERSION_CODE=32
+#Fri Apr 10 15:47:43 CST 2020
+VERSION_CODE=42