androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation files('libs/ICLoger-release.aar')
+ implementation 'com.jakewharton.threetenabp:threetenabp:1.2.2'
}
\ No newline at end of file
import android.app.Application;
import com.ic.iclooger.ICLogger;
+import com.jakewharton.threetenabp.AndroidThreeTen;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
+ AndroidThreeTen.init(this);
ICLogger.init(getApplicationContext(), "LOOP-PAGE-LAUNCHER");
}
}
import androidx.viewpager2.widget.ViewPager2;
import com.ic.launcher.loop.adapter.MainPageAdapter;
-import com.ic.launcher.loop.presenter.MainPagePresenter;
+import com.ic.launcher.loop.presenter.LauncherPresenter;
import com.ic.launcher.loop.view.SimpleStatusBarView;
import com.ic.launcher.loop.view.StatusBarView;
public class LauncherActivity extends AppCompatActivity {
private MainPageAdapter mainPageAdapter;
- private MainPagePresenter mainPagePresenter;
+ private LauncherPresenter mainPagePresenter;
private ViewPager2 looperPage;
private StatusBarView statusBar;
private SimpleStatusBarView simpleStatusBar;
}
private void initPresenter() {
- mainPagePresenter = MainPagePresenter.getInstance(this);
+ mainPagePresenter = LauncherPresenter.getInstance(this);
mainPagePresenter.appListValues.observe(this, newList -> {
mainPageAdapter.updateAppList(newList);
//数据设置的时候,把页面移动到中间
private void initView() {
looperPage = findViewById(R.id.main_looper_pager);
- mainPageAdapter = new MainPageAdapter();
+ mainPageAdapter = new MainPageAdapter(this);
looperPage.setAdapter(mainPageAdapter);
statusBar = findViewById(R.id.status_bar);
statusBar.initPresenter(this);
import android.widget.TextView;
import androidx.annotation.NonNull;
+import androidx.lifecycle.LifecycleOwner;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.viewpager2.widget.ViewPager2;
import com.ic.launcher.loop.R;
import com.ic.launcher.loop.data.AppItem;
+import com.ic.launcher.loop.view.MainPageView;
import java.util.ArrayList;
import java.util.List;
public class MainPageAdapter extends RecyclerView.Adapter<MainPageAdapter.InnerHolder> {
+ private final LifecycleOwner mLifeOwner;
+
+ public MainPageAdapter(LifecycleOwner owner) {
+ this.mLifeOwner = owner;
+ }
+
private OnItemClickListener mItemClickListener = null;
private List<AppItem> appItemList = new ArrayList<>();
//创建Item
if (viewType == TYPE_MAIN) {
//主页面
- itemView = LayoutInflater.from(parent.getContext()).inflate(
- R.layout.item_main_page, parent, false
- );
+ itemView = new MainPageView(parent.getContext());
+ ((MainPageView) itemView).initViewModel(mLifeOwner);
+ ViewPager2.LayoutParams layoutParams = new ViewPager2.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ itemView.setLayoutParams(layoutParams);
} else {
//App的Item页面
itemView = LayoutInflater.from(parent.getContext()).inflate(
--- /dev/null
+package com.ic.launcher.loop.presenter;
+
+import android.content.Context;
+
+import androidx.lifecycle.MutableLiveData;
+
+import com.ic.launcher.loop.data.AppItem;
+import com.ic.launcher.loop.data.HardCodeAppListRepository;
+import com.ic.launcher.loop.data.IAppListRepository;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 首页的业务类
+ */
+public class LauncherPresenter extends BasePresenter {
+
+ //关心的数据:
+ //应用列表
+ public MutableLiveData<List<AppItem>> appListValues = new MutableLiveData<>();
+
+ private final ExecutorService executorService;
+ private final IAppListRepository appListRepository;
+
+ private LauncherPresenter(Context context) {
+ executorService = Executors.newSingleThreadExecutor();
+ appListRepository = HardCodeAppListRepository.getInstance(context);
+ //去获取应用列表内容
+ initAppList();
+ }
+
+ private void initAppList() {
+ executorService.execute(() -> {
+ //获取应用列表
+ List<AppItem> appList = appListRepository.getAppList();
+ appListValues.postValue(appList);
+ });
+ }
+
+ private static LauncherPresenter sInstance = null;
+
+ public static LauncherPresenter getInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new LauncherPresenter(context);
+ }
+ return sInstance;
+ }
+}
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.Handler;
+import android.os.HandlerThread;
+import android.text.TextUtils;
import androidx.lifecycle.MutableLiveData;
-import com.ic.launcher.loop.data.AppItem;
-import com.ic.launcher.loop.data.HardCodeAppListRepository;
-import com.ic.launcher.loop.data.IAppListRepository;
+import com.ic.iclooger.ICLogger;
+import com.ic.launcher.loop.R;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import org.threeten.bp.Instant;
+import org.threeten.bp.LocalDateTime;
+import org.threeten.bp.ZoneId;
+import org.threeten.bp.format.DateTimeFormatter;
-/**
- * 首页的业务类
- */
public class MainPagePresenter extends BasePresenter {
- //关心的数据:
- //应用列表
- public MutableLiveData<List<AppItem>> appListValues = new MutableLiveData<>();
+ private static final DateTimeFormatter HH_MM = DateTimeFormatter.ofPattern("HH:mm");
+ private static final DateTimeFormatter MM_DD = DateTimeFormatter.ofPattern("MM-dd");
- private final ExecutorService executorService;
- private final IAppListRepository appListRepository;
+ //所关心的数据
+ //时间
+ public MutableLiveData<String> timeValue = new MutableLiveData<>();
+ //日期
+ public MutableLiveData<String> dateValue = new MutableLiveData<>();
+ //星期
+ public MutableLiveData<String> weekValue = new MutableLiveData<>();
+ //心率
+ public MutableLiveData<String> heartRate = new MutableLiveData<>();
+ //血氧
+ public MutableLiveData<String> oxygenValue = new MutableLiveData<>();
+ //体温
+ public MutableLiveData<String> bodyTempValue = new MutableLiveData<>();
+ //环境温度
+ public MutableLiveData<String> envTempValue = new MutableLiveData<>();
+
+ private final Context mContext;
+ private final Handler handler;
private MainPagePresenter(Context context) {
- executorService = Executors.newSingleThreadExecutor();
- appListRepository = HardCodeAppListRepository.getInstance(context);
- //去获取应用列表内容
- initAppList();
+ this.mContext = context;
+ //监听数据变化
+ HandlerThread handlerThread = new HandlerThread("ic:launcher.main.page");
+ //开启任务执行
+ handlerThread.start();
+ handler = new Handler(handlerThread.getLooper());
+ //handler.post(updateTimeTask);
+ //监听网路广播
+ registerTimeDateReceiver();
+ updateTime(null);
+ //TODO:
+ }
+
+ private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ ICLogger.d("action == > " + action);
+ if (TextUtils.isEmpty(action)) return;
+ if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
+ updateTime(intent.getStringExtra("time-zone"));
+ } else {
+ updateTime(null);
+ }
+ }
+ };
+
+ public void registerTimeDateReceiver() {
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_TIME_TICK);
+ filter.addAction(Intent.ACTION_TIME_CHANGED);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+ mContext.registerReceiver(mIntentReceiver, filter);
+ }
+
+
+ private final Runnable updateTimeTask = new Runnable() {
+ @Override
+ public void run() {
+ //更新时间
+ updateTime(null);
+ //60秒更新一次
+ handler.postDelayed(this, 1000 * 60);
+ }
+ };
+
+ private void updateTime(String timeZoom) {
+ LocalDateTime currDateTime;
+ if (!TextUtils.isEmpty(timeZoom)) {
+ ZoneId zone = ZoneId.of(timeZoom).getRules().getOffset(Instant.now());
+ currDateTime = LocalDateTime.now(zone);
+ } else {
+ currDateTime = LocalDateTime.now(ZoneId.systemDefault());
+ }
+ String format = currDateTime.format(HH_MM);
+ timeValue.postValue(format);
+ dateValue.postValue(currDateTime.format(MM_DD));
+ computeMainClockTime(currDateTime);
+ }
+
+
+ private void computeMainClockTime(LocalDateTime localDateTime) {
+ switch (localDateTime.getDayOfWeek()) {
+ case MONDAY:
+ weekValue.setValue(mContext.getString(R.string.monday));
+ break;
+ case TUESDAY:
+ weekValue.setValue(mContext.getString(R.string.tuesday));
+ break;
+ case WEDNESDAY:
+ weekValue.setValue(mContext.getString(R.string.wednesday));
+ break;
+ case THURSDAY:
+ weekValue.setValue(mContext.getString(R.string.thursday));
+ break;
+ case FRIDAY:
+ weekValue.setValue(mContext.getString(R.string.friday));
+ break;
+ case SATURDAY:
+ weekValue.setValue(mContext.getString(R.string.saturday));
+ break;
+ case SUNDAY:
+ weekValue.setValue(mContext.getString(R.string.sunday));
+ break;
+ }
}
- private void initAppList() {
- executorService.execute(() -> {
- //获取应用列表
- List<AppItem> appList = appListRepository.getAppList();
- appListValues.postValue(appList);
- });
+
+ @Override
+ protected void onClean() {
+ super.onClean();
+ handler.removeCallbacks(updateTimeTask);
+ mContext.unregisterReceiver(mIntentReceiver);
}
private static MainPagePresenter sInstance = null;
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 androidx.lifecycle.LifecycleOwner;
+
+import com.ic.iclooger.ICLogger;
+import com.ic.launcher.loop.R;
+import com.ic.launcher.loop.presenter.MainPagePresenter;
public class MainPageView extends LinearLayout {
+ private MainPagePresenter mainPagerPresenter;
+ private TextView dateView;
+ private TextView timeView;
+ private TextView weekView;
+
public MainPageView(@NonNull Context context) {
- super(context);
+ this(context, null);
}
public MainPageView(@NonNull Context context, @Nullable AttributeSet attrs) {
- super(context, attrs);
+ this(context, attrs, 0);
}
public MainPageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
+ LayoutInflater.from(getContext()).inflate(
+ R.layout.item_main_page, this
+ );
+ initView();
+ }
+
+ public void initViewModel(LifecycleOwner lifecycleOwner) {
+ ICLogger.d("initViewModel...");
+ mainPagerPresenter = MainPagePresenter.getInstance(getContext());
+ mainPagerPresenter.dateValue.observe(lifecycleOwner, dateValue -> {
+ //ICLogger.d("dateValue == > " + dateValue);
+ dateView.setText(dateValue);
+ });
+ mainPagerPresenter.timeValue.observe(lifecycleOwner, timeValue -> {
+ //ICLogger.d("timeValue == > " + timeValue);
+ timeView.setText(timeValue);
+ });
+ mainPagerPresenter.weekValue.observe(lifecycleOwner, weekValue -> {
+ weekView.setText(weekValue);
+ });
+ }
+
+ private void initView() {
+ dateView = findViewById(R.id.date_tv);
+ timeView = findViewById(R.id.time_tv);
+ weekView = findViewById(R.id.week_date_tv);
+ // ICLogger.d("init view..." + getChildCount());
}
}
<?xml version="1.0" encoding="utf-8"?>
-<com.ic.launcher.loop.view.MainPageView xmlns:android="http://schemas.android.com/apk/res/android"
+<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="00:00"
+ android:text="--:--"
android:textColor="@color/white"
android:textSize="120sp" />
android:layout_height="wrap_content"
android:layout_gravity="left"
android:includeFontPadding="false"
- android:text="02-30"
+ android:text="||-||"
android:textColor="@color/white"
android:textSize="40sp" />
android:layout_height="wrap_content"
android:layout_gravity="right"
android:includeFontPadding="false"
- android:text="星期天"
+ android:text="星期#"
android:textColor="@color/white"
android:textSize="40sp" />
android:id="@+id/out_temp_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="24.0"
+ android:text="00.0"
android:textColor="@color/white"
android:textSize="24sp" />
android:id="@+id/heart_rate_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="98"
+ android:text="00"
android:textColor="@color/white"
android:textSize="24sp" />
android:id="@+id/blood_oxygen_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="120"
+ android:text="000"
android:textColor="@color/white"
android:textSize="24sp" />
android:id="@+id/body_temp_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="36.5"
+ android:text="00.0"
android:textColor="@color/white"
android:textSize="24sp" />
</LinearLayout>
-</com.ic.launcher.loop.view.MainPageView>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
<string name="app_package_name_sign">com.ic.sign</string>
<string name="app_package_name_settings">com.eqc.setting</string>
<string name="no_application_tips_text">未找到相关应用.</string>
+
+ <string name="monday">星期一</string>
+ <string name="tuesday">星期二</string>
+ <string name="wednesday">星期三</string>
+ <string name="thursday">星期四</string>
+ <string name="friday">星期五</string>
+ <string name="saturday">星期六</string>
+ <string name="sunday">星期日</string>
</resources>
\ No newline at end of file