import androidx.appcompat.app.AppCompatActivity;
-import android.app.AlarmManager;
import android.content.Context;
-import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
-import android.os.SystemClock;
import android.widget.Button;
-import com.ic.work.hardware.WritePedTotalRunnable;
-import com.ic.work.utils.IcLog;
-import com.ic.work.utils.PedUtil;
+import com.ic.work.hardware.BeforeDawnRunnable;
import com.ic.work.utils.ServiceUtil;
+import com.ic.work.weather.LocationState;
+import com.ic.work.weather.WeatherHelper;
-import org.threeten.bp.Instant;
-import org.threeten.bp.LocalDate;
-import org.threeten.bp.LocalDateTime;
-import org.threeten.bp.LocalTime;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.format.DateTimeFormatter;
-import java.math.BigDecimal;
-
public class MainActivity extends AppCompatActivity {
private static final String TAG="MainActivity";
context = this;
app =(WorkServiceApp) getApplication();
- OffsetDateTime time = OffsetDateTime.now(ZoneId.systemDefault()).plusDays(1);
+ /**OffsetDateTime time = OffsetDateTime.now(ZoneId.systemDefault()).plusDays(1);
+
+ ThreadPoolManager.getInstance().execute(new BeforeDawnRunnable(
+ app.getApplicationContext(),
+ app.getRepository(),
+ app.getWeatherRepository(),
+ 11000));
- /**new Handler().postDelayed(new Runnable() {
+ new Handler().postDelayed(new Runnable() {
@Override
public void run() {
- int count=0;
- while (count<5){
- ThreadPoolManager.getInstance().execute(new WritePedTotalRunnable(
- context,
- app.getRepository(),
- 3000+count));
-
- count++;
- }
-
+ WeatherHelper weather = new WeatherHelper();
+ LocationState state = new LocationState(null,true,"深圳市");
+ weather.queryWeatherServerInfo(app.getWeatherRepository(),state);
}
- },1000);**/
+ },10000);**/
}
import com.ic.work.event.ThreadPoolEvent;
import com.ic.work.event.WeatherAgainEvent;
import com.ic.work.event.WeatherResultEvent;
+import com.ic.work.hardware.BeforeDawnRunnable;
import com.ic.work.hardware.BloodRunnable;
import com.ic.work.hardware.MessengerCoreService;
import com.ic.work.hardware.PedRecordRunnable;
import com.ic.work.hardware.PedRunnable;
-import com.ic.work.hardware.WritePedTotalRunnable;
import com.ic.work.process.BloodProcess;
import com.ic.work.process.PedProcess;
import com.ic.work.process.WeatherProcess;
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(WeatherAgainEvent event) {
if (mWeatherHelper != null) {
- mWeatherHelper.startLocation(getApplicationContext(), false);
+ mWeatherHelper.startLocation(getApplicationContext());
}
}
public void onMessageEvent(ThreadPoolEvent event) {
switch (event.getEventType()) {
case 1:
- postPedThread();
+ ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(),mApp.getRepository()));
break;
case 2:
ThreadPoolManager.getInstance().execute(new PedRecordRunnable(mApp.getRepository()));
}
switch (acyion) {
case GET_PED_ACTION:
- postPedThread();
+ ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(),mApp.getRepository()));
break;
case Intent.ACTION_TIMEZONE_CHANGED:
- mWeatherHelper.startLocation(getApplicationContext(), true);
+ mWeatherHelper.startLocation(getApplicationContext());
break;
case PED_FINISH_ACTION:
IcLog.i(TAG,"PED_FINISH_ACTION");
}
IcLog.i(TAG,"everyDayFinish");
mFinishTime = LocalDateTime.now(ZoneId.systemDefault());
-
//完成,需要把所有的今天的数据全部写入到数据中
- mWeatherHelper.startLocation(getApplicationContext(), true);
- int count = intent.getIntExtra(PED_TOTAL_KEY, 0);
- ThreadPoolManager.getInstance().execute(new WritePedTotalRunnable(
+ ThreadPoolManager.getInstance().execute(new BeforeDawnRunnable(
mApp.getApplicationContext(),
mApp.getRepository(),
- count));
- postPedThread();
- }
-
- private void postPedThread() {
- ThreadPoolManager.getInstance().execute(new PedRunnable(mApp.getApplicationContext(), mApp.getRepository()));
+ mApp.getWeatherRepository(),
+ intent.getIntExtra(PED_TOTAL_KEY, 0)));
}
}
import com.ic.work.db.entity.PedEntity;
import com.ic.work.db.entity.WeatherEntity;
-@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 3,exportSchema = false)
+@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 4,exportSchema = false)
@TypeConverters(TiviTypeConverters.class)
public abstract class AppDatabase extends RoomDatabase {
import com.ic.work.db.dao.WeatherDao;
import com.ic.work.db.entity.WeatherEntity;
-import org.threeten.bp.LocalDate;
-import org.threeten.bp.OffsetDateTime;
-
import java.util.List;
public class WeatherInjection {
import androidx.room.Index;
import androidx.room.PrimaryKey;
+import org.threeten.bp.OffsetDateTime;
+
@Entity(tableName = "icWeatherDb",
indices = {@Index("id")})
private String temperatureDay; // 白天温度 或 最低温度
private String temperatureNight; // 晚上温度 或 最低温度
private String updateTime; // 更新时间
+ private OffsetDateTime queryTime;
public int getId() {
return id;
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
+
+ public OffsetDateTime getQueryTime() {
+ return queryTime;
+ }
+
+ public void setQueryTime(OffsetDateTime queryTime) {
+ this.queryTime = queryTime;
+ }
}
--- /dev/null
+package com.ic.work.hardware;
+
+import android.content.Context;
+
+import com.ic.work.db.PedInjection;
+import com.ic.work.db.WeatherInjection;
+import com.ic.work.utils.IcLog;
+
+public class BeforeDawnRunnable extends PedBaseRunnable implements Runnable {
+
+ private static final String TAG = "BeforeDawnRunnable";
+
+ private int mTotalPed;
+ private WeatherInjection weatherInjection;
+
+ public BeforeDawnRunnable(Context context, PedInjection pedInjection, WeatherInjection weatherInjection, int totalPed) {
+ super(context, pedInjection);
+ this.mTotalPed = totalPed;
+ this.weatherInjection = weatherInjection;
+ }
+
+ @Override
+ public void run() {
+
+ if(weatherInjection != null){
+ weatherInjection.deleteDBWeatherDate();
+ }
+
+ IcLog.i(TAG, "Before Ped Count" + mTotalPed);
+
+ updateCountDB(mTotalPed, getFrontOffsetDateTime());
+
+ updateCountDB(0,getOffsetDateTime());
+ }
+}
mWeight = SPUtils.getPedWighttSP(context);
}
- protected boolean isCheckPedInjection() {
+ private boolean isCheckPedInjection() {
return mPedInjection == null;
}
- protected int queryDBPedCount() {
+ private int queryDBPedCount() {
return mPedInjection.queryDBPedCount();
}
- protected List<PedEntity> queryTodayPedEntity(){
- return mPedInjection.queryDBPedDate(getOffsetDateTime());
+ private List<PedEntity> queryTimePedEntity(OffsetDateTime time){
+ return mPedInjection.queryDBPedDate(time);
}
- protected void insertDBPedEntity(int number, OffsetDateTime date, int size) {
+ private void insertDBPedEntity(int number, OffsetDateTime date, int size) {
//判断 size 超过
if (size >= 60) {
//删除一条最早的数据
mPedInjection.updateDBPedDate(entity);
}
- protected void processPedCountDB(int pedCount){
+ protected void updateCountDB(int ped,OffsetDateTime dateTime){
if (isCheckPedInjection()) {
return;
}
int size = queryDBPedCount();
-
- if (size == 0) {
+ if(size == 0){
//如果数据库中无记录,把当前数据插入到数据库中
- insertDBPedEntity(pedCount, getOffsetDateTime(), size);
- } else {
- //2.去查询数据中是否有当天的记录。
- List<PedEntity> todayPed = queryTodayPedEntity();
+ insertDBPedEntity(ped, dateTime, size);
+ }else {
+ //2.去查询数据中是否有记录。
+ List<PedEntity> todayPed = queryTimePedEntity(dateTime);
if (todayPed != null && todayPed.size() > 0) {
//3.如果数据中有当天的数据,并更新数据
- if (pedCount > 0 && pedCount > todayPed.get(0).getPedNumber()) {
- todayPed.get(0).setPedNumber(pedCount);
+ if (ped > 0 && ped > todayPed.get(0).getPedNumber()) {
+ todayPed.get(0).setPedNumber(ped);
updateDBPedEntity(todayPed.get(0));
}
} else {
//直接 插入今天的数据
- insertDBPedEntity(pedCount, getOffsetDateTime(), size);
+ insertDBPedEntity(ped, dateTime, size);
}
}
}
return OffsetDateTime.now(ZoneId.systemDefault());
}
- private OffsetDateTime getFrontOffsetDateTime() {
+ protected OffsetDateTime getFrontOffsetDateTime() {
return getOffsetDateTime().minusDays(1);
}
import android.content.Context;
import com.ic.work.db.PedInjection;
-import com.ic.work.db.entity.PedEntity;
import com.ic.work.event.PedCountEvent;
import com.ic.work.utils.HardwareUtils;
import com.ic.work.utils.IcLog;
-import com.ic.work.utils.PedUtil;
import org.greenrobot.eventbus.EventBus;
-import org.threeten.bp.OffsetDateTime;
-import org.threeten.bp.ZoneId;
-
-import java.math.BigDecimal;
-import java.util.List;
public class PedRunnable extends PedBaseRunnable implements Runnable {
private static final String TAG = "PedRunnable";
- private boolean isRuning = false;
-
public PedRunnable(Context context,PedInjection pedDB) {
super(context,pedDB);
}
@Override
public void run() {
-
- if (isRuning) {
- return;
- }
-
- isRuning = true;
-
- //1.先获取一次当前的计步数
- int currCount = HardwareUtils.getNdkStepCountValue();
- IcLog.i(TAG, "Ped Count" + currCount);
+ int ped = HardwareUtils.getNdkStepCountValue();
+ IcLog.i(TAG, "Get Ped Count" + ped);
//发送给主线程。主线更新数据UI
- EventBus.getDefault().post(new PedCountEvent(currCount));
- processPedCountDB(currCount);
-
- isRuning = false;
+ EventBus.getDefault().post(new PedCountEvent(ped));
+ updateCountDB(ped,getOffsetDateTime());
}
}
+++ /dev/null
-package com.ic.work.hardware;
-
-import android.content.Context;
-import com.ic.work.db.PedInjection;
-
-public class WritePedTotalRunnable extends PedBaseRunnable implements Runnable {
-
- private int mTotalPed;
-
- public WritePedTotalRunnable(Context context, PedInjection pedDB, int totalPed) {
- super(context, pedDB);
- mTotalPed = totalPed;
- }
-
- @Override
- public void run() {
- processPedCountDB(mTotalPed);
- }
-}
import com.ic.work.db.WeatherInjection;
import com.ic.work.weather.melon.SocketThread;
-import org.threeten.bp.Duration;
-import org.threeten.bp.LocalDateTime;
-import org.threeten.bp.ZoneId;
-
public class WeatherHelper {
private LocationHelper mLocation = null;
- private LocationState locationState = null;
- public void startLocation(Context context,boolean force) {
+ public void startLocation(Context context) {
//如果已经定位成功
- if(!force && locationState != null && !TextUtils.isEmpty(locationState.getCity())){
- LocalDateTime oldTime = locationState.getTime();
- LocalDateTime currTime = LocalDateTime.now(ZoneId.systemDefault());
- Duration duration = Duration.between(currTime,oldTime);
- if(duration.toDays() <1){
- return;
- }
- }
-
mLocation = new LocationHelper(context);
mLocation.startLocationService();
}
return;
}
- locationState = state;
-
final String serverHost = "118.190.120.79";
final int port = 11645;
import org.greenrobot.eventbus.EventBus;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
+import org.threeten.bp.ZoneId;
import org.threeten.bp.format.DateTimeFormatter;
import java.util.ArrayList;
weather.setUpdateTime(fJson.getString("date"));
db.setUpdateTime(fJson.getString("date"));
+ db.setQueryTime(OffsetDateTime.now(ZoneId.systemDefault()));
+
if (BuildConfig.DEBUG) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(weather.getStatusDay()).append("-").append(weather.getStatusNight())
}
EventBus.getDefault().post(new WeatherResultEvent(wpList));
- //插入数据库
weatherInjection.deleteDBWeatherDate();
weatherInjection.insertWeatherEntity(dbList);
}
-#Tue Mar 31 18:36:21 CST 2020
-VERSION_CODE=19
+#Fri Apr 10 13:53:45 CST 2020
+VERSION_CODE=29