diff --git a/base/src/main/AndroidManifest.xml b/base/src/main/AndroidManifest.xml
index d87fb78..9766bbf 100644
--- a/base/src/main/AndroidManifest.xml
+++ b/base/src/main/AndroidManifest.xml
@@ -5,6 +5,8 @@
+
+
diff --git a/base/src/main/java/com/heyongrui/base/utils/LocationUtil.java b/base/src/main/java/com/heyongrui/base/utils/LocationUtil.java
new file mode 100644
index 0000000..3299958
--- /dev/null
+++ b/base/src/main/java/com/heyongrui/base/utils/LocationUtil.java
@@ -0,0 +1,200 @@
+package com.heyongrui.base.utils;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
+
+import java.util.List;
+
+public class LocationUtil {
+
+ // private volatile static LocationUtil uniqueInstance;
+ private LocationManager mLocationManager;
+ private LocationListener mLocationListener;
+ private Location mLocation;
+ private Context mContext;
+ private String TAG;
+
+ public LocationUtil(@NonNull Context context) {
+ TAG = this.getClass().getSimpleName();
+ mContext = context;
+ init();
+ }
+
+// //采用Double CheckLock(DCL)实现单例
+// public static LocationUtil getInstance(Context context) {
+// if (uniqueInstance == null) {
+// synchronized (LocationUtil.class) {
+// if (uniqueInstance == null) {
+// uniqueInstance = new LocationUtil(context);
+// }
+// }
+// }
+// return uniqueInstance;
+// }
+
+ //判断用户选择的定位类型
+ private void init() {
+ //获取位置管理器
+ mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
+ //获取已经启用的位置提供器
+// List enableProviderList = mLocationManager.getProviders(true);
+// if (null != enableProviderList) {
+// for (String provider : enableProviderList) {
+// if (TextUtils.equals(LocationManager.NETWORK_PROVIDER, provider)) {
+// mLocationProvider = LocationManager.NETWORK_PROVIDER;
+// } else if (TextUtils.equals(LocationManager.GPS_PROVIDER, provider)) {
+// mLocationProvider = LocationManager.GPS_PROVIDER;
+// break;
+// }
+// }
+// }
+//
+// if (null == mLocationProvider) {
+// Log.i(TAG, "没有可用的位置提供器");
+// return;
+// }
+//
+// if (TextUtils.equals(LocationManager.NETWORK_PROVIDER, mLocationProvider)) {
+// Log.i(TAG, "是网络定位");
+// } else if (TextUtils.equals(LocationManager.GPS_PROVIDER, mLocationProvider)) {
+// Log.i(TAG, "是GPS定位");
+// }
+
+// if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
+// ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+// return;
+// }
+ //获取上次的位置,一般第一次运行,此值为null
+ getLastKnownLocation();
+// Location lastKnownLocation = mLocationManager.getLastKnownLocation(mLocationProvider);
+// if (lastKnownLocation != null) {
+// setLocation(lastKnownLocation);
+// }
+// // 监视地理位置变化,第二个和第三个参数分别为更新的最短时间minTime和最短距离minDistace
+// mLocationManager.requestLocationUpdates(mLocationProvider, 0, 0, locationListener);
+ }
+
+ private void setLocation(Location location) {
+ this.mLocation = location;
+ if (null != location) {
+ Log.d(TAG, "纬度:" + location.getLatitude() + "经度:" + location.getLongitude());
+ }
+ }
+
+ public Location getLastKnownLocation() {
+ if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
+ ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ return mLocation;
+ }
+
+ List enableProviderList = mLocationManager.getProviders(true);
+ Location bestLocation = null;
+ if (null != enableProviderList) {
+ for (String provider : enableProviderList) {
+ Location l = mLocationManager.getLastKnownLocation(provider);
+ if (l == null) {
+ continue;
+ }
+ if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
+ bestLocation = l;
+ }
+ }
+ }
+ if (null != bestLocation) {
+ setLocation(bestLocation);
+ return bestLocation;
+ } else {
+ return mLocation;
+ }
+ }
+
+ public void addLocationListener() {
+ addLocationListener(null);
+ }
+
+ public void addLocationListener(LocationListener locationListener) {
+ mLocationListener = null != locationListener ? locationListener : new LocationListener() {
+ /**
+ * 当某个位置提供者的状态发生改变时
+ */
+ @Override
+ public void onStatusChanged(String provider, int status, Bundle arg2) {
+
+ }
+
+ /**
+ * 某个设备打开时
+ */
+ @Override
+ public void onProviderEnabled(String provider) {
+
+ }
+
+ /**
+ * 某个设备关闭时
+ */
+ @Override
+ public void onProviderDisabled(String provider) {
+
+ }
+
+ /**
+ * 手机位置发生变动
+ */
+ @Override
+ public void onLocationChanged(Location location) {
+ location.getAccuracy();//精确度
+ setLocation(location);
+ }
+ };
+
+ if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
+ ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ List enableProviderList = mLocationManager.getProviders(true);
+ if (null != enableProviderList) {
+ for (String provider : enableProviderList) {
+ mLocationManager.requestLocationUpdates(provider, 0, 0, locationListener);
+ }
+ }
+ }
+
+ // 移除定位监听
+ public void removeLocationUpdatesListener() {
+ if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
+ ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ if (null != mLocationManager && null != mLocationListener) {
+// uniqueInstance = null;
+ mLocationManager.removeUpdates(mLocationListener);
+ }
+ }
+
+ /**
+ * 判断GPS是否开启,GPS或者AGPS开启一个就认为是开启的
+ */
+ public static boolean isOpenGps(@NonNull Context context) {
+ if (null == context) return false;
+ LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+ // 通过GPS卫星定位,定位级别可以精确到街(通过24颗卫星定位,在室外和空旷的地方定位准确、速度快)
+ boolean gps = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
+ // 通过WLAN或移动网络(3G/2G)确定的位置(也称作AGPS,辅助GPS定位。主要用于在室内或遮盖物(建筑群或茂密的深林等)密集的地方定位)
+ boolean network = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+ Log.i("isOpenGps", "Gps: " + gps + "\tNetWork: " + network);
+ if (gps || network) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/base/src/main/res/values/strings.xml b/base/src/main/res/values/strings.xml
index 2fbb601..586dc07 100644
--- a/base/src/main/res/values/strings.xml
+++ b/base/src/main/res/values/strings.xml
@@ -15,6 +15,7 @@
取消
权限提示
此功能需要开启读写权限
+ 此功能需要开启定位权限
此功能需要开启相关权限
请开启安装权限
系统提示
diff --git a/main/src/main/assets/sunny.json b/main/src/main/assets/sunny.json
new file mode 100644
index 0000000..9060985
--- /dev/null
+++ b/main/src/main/assets/sunny.json
@@ -0,0 +1,1143 @@
+{
+ "v": "5.1.1",
+ "fr": 60,
+ "ip": 0,
+ "op": 180,
+ "w": 256,
+ "h": 256,
+ "nm": "Sunny",
+ "ddd": 0,
+ "assets": [],
+ "layers": [
+ {
+ "ddd": 0,
+ "ind": 1,
+ "ty": 4,
+ "nm": "Oval ",
+ "sr": 1,
+ "ks": {
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 11
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 10
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 127.43,
+ 127.43,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 1,
+ "k": [
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ -0.294
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_-0p294_0p333_0"
+ ],
+ "t": 0,
+ "s": [
+ 100,
+ 100,
+ 100
+ ],
+ "e": [
+ 103,
+ 103,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 1.985
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_1p985_0p333_0"
+ ],
+ "t": 35,
+ "s": [
+ 103,
+ 103,
+ 100
+ ],
+ "e": [
+ 100,
+ 100,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 15.47
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_15p47_0p333_0"
+ ],
+ "t": 80,
+ "s": [
+ 100,
+ 100,
+ 100
+ ],
+ "e": [
+ 103,
+ 103,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ -13.47
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_-13p47_0p333_0"
+ ],
+ "t": 125,
+ "s": [
+ 103,
+ 103,
+ 100
+ ],
+ "e": [
+ 100,
+ 100,
+ 100
+ ]
+ },
+ {
+ "t": 180
+ }
+ ],
+ "ix": 6
+ }
+ },
+ "ao": 0,
+ "shapes": [
+ {
+ "ty": "gr",
+ "it": [
+ {
+ "d": 1,
+ "ty": "el",
+ "s": {
+ "a": 0,
+ "k": [
+ 153.6,
+ 153.6
+ ],
+ "ix": 2
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 3
+ },
+ "nm": "Ellipse Path 1",
+ "mn": "ADBE Vector Shape - Ellipse",
+ "hd": false
+ },
+ {
+ "ty": "fl",
+ "c": {
+ "a": 0,
+ "k": [
+ 1,
+ 0.788235008717,
+ 0.188234999776,
+ 1
+ ],
+ "ix": 4
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 5
+ },
+ "r": 1,
+ "nm": "Fill 1",
+ "mn": "ADBE Vector Graphic - Fill",
+ "hd": false
+ },
+ {
+ "ty": "tr",
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 0,
+ "k": [
+ 100,
+ 100
+ ],
+ "ix": 3
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 6
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 7
+ },
+ "sk": {
+ "a": 0,
+ "k": 0,
+ "ix": 4
+ },
+ "sa": {
+ "a": 0,
+ "k": 0,
+ "ix": 5
+ },
+ "nm": "Transform"
+ }
+ ],
+ "nm": "Oval ",
+ "np": 2,
+ "cix": 2,
+ "ix": 1,
+ "mn": "ADBE Vector Group",
+ "hd": false
+ }
+ ],
+ "ip": 0,
+ "op": 180,
+ "st": 0,
+ "bm": 0
+ },
+ {
+ "ddd": 0,
+ "ind": 2,
+ "ty": 4,
+ "nm": "Oval",
+ "sr": 1,
+ "ks": {
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 11
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 10
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 127.435,
+ 127.435,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 1,
+ "k": [
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 0.833
+ ]
+ },
+ "o": {
+ "x": [
+ 0.167,
+ 0.167,
+ 0.167
+ ],
+ "y": [
+ 0.167,
+ 0.167,
+ 0.167
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p167_0p167",
+ "0p833_0p833_0p167_0p167",
+ "0p833_0p833_0p167_0p167"
+ ],
+ "t": 0,
+ "s": [
+ 98,
+ 98,
+ 100
+ ],
+ "e": [
+ 101,
+ 101,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 2.005
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_2p005_0p333_0"
+ ],
+ "t": 40,
+ "s": [
+ 101,
+ 101,
+ 100
+ ],
+ "e": [
+ 98,
+ 98,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ -0.005
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_-0p005_0p333_0"
+ ],
+ "t": 85,
+ "s": [
+ 98,
+ 98,
+ 100
+ ],
+ "e": [
+ 101,
+ 101,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 1,
+ 1,
+ 1
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_1_0p333_0",
+ "0p833_1_0p333_0",
+ "0p833_1_0p333_0"
+ ],
+ "t": 130,
+ "s": [
+ 101,
+ 101,
+ 100
+ ],
+ "e": [
+ 98,
+ 98,
+ 100
+ ]
+ },
+ {
+ "t": 180
+ }
+ ],
+ "ix": 6
+ }
+ },
+ "ao": 0,
+ "shapes": [
+ {
+ "ty": "gr",
+ "it": [
+ {
+ "d": 1,
+ "ty": "el",
+ "s": {
+ "a": 0,
+ "k": [
+ 180.91,
+ 180.91
+ ],
+ "ix": 2
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 3
+ },
+ "nm": "Ellipse Path 1",
+ "mn": "ADBE Vector Shape - Ellipse",
+ "hd": false
+ },
+ {
+ "ty": "st",
+ "c": {
+ "a": 0,
+ "k": [
+ 1,
+ 0.860368013382,
+ 0.464744985104,
+ 1
+ ],
+ "ix": 3
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 4
+ },
+ "w": {
+ "a": 0,
+ "k": 8.533,
+ "ix": 5
+ },
+ "lc": 1,
+ "lj": 1,
+ "ml": 4,
+ "nm": "Stroke 1",
+ "mn": "ADBE Vector Graphic - Stroke",
+ "hd": false
+ },
+ {
+ "ty": "tr",
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 0,
+ "k": [
+ 100,
+ 100
+ ],
+ "ix": 3
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 6
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 7
+ },
+ "sk": {
+ "a": 0,
+ "k": 0,
+ "ix": 4
+ },
+ "sa": {
+ "a": 0,
+ "k": 0,
+ "ix": 5
+ },
+ "nm": "Transform"
+ }
+ ],
+ "nm": "Oval",
+ "np": 2,
+ "cix": 2,
+ "ix": 1,
+ "mn": "ADBE Vector Group",
+ "hd": false
+ }
+ ],
+ "ip": 0,
+ "op": 180,
+ "st": 0,
+ "bm": 0
+ },
+ {
+ "ddd": 0,
+ "ind": 3,
+ "ty": 4,
+ "nm": "Oval",
+ "sr": 1,
+ "ks": {
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 11
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 10
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 128,
+ 128,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 1,
+ "k": [
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 0.015
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_0p015_0p333_0"
+ ],
+ "t": 0,
+ "s": [
+ 100,
+ 100,
+ 100
+ ],
+ "e": [
+ 103,
+ 103,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 1.985
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_1p985_0p333_0"
+ ],
+ "t": 45,
+ "s": [
+ 103,
+ 103,
+ 100
+ ],
+ "e": [
+ 100,
+ 100,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 0.015
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_0p015_0p333_0"
+ ],
+ "t": 90,
+ "s": [
+ 100,
+ 100,
+ 100
+ ],
+ "e": [
+ 103,
+ 103,
+ 100
+ ]
+ },
+ {
+ "i": {
+ "x": [
+ 0.833,
+ 0.833,
+ 0.833
+ ],
+ "y": [
+ 0.833,
+ 0.833,
+ 1.985
+ ]
+ },
+ "o": {
+ "x": [
+ 0.333,
+ 0.333,
+ 0.333
+ ],
+ "y": [
+ 0,
+ 0,
+ 0
+ ]
+ },
+ "n": [
+ "0p833_0p833_0p333_0",
+ "0p833_0p833_0p333_0",
+ "0p833_1p985_0p333_0"
+ ],
+ "t": 135,
+ "s": [
+ 103,
+ 103,
+ 100
+ ],
+ "e": [
+ 100,
+ 100,
+ 100
+ ]
+ },
+ {
+ "t": 180
+ }
+ ],
+ "ix": 6
+ }
+ },
+ "ao": 0,
+ "shapes": [
+ {
+ "ty": "gr",
+ "it": [
+ {
+ "d": 1,
+ "ty": "el",
+ "s": {
+ "a": 0,
+ "k": [
+ 204.8,
+ 204.8
+ ],
+ "ix": 2
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 3
+ },
+ "nm": "Ellipse Path 1",
+ "mn": "ADBE Vector Shape - Ellipse",
+ "hd": false
+ },
+ {
+ "ty": "st",
+ "c": {
+ "a": 0,
+ "k": [
+ 1,
+ 0.961977005005,
+ 0.856356978416,
+ 1
+ ],
+ "ix": 3
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 4
+ },
+ "w": {
+ "a": 0,
+ "k": 4.571,
+ "ix": 5
+ },
+ "lc": 1,
+ "lj": 1,
+ "ml": 4,
+ "nm": "Stroke 1",
+ "mn": "ADBE Vector Graphic - Stroke",
+ "hd": false
+ },
+ {
+ "ty": "tr",
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 0,
+ "k": [
+ 100,
+ 100
+ ],
+ "ix": 3
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 6
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 7
+ },
+ "sk": {
+ "a": 0,
+ "k": 0,
+ "ix": 4
+ },
+ "sa": {
+ "a": 0,
+ "k": 0,
+ "ix": 5
+ },
+ "nm": "Transform"
+ }
+ ],
+ "nm": "Oval",
+ "np": 2,
+ "cix": 2,
+ "ix": 1,
+ "mn": "ADBE Vector Group",
+ "hd": false
+ }
+ ],
+ "ip": 0,
+ "op": 180,
+ "st": 0,
+ "bm": 0
+ },
+ {
+ "ddd": 0,
+ "ind": 4,
+ "ty": 4,
+ "nm": "bond",
+ "sr": 1,
+ "ks": {
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 11
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 10
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 128,
+ 128,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 0,
+ "k": [
+ 100,
+ 100,
+ 100
+ ],
+ "ix": 6
+ }
+ },
+ "ao": 0,
+ "shapes": [
+ {
+ "ty": "gr",
+ "it": [
+ {
+ "ty": "rc",
+ "d": 1,
+ "s": {
+ "a": 0,
+ "k": [
+ 256,
+ 256
+ ],
+ "ix": 2
+ },
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 3
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 4
+ },
+ "nm": "Rectangle Path 1",
+ "mn": "ADBE Vector Shape - Rect",
+ "hd": false
+ },
+ {
+ "ty": "tr",
+ "p": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 2
+ },
+ "a": {
+ "a": 0,
+ "k": [
+ 0,
+ 0
+ ],
+ "ix": 1
+ },
+ "s": {
+ "a": 0,
+ "k": [
+ 100,
+ 100
+ ],
+ "ix": 3
+ },
+ "r": {
+ "a": 0,
+ "k": 0,
+ "ix": 6
+ },
+ "o": {
+ "a": 0,
+ "k": 100,
+ "ix": 7
+ },
+ "sk": {
+ "a": 0,
+ "k": 0,
+ "ix": 4
+ },
+ "sa": {
+ "a": 0,
+ "k": 0,
+ "ix": 5
+ },
+ "nm": "Transform"
+ }
+ ],
+ "nm": "bond",
+ "np": 1,
+ "cix": 2,
+ "ix": 1,
+ "mn": "ADBE Vector Group",
+ "hd": false
+ }
+ ],
+ "ip": 0,
+ "op": 180,
+ "st": 0,
+ "bm": 0
+ }
+ ],
+ "markers": []
+}
\ No newline at end of file
diff --git a/main/src/main/java/com/heyongrui/main/adapter/HomeSectionAdapter.java b/main/src/main/java/com/heyongrui/main/adapter/HomeSectionAdapter.java
index c57d9b6..7c060d2 100644
--- a/main/src/main/java/com/heyongrui/main/adapter/HomeSectionAdapter.java
+++ b/main/src/main/java/com/heyongrui/main/adapter/HomeSectionAdapter.java
@@ -4,8 +4,10 @@
import com.chad.library.adapter.base.BaseSectionMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
+import com.heyongrui.base.utils.TimeUtil;
import com.heyongrui.main.R;
import com.heyongrui.main.data.dto.FlightDto;
+import com.heyongrui.main.data.dto.WeatherDto;
import java.util.List;
@@ -23,6 +25,7 @@ public HomeSectionAdapter(List data) {
public HomeSectionAdapter(int sectionHeadResId, List data) {
super(sectionHeadResId, data);
addItemType(HomeSectionEntity.FLIGHT, R.layout.recycle_item_flight);
+ addItemType(HomeSectionEntity.WEATHER, R.layout.recycle_item_weather);
}
@Override
@@ -84,6 +87,27 @@ protected void convert(BaseViewHolder helper, HomeSectionEntity item) {
helper.setText(R.id.tv_flight_cycle, TextUtils.isEmpty(flightCycle) ? "" : flightCycle);
}
break;
+ case HomeSectionEntity.WEATHER: {
+ WeatherDto.FutureBean futureBean = item.getFutureBean();
+ String temperature = "";
+ StringBuilder date = new StringBuilder();
+ StringBuilder weather = new StringBuilder();
+ if (null != futureBean) {
+ date.append(TimeUtil.getDateString(futureBean.getDate(), "yyyy-MM-dd", "MM/dd"));
+ date.append("\t");
+ date.append(futureBean.getWeek());
+
+ weather.append(futureBean.getDayTime());
+// weather.append("\t");
+// weather.append(futureBean.getWind());
+
+ temperature = futureBean.getTemperature();
+ }
+ helper.setText(R.id.tv_date, TextUtils.isEmpty(date) ? "" : date);
+ helper.setText(R.id.tv_weather, TextUtils.isEmpty(weather) ? "" : weather);
+ helper.setText(R.id.tv_temperature, TextUtils.isEmpty(temperature) ? "" : temperature);
+ }
+ break;
}
}
}
diff --git a/main/src/main/java/com/heyongrui/main/adapter/HomeSectionEntity.java b/main/src/main/java/com/heyongrui/main/adapter/HomeSectionEntity.java
index 06beb91..7277c4e 100644
--- a/main/src/main/java/com/heyongrui/main/adapter/HomeSectionEntity.java
+++ b/main/src/main/java/com/heyongrui/main/adapter/HomeSectionEntity.java
@@ -3,6 +3,7 @@
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.entity.SectionMultiEntity;
import com.heyongrui.main.data.dto.FlightDto;
+import com.heyongrui.main.data.dto.WeatherDto;
import java.util.List;
@@ -13,12 +14,14 @@
public class HomeSectionEntity extends SectionMultiEntity implements MultiItemEntity {
public static final int FLIGHT = 100;
+ public static final int WEATHER = 101;
private int itemType;
private int spanSize;
private Object object;
private FlightDto flightDto;
+ private WeatherDto.FutureBean futureBean;
public HomeSectionEntity(boolean isHeader, String header, boolean isShow) {
super(isHeader, header);
@@ -41,6 +44,8 @@ public HomeSectionEntity(int itemType, int spanSize, Object object) {
// }
} else if (object instanceof FlightDto) {
this.flightDto = (FlightDto) object;
+ } else if (object instanceof WeatherDto.FutureBean) {
+ this.futureBean = (WeatherDto.FutureBean) object;
}
}
}
@@ -77,4 +82,12 @@ public FlightDto getFlightDto() {
public void setFlightDto(FlightDto flightDto) {
this.flightDto = flightDto;
}
+
+ public WeatherDto.FutureBean getFutureBean() {
+ return futureBean;
+ }
+
+ public void setFutureBean(WeatherDto.FutureBean futureBean) {
+ this.futureBean = futureBean;
+ }
}
diff --git a/main/src/main/java/com/heyongrui/main/dagger/HomeComponent.java b/main/src/main/java/com/heyongrui/main/dagger/HomeComponent.java
index 07f40c2..36a69ad 100644
--- a/main/src/main/java/com/heyongrui/main/dagger/HomeComponent.java
+++ b/main/src/main/java/com/heyongrui/main/dagger/HomeComponent.java
@@ -7,6 +7,7 @@
import com.heyongrui.base.dagger.AppComponent;
import com.heyongrui.base.dagger.PerActivity;
import com.heyongrui.main.mob.presenter.MobPresenter;
+import com.heyongrui.main.mob.presenter.MobWeatherPresenter;
import dagger.Component;
@@ -24,4 +25,6 @@ public interface HomeComponent {
Fragment getFragment();
void inject(MobPresenter mobPresenter);
+
+ void inject(MobWeatherPresenter mobWeatherPresenter);
}
diff --git a/main/src/main/java/com/heyongrui/main/dagger/HomeModule.java b/main/src/main/java/com/heyongrui/main/dagger/HomeModule.java
index e5ad892..629dd6e 100644
--- a/main/src/main/java/com/heyongrui/main/dagger/HomeModule.java
+++ b/main/src/main/java/com/heyongrui/main/dagger/HomeModule.java
@@ -6,6 +6,7 @@
import androidx.fragment.app.Fragment;
+import com.heyongrui.base.assist.RxManager;
import com.heyongrui.base.dagger.PerActivity;
import com.heyongrui.main.data.service.MobService;
@@ -59,4 +60,9 @@ Context providesContext() {
MobService provideMobService() {
return new MobService();
}
+
+ @Provides
+ RxManager provideRxManager() {
+ return new RxManager();
+ }
}
diff --git a/main/src/main/java/com/heyongrui/main/data/api/MobApi.java b/main/src/main/java/com/heyongrui/main/data/api/MobApi.java
index aff503c..377c88a 100644
--- a/main/src/main/java/com/heyongrui/main/data/api/MobApi.java
+++ b/main/src/main/java/com/heyongrui/main/data/api/MobApi.java
@@ -2,6 +2,7 @@
import com.heyongrui.main.data.dto.DictionaryDto;
import com.heyongrui.main.data.dto.FlightDto;
+import com.heyongrui.main.data.dto.GeocoderDto;
import com.heyongrui.main.data.dto.IDCardDto;
import com.heyongrui.main.data.dto.IdiomDto;
import com.heyongrui.main.data.dto.MobResponse;
@@ -66,11 +67,27 @@ Observable>> flightNoQuery(@Query("key") String key,
@Query("name") String flightNo);
/**
- * 根据ip地址查询天气
+ * 查询天气(根据ip地址)
*/
@GET("v1/weather/ip")
Observable>> weatherQueryByIp(@Query("key") String key,
@Query("duid") String duid,
@Query("ip") String ip);
+ /**
+ * 查询天气(根据城市名称)
+ */
+ @GET("v1/weather/query")
+ Observable>> weatherQueryByCity(@Query("key") String key,
+ @Query("duid") String duid,
+ @Query("city") String city);
+
+ /**
+ * 根据经纬度获取地址信息
+ */
+ @GET("geocoder")
+ Observable getAddressByLocation(@Query("output") String output,
+ @Query("location") String location,
+ @Query("ak") String ak);
+
}
diff --git a/main/src/main/java/com/heyongrui/main/data/dto/GeocoderDto.java b/main/src/main/java/com/heyongrui/main/data/dto/GeocoderDto.java
new file mode 100644
index 0000000..5db88f5
--- /dev/null
+++ b/main/src/main/java/com/heyongrui/main/data/dto/GeocoderDto.java
@@ -0,0 +1,185 @@
+package com.heyongrui.main.data.dto;
+
+public class GeocoderDto {
+ /**
+ * status : OK
+ * result : {"location":{"lng":116.379763,"lat":34.813542},"formatted_address":"山东省菏泽市单县","business":"","addressComponent":{"city":"菏泽市","direction":"","distance":"","district":"单县","province":"山东省","street":"","street_number":""},"cityCode":353}
+ */
+
+ private String status;
+ private ResultBean result;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public ResultBean getResult() {
+ return result;
+ }
+
+ public void setResult(ResultBean result) {
+ this.result = result;
+ }
+
+ public static class ResultBean {
+ /**
+ * location : {"lng":116.379763,"lat":34.813542}
+ * formatted_address : 山东省菏泽市单县
+ * business :
+ * addressComponent : {"city":"菏泽市","direction":"","distance":"","district":"单县","province":"山东省","street":"","street_number":""}
+ * cityCode : 353
+ */
+
+ private LocationBean location;
+ private String formatted_address;
+ private String business;
+ private AddressComponentBean addressComponent;
+ private int cityCode;
+
+ public LocationBean getLocation() {
+ return location;
+ }
+
+ public void setLocation(LocationBean location) {
+ this.location = location;
+ }
+
+ public String getFormatted_address() {
+ return formatted_address;
+ }
+
+ public void setFormatted_address(String formatted_address) {
+ this.formatted_address = formatted_address;
+ }
+
+ public String getBusiness() {
+ return business;
+ }
+
+ public void setBusiness(String business) {
+ this.business = business;
+ }
+
+ public AddressComponentBean getAddressComponent() {
+ return addressComponent;
+ }
+
+ public void setAddressComponent(AddressComponentBean addressComponent) {
+ this.addressComponent = addressComponent;
+ }
+
+ public int getCityCode() {
+ return cityCode;
+ }
+
+ public void setCityCode(int cityCode) {
+ this.cityCode = cityCode;
+ }
+
+ public static class LocationBean {
+ /**
+ * lng : 116.379763
+ * lat : 34.813542
+ */
+
+ private double lng;
+ private double lat;
+
+ public double getLng() {
+ return lng;
+ }
+
+ public void setLng(double lng) {
+ this.lng = lng;
+ }
+
+ public double getLat() {
+ return lat;
+ }
+
+ public void setLat(double lat) {
+ this.lat = lat;
+ }
+ }
+
+ public static class AddressComponentBean {
+ /**
+ * city : 菏泽市
+ * direction :
+ * distance :
+ * district : 单县
+ * province : 山东省
+ * street :
+ * street_number :
+ */
+
+ private String city;
+ private String direction;
+ private String distance;
+ private String district;
+ private String province;
+ private String street;
+ private String street_number;
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getDirection() {
+ return direction;
+ }
+
+ public void setDirection(String direction) {
+ this.direction = direction;
+ }
+
+ public String getDistance() {
+ return distance;
+ }
+
+ public void setDistance(String distance) {
+ this.distance = distance;
+ }
+
+ public String getDistrict() {
+ return district;
+ }
+
+ public void setDistrict(String district) {
+ this.district = district;
+ }
+
+ public String getProvince() {
+ return province;
+ }
+
+ public void setProvince(String province) {
+ this.province = province;
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getStreet_number() {
+ return street_number;
+ }
+
+ public void setStreet_number(String street_number) {
+ this.street_number = street_number;
+ }
+ }
+ }
+}
diff --git a/main/src/main/java/com/heyongrui/main/data/service/MobService.java b/main/src/main/java/com/heyongrui/main/data/service/MobService.java
index c20f688..8651e0c 100644
--- a/main/src/main/java/com/heyongrui/main/data/service/MobService.java
+++ b/main/src/main/java/com/heyongrui/main/data/service/MobService.java
@@ -5,6 +5,7 @@
import com.heyongrui.main.data.api.MobApi;
import com.heyongrui.main.data.dto.DictionaryDto;
import com.heyongrui.main.data.dto.FlightDto;
+import com.heyongrui.main.data.dto.GeocoderDto;
import com.heyongrui.main.data.dto.IDCardDto;
import com.heyongrui.main.data.dto.IdiomDto;
import com.heyongrui.main.data.dto.MobResponse;
@@ -90,4 +91,22 @@ public Observable>> weatherQueryByIp(String ip) {
.compose(RxHelper.rxSchedulerHelper());
}
+ /**
+ * 根据城市名称查询天气
+ */
+ public Observable>> weatherQueryByCity(String city) {
+ return ApiService.createApi(MobApi.class, "http://apicloud.mob.com/")
+ .weatherQueryByCity("moba6b6c6d6", "43275ff45b034bffaf6b9941a216fe6dbae31dc9", city)
+ .compose(RxHelper.rxSchedulerHelper());
+ }
+
+ /**
+ * 根据经纬度获取地址信息
+ */
+ public Observable getAddressByLocation(double lat, double lon) {
+ return ApiService.createApi(MobApi.class, "http://api.map.baidu.com/")
+ .getAddressByLocation("json", lat + "," + lon, "esNPFDwwsXWtsQfw4NMNmur1")
+ .compose(RxHelper.rxSchedulerHelper());
+ }
+
}
diff --git a/main/src/main/java/com/heyongrui/main/mob/view/BezierEvaluator.java b/main/src/main/java/com/heyongrui/main/mob/BezierEvaluator.java
similarity index 98%
rename from main/src/main/java/com/heyongrui/main/mob/view/BezierEvaluator.java
rename to main/src/main/java/com/heyongrui/main/mob/BezierEvaluator.java
index cad9b07..d70c54b 100644
--- a/main/src/main/java/com/heyongrui/main/mob/view/BezierEvaluator.java
+++ b/main/src/main/java/com/heyongrui/main/mob/BezierEvaluator.java
@@ -1,4 +1,4 @@
-package com.heyongrui.main.mob.view;
+package com.heyongrui.main.mob;
import android.animation.TypeEvaluator;
import android.graphics.PointF;
diff --git a/main/src/main/java/com/heyongrui/main/mob/contract/MobWeatherContract.java b/main/src/main/java/com/heyongrui/main/mob/contract/MobWeatherContract.java
new file mode 100644
index 0000000..3c2dee8
--- /dev/null
+++ b/main/src/main/java/com/heyongrui/main/mob/contract/MobWeatherContract.java
@@ -0,0 +1,28 @@
+package com.heyongrui.main.mob.contract;
+
+import androidx.annotation.FloatRange;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.heyongrui.base.base.BasePresenter;
+import com.heyongrui.base.base.BaseView;
+import com.heyongrui.main.adapter.HomeSectionAdapter;
+import com.heyongrui.main.data.dto.WeatherDto;
+
+import java.util.List;
+
+public interface MobWeatherContract {
+ interface View extends BaseView {
+ void weatherQuerySuccess(List weatherDtoList);
+
+ void playSunAnim(@FloatRange(from = 0.0, to = 1.0) float persent);
+ }
+
+ abstract class Presenter extends BasePresenter {
+ public abstract HomeSectionAdapter initRecyclerView(RecyclerView recyclerView, BaseQuickAdapter.OnItemClickListener listener);
+
+ public abstract void weatherQuery(String cityName);
+
+ public abstract void getAddressByLocation(double lat, double lon);
+ }
+}
diff --git a/main/src/main/java/com/heyongrui/main/mob/presenter/MobWeatherPresenter.java b/main/src/main/java/com/heyongrui/main/mob/presenter/MobWeatherPresenter.java
new file mode 100644
index 0000000..22a142f
--- /dev/null
+++ b/main/src/main/java/com/heyongrui/main/mob/presenter/MobWeatherPresenter.java
@@ -0,0 +1,143 @@
+package com.heyongrui.main.mob.presenter;
+
+import android.graphics.Color;
+import android.graphics.drawable.GradientDrawable;
+import android.text.TextUtils;
+
+import androidx.core.view.ViewCompat;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.blankj.utilcode.util.ConvertUtils;
+import com.blankj.utilcode.util.ToastUtils;
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.heyongrui.base.app.BaseApplication;
+import com.heyongrui.base.assist.RxManager;
+import com.heyongrui.base.utils.DrawableUtil;
+import com.heyongrui.base.widget.itemdecoration.RecycleViewItemDecoration;
+import com.heyongrui.main.adapter.HomeSectionAdapter;
+import com.heyongrui.main.adapter.HomeSectionEntity;
+import com.heyongrui.main.dagger.DaggerHomeComponent;
+import com.heyongrui.main.dagger.HomeModule;
+import com.heyongrui.main.data.dto.GeocoderDto;
+import com.heyongrui.main.data.dto.MobResponse;
+import com.heyongrui.main.data.dto.WeatherDto;
+import com.heyongrui.main.data.service.MobService;
+import com.heyongrui.main.mob.contract.MobWeatherContract;
+import com.heyongrui.network.configure.ResponseDisposable;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+import javax.inject.Inject;
+
+public class MobWeatherPresenter extends MobWeatherContract.Presenter {
+
+ @Inject
+ RxManager mRxManager;
+ @Inject
+ MobService mMobService;
+
+ public MobWeatherPresenter() {
+ DaggerHomeComponent
+ .builder()
+ .appComponent(BaseApplication.getAppComponent())
+ .homeModule(new HomeModule())
+ .build()
+ .inject(this);
+ }
+
+ @Override
+ public HomeSectionAdapter initRecyclerView(RecyclerView recyclerView, BaseQuickAdapter.OnItemClickListener listener) {
+ GradientDrawable gradientDrawable = new DrawableUtil.DrawableBuilder(mContext)
+ .setColor(Color.parseColor("#4F747474")).setGradientRoundRadius(20)
+ .createGradientDrawable();
+ ViewCompat.setBackground(recyclerView, gradientDrawable);
+ List data = new ArrayList<>();
+ HomeSectionAdapter moduleSectionAdapter = new HomeSectionAdapter(data);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ moduleSectionAdapter.bindToRecyclerView(recyclerView);
+ int dp1 = ConvertUtils.dp2px(0.5f);
+ recyclerView.addItemDecoration(new RecycleViewItemDecoration(mContext, dp1, Color.WHITE));
+// moduleSectionAdapter.setSpanSizeLookup((gridLayoutManager, position) -> data.get(position).getSpanSize());
+ if (null != listener) {
+ moduleSectionAdapter.setOnItemClickListener(listener);
+ }
+ return moduleSectionAdapter;
+ }
+
+ @Override
+ public void weatherQuery(String cityName) {
+ mRxManager.add(mMobService.weatherQueryByCity(cityName)
+ .subscribeWith(new ResponseDisposable>>(mContext, false) {
+ @Override
+ protected void onSuccess(MobResponse> listMobResponse) {
+ if (null != listMobResponse) {
+ if (200 == listMobResponse.getRetCode()) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(Calendar.HOUR_OF_DAY, 6);
+ calendar.set(Calendar.MINUTE, 0);
+ calendar.set(Calendar.SECOND, 0);
+ calendar.set(Calendar.MILLISECOND, 0);
+
+ long start = calendar.getTimeInMillis();
+
+ calendar.set(Calendar.HOUR_OF_DAY, 18);
+ long end = calendar.getTimeInMillis();
+
+ long current = Calendar.getInstance().getTimeInMillis();
+
+ float molecule = current - start;
+ molecule = molecule <= 0 ? 0 : molecule;
+ float persent = (float) (molecule) / (end - start);
+ persent = persent >= 1 ? 1 : persent;
+ if (null != mView) {
+ mView.playSunAnim(persent);
+ mView.weatherQuerySuccess(listMobResponse.getResult());
+ }
+ } else {
+ ToastUtils.showShort(listMobResponse.getMsg());
+ }
+ }
+ }
+
+ @Override
+ protected void onFailure(int errorCode, String errorMsg) {
+ ToastUtils.showShort(errorMsg);
+ }
+ }));
+ }
+
+ @Override
+ public void getAddressByLocation(double lat, double lon) {
+ mRxManager.add(mMobService.getAddressByLocation(lat, lon)
+ .subscribeWith(new ResponseDisposable(mContext, false) {
+ @Override
+ protected void onSuccess(GeocoderDto geocoderDto) {
+ if (null != geocoderDto) {
+ GeocoderDto.ResultBean result = geocoderDto.getResult();
+ if (null != result) {
+ GeocoderDto.ResultBean.AddressComponentBean addressComponent = result.getAddressComponent();
+ if (null != addressComponent) {
+ String city = addressComponent.getCity();
+ if (!TextUtils.isEmpty(city)) {
+ try {
+ city = city.replace("市", "");
+ weatherQuery(city);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onFailure(int errorCode, String errorMsg) {
+ ToastUtils.showShort(errorMsg);
+ }
+ }));
+ }
+}
diff --git a/main/src/main/java/com/heyongrui/main/mob/view/MobWeatherActivity.java b/main/src/main/java/com/heyongrui/main/mob/view/MobWeatherActivity.java
index 28ae78f..99e3f9c 100644
--- a/main/src/main/java/com/heyongrui/main/mob/view/MobWeatherActivity.java
+++ b/main/src/main/java/com/heyongrui/main/mob/view/MobWeatherActivity.java
@@ -3,32 +3,96 @@
import android.animation.ValueAnimator;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
+import android.location.Location;
+import android.location.LocationListener;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
+import android.widget.TextView;
+import androidx.annotation.FloatRange;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
+import androidx.recyclerview.widget.RecyclerView;
+import com.airbnb.lottie.LottieAnimationView;
import com.alibaba.android.arouter.facade.annotation.Route;
+import com.blankj.utilcode.constant.PermissionConstants;
+import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ScreenUtils;
+import com.chad.library.adapter.base.BaseQuickAdapter;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.heyongrui.base.assist.ConfigConstants;
import com.heyongrui.base.base.BaseActivity;
+import com.heyongrui.base.utils.DialogUtil;
import com.heyongrui.base.utils.DrawableUtil;
+import com.heyongrui.base.utils.LocationUtil;
+import com.heyongrui.base.utils.TimeUtil;
+import com.heyongrui.base.widget.numberruntextview.NumberRunningTextView;
import com.heyongrui.main.R;
+import com.heyongrui.main.adapter.HomeSectionAdapter;
+import com.heyongrui.main.adapter.HomeSectionEntity;
+import com.heyongrui.main.data.dto.WeatherDto;
+import com.heyongrui.main.mob.BezierEvaluator;
+import com.heyongrui.main.mob.contract.MobWeatherContract;
+import com.heyongrui.main.mob.presenter.MobWeatherPresenter;
+
+import java.util.ArrayList;
+import java.util.List;
@Route(path = ConfigConstants.PATH_WEATHER)
-public class MobWeatherActivity extends BaseActivity implements View.OnClickListener {
+public class MobWeatherActivity extends BaseActivity implements
+ MobWeatherContract.View, View.OnClickListener, BaseQuickAdapter.OnItemClickListener {
private ImageView ivSun;
private ImageView ivMask;
+ private HomeSectionAdapter mWeatherAdapter;
+
+ private LocationUtil mLocationUtil;
+ private Location mLocation;
+ private LocationListener mLocationListener = new LocationListener() {
+ @Override
+ public void onLocationChanged(Location location) {
+ if (null == mLocation) {
+ if (null != location) {
+ mLocation = location;
+ if (null != mPresenter) {
+ mPresenter.getAddressByLocation(location.getLatitude(), location.getLongitude());
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+
+ }
+
+ @Override
+ public void onProviderEnabled(String provider) {
+
+ }
+
+ @Override
+ public void onProviderDisabled(String provider) {
+
+ }
+ };
+ private LottieAnimationView lottieView;
+ private NumberRunningTextView numberRunTv;
+ private TextView tvWeather;
+
@Override
protected void initImmersionBar() {
- ImmersionBar.with(this).fullScreen(true).hideBar(BarHide.FLAG_SHOW_BAR).init();
+ ImmersionBar.with(this).fullScreen(true).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init();
+ }
+
+ @Override
+ protected MobWeatherContract.Presenter setPresenter() {
+ return new MobWeatherPresenter();
}
@Override
@@ -50,7 +114,13 @@ protected void init(Bundle savedInstanceState) {
ImageView ivBack = findViewById(R.id.iv_back);
ivSun = findViewById(R.id.iv_sun);
ivMask = findViewById(R.id.iv_mask);
+ lottieView = findViewById(R.id.lottie_view);
+ numberRunTv = findViewById(R.id.number_run_tv);
+ tvWeather = findViewById(R.id.tv_weather);
+ RecyclerView rlvWeather = findViewById(R.id.rlv_weather);
+
ivMask.getBackground().mutate().setAlpha(0);
+ mWeatherAdapter = mPresenter.initRecyclerView(rlvWeather, this);
int statusBarHeight = ImmersionBar.getStatusBarHeight(this);
ViewGroup.LayoutParams layoutParams = ivBack.getLayoutParams();
@@ -68,15 +138,62 @@ protected void init(Bundle savedInstanceState) {
addOnClickListeners(this, ivBack);
}
- private void playSunAnim(float stopPercent) {
+ @Override
+ public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
+
+ }
+
+ @Override
+ public void weatherQuerySuccess(List weatherDtoList) {
+ if (null != weatherDtoList) {
+ WeatherDto weatherDto = weatherDtoList.get(0);
+ String temperature = weatherDto.getTemperature();
+ temperature = temperature.replace("℃", "");
+ numberRunTv.setContent(temperature);
+
+ StringBuilder weatherBuilder = new StringBuilder();
+ String weather = weatherDto.getWeather();
+ String week = weatherDto.getWeek();
+ String wind = weatherDto.getWind();
+ String date = weatherDto.getDate();
+ date = TimeUtil.getDateString(date, "yyyy-MM-dd", "yyyy/MM/dd");
+ weatherBuilder.append(date);
+ weatherBuilder.append("\t");
+ weatherBuilder.append(week);
+ weatherBuilder.append("\n");
+ weatherBuilder.append(weather);
+ weatherBuilder.append("\t");
+ weatherBuilder.append(wind);
+ tvWeather.setText(weatherBuilder);
+
+ lottieView.setAnimation("sunny.json");
+ lottieView.setRepeatCount(ValueAnimator.INFINITE);
+ lottieView.playAnimation();
+
+ List dataList = new ArrayList<>();
+ List futureBeanList = weatherDto.getFuture();
+ if (null != futureBeanList) {
+ for (WeatherDto.FutureBean futureBean : futureBeanList) {
+ dataList.add(new HomeSectionEntity(HomeSectionEntity.WEATHER, futureBean));
+ }
+ }
+ mWeatherAdapter.replaceData(dataList);
+ }
+ }
+
+ @Override
+ public void playSunAnim(@FloatRange(from = 0.0, to = 1.0) float stopPercent) {
+ int screenWidth = ScreenUtils.getScreenWidth();
+ int screenHeight = ScreenUtils.getScreenHeight();
+
float startX = 0;
- float startY = ivSun.getY();
+ float startY = screenHeight / 4;
- float endX = ScreenUtils.getScreenWidth();
+ float endX = screenWidth;
float endY = startY;
- float controlY = 0;
- float controlX = ScreenUtils.getScreenWidth() / 2;
+ float controlY = -200;
+ float controlX = screenWidth / 2;
//贝塞尔二阶曲线控制点
PointF controlP = new PointF(controlX, controlY);
//构造贝塞尔估值器
@@ -87,9 +204,6 @@ private void playSunAnim(float stopPercent) {
animator.addUpdateListener(valueAnimator -> {
PointF pointF = (PointF) valueAnimator.getAnimatedValue();
//设置目标位置
- if (ivSun.getVisibility() != View.VISIBLE) {
- ivSun.setVisibility(View.VISIBLE);
- }
ivSun.setX(pointF.x);
ivSun.setY(pointF.y);
//设置透明度
@@ -131,5 +245,33 @@ private void playSunAnim(float stopPercent) {
animator.setTarget(ivSun);
animator.setDuration(4000);
animator.start();
+ ivSun.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ PermissionUtils.permission(PermissionConstants.LOCATION)
+ .rationale(shouldRequest -> shouldRequest.again(true))
+ .callback(new PermissionUtils.FullCallback() {
+ @Override
+ public void onGranted(List permissionsGranted) {
+ mLocationUtil = null != mLocationUtil ? mLocationUtil : new LocationUtil(MobWeatherActivity.this);
+ mLocationUtil.addLocationListener(mLocationListener);
+ }
+
+ @Override
+ public void onDenied(List permissionsDeniedForever, List permissionsDenied) {
+ DialogUtil.showPermissionDialog(MobWeatherActivity.this, getString(R.string.location_permisson));
+ }
+ }).request();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (null != mLocationUtil) {
+ mLocationUtil.removeLocationUpdatesListener();
+ }
}
}
diff --git a/main/src/main/res/layout/activity_mob_weather.xml b/main/src/main/res/layout/activity_mob_weather.xml
index d1a2369..4a302f8 100644
--- a/main/src/main/res/layout/activity_mob_weather.xml
+++ b/main/src/main/res/layout/activity_mob_weather.xml
@@ -20,11 +20,11 @@
android:layout_height="@dimen/dp_60"
android:scaleType="centerCrop"
android:src="@drawable/ic_sun"
- android:visibility="gone"
+ android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.3" />
+ app:layout_constraintVertical_bias="0.2" />
-
+ app:layout_constraintVertical_bias="0.25" />
-
+
+
+
+
+ app:layout_constraintTop_toBottomOf="@+id/number_run_tv"
+ tools:text="@string/app_name" />
+ app:layout_constraintTop_toBottomOf="@+id/tv_weather" />
\ No newline at end of file
diff --git a/main/src/main/res/layout/recycle_item_weather.xml b/main/src/main/res/layout/recycle_item_weather.xml
new file mode 100644
index 0000000..0f64580
--- /dev/null
+++ b/main/src/main/res/layout/recycle_item_weather.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file