package com.ic.launcher.loop.presenter;
+import android.content.Context;
+
public class SimpleStatusBarPresenter extends StatusBarBasePresenter {
+ public SimpleStatusBarPresenter(Context context) {
+ super(context);
+ }
}
package com.ic.launcher.loop.presenter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.telephony.CellInfo;
+import android.telephony.CellInfoCdma;
+import android.telephony.CellInfoGsm;
+import android.telephony.CellInfoLte;
+import android.telephony.CellInfoWcdma;
+import android.telephony.TelephonyManager;
+
import androidx.lifecycle.MutableLiveData;
+import com.ic.launcher.loop.utils.SystemUtils;
+
+import java.util.List;
+
public class StatusBarBasePresenter extends BasePresenter {
+ protected final Context mContext;
//电量状态
- public MutableLiveData<Boolean> isCharging = new MutableLiveData<>();
+ public MutableLiveData<Boolean> isChargingValue = new MutableLiveData<>();
//电量
public MutableLiveData<Integer> batteryLev = new MutableLiveData<>();
//信号强度
public MutableLiveData<Integer> signalLev = new MutableLiveData<>();
+ //连接状态
+ public MutableLiveData<Boolean> isServerConnected = new MutableLiveData<>();
+
+ private Handler handler;
+ private TelephonyManager mTelephony;
+ private int oldSignalLevel;
+
+ public StatusBarBasePresenter(Context context) {
+ this.mContext = context;
+ //获取电量和充电状态
+ getBatteryLev();
+ getSignalLev();
+ checkCharging();
+ }
+
+ private void checkCharging() {
+ //充电状态
+ IntentFilter batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
+ 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);
+ }
+ };
+
+ private void getSignalLev() {
+ HandlerThread handlerThread = new HandlerThread("ic:launcher-status-bar");
+ handlerThread.start();
+ handler = new Handler(handlerThread.getLooper());
+ this.mTelephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+ //获取信号强度
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ getSignalStrength();
+ getConnectionState();
+ handler.postDelayed(this, 1000);
+ }
+ });
+ }
+
+
+ public void getSignalStrength() {
+ if (mTelephony == null) {
+ return;
+ }
+
+ List<CellInfo> cellInfoList = mTelephony.getAllCellInfo();
+ if (cellInfoList == null || cellInfoList.size() == 0) {
+ return;
+ }
+
+ int level = 1;
+
+ for (CellInfo cellInfo : cellInfoList) {
+ if (cellInfo instanceof CellInfoLte) {
+ level = ((CellInfoLte) cellInfo).getCellSignalStrength().getLevel() + 1;
+ } else if (cellInfo instanceof CellInfoCdma) {
+ level = ((CellInfoCdma) cellInfo).getCellSignalStrength().getLevel() + 1;
+ } else if (cellInfo instanceof CellInfoGsm) {
+ level = ((CellInfoGsm) cellInfo).getCellSignalStrength().getLevel() + 1;
+ } else if (cellInfo instanceof CellInfoWcdma) {
+ level = ((CellInfoWcdma) cellInfo).getCellSignalStrength().getLevel() + 1;
+ }
+ }
+
+ // ICLogger.d("level == > " + level);
+ if (level != oldSignalLevel) {
+ oldSignalLevel = level;
+ signalLev.postValue(level);
+ }
+ }
+
+ //获取链接状态
+ private void getConnectionState() {
+ boolean connected = SystemUtils.getSystemPropertiesBoolean("persist.sys.server_connected", false);
+ isServerConnected.postValue(connected);
+ }
+
+
+ private void getBatteryLev() {
+
+ }
}
package com.ic.launcher.loop.presenter;
+import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.location.LocationManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
+import android.provider.Settings;
import androidx.lifecycle.MutableLiveData;
public class StatusBarPresenter extends StatusBarBasePresenter {
- private final Context mContext;
//网络状态
public MutableLiveData<Boolean> isWifiOpen = new MutableLiveData<>();
//GPS状态
public MutableLiveData<Boolean> silentState = new MutableLiveData<>();
//微聊新消息
public MutableLiveData<Boolean> icTalkMsgState = new MutableLiveData<>();
- //连接状态
- public MutableLiveData<Boolean> isServerConnected = new MutableLiveData<>();
//
private final ExecutorService executorService;
//
private NetworkConnectChangedReceiver mNetworkChangeListener;
private StatusBarPresenter(Context context) {
- this.mContext = context;
+ super(context);
executorService = Executors.newSingleThreadExecutor();
//监听各种状态
//需要初始化一次,然后进行监听
getSilentState();
checkIcTalkMsg();
checkHasMissCall();
- checkServerConnected();
- }
-
- private void checkServerConnected() {
- isServerConnected.postValue(true);
}
private void checkHasMissCall() {
- //TODO:
- missCallState.postValue(true);
+ // missCallState.postValue(true);
}
private void getSilentState() {
- //TODO:
- silentState.postValue(true);
+ // silentState.postValue(true);
}
private void checkIcTalkMsg() {
- icTalkMsgState.postValue(true);
+ // icTalkMsgState.postValue(true);
}
private void getWarningMsgReadState() {
- warningReadState.postValue(true);
+ // warningReadState.postValue(true);
}
private void getAlarmState() {
- alarmState.postValue(true);
+ // alarmState.postValue(true);
}
private void getUnReadMsgState() {
- msgUnReadState.postValue(true);
+ // msgUnReadState.postValue(true);
}
private void getWearState() {
- wearState.postValue(true);
+ // wearState.postValue(true);
}
private void getBtState() {
- btState.postValue(true);
+ //蓝牙
+ IntentFilter btFilter = new IntentFilter();
+ btFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+ mContext.registerReceiver(mBtReceiver, btFilter);
}
+
+ private final BroadcastReceiver mBtReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
+ int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
+ switch (blueState) {
+ case BluetoothAdapter.STATE_TURNING_ON:
+ case BluetoothAdapter.STATE_ON:
+ btState.postValue(true);
+ ICLogger.d("ON BT OPEN");
+ break;
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ case BluetoothAdapter.STATE_OFF:
+ ICLogger.d("ON BT CLOSE");
+ btState.postValue(false);
+ break;
+ }
+ }
+ }
+ };
+
+
private void getGpsState() {
- gpsState.postValue(true);
+ //GPS
+ mContext.getContentResolver()
+ .registerContentObserver(
+ Settings.Secure
+ .getUriFor(Settings.System.LOCATION_PROVIDERS_ALLOWED),
+ false, mGpsMonitor);
}
private void getWifiState() {
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
mNetworkChangeListener = new NetworkConnectChangedReceiver();
+ mContext.registerReceiver(mNetworkChangeListener, filter);
+
}
+ private ContentObserver mGpsMonitor = new ContentObserver(null) {
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ LocationManager mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
+ boolean enabled = mLocationManager
+ .isProviderEnabled(LocationManager.GPS_PROVIDER);
+ gpsState.postValue(enabled);
+ }
+ };
+
+
class NetworkConnectChangedReceiver extends BroadcastReceiver {
@Override
--- /dev/null
+package com.ic.launcher.loop.utils;
+
+
+import java.io.FileInputStream;
+import java.lang.reflect.Method;
+
+public class SystemUtils {
+
+ public static String GetCidFromSystem() {
+ String cid_file = getSystemProperties("ro.product.partitionpath") + "miscdata";
+ byte[] resCid = new byte[16];
+ try {
+ byte[] buf = new byte[50];
+ FileInputStream inputStream = new FileInputStream(cid_file);
+ int len = inputStream.read(buf);
+ if (len < 50) return null;
+ for (int i = 0; i < 16; i++) {
+ resCid[i] = buf[i + 28];
+ }
+ for (int i = 0; i < 16; i++) {
+ if ((resCid[i] >= 0x30 && resCid[i] <= 0x39) || (resCid[i] >= 0x61 && resCid[i] <= 0x7A) || (resCid[i] >= 0x41 && resCid[i] <= 0x5A)) {
+ // valid
+ } else {
+ // invalid
+ for (int j = 28; j < 28 + 16; j++) {
+ resCid[j] = 0x30;
+ }
+ break;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ String cid = new String(resCid);
+ return cid;
+ }
+
+ public static boolean showOutTemp(){
+ boolean show=true;
+ show=!getSystemPropertiesBoolean("persyst.sys.disableTempOut",false);
+ return show;
+ }
+ public static boolean isL02()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("l02")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isDC001()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("dc001")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isC5FZD(){
+ String launcher=getLauncherName();
+ if (launcher.equals("c5fzd")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean h88tinyMode(){
+ String launcher=getLauncherName();
+ if (launcher.equals("h88tiny")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isH88()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("h88")){
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isL56A_anan()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("l56a_anan")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isN123()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("n123")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isS123()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("s123")){
+ return true;
+ }
+ return false;
+ }
+ public static boolean isq3fyt()
+ {
+ String launcher=getLauncherName();
+ if (launcher.equals("q3fyt")){
+ return true;
+ }
+ return false;
+ }
+ public static String getLauncherName(){
+ return getSystemPropertiesString("persist.sys.launcherName","l02");
+ }
+
+ public static boolean isYT(){
+ String launcher=getLauncherName();
+ if (launcher.equals("q3fyt")){
+ return true;
+ }
+ return false;
+ }
+
+
+ public static String getSystemPropertiesString(String prop, String defaultvlaue){
+ String ret=defaultvlaue;
+ String temp=getSystemProperties(prop);
+ if (!temp.trim().isEmpty()){
+ ret = temp;
+ }
+ return ret;
+ }
+ public static boolean getSystemPropertiesBoolean(String prop, boolean defaultvlaue){
+
+ boolean ret=defaultvlaue;
+ String temp=getSystemProperties(prop);
+ if (!temp.trim().isEmpty()){
+ if( temp.trim().equals("true")) {
+ ret = true;
+ }else if (temp.trim().equals("false")) {
+ ret = false;
+ }
+ }
+
+ return ret;
+ }
+ public static String getSystemProperties(String prop) {
+
+ String str = "";
+ Class clazz = null;
+ try {
+ clazz = Class.forName("android.os.SystemProperties");
+ str = (String) clazz.getMethod("get", new Class[]{String.class}).invoke(clazz, new Object[]{prop});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return str;
+ }
+
+ static public void setSystemProperties(String key, String defaultValue) {
+
+ String value = defaultValue;
+ try {
+
+ Class<?> c = Class.forName("android.os.SystemProperties");
+
+ Method get = c.getMethod("set", String.class, String.class);
+
+ get.invoke(c, key, value);
+
+ } catch (Exception e) {
+
+ e.printStackTrace();
+
+ }
+ }
+}
private View newMsgView;
private View wearView;
private View phoneView;
+ private View icTalkView;
+ private View silentIconView;
public StatusBarView(@NonNull Context context) {
this(context, null);
signalView.noNetwork();
batteryView = findViewById(R.id.right_battery_view);
batteryValueTv = findViewById(R.id.battery_value);
- //MarqueeView marqueeView = findViewById(R.id.mar_queue_view);
wifiView = findViewById(R.id.top_icon_wifi);
locationView = findViewById(R.id.top_icon_location);
btView = findViewById(R.id.top_icon_bt);
newMsgView = findViewById(R.id.top_icon_new_msg);
wearView = findViewById(R.id.top_icon_wear);
phoneView = findViewById(R.id.top_icon_phone);
- phoneView.postDelayed(new Runnable() {
- @Override
- public void run() {
- phoneView.setVisibility(GONE);
- }
- }, 10 * 1000);
+ icTalkView = findViewById(R.id.top_icon_ic_talk);
+ silentIconView = findViewById(R.id.top_icon_silent);
}
public void initPresenter(LifecycleOwner lifecycleOwner) {
statusBarPresenter = StatusBarPresenter.getInstance(getContext());
statusBarPresenter.alarmState.observe(lifecycleOwner, isAlarmOpen -> {
//设置闹钟图标显示还是隐藏
- // alarmView.setVisibility(isAlarmOpen ? VISIBLE : GONE);
+ alarmView.setVisibility(isAlarmOpen ? VISIBLE : GONE);
});
statusBarPresenter.btState.observe(lifecycleOwner, isOpen -> {
//蓝牙是否显示
- //btView.setVisibility(isOpen ? VISIBLE : GONE);
+ btView.setVisibility(isOpen ? VISIBLE : GONE);
});
statusBarPresenter.gpsState.observe(lifecycleOwner, isOpen -> {
//GPS定位是否打开
});
statusBarPresenter.icTalkMsgState.observe(lifecycleOwner, hasIcTalkMsg -> {
//是否有微聊消息
- //TODO:缺少图标
+ icTalkView.setVisibility(hasIcTalkMsg ? VISIBLE : GONE);
});
statusBarPresenter.isWifiOpen.observe(lifecycleOwner, isWifiOpen -> {
//wifi是否打开
});
statusBarPresenter.silentState.observe(lifecycleOwner, isSilent -> {
//是不是静音状态
- //TODO:缺少
+ silentIconView.setVisibility(isSilent ? VISIBLE : GONE);
});
statusBarPresenter.batteryLev.observe(lifecycleOwner, lev -> {
//电量还有多少
signalView.updateLev(lev);
}
});
- statusBarPresenter.isCharging.observe(lifecycleOwner, isCharging -> {
+ statusBarPresenter.isChargingValue.observe(lifecycleOwner, isCharging -> {
//是否在充电
+ //如果电量不是100%,那么就进行播放充电动画
+ batteryView.charging(isCharging);
});
statusBarPresenter.isServerConnected.observe(lifecycleOwner, isConnected -> {
//是否已经链接到服务器
android:visibility="gone" />
- <ImageView
- android:id="@+id/top_icon_connected"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/top_icon_connected"
- android:visibility="gone" />
-
<ImageView
android:id="@+id/top_icon_wear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingTop="5dp"
- android:paddingBottom="5dp"
+ android:paddingTop="10dp"
android:src="@mipmap/top_icon_wear"
android:visibility="gone" />
+
<ImageView
- android:id="@+id/top_warning_msg_un_read"
+ android:id="@+id/top_icon_connected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:src="@mipmap/top_icon_warning_msg_un_read"
+ android:src="@mipmap/top_icon_connected"
android:visibility="gone" />
+
<ImageView
android:id="@+id/top_icon_alarm"
android:layout_width="wrap_content"
android:src="@mipmap/top_icon_new_msg"
android:visibility="gone" />
+ <ImageView
+ android:id="@+id/top_warning_msg_un_read"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_warning_msg_un_read"
+ android:visibility="gone" />
+
<ImageView
android:id="@+id/top_icon_phone"
android:src="@mipmap/top_icon_miss_phone"
android:visibility="gone" />
+ <ImageView
+ android:id="@+id/top_icon_ic_talk"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_ic_talk_msg"
+ android:visibility="gone" />
+
+ <ImageView
+ android:id="@+id/top_icon_silent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@mipmap/top_icon_silent"
+ android:visibility="gone" />
+
+
</com.ic.launcher.loop.view.MarqueeView>
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintRight_toLeftOf="@id/right_battery_view"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintRight_toLeftOf="@id/right_battery_view" />
<com.ic.launcher.loop.view.BatteryView
android:id="@+id/right_battery_view"