create main page for c5
authorTrillGates <williamtrillgates@gmail.com>
Fri, 17 Sep 2021 12:39:00 +0000 (20:39 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 17 Sep 2021 12:39:00 +0000 (20:39 +0800)
app/proguard-rules.pro
app/src/main/java/com/ic/launcher/adapter/MainPageAdapter.java
app/src/main/java/com/ic/launcher/data/repository/AppsC5P3Repository.java [moved from app/src/main/java/com/ic/launcher/data/repository/AppsC53Repository.java with 97% similarity]
app/src/main/java/com/ic/launcher/presenter/LauncherPresenter.java
app/src/main/java/com/ic/launcher/presenter/MainPagePresenter.java
app/src/main/java/com/ic/launcher/view/MainPageView.java
app/src/main/java/com/ic/launcher/view/pager/MainPageViewC5P3.java [new file with mode: 0644]
app/src/main/res/layout/item_main_page_c5.xml [new file with mode: 0644]
app/src/main/res/mipmap-mdpi/icon_pedometer.png [new file with mode: 0644]

index be4edd4..c4c0733 100644 (file)
@@ -76,6 +76,8 @@
 
 # 保留R下面的资源
 -keep class **.R$* {*;}
+# 保留反射内容
+-keep class com.ic.launcher.data.repository.* {*;}
 -keepclassmembers class **.R$* {
     public static <fields>;
 }
index 39bbdc2..2618fba 100644 (file)
@@ -1,5 +1,6 @@
 package com.ic.launcher.adapter;
 
+import android.content.Context;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -11,11 +12,13 @@ import androidx.lifecycle.LifecycleOwner;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.viewpager2.widget.ViewPager2;
 
+import com.ic.iclooger.ICLogger;
 import com.ic.launcher.R;
 import com.ic.launcher.data.AppItem;
-
+import com.ic.launcher.utils.SystemUtils;
 import com.ic.launcher.view.MainPageView;
 
+import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -50,12 +53,28 @@ public class MainPageAdapter extends RecyclerView.Adapter<MainPageAdapter.InnerH
     @NonNull
     @Override
     public InnerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
-        View itemView;
+        View itemView = null;
         //创建Item
         if (viewType == TYPE_MAIN) {
+            try {
+                String idNum = SystemUtils.getSystemProperties("persist.sys.id_num");
+                String protocol = SystemUtils.getSystemProperties("persist.sys.protocol_no");
+                ICLogger.d("property ==> " + idNum);
+                ICLogger.d("protocol ==> " + protocol);
+                String targetName = "com.ic.launcher.view.pager.MainPageView" + idNum + "P" + protocol;
+                ICLogger.d("targetName ==> " + targetName);
+                Class<?> clazz = Class.forName(targetName);
+                Constructor<?> constructor = clazz.getConstructor(Context.class);
+                itemView = (View) constructor.newInstance(parent.getContext());
+            } catch (Exception e) {
+                e.printStackTrace();
+                itemView = null;
+            }
+            //MainPageViewC5P3
             //主页面
-            itemView = new MainPageView(parent.getContext());
-            ((MainPageView) itemView).initViewModel();
+            if (itemView == null) {
+                itemView = new MainPageView(parent.getContext());
+            }
             ViewPager2.LayoutParams layoutParams = new ViewPager2.LayoutParams(
                     ViewGroup.LayoutParams.MATCH_PARENT,
                     ViewGroup.LayoutParams.MATCH_PARENT);
@@ -10,7 +10,7 @@ import java.util.List;
 /**
  * 此类不可以被混淆,由反射去创建
  */
-public class AppsC53Repository implements IAppListRepository {
+public class AppsC5P3Repository implements IAppListRepository {
 
     @Override
     public List<AppItem> getAppList() {
index 9c971c1..8e2c6e8 100644 (file)
@@ -46,14 +46,14 @@ public class LauncherPresenter extends BasePresenter {
         //动态创建即可
         //App列表目录,动态创建
         //注意不要混淆了,否则反射就没用了
-        //data/repository/Apps+numID+protocol+Repository,比如说:AppsC57Repository ,numberId = C5,7为协议号
+        //data/repository/Apps+numID+P+protocol+Repository,比如说:AppsC57Repository ,numberId = C5,P7为协议号
         try {
             String idNum = SystemUtils.getSystemProperties("persist.sys.id_num");
             String protocol = SystemUtils.getSystemProperties("persist.sys.protocol_no");
             ICLogger.d("property ==> " + idNum);
             ICLogger.d("protocol ==> " + protocol);
             if (!TextUtils.isEmpty(idNum) && !TextUtils.isEmpty(protocol)) {
-                String targetName = "com.ic.launcher.data.repository.Apps" + idNum + protocol + "Repository";
+                String targetName = "com.ic.launcher.data.repository.Apps" + idNum +"P"+ protocol + "Repository";
                 ICLogger.d("target reposition ==> " + targetName);
                 appListRepository = (IAppListRepository) Class.forName(targetName).newInstance();
                 ICLogger.d("create repository okay..");
index def41da..2f548c3 100644 (file)
@@ -54,6 +54,8 @@ public class MainPagePresenter extends BasePresenter {
     public MutableLiveData<String> bodyTempValue = new MutableLiveData<>();
     //环境温度
     public MutableLiveData<String> envTempValue = new MutableLiveData<>();
+    //步数
+    public MutableLiveData<String> stepCountValue = new MutableLiveData<>();
 
     private final Context mContext;
 
@@ -72,6 +74,12 @@ public class MainPagePresenter extends BasePresenter {
         updateTime(null);
         //注册广播,监听灭屏和亮屏
         listenerScreenState();
+        //获取步数
+        getStepCount();
+    }
+
+    private void getStepCount() {
+        getValue(KEY_STEP_COUNT);
     }
 
     private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
@@ -282,6 +290,14 @@ public class MainPagePresenter extends BasePresenter {
                         updateEnvTemp();
                     }
                 });
+        context.getContentResolver().registerContentObserver(Uri.parse(SETTINGS + ".sport_step_count"),
+                true, new ContentObserver(null) {
+                    @Override
+                    public void onChange(boolean selfChange) {
+                        //更新血压
+                        getStepCount();
+                    }
+                });
     }
 
     private void getValueByKey(String key) {
@@ -323,6 +339,7 @@ public class MainPagePresenter extends BasePresenter {
     public static final String KEY_HEART_RATE = "heart_rate";
     public static final String KEY_ENV_TEMP = "env_temperature";
     public static final String KEY_TEMP = "body_temperature";
+    public static final String KEY_STEP_COUNT = "sport_step_count";
 
 
     private void updateTemperature() {
index 7cca92c..6b17865 100644 (file)
@@ -38,9 +38,10 @@ public class MainPageView extends LinearLayout {
                 R.layout.item_main_page, this
         );
         initView();
+        initViewModel();
     }
 
-    public void initViewModel() {
+    private void initViewModel() {
         ICLogger.d("initViewModel...");
         mainPagerPresenter = MainPagePresenter.getInstance(getContext());
         mainPagerPresenter.dateValue.observeForever(dateValue -> {
diff --git a/app/src/main/java/com/ic/launcher/view/pager/MainPageViewC5P3.java b/app/src/main/java/com/ic/launcher/view/pager/MainPageViewC5P3.java
new file mode 100644 (file)
index 0000000..74e1144
--- /dev/null
@@ -0,0 +1,79 @@
+package com.ic.launcher.view.pager;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.ic.iclooger.ICLogger;
+import com.ic.launcher.R;
+import com.ic.launcher.presenter.MainPagePresenter;
+
+public class MainPageViewC5P3 extends LinearLayout {
+
+    private MainPagePresenter mainPagerPresenter;
+    private TextView dateView;
+    private TextView timeView;
+    private TextView weekView;
+    private TextView heartRateView;
+    private TextView bloodOxygenView;
+    private TextView stepCountView;
+
+    public MainPageViewC5P3(@NonNull Context context) {
+        this(context, null);
+    }
+
+    public MainPageViewC5P3(@NonNull Context context, @Nullable AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public MainPageViewC5P3(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        LayoutInflater.from(getContext()).inflate(
+                R.layout.item_main_page_c5, this
+        );
+        initView();
+        initViewModel();
+    }
+
+    public void initViewModel() {
+        ICLogger.d("initViewModel...");
+        mainPagerPresenter = MainPagePresenter.getInstance(getContext());
+        mainPagerPresenter.dateValue.observeForever(dateValue -> {
+            //ICLogger.d("dateValue == > " + dateValue);
+            dateView.setText(dateValue);
+        });
+        mainPagerPresenter.timeValue.observeForever(timeValue -> {
+            //ICLogger.d("timeValue == > " + timeValue);
+            timeView.setText(timeValue);
+        });
+        mainPagerPresenter.weekValue.observeForever(weekValue -> {
+            weekView.setText(weekValue);
+        });
+        mainPagerPresenter.bodyTempValue.observeForever(bodyTempValue -> {
+            stepCountView.setText(bodyTempValue);
+        });
+        mainPagerPresenter.oxygenValue.observeForever(oxygenValue -> {
+            bloodOxygenView.setText(oxygenValue);
+        });
+        mainPagerPresenter.heartRate.observeForever(heartRate -> {
+            heartRateView.setText(heartRate);
+        });
+        mainPagerPresenter.stepCountValue.observeForever(stepCount -> {
+            stepCountView.setText(stepCount);
+        });
+    }
+
+    private void initView() {
+        dateView = findViewById(R.id.date_tv);
+        timeView = findViewById(R.id.time_tv);
+        weekView = findViewById(R.id.week_date_tv);
+        heartRateView = findViewById(R.id.heart_rate_tv);
+        bloodOxygenView = findViewById(R.id.blood_oxygen_tv);
+        stepCountView = findViewById(R.id.step_count_tv);
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/item_main_page_c5.xml b/app/src/main/res/layout/item_main_page_c5.xml
new file mode 100644 (file)
index 0000000..9283ee8
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <TextView
+        android:id="@+id/time_tv"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_horizontal"
+        android:includeFontPadding="false"
+        android:text="--:--"
+        android:textColor="@color/white"
+        android:textSize="120sp" />
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="22dp"
+        android:layout_marginRight="22dp"
+        android:orientation="horizontal">
+
+        <TextView
+            android:id="@+id/date_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="left"
+            android:includeFontPadding="false"
+            android:text="||-||"
+            android:textColor="@color/white"
+            android:textSize="40sp" />
+
+        <TextView
+            android:id="@+id/week_date_tv"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="right"
+            android:includeFontPadding="false"
+            android:text="星期#"
+            android:textColor="@color/white"
+            android:textSize="40sp" />
+
+    </FrameLayout>
+
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="20dp"
+        android:orientation="horizontal">
+
+        <LinearLayout
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:gravity="center_horizontal"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="50dp"
+                android:layout_height="50dp"
+                android:src="@mipmap/heart_rate" />
+
+            <TextView
+                android:id="@+id/heart_rate_tv"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="00"
+                android:textColor="@color/white"
+                android:textSize="24sp" />
+
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:gravity="center_horizontal"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="50dp"
+                android:layout_height="50dp"
+                android:src="@mipmap/spo2" />
+
+            <TextView
+                android:id="@+id/blood_oxygen_tv"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="00"
+                android:textColor="@color/white"
+                android:textSize="24sp" />
+
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:gravity="center_horizontal"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="50dp"
+                android:layout_height="50dp"
+                android:src="@mipmap/icon_pedometer" />
+
+            <TextView
+                android:id="@+id/step_count_tv"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="00"
+                android:textColor="@color/white"
+                android:textSize="24sp" />
+
+
+        </LinearLayout>
+    </LinearLayout>
+
+
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-mdpi/icon_pedometer.png b/app/src/main/res/mipmap-mdpi/icon_pedometer.png
new file mode 100644 (file)
index 0000000..8881488
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/icon_pedometer.png differ