-keep public class com.android.support.b
-keep public class rx.internal.util
+#androidx 混淆
+-keep class com.google.android.material.** {*;}
+-keep class androidx.** {*;}
+-keep public class * extends androidx.**
+-keep interface androidx.** {*;}
+-dontwarn com.google.android.material.**
+-dontnote com.google.android.material.**
+-dontwarn androidx.**
+
#event bus
-keepattributes *Annotation*
-keepclassmembers class * {
android:name="com.amap.api.v2.apikey"
android:value="80c129088f7bbe251a846d645ee8360a" />
+ <!--android:process=":remote"-->
<service
android:name=".WorkService"
android:enabled="true"
android:exported="true"
- android:process=":remote">
+ >
<intent-filter>
<action android:name="com.ic.action.WORK_SERVICE" />
</intent-filter>
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
- void updateCurrWeather(in WeatherParcelable weather);
+ void updateCurrWeather(in List<WeatherParcelable> weather);
}
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.LinkProperties;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;
+import android.os.Build;
import android.os.IBinder;
import android.text.TextUtils;
+import androidx.annotation.RequiresApi;
+
import com.ic.work.event.BloodCheckResultEvent;
import com.ic.work.event.BloodCheckTipsEvent;
import com.ic.work.event.LocationResultEvent;
import com.ic.work.process.WeatherProcess;
import com.ic.work.utils.IcLog;
import com.ic.work.utils.SPUtils;
+import com.ic.work.weather.LocationState;
import com.ic.work.weather.WeatherHelper;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
+import org.threeten.bp.LocalDateTime;
+import org.threeten.bp.ZoneId;
public class WorkService extends Service {
private WorkServiceApp mApp;
- private MessengerCoreService coreService;
+ private MessengerCoreService coreService;
@Override
public IBinder onBind(Intent intent) {
if (intent != null) {
- IcLog.i(TAG,intent.getPackage());
+ IcLog.i(TAG, intent.getPackage());
switch (intent.getPackage()) {
case "com.ic.weather":
//天气
return null;
}
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onCreate() {
super.onCreate();
EventBus.getDefault().register(this);
- mWeatherHelper.startLocation(getApplicationContext());
-
registerBroadcast();
coreService = new MessengerCoreService();
coreService.bindCoreService(getApplicationContext());
+ mWeatherHelper.startLocation(getApplicationContext(),false);
+
IcLog.i(TAG, "work service is start");
}
unregisterReceiver(mIntentReceiver);
- if(coreService != null){
+ if (coreService != null) {
coreService.onUnBindCoreService(getApplicationContext());
- coreService=null;
+ coreService = null;
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(LocationResultEvent event) {
- mWeatherHelper.queryWeatherServerInfo(mApp.getWeatherRepository(), event.getmCity());
+ mWeatherHelper.queryWeatherServerInfo(mApp.getWeatherRepository(), event.getLocation());
}
@Subscribe(threadMode = ThreadMode.MAIN)
event.getLow(), event.getHeart());
}
- if(coreService != null){
- coreService.sendBloodValueMessage(event.getHigh(),event.getLow(),event.getHeart());
+ if (coreService != null) {
+ coreService.sendBloodValueMessage(event.getHigh(), event.getLow(), event.getHeart());
}
//发送一次广播给 心率 launcher
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(WeatherAgainEvent event) {
if (mWeatherHelper != null) {
- mWeatherHelper.startLocation(getApplicationContext());
+ mWeatherHelper.startLocation(getApplicationContext(),false);
}
}
public void registerBroadcast() {
IntentFilter filter = new IntentFilter();
filter.addAction(GET_PED_ACTION);
+ filter.addAction(Intent.ACTION_TIME_TICK);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mIntentReceiver, filter);
}
sendBroadcast(pedIntent);
}
- private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+ private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
case GET_PED_ACTION:
pedProcess.startPedRunGetCount();
break;
+ case Intent.ACTION_TIMEZONE_CHANGED:
+ mWeatherHelper.startLocation(getApplicationContext(),true);
+ break;
+ case Intent.ACTION_TIME_TICK:
+ mWeatherHelper.startLocation(getApplicationContext(),false);
+ break;
}
}
}
import com.ic.work.db.entity.PedEntity;
import com.ic.work.db.entity.WeatherEntity;
-@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 2,exportSchema = false)
+@Database(entities = {PedEntity.class, WeatherEntity.class}, version = 3,exportSchema = false)
@TypeConverters(TiviTypeConverters.class)
public abstract class AppDatabase extends RoomDatabase {
}
private static AppDatabase buildDatabase(final Context appContext) {
- return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME).build();
+ return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME).fallbackToDestructiveMigration().build();
}
}
return mDatabase.loadWeatherDao();
}
- public List<WeatherEntity> queryDBWeatherDate(LocalDate date) {
- return getWeatherDao().loadAllDateWeatherList(date);
+ public List<WeatherEntity> queryDBWeatherDate() {
+ return getWeatherDao().loadAllDateWeatherList();
}
public void deleteDBWeatherDate() {
getWeatherDao().deleteWeatherList();
}
- public void insertWeatherEntity(WeatherEntity entity){
+ public void insertWeatherEntity(List<WeatherEntity> entity){
getWeatherDao().insertWeatherEntity(entity);
}
}
import androidx.room.Dao;
import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import com.ic.work.db.entity.WeatherEntity;
-import org.threeten.bp.LocalDate;
-import org.threeten.bp.OffsetDateTime;
-
import java.util.List;
@Dao
public interface WeatherDao {
- @Query("SELECT * FROM icWeatherDb WHERE updateTime= :currDate")
- List<WeatherEntity> loadAllDateWeatherList(LocalDate currDate);
+ @Query("SELECT * FROM icWeatherDb")
+ List<WeatherEntity> loadAllDateWeatherList();
@Query("DELETE from icWeatherDb")
void deleteWeatherList();
- @Insert
- void insertWeatherEntity(WeatherEntity entity);
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insertWeatherEntity(List<WeatherEntity> entity);
}
import androidx.room.Index;
import androidx.room.PrimaryKey;
-import org.threeten.bp.LocalDate;
@Entity(tableName = "icWeatherDb",
indices = {@Index("id")})
private String figureNight;
private String temperatureDay; // 白天温度 或 最低温度
private String temperatureNight; // 晚上温度 或 最低温度
- private LocalDate updateTime; // 更新时间
+ private String updateTime; // 更新时间
public int getId() {
return id;
this.temperatureNight = temperatureNight;
}
- public LocalDate getUpdateTime() {
+ public String getUpdateTime() {
return updateTime;
}
- public void setUpdateTime(LocalDate updateTime) {
+ public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
}
package com.ic.work.event;
+import com.ic.work.weather.LocationState;
+
public class LocationResultEvent {
- private String mCity;
+ private LocationState location;
- public LocationResultEvent(String city) {
- this.mCity = city;
+ public LocationResultEvent(LocationState location) {
+ this.location = location;
}
- public String getmCity() {
- return mCity;
+ public LocationState getLocation() {
+ return location;
}
}
import com.ic.aidl.weather.WeatherParcelable;
+import java.util.List;
+
public class WeatherResultEvent {
- private WeatherParcelable parcelable;
+ private List<WeatherParcelable> parcelable;
- public WeatherResultEvent(WeatherParcelable parcelable) {
+ public WeatherResultEvent(List<WeatherParcelable> parcelable) {
this.parcelable = parcelable;
}
- public WeatherParcelable getParcelable() {
+ public List<WeatherParcelable> getParcelable() {
return parcelable;
}
}
import com.ic.work.utils.IcLog;
import com.ic.work.weather.WeatherDBRun;
+import java.util.List;
+
public class WeatherProcess {
private static final String TAG = "WeatherProcess";
}
};
- public void sendCurrWeather(WeatherParcelable parcelable) {
+ public void sendCurrWeather(List<WeatherParcelable> parcelable) {
int N = 0;
try {
N = mCallbacks.beginBroadcast();
import com.ic.work.utils.IcLog;
import org.greenrobot.eventbus.EventBus;
+import org.threeten.bp.LocalDateTime;
+import org.threeten.bp.ZoneId;
public class LocationHelper {
- private static final String TAG ="LocationHelper";
+ private static final String TAG = "LocationHelper";
public AMapLocationClient mLocationClient;
mLocationClient = new AMapLocationClient(context);
//定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
AMapLocationListener mLocationListener = aMapLocation -> {
+ LocalDateTime time = LocalDateTime.now(ZoneId.systemDefault());
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
- IcLog.i(TAG,"Loaction City:"+aMapLocation.getCity());
- EventBus.getDefault().post(new LocationResultEvent(aMapLocation.getCity()));
+ IcLog.i(TAG, "Loaction City:" + aMapLocation.getCity());
+ LocationState state = new LocationState(time, true, aMapLocation.getCity());
+ EventBus.getDefault().post(new LocationResultEvent(state));
} else {
//定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
IcLog.e(TAG, "location Error, ErrCode:"
+ aMapLocation.getErrorCode() + ", errInfo:"
- + aMapLocation.getErrorInfo(),null);
- EventBus.getDefault().post(new LocationResultEvent(""));
+ + aMapLocation.getErrorInfo(), null);
+ EventBus.getDefault().post(new LocationResultEvent(new LocationState(time, false, null)));
}
}
};
mLocationClient.setLocationOption(getDefaultOption());
}
- public void startLocationService(){
- if(mLocationClient != null){
+ public void startLocationService() {
+ if (mLocationClient != null) {
mLocationClient.startLocation();
}
}
- public void stopLocationService(){
- if(mLocationClient != null){
+ public void stopLocationService() {
+ if (mLocationClient != null) {
mLocationClient.stopLocation();
mLocationClient.onDestroy();
--- /dev/null
+package com.ic.work.weather;
+
+
+import org.threeten.bp.LocalDateTime;
+
+public class LocationState {
+ private LocalDateTime time;
+ private boolean state;
+ private String city;
+
+ public LocationState(LocalDateTime oldTime, boolean state, String city) {
+ this.time = oldTime;
+ this.state = state;
+ this.city = city;
+ }
+
+ public LocalDateTime getTime() {
+ return time;
+ }
+
+ public void setTime(LocalDateTime oldTime) {
+ this.time = oldTime;
+ }
+
+ public boolean isState() {
+ return state;
+ }
+
+ public void setState(boolean state) {
+ this.state = state;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+}
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;
+import java.util.ArrayList;
import java.util.List;
public class WeatherDBRun implements Runnable {
@Override
public void run() {
- List<WeatherEntity> weatherList = weatherDb.queryDBWeatherDate(LocalDate.now());
+ List<WeatherEntity> weatherList = weatherDb.queryDBWeatherDate();
if(weatherList == null || weatherList.size() ==0){
//通知主线程 开始定位 并通过Socket 获取天气
EventBus.getDefault().post(new WeatherAgainEvent());
- //删除表中所有数据
- weatherDb.deleteDBWeatherDate();
}else {
- WeatherEntity entity = weatherList.get(0);
-
- WeatherParcelable parcelable = new WeatherParcelable();
- parcelable.setCity(entity.getCity());
- parcelable.setFigureDay(entity.getFigureDay());
- parcelable.setFigureNight(entity.getFigureNight());
- parcelable.setStatusDay(entity.getStatusDay());
- parcelable.setStatusNight(entity.getStatusNight());
- parcelable.setTemperatureDay(entity.getTemperatureDay());
- parcelable.setTemperatureNight(entity.getTemperatureNight());
- parcelable.setUpdateTime(entity.getUpdateTime().format(formatter));
+ List<WeatherParcelable> wpList = new ArrayList<>(weatherList.size());
+ for (int i=0; i<weatherList.size(); i++){
+ WeatherEntity entity = weatherList.get(i);
+
+ WeatherParcelable parcelable = new WeatherParcelable();
+ parcelable.setCity(entity.getCity());
+ parcelable.setFigureDay(entity.getFigureDay());
+ parcelable.setFigureNight(entity.getFigureNight());
+ parcelable.setStatusDay(entity.getStatusDay());
+ parcelable.setStatusNight(entity.getStatusNight());
+ parcelable.setTemperatureDay(entity.getTemperatureDay());
+ parcelable.setTemperatureNight(entity.getTemperatureNight());
+ parcelable.setUpdateTime(entity.getUpdateTime());
+ wpList.add(parcelable);
+ }
//通知主线程 更新UI
- EventBus.getDefault().post(new WeatherResultEvent(parcelable));
+ EventBus.getDefault().post(new WeatherResultEvent(wpList));
}
}
}
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) {
+ //如果已经定位成功
+ 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;
+ }
+ }
- public void startLocation(Context context) {
mLocation = new LocationHelper(context);
mLocation.startLocationService();
}
}
- public void queryWeatherServerInfo(WeatherInjection weatherDb,String city) {
+ public void queryWeatherServerInfo(WeatherInjection weatherDb,LocationState state) {
stopLocation();
- if(TextUtils.isEmpty(city)){
+ if(!state.isState() || TextUtils.isEmpty(state.getCity())){
+ //定位失败 或者获取到的城市为空
return;
}
+ locationState = state;
+
final String serverHost = "118.190.120.79";
final int port = 11645;
paramJson.put("channel", "西瓜皮-西瓜皮");
final String param = paramJson.toJSONString();
- SocketThread socket = new SocketThread(weatherDb,serverHost, port, param,city);
+ SocketThread socket = new SocketThread(weatherDb,serverHost, port, param,state.getCity());
ThreadPoolManager.getInstance().execute(socket);
}
}
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+
import static java.nio.charset.StandardCharsets.UTF_8;
public class SocketThread implements Runnable {
if (stringStatus.equalsIgnoreCase("ok")) {
JSONArray jsonObjectForecast = jsonObjectRoot.getJSONArray("daily_forecast");
- JSONObject fJson = jsonObjectForecast.getJSONObject(0);
-
- JSONObject jObjectCond = fJson.getJSONObject("cond");
- JSONObject jObjectTemp = fJson.getJSONObject("tmp");
-
- WeatherParcelable weather = new WeatherParcelable();
- WeatherEntity db = new WeatherEntity();
- weather.setCity(mCity);
- db.setCity(mCity);
-
- weather.setStatusDay(jObjectCond.getString("txt_d")); // 白天天气描述
- db.setStatusDay(weather.getStatusDay());
- weather.setStatusNight(jObjectCond.getString("txt_n")); // 夜间天气描述
- db.setStatusNight(weather.getStatusNight());
-
- weather.setFigureDay(jObjectCond.getString("code_d")); // 天气索引
- db.setFigureDay(weather.getFigureDay());
- weather.setFigureNight(jObjectCond.getString("code_n"));
- db.setFigureNight(weather.getFigureNight());
-
- weather.setTemperatureDay(jObjectTemp.getString("min")); // 白天温度-对应“和风天气”的最低温度
- db.setTemperatureDay(weather.getTemperatureDay());
- weather.setTemperatureNight(jObjectTemp.getString("max")); // 夜间温度-对应“和风天气”的最高温度
- db.setTemperatureNight(weather.getTemperatureNight());
-
- weather.setUpdateTime(LocalDate.now().format(formatter));
- db.setUpdateTime(LocalDate.now());
-
- if (BuildConfig.DEBUG) {
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append(weather.getStatusDay()).append("-").append(weather.getStatusNight())
- .append("|")
- .append(weather.getTemperatureDay()).append("-").append(weather.getTemperatureNight())
- .append("|")
- .append(weather.getUpdateTime());
- IcLog.i(TAG, "Response is weather:" + stringBuffer.toString());
+ int size =jsonObjectForecast.size();
+
+ if(size <=0){
+ return;
+ }
+
+ List<WeatherParcelable> wpList = new ArrayList<>(size);
+ List<WeatherEntity> dbList = new ArrayList<>(size);
+
+ for (int i=0; i< jsonObjectForecast.size(); i++){
+ JSONObject fJson = jsonObjectForecast.getJSONObject(i);
+
+ JSONObject jObjectCond = fJson.getJSONObject("cond");
+ JSONObject jObjectTemp = fJson.getJSONObject("tmp");
+
+ WeatherParcelable weather = new WeatherParcelable();
+ WeatherEntity db = new WeatherEntity();
+ weather.setCity(mCity);
+ db.setCity(mCity);
+
+ weather.setStatusDay(jObjectCond.getString("txt_d")); // 白天天气描述
+ db.setStatusDay(weather.getStatusDay());
+ weather.setStatusNight(jObjectCond.getString("txt_n")); // 夜间天气描述
+ db.setStatusNight(weather.getStatusNight());
+
+ weather.setFigureDay(jObjectCond.getString("code_d")); // 天气索引
+ db.setFigureDay(weather.getFigureDay());
+ weather.setFigureNight(jObjectCond.getString("code_n"));
+ db.setFigureNight(weather.getFigureNight());
+
+ weather.setTemperatureDay(jObjectTemp.getString("min")); // 白天温度-对应“和风天气”的最低温度
+ db.setTemperatureDay(weather.getTemperatureDay());
+ weather.setTemperatureNight(jObjectTemp.getString("max")); // 夜间温度-对应“和风天气”的最高温度
+ db.setTemperatureNight(weather.getTemperatureNight());
+
+ weather.setUpdateTime(fJson.getString("date"));
+ db.setUpdateTime(fJson.getString("date"));
+
+ if (BuildConfig.DEBUG) {
+ StringBuffer stringBuffer = new StringBuffer();
+ stringBuffer.append(weather.getStatusDay()).append("-").append(weather.getStatusNight())
+ .append("|")
+ .append(weather.getTemperatureDay()).append("-").append(weather.getTemperatureNight())
+ .append("|")
+ .append(weather.getUpdateTime());
+ IcLog.i(TAG, "Response is weather:" + stringBuffer.toString());
+ }
+
+ wpList.add(weather);
+ dbList.add(db);
}
- EventBus.getDefault().post(new WeatherResultEvent(weather));
+ EventBus.getDefault().post(new WeatherResultEvent(wpList));
//插入数据库
weatherInjection.deleteDBWeatherDate();
- weatherInjection.insertWeatherEntity(db);
+ weatherInjection.insertWeatherEntity(dbList);
}
}
}
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/start_service_bt" />
+ app:layout_constraintTop_toBottomOf="@id/start_service_bt" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
-#Tue Mar 24 18:46:07 CST 2020
-VERSION_CODE=13
+#Mon Mar 30 12:03:25 CST 2020
+VERSION_CODE=16