Prechádzať zdrojové kódy

1.增加重置密码
2.增加检查更新
3.增加连接服务器
4.增加登录功能
5.增加广告

Tony 5 rokov pred
rodič
commit
d9c4e80aee
78 zmenil súbory, kde vykonal 4452 pridanie a 413 odobranie
  1. 42 2
      app/src/main/AndroidManifest.xml
  2. 3 4
      app/src/main/java/com/sunzee/base/BaseActivity.java
  3. 28 2
      app/src/main/java/com/sunzee/base/BaseApplication.java
  4. 1 2
      app/src/main/java/com/sunzee/base/BasePresenter.java
  5. 36 0
      app/src/main/java/com/sunzee/model/Heartbeat.java
  6. 9 0
      app/src/main/java/com/sunzee/model/HttpResult.java
  7. 104 0
      app/src/main/java/com/sunzee/model/domain/ApkInfoBean.java
  8. 3 0
      app/src/main/java/com/sunzee/model/domain/GeTuiBean.java
  9. 124 0
      app/src/main/java/com/sunzee/model/domain/GetAdBean.java
  10. 0 13
      app/src/main/java/com/sunzee/model/domain/Heartbeat.java
  11. 163 0
      app/src/main/java/com/sunzee/model/domain/HeartbeatBean.java
  12. 15 2
      app/src/main/java/com/sunzee/model/domain/Name.java
  13. 44 0
      app/src/main/java/com/sunzee/model/domain/TimeRuleBean.java
  14. 57 0
      app/src/main/java/com/sunzee/model/message/DownLoadMessageEvent.java
  15. 3 1
      app/src/main/java/com/sunzee/mvp/advanceparameter/AdvanceParameterPresenter.java
  16. 3 0
      app/src/main/java/com/sunzee/mvp/advanceparameter/AdvanceParameterView.java
  17. 223 0
      app/src/main/java/com/sunzee/mvp/advertising/AdvertisingPresenter.java
  18. 32 0
      app/src/main/java/com/sunzee/mvp/advertising/AdvertisingView.java
  19. 3 1
      app/src/main/java/com/sunzee/mvp/alarmrecord/AlarmRecordPresenter.java
  20. 3 0
      app/src/main/java/com/sunzee/mvp/alarmrecord/AlarmRecordView.java
  21. 3 0
      app/src/main/java/com/sunzee/mvp/debug/DebugPresenter.java
  22. 3 0
      app/src/main/java/com/sunzee/mvp/debug/DebugView.java
  23. 3 0
      app/src/main/java/com/sunzee/mvp/generalparameter/GeneralParameterPresenter.java
  24. 3 0
      app/src/main/java/com/sunzee/mvp/generalparameter/GeneralParameterView.java
  25. 70 7
      app/src/main/java/com/sunzee/mvp/home/HomePresenter.java
  26. 7 0
      app/src/main/java/com/sunzee/mvp/home/HomeView.java
  27. 3 1
      app/src/main/java/com/sunzee/mvp/homepage/HomePagePresenter.java
  28. 3 0
      app/src/main/java/com/sunzee/mvp/homepage/HomePageView.java
  29. 3 1
      app/src/main/java/com/sunzee/mvp/languageset/LanguageSetPresenter.java
  30. 3 0
      app/src/main/java/com/sunzee/mvp/languageset/LanguageSetView.java
  31. 82 0
      app/src/main/java/com/sunzee/mvp/login/LoginPresenter.java
  32. 24 0
      app/src/main/java/com/sunzee/mvp/login/LoginView.java
  33. 3 1
      app/src/main/java/com/sunzee/mvp/other/OtherPresenter.java
  34. 3 0
      app/src/main/java/com/sunzee/mvp/other/OtherView.java
  35. 111 1
      app/src/main/java/com/sunzee/mvp/passwordreset/PasswordResetPresenter.java
  36. 4 0
      app/src/main/java/com/sunzee/mvp/passwordreset/PasswordResetView.java
  37. 3 1
      app/src/main/java/com/sunzee/mvp/showmaterial/ShowMaterialPresenter.java
  38. 3 0
      app/src/main/java/com/sunzee/mvp/showmaterial/ShowMaterialView.java
  39. 3 2
      app/src/main/java/com/sunzee/mvp/statistics/StatisticsPresenter.java
  40. 3 0
      app/src/main/java/com/sunzee/mvp/statistics/StatisticsView.java
  41. 35 0
      app/src/main/java/com/sunzee/receiver/Alarmreceiver.java
  42. 106 0
      app/src/main/java/com/sunzee/receiver/DownReceiver.java
  43. 0 2
      app/src/main/java/com/sunzee/retrofit/ApiCallback.java
  44. 33 2
      app/src/main/java/com/sunzee/retrofit/ApiStores.java
  45. 280 0
      app/src/main/java/com/sunzee/service/DownPresenter.java
  46. 32 0
      app/src/main/java/com/sunzee/service/DownServer.java
  47. 182 49
      app/src/main/java/com/sunzee/service/MyIntentService.java
  48. 710 0
      app/src/main/java/com/sunzee/service/MyService.java
  49. 203 0
      app/src/main/java/com/sunzee/ui/activity/AdvertisingActivity.java
  50. 274 48
      app/src/main/java/com/sunzee/ui/activity/HomeActivity.java
  51. 87 0
      app/src/main/java/com/sunzee/ui/activity/LoginActivity.java
  52. 1 6
      app/src/main/java/com/sunzee/ui/activity/MainActivity.java
  53. 3 0
      app/src/main/java/com/sunzee/ui/dialog/ManagementSystemDialog.java
  54. 190 0
      app/src/main/java/com/sunzee/ui/dialog/NormalDialog.java
  55. 134 0
      app/src/main/java/com/sunzee/ui/dialog/ShutdownDialog.java
  56. 0 2
      app/src/main/java/com/sunzee/ui/fragment/AlarmRecordFragment.java
  57. 0 2
      app/src/main/java/com/sunzee/ui/fragment/DebugFragment.java
  58. 0 2
      app/src/main/java/com/sunzee/ui/fragment/GeneralParameterFragment.java
  59. 0 2
      app/src/main/java/com/sunzee/ui/fragment/LanguageSetFragment.java
  60. 0 2
      app/src/main/java/com/sunzee/ui/fragment/OtherFragment.java
  61. 63 4
      app/src/main/java/com/sunzee/ui/fragment/PasswordResetFragment.java
  62. 1 3
      app/src/main/java/com/sunzee/ui/fragment/ShowMaterialFragment.java
  63. 0 2
      app/src/main/java/com/sunzee/ui/fragment/StatisticsFragment.java
  64. 48 0
      app/src/main/java/com/sunzee/utils/DensityUtil.java
  65. 20 26
      app/src/main/java/com/sunzee/utils/FileUtil.java
  66. 73 0
      app/src/main/java/com/sunzee/utils/LongClickUtils.java
  67. 0 1
      app/src/main/java/com/sunzee/utils/SharedPreferencesUtils.java
  68. 285 0
      app/src/main/java/com/sunzee/utils/TimeUtil.java
  69. 26 0
      app/src/main/java/com/sunzee/utils/ToastUtil.java
  70. 45 0
      app/src/main/java/com/sunzee/utils/UiUtil.java
  71. 134 0
      app/src/main/res/layout/activity_advertising.xml
  72. 32 28
      app/src/main/res/layout/activity_home.xml
  73. 69 56
      app/src/main/res/layout/activity_login.xml
  74. 1 2
      app/src/main/res/layout/activity_main.xml
  75. 1 0
      app/src/main/res/layout/dialog_connect_server.xml
  76. 85 74
      app/src/main/res/layout/fragment_change_password.xml
  77. 60 56
      app/src/main/res/layout/fragment_home.xml
  78. 3 3
      app/src/main/res/layout/navigation_layout.xml

+ 42 - 2
app/src/main/AndroidManifest.xml

@@ -14,8 +14,9 @@
 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
-    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission
+        android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
         tools:ignore="ProtectedPermissions" />
 
     <application
@@ -31,6 +32,10 @@
 
         </activity>
         <activity android:name=".ui.activity.HomeActivity">
+
+        </activity>
+        <activity android:name=".ui.activity.LoginActivity" />
+        <activity android:name=".ui.activity.AdvertisingActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
@@ -46,6 +51,41 @@
         <service
             android:name=".service.MyIntentService"
             android:permission="android.permission.BIND_JOB_SERVICE" />
+
+        <service android:name=".service.DownServer" />
+
+        <service android:name=".service.MyService" />
+
+        <service
+            android:name="com.igexin.sdk.PushService"
+            android:exported="true"
+            android:label="NotificationCenter"
+            android:permission="android.permission.BIND_JOB_SERVICE"
+            android:process=":pushservice"
+            tools:replace="android:exported">
+            <intent-filter>
+                <action android:name="com.igexin.sdk.action.service.message" />
+            </intent-filter>
+        </service>
+
+
+        <receiver android:name="com.igexin.sdk.PushReceiver">
+            <intent-filter>
+                <action android:name="android.intent.action.BOOT_COMPLETED" />
+                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+                <action android:name="android.intent.action.USER_PRESENT" />
+                <!-- 以下三项为可选的action声明,可⼤⼤提⾼service存活率和消息到达速度 -->
+                <action android:name="android.intent.action.MEDIA_MOUNTED" />
+                <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
+                <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
+            </intent-filter>
+        </receiver>
+
+        <receiver android:name=".receiver.DownReceiver">
+            <intent-filter>
+                <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
+            </intent-filter>
+        </receiver>
     </application>
 
 </manifest>

+ 3 - 4
app/src/main/java/com/sunzee/base/BaseActivity.java

@@ -12,10 +12,9 @@ import android.view.ViewGroup;
 import android.widget.TextView;
 import android.widget.Toast;
 
-
+import com.sunzee.R;
 import com.sunzee.retrofit.ApiClient;
 import com.sunzee.retrofit.ApiStores;
-import com.sunzee.R;
 import com.wuxiaolong.androidutils.library.LogUtil;
 
 import java.util.ArrayList;
@@ -135,10 +134,10 @@ public abstract class BaseActivity extends AppCompatActivity {
 
     public Toolbar initToolBarAsHome(String title) {
 
-        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+        Toolbar toolbar = findViewById(R.id.toolbar);
         if (toolbar != null) {
             setSupportActionBar(toolbar);
-            TextView toolbaTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
+            TextView toolbaTitle = toolbar.findViewById(R.id.toolbar_title);
             toolbaTitle.setText(title);
         }
         ActionBar actionBar = getSupportActionBar();

+ 28 - 2
app/src/main/java/com/sunzee/base/BaseApplication.java

@@ -2,10 +2,15 @@ package com.sunzee.base;
 
 import android.app.Application;
 import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
 
-import com.sunzee.model.domain.Heartbeat;
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.domain.Name;
+import com.sunzee.service.MyService;
 import com.sunzee.utils.FileUtil;
-import com.sunzee.utils.GeTuiUtil;
+import com.sunzee.utils.SharedPreferencesUtils;
 
 /**
  * Created by MinKin.
@@ -14,13 +19,34 @@ public class BaseApplication extends Application {
 
     public static Context mContext;
 
+
     @Override
     public void onCreate() {
         super.onCreate();
         mContext = this;
+        Hawk.init(this).build();
         Heartbeat.deviceId = FileUtil.getDeviceId();
+        Heartbeat.managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
+
+        startMyService();
+        firstHeartbeat();
     }
 
+    /**
+     * 首次心跳
+     */
+    private void firstHeartbeat() {
+        Intent intent = new Intent(this, MyService.class);
+        Bundle bundle = new Bundle();
+        bundle.putInt("first", 4);
+        intent.putExtras(bundle);
+        startService(intent);
+    }
+
+    private void startMyService() {
+        Intent intentOne = new Intent(this, MyService.class);
+        startService(intentOne);
+    }
 
     public static Context getContext() {
         return mContext;

+ 1 - 2
app/src/main/java/com/sunzee/base/BasePresenter.java

@@ -1,7 +1,7 @@
 package com.sunzee.base;
 
-import com.sunzee.retrofit.ApiStores;
 import com.sunzee.retrofit.ApiClient;
+import com.sunzee.retrofit.ApiStores;
 
 import io.reactivex.Observable;
 import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -10,7 +10,6 @@ import io.reactivex.observers.DisposableObserver;
 import io.reactivex.schedulers.Schedulers;
 
 
-
 public class BasePresenter<V> {
     public V mvpView;
     protected ApiStores apiStores;

+ 36 - 0
app/src/main/java/com/sunzee/model/Heartbeat.java

@@ -0,0 +1,36 @@
+package com.sunzee.model;
+
+/**
+ * @author whw
+ * @time 2019/4/8
+ * @Description 心跳包
+ */
+public class Heartbeat {
+
+
+    //室内湿度
+    public static String cabinetHd = "cabinetHd";
+    //室内温度
+    public static String cabinetTm= "cabinetTm";
+    //人流量
+    public static long peopleCounting= 0;
+    //机器温度
+    public static String furnaceTm= "furnaceTm";
+    //消毒水余量
+    public static int disinfectant= 0;
+    //气味浓度
+    public static Integer odorConcentration= 1;
+    //清洁剂余量
+    public static int cleaner= 0;
+
+    public static String clientId= "clientId";
+    public static String furnaceSp= "furnaceSp";
+    public static String lastUpdateTime= "lastUpdateTime";
+    public static double latitude = 0;
+    public static double longitude = 0;
+    public static String managerId= "managerId";
+    public static String netWorkingMode= "netWorkingMode";
+    public static String deviceId= "deviceId";
+
+
+}

+ 9 - 0
app/src/main/java/com/sunzee/model/HttpResult.java

@@ -43,4 +43,13 @@ public class HttpResult<T> {
     public boolean isSuccess() {
         return code == 0;
     }
+
+    @Override
+    public String toString() {
+        return "HttpResult{" +
+                "code=" + code +
+                ", data=" + data +
+                ", errorMsg='" + errorMsg + '\'' +
+                '}';
+    }
 }

+ 104 - 0
app/src/main/java/com/sunzee/model/domain/ApkInfoBean.java

@@ -0,0 +1,104 @@
+package com.sunzee.model.domain;
+
+/**
+ * @author whw
+ * @time 2019/5/5
+ * @Description 检查数据更新实体
+ */
+public class ApkInfoBean {
+
+
+    /**
+     * apkSize : 212
+     * createDate : 1557047448000
+     * downloadUrl : http://127.0.0.1:8080/i/upload/file/201905/timg_ba821b0e-7c32-4ccb-9694-71d5b676212f.apk
+     * id : 1
+     * isForce : false
+     * modifyDate : 1557047448000
+     * version : 2
+     * versionInfo : sadf
+     * versionName : 1.0.1
+     */
+
+    private int apkSize;
+    private long createDate;
+    private String downloadUrl;
+    private int id;
+    private boolean isForce;
+    private long modifyDate;
+    private int version;
+    private String versionInfo;
+    private String versionName;
+
+    public int getApkSize() {
+        return apkSize;
+    }
+
+    public void setApkSize(int apkSize) {
+        this.apkSize = apkSize;
+    }
+
+    public long getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(long createDate) {
+        this.createDate = createDate;
+    }
+
+    public String getDownloadUrl() {
+        return downloadUrl;
+    }
+
+    public void setDownloadUrl(String downloadUrl) {
+        this.downloadUrl = downloadUrl;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public boolean isIsForce() {
+        return isForce;
+    }
+
+    public void setIsForce(boolean isForce) {
+        this.isForce = isForce;
+    }
+
+    public long getModifyDate() {
+        return modifyDate;
+    }
+
+    public void setModifyDate(long modifyDate) {
+        this.modifyDate = modifyDate;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+
+    public String getVersionInfo() {
+        return versionInfo;
+    }
+
+    public void setVersionInfo(String versionInfo) {
+        this.versionInfo = versionInfo;
+    }
+
+    public String getVersionName() {
+        return versionName;
+    }
+
+    public void setVersionName(String versionName) {
+        this.versionName = versionName;
+    }
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 3 - 0
app/src/main/java/com/sunzee/model/domain/GeTuiBean.java


+ 124 - 0
app/src/main/java/com/sunzee/model/domain/GetAdBean.java

@@ -0,0 +1,124 @@
+package com.sunzee.model.domain;
+
+/**
+ *
+ */
+public class GetAdBean {
+
+    /**
+     * adType : 视频
+     * createDate : 1555904218000
+     * locationType : 棉花糖宣传广告
+     * name : 啊啊啊
+     * order : 1
+     * url : http://app.sunzee.com.cn:80/upload/video/ce4b816e-935a-4dd8-bbec-6b83e06c3c64.mp4
+     */
+
+    private String adType;
+    private long createDate;
+    private String locationType;
+    private String name;
+    private int order;
+    private String url;
+    private String id;
+    private int duration;
+    private String mediaPreview;
+    //广告位置的 a b
+    private int screenType;
+
+    public String getAdType() {
+        return adType;
+    }
+
+    public void setAdType(String adType) {
+        this.adType = adType;
+    }
+
+    public long getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(long createDate) {
+        this.createDate = createDate;
+    }
+
+    public String getLocationType() {
+        return locationType;
+    }
+
+    public void setLocationType(String locationType) {
+        this.locationType = locationType;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getOrder() {
+        return order;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public int getDuration() {
+        return duration;
+    }
+
+    public void setDuration(int duration) {
+        this.duration = duration;
+    }
+
+    public String getMediaPreview() {
+        return mediaPreview;
+    }
+
+    public void setMediaPreview(String mediaPreview) {
+        this.mediaPreview = mediaPreview;
+    }
+
+    public int getScreenType() {
+        return screenType;
+    }
+
+    public void setScreenType(int screenType) {
+        this.screenType = screenType;
+    }
+
+    @Override
+    public String toString() {
+        return "GetAdBean{" +
+                "adType='" + adType + '\'' +
+                ", createDate=" + createDate +
+                ", locationType='" + locationType + '\'' +
+                ", name='" + name + '\'' +
+                ", order=" + order +
+                ", url='" + url + '\'' +
+                ", id='" + id + '\'' +
+                ", duration=" + duration +
+                ", mediaPreview='" + mediaPreview + '\'' +
+                ", screenType=" + screenType +
+                '}';
+    }
+}

+ 0 - 13
app/src/main/java/com/sunzee/model/domain/Heartbeat.java

@@ -1,13 +0,0 @@
-package com.sunzee.model.domain;
-
-/**
- * @Description 心跳包
- */
-public class Heartbeat {
-
-    public static String managerId;
-    public static String deviceId;
-    public static String clientId;
-
-
-}

+ 163 - 0
app/src/main/java/com/sunzee/model/domain/HeartbeatBean.java

@@ -0,0 +1,163 @@
+package com.sunzee.model.domain;
+
+/**
+ * @author whw
+ * @time 2019/4/8
+ * @Description 心跳实体
+ */
+public class HeartbeatBean {
+    //室内湿度
+    private String cabinetHd;
+    //室内温度
+    private String cabinetTm;
+    //人流量
+    private long peopleCounting;
+    //机器温度
+    private String furnaceTm;
+    //消毒水余量
+    private int disinfectant;
+    //气味浓度
+    private Integer odorConcentration;
+    //清洁剂余量
+    private int cleaner;
+
+
+    private String clientId;
+    private String furnaceSp;
+    private String lastUpdateTime;
+    private double latitude;
+    private double longitude;
+    private String managerId;
+    private String netWorkingMode;
+    private String deviceId;
+
+    public long getPeopleCounting() {
+        return peopleCounting;
+    }
+
+    public void setPeopleCounting(long peopleCounting) {
+        this.peopleCounting = peopleCounting;
+    }
+
+    public int getDisinfectant() {
+        return disinfectant;
+    }
+
+    public void setDisinfectant(int disinfectant) {
+        this.disinfectant = disinfectant;
+    }
+
+    public Integer getOdorConcentration() {
+        return odorConcentration;
+    }
+
+    public void setOdorConcentration(Integer odorConcentration) {
+        this.odorConcentration = odorConcentration;
+    }
+
+    public int getCleaner() {
+        return cleaner;
+    }
+
+    public void setCleaner(int cleaner) {
+        this.cleaner = cleaner;
+    }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    private String gtClientId;
+
+    public String getCabinetHd() {
+        return cabinetHd;
+    }
+
+    public void setCabinetHd(String cabinetHd) {
+        this.cabinetHd = cabinetHd;
+    }
+
+    public String getCabinetTm() {
+        return cabinetTm;
+    }
+
+    public void setCabinetTm(String cabinetTm) {
+        this.cabinetTm = cabinetTm;
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+
+    public String getFurnaceSp() {
+        return furnaceSp;
+    }
+
+    public void setFurnaceSp(String furnaceSp) {
+        this.furnaceSp = furnaceSp;
+    }
+
+    public String getFurnaceTm() {
+        return furnaceTm;
+    }
+
+    public void setFurnaceTm(String furnaceTm) {
+        this.furnaceTm = furnaceTm;
+    }
+
+    public String getLastUpdateTime() {
+        return lastUpdateTime;
+    }
+
+    public void setLastUpdateTime(String lastUpdateTime) {
+        this.lastUpdateTime = lastUpdateTime;
+    }
+
+    public double getLatitude() {
+        return latitude;
+    }
+
+    public void setLatitude(double latitude) {
+        this.latitude = latitude;
+    }
+
+    public double getLongitude() {
+        return longitude;
+    }
+
+    public void setLongitude(double longitude) {
+        this.longitude = longitude;
+    }
+
+    public String getManagerId() {
+        return managerId;
+    }
+
+    public void setManagerId(String managerId) {
+        this.managerId = managerId;
+    }
+
+    public String getNetWorkingMode() {
+        return netWorkingMode;
+    }
+
+    public void setNetWorkingMode(String netWorkingMode) {
+        this.netWorkingMode = netWorkingMode;
+    }
+
+    public String getGtClientId() {
+        return gtClientId;
+    }
+
+    public void setGtClientId(String gtClientId) {
+        this.gtClientId = gtClientId;
+    }
+}

+ 15 - 2
app/src/main/java/com/sunzee/model/domain/Name.java

@@ -11,8 +11,21 @@ public interface Name {
      * 1-连接中
      * 2-已连接
      */
-    String CONNECT_STATE="CONNECT_STATE";
+    String CONNECT_STATE = "CONNECT_STATE";
 
     //系统id
-    String SYSTEM_ID="system_Id";
+    String SYSTEM_ID = "system_Id";
+    String ADMIN = "admin";
+    String GUEST = "guest";
+    String ACCOUNT_STATE = "account_state";
+
+    /**
+     * 语言设置
+     * 1-中文
+     * 2-英文
+     */
+    String LANGUAGE_TYPE = "language_type";
+
+    //网络状态
+    String NET_TYPE = "net_type";
 }

+ 44 - 0
app/src/main/java/com/sunzee/model/domain/TimeRuleBean.java

@@ -0,0 +1,44 @@
+package com.sunzee.model.domain;
+
+import java.util.List;
+
+/**
+ * 广告规则实体
+ */
+public class TimeRuleBean {
+
+
+    /**
+     * ad : ["38"]
+     * name : 测试1
+     * time : 0-1
+     */
+
+    private String name;
+    private String time;
+    private List<String> ad;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getTime() {
+        return time;
+    }
+
+    public void setTime(String time) {
+        this.time = time;
+    }
+
+    public List<String> getAd() {
+        return ad;
+    }
+
+    public void setAd(List<String> ad) {
+        this.ad = ad;
+    }
+}

+ 57 - 0
app/src/main/java/com/sunzee/model/message/DownLoadMessageEvent.java

@@ -0,0 +1,57 @@
+package com.sunzee.model.message;
+
+/**
+ * @author whw
+ * @time 2019/4/17
+ * @Description 视频下载完成
+ */
+public class DownLoadMessageEvent {
+
+    public int getScreenType() {
+        return screenType;
+    }
+
+    public void setScreenType(int screenType) {
+        this.screenType = screenType;
+    }
+
+    private int screenType;
+
+    public DownLoadMessageEvent(Type type, Object data, int screenType) {
+        this.type = type;
+        this.data = data;
+        this.screenType=screenType;
+    }
+
+    public enum Type {
+        success,
+        failed,
+        downloadAll,//全部下载完成
+        downloadApkSuccess,
+        downloadApkFailed,
+        downloadApkProcess
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public void setType(Type type) {
+        this.type = type;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    private Type type;
+
+    private Object data;
+
+
+
+}

+ 3 - 1
app/src/main/java/com/sunzee/mvp/advanceparameter/AdvanceParameterPresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.advanceparameter;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.home.HomeView;
 
+/**
+ * 进阶参数presenter
+ */
 public class AdvanceParameterPresenter extends BasePresenter<AdvanceParameterView> {
     public AdvanceParameterPresenter(AdvanceParameterView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/advanceparameter/AdvanceParameterView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.advanceparameter;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 进阶参数界面 view
+ */
 public interface AdvanceParameterView extends BaseView {
 }

+ 223 - 0
app/src/main/java/com/sunzee/mvp/advertising/AdvertisingPresenter.java

@@ -0,0 +1,223 @@
+package com.sunzee.mvp.advertising;
+
+import android.os.Environment;
+import android.util.Log;
+
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.base.BasePresenter;
+import com.sunzee.model.domain.GetAdBean;
+import com.sunzee.utils.FileUtil;
+import com.wuxiaolong.androidutils.library.LogUtil;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 广告界面 presenter
+ * 需求:
+ */
+public class AdvertisingPresenter extends BasePresenter<AdvertisingView> {
+
+    private static final String TAG = "AdvertisingPresenter";
+
+    public AdvertisingPresenter(AdvertisingView view) {
+        attachView(view);
+    }
+
+
+    //--------------------------------------------------------------------------广告 start----------------------------------------------------------------------------------------------
+    public void play() {
+        showOut = Hawk.get("show_out", new HashMap<Integer, GetAdBean>());
+        Log.d(TAG, "initView: " + showOut.get(0));
+        //2.读文件的数据
+        int leftFileSize = leftVideoImageFile();
+        int rightFileSize = rightVideoImageFile();
+        Log.d(TAG, "initView: leftFileSize" + leftFileSize);
+        Log.d(TAG, "initView: rightFileSize" + rightFileSize);
+        if (leftFileSize != 0) {
+            mvpView.playRight(playFile);
+        }
+        if (rightFileSize != 0) {
+            mvpView.playLeft(playFileList);
+        }
+    }
+
+    //下载在本地的所有文件
+    private File[] allFiles;
+    //本地所有<文件名字,文件>的对应
+    private Map<String, File> playList;
+    //要播放的文件
+    private Map<Integer, GetAdBean> showOut;
+    //要播放的文件名字(实体)
+    private ArrayList<GetAdBean> names;
+    //要播放的文件列表
+    private List<File> allPlayList;
+
+    /**
+     * 获取左边视频图片的文件
+     *
+     * @return
+     */
+    private int rightVideoImageFile() {
+        this.allFiles = FileUtil.getAllFiles(Environment.getExternalStorageDirectory().getPath() + "/rightvideoimg/", "");
+        //判断是否为空
+        if (this.allFiles == null || this.allFiles.length <= 0) {
+            LogUtil.d(TAG, "initView: 文件为空,没有下载");
+            return 0;
+        }
+//获取本地所有文件的名字
+        playList = new HashMap<>();
+        //获取名字与文件对应关系
+        for (int i = 0; i < this.allFiles.length; i++) {
+            String name = this.allFiles[i].getName();
+            String fileName = name.substring(0, name.length() - 4);//获取文件名
+            LogUtil.d(TAG, "initView: 本地所有的文件名:" + fileName);
+            // 文件名 文件
+
+            playList.put(fileName, this.allFiles[i]);
+        }
+        if (showOut == null || showOut.size() <= 0) {
+            //没有要播放的文件
+            LogUtil.d(TAG, "initView: 没有要播放的文件");
+            return 0;
+        }
+        names = new ArrayList<>();
+        for (int i = 0; i < allFiles.length; i++) {
+            if (showOut.get(i) != null) {
+                String name = showOut.get(i).getId();
+                LogUtil.d(TAG, "initView: 广告选择要播放的文件名:" + name);
+                names.add(showOut.get(i));
+            }
+        }
+        if (names == null || names.size() <= 0) {
+//            ToastUtil.showToast("请选择文件播放");
+            LogUtil.d(TAG, "initView: 没有选择播放的文件");
+            return 0;
+        }
+        allPlayList = new ArrayList<>();
+        if (playList == null || playList.size() <= 0) {
+            LogUtil.d(TAG, "initView: playList为空");
+            return 0;
+        }
+        //通过名字找出要找出需要播放的文件
+        for (int i = 0; i < names.size(); i++) {
+            File file = playList.get(names.get(i).getId());
+            if (file != null) {
+                LogUtil.d(TAG, "initView: 通过名字找到的播放文件:" + file.getName());
+                allPlayList.add(file);
+            }
+        }
+        if (allPlayList == null || allPlayList.size() <= 0) {
+            LogUtil.d(TAG, "initView: allPlayList为0");
+            return 0;
+        }
+        return setTimeRules();
+    }
+
+    //真正要播放的文件
+    private ArrayList<File> playFileList;
+    //要播放的实体 用于判断是图片还是视频
+    private ArrayList<GetAdBean> playRules;
+
+    /**
+     * 获取当前时间规则与要播放的文件
+     */
+    private int setTimeRules() {
+        playFileList = new ArrayList<>();
+        playRules = new ArrayList<>();
+        HashMap<String, String> ad_rules_map = Hawk.get("ad_rules_map", new HashMap<String, String>());
+        Calendar calendar = Calendar.getInstance();
+        int hour = calendar.get(Calendar.HOUR_OF_DAY);
+        LogUtil.e(TAG, "judeImgVideoAndPlay: hour=" + hour);
+        //当前时间段
+        String timeSort = hour + "-" + (hour + 1);
+        LogUtil.d(TAG, "judeImgVideoAndPlay:timeSort= " + timeSort);
+        Log.d(TAG, "setTimeRules: names" + names);
+        //获取当前时间段的要播放的id
+        for (int i = 0; i < names.size(); i++) {
+            for (Map.Entry<String, String> entry : ad_rules_map.entrySet()) {
+                entry.getKey();
+                entry.getValue();
+                if (entry.getValue().contains(timeSort)) {
+                    if (entry.getKey().equals(names.get(i).getId())) {
+                        LogUtil.d(TAG, "judeImgVideoAndPlay: 添加要播放的文件:" + names.get(i).getId());
+                        playRules.add(names.get(i));
+                    }
+                }
+            }
+
+        }
+        //获取当前时间段要播放的实体
+        for (int i = 0; i < playRules.size(); i++) {
+
+            //当前时间段要播放的文件
+            File file = playList.get(playRules.get(i).getId());
+            if (file != null) {
+                LogUtil.d(TAG, "judeImgVideoAndPlay: 当前时间段要播放的文件的id:" + playRules.get(i).getId());
+                playFileList.add(file);
+            }
+        }
+        LogUtil.e(TAG, "setTimeRules: playFileList.size()=" + playFileList.size());
+        if (playFileList.size() <= 0) {
+            LogUtil.d(TAG, "playFileList: 空");
+            return 0;
+        }
+        return playFileList.size();
+    }
+
+
+    //A屏 要播放的文件
+    private ArrayList<File> playFile;
+    private ArrayList<GetAdBean> adBeans;
+
+    /**
+     * 获取右边视频图片的文件
+     *
+     * @return
+     */
+    private int leftVideoImageFile() {
+        File[] allFiles = FileUtil.getAllFiles(Environment.getExternalStorageDirectory().getPath() + "/leftvideoimg/", "");
+        if (allFiles == null || allFiles.length <= 0) {
+            LogUtil.e(TAG, "playCorporationAd: 没有下载A屏文件");
+            return 0;
+        }
+        adBeans = Hawk.get("showAdA", new ArrayList<GetAdBean>());
+        Log.d(TAG, "rightVideoImageFile: " + adBeans);
+        if (adBeans == null || adBeans.size() <= 0) {
+            LogUtil.e(TAG, "playCorporationAd: 没有下载A屏数据");
+            return 0;
+        }
+
+        //按照网络数据顺序添加
+        playFile = new ArrayList<>();
+        for (int i = 0; i < adBeans.size(); i++) {
+            GetAdBean getAdBean = adBeans.get(i);
+            for (int j = 0; j < allFiles.length; j++) {
+                String name = allFiles[j].getName();
+                LogUtil.d(TAG, "playCorporationAd: name= " + name);
+                String fileName = name.substring(0, name.length() - 4);//获取文件名
+                Log.d(TAG, "rightVideoImageFile: " + fileName + ":getAdBean.getId()+" + getAdBean.getId());
+                if (fileName.equals(getAdBean.getId())) {
+                    playFile.add(allFiles[j]);
+                }
+            }
+        }
+
+        if (playFile == null || playFile.size() <= 0) {
+            Log.d(TAG, "playCorporationAd: 没有匹配的广告数据");
+            return 0;
+        }
+
+        for (int i = 0; i < playFile.size(); i++) {
+            LogUtil.d(TAG, "playCorporationAd: 本地的 name=" + playFile.get(i).getName());
+            LogUtil.d(TAG, "playCorporationAd: 网络的 name=" + adBeans.get(i).getId());
+        }
+        return playFile.size();
+    }
+
+    //--------------------------------------------------------------------------广告 end----------------------------------------------------------------------------------------------
+}

+ 32 - 0
app/src/main/java/com/sunzee/mvp/advertising/AdvertisingView.java

@@ -0,0 +1,32 @@
+package com.sunzee.mvp.advertising;
+
+import com.sunzee.base.BaseView;
+
+import java.io.File;
+import java.util.ArrayList;
+
+/**
+ * 广告界面 view
+ */
+public interface AdvertisingView extends BaseView {
+    /**
+     * 播放左边视频
+     *
+     * @param playFileList
+     */
+    void playLeft(ArrayList<File> playFileList);
+
+    /**
+     * 播放右边视频
+     *
+     * @param playFile
+     */
+    void playRight(ArrayList<File> playFile);
+
+    /**
+     * 更新日期
+     *
+     * @param sysTimeStr
+     */
+    void updateTime(CharSequence sysTimeStr);
+}

+ 3 - 1
app/src/main/java/com/sunzee/mvp/alarmrecord/AlarmRecordPresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.alarmrecord;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.advanceparameter.AdvanceParameterView;
 
+/**
+ * 报警记录界面 presenter
+ */
 public class AlarmRecordPresenter extends BasePresenter<AlarmRecordView> {
     public AlarmRecordPresenter(AlarmRecordView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/alarmrecord/AlarmRecordView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.alarmrecord;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 报警记录界面 view
+ */
 public interface AlarmRecordView extends BaseView {
 }

+ 3 - 0
app/src/main/java/com/sunzee/mvp/debug/DebugPresenter.java

@@ -2,6 +2,9 @@ package com.sunzee.mvp.debug;
 
 import com.sunzee.base.BasePresenter;
 
+/**
+ * 调试页界面 presenter
+ */
 public class DebugPresenter extends BasePresenter<DebugView> {
     public DebugPresenter(DebugView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/debug/DebugView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.debug;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 调试页界面 view
+ */
 public interface DebugView extends BaseView {
 }

+ 3 - 0
app/src/main/java/com/sunzee/mvp/generalparameter/GeneralParameterPresenter.java

@@ -2,6 +2,9 @@ package com.sunzee.mvp.generalparameter;
 
 import com.sunzee.base.BasePresenter;
 
+/**
+ * 通用参数界面 presenter
+ */
 public class GeneralParameterPresenter  extends BasePresenter<GeneralParameterView> {
     public GeneralParameterPresenter(GeneralParameterView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/generalparameter/GeneralParameterView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.generalparameter;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 通用参数界面 view
+ */
 public interface GeneralParameterView extends BaseView {
 }

+ 70 - 7
app/src/main/java/com/sunzee/mvp/home/HomePresenter.java

@@ -1,50 +1,69 @@
 package com.sunzee.mvp.home;
 
+import android.content.Intent;
+import android.os.Bundle;
 import android.util.Log;
-import android.widget.Toast;
 
+import com.google.gson.Gson;
+import com.sunzee.R;
+import com.sunzee.base.BaseApplication;
 import com.sunzee.base.BasePresenter;
+import com.sunzee.model.Heartbeat;
 import com.sunzee.model.HttpResult;
-import com.sunzee.model.domain.Heartbeat;
+import com.sunzee.model.domain.ApkInfoBean;
 import com.sunzee.model.domain.Name;
 import com.sunzee.retrofit.ApiCallback;
-import com.sunzee.ui.activity.HomeActivity;
+import com.sunzee.service.DownServer;
 import com.sunzee.utils.FileUtil;
 import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
 
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * 后台首页 presenter
+ */
 public class HomePresenter extends BasePresenter<HomeView> {
+    private static final String TAG = "HomePresenter";
+
     public HomePresenter(HomeView view) {
         attachView(view);
     }
 
 
     public void connectionSystem(String text) {
+
+        SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 1);
         mvpView.showLoading();
         if (Heartbeat.clientId == null || Heartbeat.clientId.equals("")) {
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.idsb));
             return;
         }
 
-        Map<String, String> params = new HashMap<>();
         SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
         Heartbeat.deviceId = FileUtil.getDeviceId();
         SharedPreferencesUtils.setParam(Name.CONNECT_STATE, -1);
+        Map<String, String> params = new HashMap<>();
         params.put("clientId", Heartbeat.deviceId);
         params.put("managerId", text);
         params.put("gtClientId", Heartbeat.clientId);
         Heartbeat.managerId = text;
-        Log.d("HomePresenter", "onClickListener: Heartbeat.deviceId=" + Heartbeat.deviceId + ";text=" + text + ";Heartbeat.clientId" + Heartbeat.clientId);
         addSubscription(apiStores.init(params), new ApiCallback<HttpResult<String>>() {
             @Override
             public void onSuccess(HttpResult<String> model) {
-                Log.d("HomePresenter", "onSuccess: data=" + model.getData() + ";code=" + model.getCode());
+                Log.d(TAG, "onSuccess: " + model);
+                if (model.getData()==null) {
+                    mvpView.initSuccess(model.getErrorMsg());
+                }else if (model.getErrorMsg()==null){
+                    mvpView.initSuccess(model.getData());
+                }
             }
 
             @Override
             public void onFailure(String msg) {
-                Log.d("HomePresenter", "onFailure: " + msg);
+                Log.d(TAG, "onFailure: " + msg);
             }
 
             @Override
@@ -53,4 +72,48 @@ public class HomePresenter extends BasePresenter<HomeView> {
             }
         });
     }
+
+    /**
+     * 获取下载连接
+     */
+    public void updataapk() {
+        Map<String, String> map = new HashMap<>();
+        map.put("model", "301ch");
+        addSubscription(apiStores.updataAPK(map), new ApiCallback<HttpResult<String>>() {
+            @Override
+            public void onSuccess(HttpResult<String> model) {
+                Log.d(TAG, "onFailure: "+model);
+                Gson gson=new Gson();
+                ApkInfoBean apkInfoBean = gson.fromJson(model.getData(), ApkInfoBean.class);
+                mvpView.updataSuccess(apkInfoBean);
+            }
+
+            @Override
+            public void onFailure(String msg) {
+                Log.d(TAG, "onFailure: "+msg);
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
+    /**
+     * 下载apk
+     *
+     * @param url     地址
+     * @param version 版本号(用于起名)
+     */
+    public void downloadApk(String url, int version) {
+        //开始下载
+        Intent downloadApkIntent = new Intent(BaseApplication.getContext(), DownServer.class);
+        Bundle bundle = new Bundle();
+        bundle.putString("downloadApkUrl", url);
+        bundle.putString("title", "mht" + ".apk");
+        bundle.putString("downloadtype", "apk");
+        downloadApkIntent.putExtra("download", bundle);
+        BaseApplication.getContext().startService(downloadApkIntent);
+    }
 }

+ 7 - 0
app/src/main/java/com/sunzee/mvp/home/HomeView.java

@@ -1,6 +1,13 @@
 package com.sunzee.mvp.home;
 
 import com.sunzee.base.BaseView;
+import com.sunzee.model.domain.ApkInfoBean;
 
+/**
+ * 后台首页 view
+ */
 public interface HomeView extends BaseView {
+    void initSuccess(String data);
+
+    void updataSuccess(ApkInfoBean apkInfoBean);
 }

+ 3 - 1
app/src/main/java/com/sunzee/mvp/homepage/HomePagePresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.homepage;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.generalparameter.GeneralParameterView;
 
+/**
+ * 首页界面 presenter
+ */
 public class HomePagePresenter extends BasePresenter<HomePageView> {
     public HomePagePresenter(HomePageView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/homepage/HomePageView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.homepage;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 首页界面 view
+ */
 public interface HomePageView extends BaseView {
 }

+ 3 - 1
app/src/main/java/com/sunzee/mvp/languageset/LanguageSetPresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.languageset;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 
+/**
+ * 语言设置界面 presenter
+ */
 public class LanguageSetPresenter  extends BasePresenter<LanguageSetView> {
     public LanguageSetPresenter(LanguageSetView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/languageset/LanguageSetView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.languageset;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 语言设置界面 view
+ */
 public interface LanguageSetView extends BaseView {
 }

+ 82 - 0
app/src/main/java/com/sunzee/mvp/login/LoginPresenter.java

@@ -0,0 +1,82 @@
+package com.sunzee.mvp.login;
+
+import android.text.TextUtils;
+
+import com.sunzee.base.BasePresenter;
+import com.sunzee.model.domain.Name;
+import com.sunzee.utils.SharedPreferencesUtils;
+
+/**
+ * 登录界面 presenter
+ */
+public class LoginPresenter extends BasePresenter<LoginView> {
+
+
+    private int inputErrorTime;
+    private boolean isThreadStart;
+    private int countdownTime = 20;
+
+    public LoginPresenter(LoginView view) {
+        attachView(view);
+        String admin = (String) SharedPreferencesUtils.getParam(Name.ADMIN, "-1");
+        String guest = (String) SharedPreferencesUtils.getParam(Name.GUEST, "-1");
+        if (admin == null || admin.equals("-1")) {
+            //本地没有密码
+            SharedPreferencesUtils.setParam(Name.ADMIN, "123456");
+        }
+
+        if (guest == null || guest.equals("-1")) {
+            //本地没有密码
+            SharedPreferencesUtils.setParam(Name.GUEST, "123456");
+        }
+    }
+
+    public void login(String userName, String password) {
+        //是否输入为空
+        if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(password)) {
+            mvpView.inputEmpty();
+            return;
+        }
+        //是否输入两次错误
+        if (inputErrorTime == 2) {
+            if (!isThreadStart) {
+                new Thread(new CountDownThread()).start();
+            }
+            mvpView.laterInput(countdownTime);
+            return;
+        }
+
+        String admin = (String) SharedPreferencesUtils.getParam(Name.ADMIN, "-1");
+        String guest = (String) SharedPreferencesUtils.getParam(Name.GUEST, "-1");
+        if (userName.equals(Name.ADMIN) && password.equals(admin)) {
+            SharedPreferencesUtils.setParam(Name.ACCOUNT_STATE, 0);
+            mvpView.loginSuccessful();
+        } else if (userName.equals(Name.GUEST) && password.equals(guest)) {
+            SharedPreferencesUtils.setParam(Name.ACCOUNT_STATE,1);
+            mvpView.loginSuccessful();
+        } else {
+            mvpView.loginUserFailed();
+            inputErrorTime++;
+        }
+    }
+
+
+    //输错两次后等待20s再尝试
+    class CountDownThread extends Thread {
+        @Override
+        public void run() {
+            isThreadStart = true;
+            try {
+                while (countdownTime >= 0) {
+                    Thread.sleep(1000);
+                    countdownTime--;
+                }
+                isThreadStart = false;
+                countdownTime = 20;
+                inputErrorTime = 0;
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

+ 24 - 0
app/src/main/java/com/sunzee/mvp/login/LoginView.java

@@ -0,0 +1,24 @@
+package com.sunzee.mvp.login;
+
+/**
+ * 登录界面 view
+ */
+public interface LoginView {
+    /**
+     * 登录成功
+     */
+    void loginSuccessful();
+
+    /**
+     * 账户名不对
+     */
+    void loginUserFailed();
+
+
+    /**
+     * 输入为空
+     */
+    void inputEmpty();
+
+    void laterInput(int time);
+}

+ 3 - 1
app/src/main/java/com/sunzee/mvp/other/OtherPresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.other;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.languageset.LanguageSetView;
 
+/**
+ * 其他页界面 presenter
+ */
 public class OtherPresenter extends BasePresenter<OtherView> {
     public OtherPresenter(OtherView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/other/OtherView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.other;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 其他页界面 view
+ */
 public interface OtherView extends BaseView {
 }

+ 111 - 1
app/src/main/java/com/sunzee/mvp/passwordreset/PasswordResetPresenter.java

@@ -1,10 +1,120 @@
 package com.sunzee.mvp.passwordreset;
 
+import android.util.Log;
+
+import com.sunzee.R;
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.other.OtherView;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.HttpResult;
+import com.sunzee.model.domain.Name;
+import com.sunzee.retrofit.ApiCallback;
+import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
+
+import java.util.HashMap;
+import java.util.Map;
 
+/**
+ * 重置密码界面 presenter
+ */
 public class PasswordResetPresenter extends BasePresenter<PasswordResetView> {
+    private int accountState = -1;
+
     public PasswordResetPresenter(PasswordResetView view) {
         attachView(view);
     }
+
+    /**
+     * //旧密码相同
+     * if (confirmPas.equals(pass)) {
+     * //新密码 重复密码
+     * if (oldPas.equals(newPas)) {
+     *
+     * @param oldPas
+     * @param newPas
+     * @param confirmPas
+     */
+
+    public void reset(String oldPas, String newPas, String confirmPas) {
+        if (oldPas == null || oldPas.equals("") || newPas == null && newPas.equals("") || confirmPas == null || confirmPas.equals("")) {
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.empty_password));
+            return;
+        }
+        accountState = (int) SharedPreferencesUtils.getParam(Name.ACCOUNT_STATE, -1);
+        if (accountState == 0) {
+            //admin
+            String adminPas = (String) SharedPreferencesUtils.getParam(Name.ADMIN, "-1");
+            checkPas(oldPas, newPas, confirmPas, adminPas);
+        } else if (accountState == 1) {
+            //guest
+            String guestPas = (String) SharedPreferencesUtils.getParam(Name.GUEST, "-1");
+            checkPas(oldPas, newPas, confirmPas, guestPas);
+        } else {
+
+        }
+    }
+
+    private static final String TAG = "PasswordResetPresenter";
+
+    /**
+     * 更新服务器密码
+     *
+     * @param newPas 新密码
+     * @param type   类型
+     */
+    private void updatePassword(String newPas, String type) {
+        Map<String, String> params = new HashMap<>();
+        params.put("clientId", Heartbeat.deviceId);
+        params.put("pwd", newPas);
+        params.put("pwdType", type);
+        addSubscription(apiStores.updatePaw(params), new ApiCallback<HttpResult<String>>() {
+            @Override
+            public void onSuccess(HttpResult<String> model) {
+                Log.d(TAG, "onSuccess: " + model);
+                if (model.getData().equals("更新密码成功")) {
+                    mvpView.showResult(true);
+                }
+            }
+
+            @Override
+            public void onFailure(String msg) {
+
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
+    /**
+     * @param oldPas     旧
+     * @param newPas     新
+     * @param pass
+     * @param confirmPas
+     */
+    private void checkPas(String oldPas, String newPas, String confirmPas, String pass) {
+        //旧密码相同
+        if (oldPas.equals(pass)) {
+            //新密码 重复密码
+            if (confirmPas.equals(newPas)) {
+                if (accountState == 0) {
+                    SharedPreferencesUtils.setParam(Name.ADMIN, newPas);
+                    updatePassword(newPas, "1");
+
+                } else {
+                    SharedPreferencesUtils.setParam(Name.GUEST, newPas);
+                    updatePassword(newPas, "0");
+                }
+            } else {
+                mvpView.showResult(false);
+                ToastUtil.showToast(UiUtil.getStringRes(R.string.mmbyz));
+            }
+        } else {
+            mvpView.showResult(false);
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.oldpas));
+        }
+    }
 }

+ 4 - 0
app/src/main/java/com/sunzee/mvp/passwordreset/PasswordResetView.java

@@ -2,5 +2,9 @@ package com.sunzee.mvp.passwordreset;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 重置密码界面 view
+ */
 public interface PasswordResetView extends BaseView {
+    void showResult(boolean b);
 }

+ 3 - 1
app/src/main/java/com/sunzee/mvp/showmaterial/ShowMaterialPresenter.java

@@ -1,8 +1,10 @@
 package com.sunzee.mvp.showmaterial;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.mvp.passwordreset.PasswordResetView;
 
+/**
+ * 查看物料界面 presenter
+ */
 public class ShowMaterialPresenter extends BasePresenter<ShowMaterialView> {
     public ShowMaterialPresenter(ShowMaterialView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/showmaterial/ShowMaterialView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.showmaterial;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 查看物料界面 view
+ */
 public interface ShowMaterialView extends BaseView {
 }

+ 3 - 2
app/src/main/java/com/sunzee/mvp/statistics/StatisticsPresenter.java

@@ -1,9 +1,10 @@
 package com.sunzee.mvp.statistics;
 
 import com.sunzee.base.BasePresenter;
-import com.sunzee.base.BaseView;
-import com.sunzee.mvp.showmaterial.ShowMaterialView;
 
+/**
+ * 数据统计界面 presenter
+ */
 public class StatisticsPresenter extends BasePresenter<StatisticsView> {
     public StatisticsPresenter(StatisticsView view) {
         attachView(view);

+ 3 - 0
app/src/main/java/com/sunzee/mvp/statistics/StatisticsView.java

@@ -2,5 +2,8 @@ package com.sunzee.mvp.statistics;
 
 import com.sunzee.base.BaseView;
 
+/**
+ * 数据统计界面 view
+ */
 public interface StatisticsView extends BaseView {
 }

+ 35 - 0
app/src/main/java/com/sunzee/receiver/Alarmreceiver.java

@@ -0,0 +1,35 @@
+package com.sunzee.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+import com.sunzee.service.MyService;
+
+/**
+ * @author whw
+ * @time 2019/4/23
+ * @Description 进程保活
+ */
+public class Alarmreceiver extends BroadcastReceiver {
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        // TODO Auto-generated method stub
+        if (intent!=null){
+            if (intent.getAction()!=null){
+
+
+            if (intent.getAction().equals("arui.alarm.action")) {
+                Intent i = new Intent();
+                i.setClass(context, MyService.class);
+                // 启动service
+                // 多次调用startService并不会启动多个service 而是会多次调用onStart
+                context.startService(i);
+            }
+        }
+        }
+
+    }
+
+}

+ 106 - 0
app/src/main/java/com/sunzee/receiver/DownReceiver.java

@@ -0,0 +1,106 @@
+package com.sunzee.receiver;
+
+import android.app.DownloadManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.util.Log;
+
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.base.BaseApplication;
+import com.sunzee.model.message.DownLoadMessageEvent;
+import com.sunzee.utils.SharedPreferencesUtils;
+
+import org.greenrobot.eventbus.EventBus;
+
+import java.util.HashMap;
+
+/**
+ * @author whw
+ * @time 2019/4/17
+ * @Description 下载状态监听
+ */
+public class DownReceiver extends BroadcastReceiver {
+    private static final String TAG = "DownReceiver";
+    private long mTaskId;
+    private DownloadManager downloadManager;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+
+        mTaskId= (long) SharedPreferencesUtils.getParam("taskid",0l);
+        checkDownloadStatus();
+    }
+
+    //检查下载状态
+    private void checkDownloadStatus() {
+        downloadManager = (DownloadManager) BaseApplication.getContext().getSystemService(Context.DOWNLOAD_SERVICE);
+        DownloadManager.Query query = new DownloadManager.Query();
+        query.setFilterById(mTaskId);//筛选下载任务,传入任务ID,可变参数
+        Cursor c = downloadManager.query(query);
+        Log.d(TAG, "checkDownloadStatus: 》》》下载");
+        if (c.moveToFirst()) {
+            int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
+            Log.d(TAG, "checkDownloadStatus: 》》》 status="+status);
+            int screenType = Hawk.get("screen_type",10);
+            HashMap<Long,String> map = Hawk.get("download");
+
+            String name = map.get(mTaskId);
+            String fileTyle=name.substring(name.lastIndexOf(".")+1);
+            Log.d(TAG, "checkDownloadStatus: 》》》 fileTyle="+fileTyle);
+            switch (status) {
+
+                case DownloadManager.STATUS_PAUSED:
+                    Log.d(TAG, "checkDownloadStatus: >>>下载暂停");
+                    break;
+                case DownloadManager.STATUS_PENDING:
+                    Log.d(TAG, "checkDownloadStatus: >>>下载延迟");
+                    break;
+                case DownloadManager.STATUS_RUNNING:
+                    Log.d(TAG, "checkDownloadStatus: >>>正在下载");
+                    /**
+                     * 计算下载下载率;
+                     */
+                    int totalSize = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
+                    int currentSize = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
+                    int progress = (int) (((float) currentSize) / ((float) totalSize) * 100);
+                    Log.d(TAG, "checkDownloadStatus: "+progress);
+                    if (fileTyle.equals("apk")){
+                        //下载文件apk
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadApkProcess,progress,-1));
+                    }
+
+                    break;
+                case DownloadManager.STATUS_SUCCESSFUL:
+                    Log.d(TAG, "checkDownloadStatus: >>>下载完成"+name);
+                    //todo 可以判断下载的文件是apk还是广告数据了
+                    if (fileTyle.equals("apk")){
+                        //下载文件apk
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadApkSuccess,name,-1));
+                    }else {
+
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.success,name,screenType));
+                    }
+
+                    break;
+                case DownloadManager.STATUS_FAILED:
+                    Log.d(TAG, "checkDownloadStatus: >>>下载失败"+name);
+
+                    if (fileTyle.equals("apk")){
+                        //下载文件apk
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadApkFailed,name,-1));
+
+                    }else {
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.failed,name,screenType));
+                    }
+
+                    break;
+            }
+            c.close();
+        }
+    }
+
+
+
+}

+ 0 - 2
app/src/main/java/com/sunzee/retrofit/ApiCallback.java

@@ -3,12 +3,10 @@ package com.sunzee.retrofit;
 
 import com.wuxiaolong.androidutils.library.LogUtil;
 
-
 import io.reactivex.observers.DisposableObserver;
 import retrofit2.HttpException;
 
 
-
 public abstract class ApiCallback<M> extends DisposableObserver<M> {
 
     public abstract void onSuccess(M model);

+ 33 - 2
app/src/main/java/com/sunzee/retrofit/ApiStores.java

@@ -7,6 +7,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import io.reactivex.Observable;
+import okhttp3.RequestBody;
+import retrofit2.http.Body;
 import retrofit2.http.FieldMap;
 import retrofit2.http.FormUrlEncoded;
 import retrofit2.http.GET;
@@ -17,8 +19,8 @@ import retrofit2.http.QueryMap;
 
 public interface ApiStores {
     //baseUrl
-    String API_SERVER_URL = "http://app.sunzee.com.cn/";
-//    String API_SERVER_URL = "http://192.168.0.185:8082";
+    String API_SERVER_URL = "http://clean.sunzee.com.cn/";
+//    String API_SERVER_URL = "http://192.168.0.184:8008";
 
     // 用bean接收 返回值
     @POST("api/coinOrder/email.htm")
@@ -33,4 +35,33 @@ public interface ApiStores {
     @POST("/api/app_equipment/index/init.htm")
     Observable<HttpResult<String>> init(@FieldMap Map<String, String> params);
 
+    //获取广告规则
+    @GET("api/app_ADIndex/ADIndex/getTimeRule.htm")
+    Observable<HttpResult<String>> getTimeRule(@QueryMap Map<String, Long> params);
+
+    //获取指定的广告,上传设备id,返回该id的的广告资源
+    @GET("/api/app_ADIndex/ADIndex/getAdNew.htm")
+    Observable<HttpResult<String>> uploadID(@QueryMap Map<String, String> params);
+
+    //同步规则
+    @GET("api/app_synchro/synchroIndex/synTimeRule.htm")
+    Observable<HttpResult<String>> synTimeRule(@QueryMap Map<String, String> params);
+
+    //下载失败上传
+    @FormUrlEncoded
+    @POST("/api/app_ADIndex/ADIndex/pushTimeUpdate.htm")
+    Observable<HttpResult<String>> pushTimeUpdate(@FieldMap Map<String, String> params);
+
+    //检查更新:获取版本数据
+    @GET("api/appApkInfo/apkinfo.htm")
+    Observable<HttpResult<String>> updataAPK(@QueryMap Map<String, String> params);
+
+    //上传心跳
+    @POST("api/app_equipment/index/heart.htm")
+    Observable<HttpResult<String>> heart(@Body RequestBody body);
+
+    //重置密码
+    @FormUrlEncoded
+    @POST("api/app_equipment/index/updatePwd.htm")
+    Observable<HttpResult<String>> updatePaw(@FieldMap Map<String, String> params);
 }

+ 280 - 0
app/src/main/java/com/sunzee/service/DownPresenter.java

@@ -0,0 +1,280 @@
+package com.sunzee.service;
+
+import android.app.DownloadManager;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.base.BaseApplication;
+import com.sunzee.utils.FileUtil;
+import com.sunzee.utils.SharedPreferencesUtils;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DownPresenter {
+    static final String TAG = "DownPresenter";
+    Context context = BaseApplication.getContext();
+    private DownloadManager mDownloadManager;
+    private boolean isRuning = true;
+    private DownPresenter.ProgressUpdate progressUpdate;
+
+    private DownPresenter() {
+        String text = "";
+        Object systemService = context.getSystemService(Context.DOWNLOAD_SERVICE);
+        mDownloadManager = (DownloadManager) systemService;
+    }
+
+    private static DownPresenter mDownPresenter;
+
+    public static DownPresenter getInstance() {
+        if (mDownPresenter == null) {
+            synchronized (DownPresenter.class) {
+                mDownPresenter = new DownPresenter();
+            }
+        }
+        return mDownPresenter;
+    }
+
+    public void onStartCommand(Intent intent, int flags, int startId) {
+        if (intent != null) {
+            Bundle downloadBundle = intent.getBundleExtra("download");
+            if (downloadBundle != null) {
+                String downloadUrl = downloadBundle.getString("downloadUrl");
+                String title = downloadBundle.getString("title");
+                String downloadtype = downloadBundle.getString("downloadtype");
+                String name = downloadBundle.getString("download_name");
+                int screenType = downloadBundle.getInt("scrrentype");
+
+                if (downloadtype.equals("apk")) {
+                    //下载apk
+                    String downloadApkUrl = downloadBundle.getString("downloadApkUrl");
+                    if (!TextUtils.isEmpty(downloadApkUrl)) {
+                        long downloadId = downloadApk1(downloadApkUrl, title, downloadtype);
+                        mTaskId = downloadId;
+                        //保存当前taskid
+                        isRuning = true;
+                        startQuery();
+                        SharedPreferencesUtils.setParam("taskid", downloadId);
+                        String filename = (String) SharedPreferencesUtils.getParam("apkname", "");
+                        //保存当前的下载文件名字以及对应的id
+                        Map<Long, String> map = new HashMap<>();
+                        map.put(downloadId, filename);
+                        Hawk.put("download", map);
+                    }
+                } else {
+                    if (!TextUtils.isEmpty(downloadUrl)) {
+                        //开始下载
+                        long downloadId = downloadAd(downloadUrl, title, downloadtype, screenType);
+                        //保存当前taskid
+                        SharedPreferencesUtils.setParam("taskid", downloadId);
+                        String filename = (String) SharedPreferencesUtils.getParam("filename", "");
+                        //保存当前的下载文件名字以及对应的id
+                        Map<Long, String> map = new HashMap<>();
+                        map.put(downloadId, filename);
+                        Hawk.put("download", map);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 下载广告数据
+     *
+     * @param url
+     * @param title
+     * @return 下载taskid
+     */
+    private long downloadAd(String url, String title, String downloadtype, int screenType) {
+        Log.d(TAG, "downloadAd: url=" + url);
+        Uri downloadUri = Uri.parse(url);
+        Log.d(TAG, "downloadAd: getPath=" + downloadUri.getPath());
+        DownloadManager.Request request = new DownloadManager.Request(downloadUri);
+        String apkName = title + "." + downloadtype;
+        DownloadManager mDownloadManager = null;
+        if (screenType == 0) {
+            Hawk.put("screen_type", 0);
+            Log.d(TAG, "downloadAd: 下载:" + apkName);
+            File externalFilesDir = new File("/leftvideoimg");
+            if (externalFilesDir == null || !externalFilesDir.exists()) {
+                externalFilesDir.mkdir();
+            }
+            File file = new File(Environment.getExternalStorageDirectory().getPath() + "/leftvideoimg/" + apkName);
+            if (file != null && file.exists()) {
+                file.delete();
+            }
+
+            request.setDestinationInExternalPublicDir("/leftvideoimg", apkName);
+            //保存当前名字
+            SharedPreferencesUtils.setParam("filename", apkName);
+            request.setVisibleInDownloadsUi(true);
+            request.setTitle(title);
+            mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+        } else {
+            Hawk.put("screen_type", 1);
+            File externalFilesDir = new File("/rightvideoimg");
+            if (externalFilesDir == null || !externalFilesDir.exists()) {
+                externalFilesDir.mkdir();
+            }
+            File file = new File(Environment.getExternalStorageDirectory().getPath() + "/rightvideoimg/" + apkName);
+            if (file != null && file.exists()) {
+                file.delete();
+            }
+            Log.d(TAG, "downloadAd: 下载:" + apkName);
+            request.setDestinationInExternalPublicDir("/rightvideoimg", apkName);
+            //保存当前名字
+            SharedPreferencesUtils.setParam("filename", apkName);
+            request.setVisibleInDownloadsUi(true);
+            request.setTitle(title);
+            mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+        }
+
+        return mDownloadManager.enqueue(request);
+    }
+
+
+    /**
+     * 下载apk
+     *
+     * @param url
+     * @param title
+     * @return 下载taskid
+     */
+    private long downloadApk1(String url, String title, String downloadtype) {
+        Uri downloadUri = Uri.parse(url);
+        DownloadManager.Request request = new DownloadManager.Request(downloadUri);
+        String apkName = "mht" + "." + "apk";
+        File externalFilesDir = context.getExternalFilesDir("apk");
+        File file1 = new File(Environment.getExternalStorageDirectory().getPath() + "/apk/");
+        if (file1.exists()) {
+            FileUtil.deleteFile(file1);
+        }
+        if (externalFilesDir == null || !externalFilesDir.exists()) {
+            externalFilesDir.mkdir();
+        }
+        File file = context.getExternalFilesDir("apk" + "/" + "mht.apk");
+        Log.d(TAG, "downloadApk1: 下载:" + file.getAbsolutePath());
+        if (file != null && file.exists()) {
+            file.delete();
+        }
+
+        request.setDestinationInExternalPublicDir("/apk", apkName);
+        //保存当前名字
+        SharedPreferencesUtils.setParam("apkname", apkName);
+        request.setVisibleInDownloadsUi(true);
+        request.setTitle(title);
+        DownloadManager mDownloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
+        Log.d(TAG, "downloadApk1: 下载apk");
+        long enqueue = mDownloadManager.enqueue(request);
+        startQuery();
+        return enqueue;
+    }
+
+
+    private long mTaskId;
+
+
+    //apk 下载进度监听
+    private final DownPresenter.QueryRunnable mQueryProgressRunnable = new QueryRunnable();
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            super.handleMessage(msg);
+            if (msg.what == 1001) {
+
+                Log.d(TAG, "handleMessage msg.arg1:  " + msg.arg1);
+                Log.d(TAG, "handleMessage msg.arg2: " + msg.arg2);
+                if (progressUpdate != null) {
+                    progressUpdate.onProgressUpdate(msg.arg1, msg.arg2);
+                }
+            }
+        }
+    };
+
+    //查询下载进度
+    private class QueryRunnable implements Runnable {
+        @Override
+        public void run() {
+            queryState();
+            Log.d(TAG, "QueryRunnablerun: ");
+            if (isRuning) {
+                mHandler.postDelayed(mQueryProgressRunnable, 100);
+            }
+        }
+    }
+
+    //更新下载进度
+    private void startQuery() {
+        if (mTaskId != 0) {
+            mHandler.post(mQueryProgressRunnable);
+            Log.d(TAG, "startQuery: ");
+        }
+    }
+
+    //查询下载进度
+    private void queryState() {
+        // 通过ID向下载管理查询下载情况,返回一个cursor
+        Cursor c = mDownloadManager.query(new DownloadManager.Query().setFilterById(mTaskId));
+        if (c != null && c.moveToFirst()) {
+            int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
+            int status = c.getInt(columnIndex);
+            switch (status) {
+                case DownloadManager.STATUS_RUNNING:
+                    Log.d(TAG, "queryState: 下载中");
+                    break;
+                case DownloadManager.STATUS_SUCCESSFUL:
+                    Log.d(TAG, "queryState: 下载成功");
+                    stopQuery();
+                    break;
+                //下载失败
+                case DownloadManager.STATUS_FAILED:
+                    Log.d(TAG, "queryState: 下载失败");
+                    break;
+            }
+        }
+        if (c == null) {
+        } else { // 以下是从游标中进行信息提取
+            if (!c.moveToFirst()) {
+                if (!c.isClosed()) {
+                    c.close();
+                }
+                return;
+            }
+            int mDownload_so_far = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
+            int mDownload_all = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
+            Message msg = Message.obtain();
+            if (mDownload_all > 0) {
+                msg.what = 1001;
+                msg.arg1 = mDownload_so_far;
+                msg.arg2 = mDownload_all;
+                mHandler.sendMessage(msg);
+            }
+            if (!c.isClosed()) {
+                c.close();
+            }
+        }
+    }
+    //停止查询下载进度
+    private void stopQuery() {
+        isRuning = false;
+        mHandler.removeCallbacks(mQueryProgressRunnable);
+    }
+    public void setProgressUpdate(DownPresenter.ProgressUpdate update) {
+        this.progressUpdate = update;
+    }
+
+    //进度更新
+    public interface ProgressUpdate {
+        void onProgressUpdate(double mDownload_so_far, double mDownload_all);
+    }
+}

+ 32 - 0
app/src/main/java/com/sunzee/service/DownServer.java

@@ -0,0 +1,32 @@
+package com.sunzee.service;
+
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+
+/**
+ * @author whw
+ * @time 2019/4/17
+ * @Description 下载服务
+ */
+public class DownServer extends Service {
+    static final String TAG = "DownServer";
+    Context context = this;
+    private final DownPresenter mDownPresenter;
+
+    public DownServer() {
+        mDownPresenter = DownPresenter.getInstance();
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        mDownPresenter.onStartCommand(intent, flags, startId);
+        return super.onStartCommand(intent, flags, startId);
+    }
+}

+ 182 - 49
app/src/main/java/com/sunzee/service/MyIntentService.java

@@ -1,24 +1,42 @@
 package com.sunzee.service;
 
 import android.content.Context;
-import android.util.Log;
 
 import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import com.igexin.sdk.GTIntentService;
 import com.igexin.sdk.message.GTCmdMessage;
 import com.igexin.sdk.message.GTNotificationMessage;
 import com.igexin.sdk.message.GTTransmitMessage;
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.HttpResult;
 import com.sunzee.model.domain.GeTuiBean;
-import com.sunzee.model.domain.Heartbeat;
+import com.sunzee.model.domain.GetAdBean;
 import com.sunzee.model.domain.Name;
+import com.sunzee.model.domain.TimeRuleBean;
 import com.sunzee.model.message.ApiMessageEvent;
-import com.sunzee.utils.GeTuiUtil;
+import com.sunzee.retrofit.ApiCallback;
+import com.sunzee.retrofit.ApiClient;
+import com.sunzee.retrofit.ApiStores;
 import com.sunzee.utils.SharedPreferencesUtils;
+import com.wuxiaolong.androidutils.library.LogUtil;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.reactivex.Observable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.CompositeDisposable;
+import io.reactivex.observers.DisposableObserver;
+import io.reactivex.schedulers.Schedulers;
+
 
 /**
  * 继承 GTIntentService 接收来自个推的消息,所有消息在线程中回调,
@@ -29,6 +47,7 @@ public class MyIntentService extends GTIntentService {
     public void onReceiveServicePid(Context context, int i) {
 
     }
+
     @Subscribe
     @Override
     public void onCreate() {
@@ -46,20 +65,17 @@ public class MyIntentService extends GTIntentService {
     /**
      * 接收 cid
      *
-     * @param context
-     * @param clientid
+     * @param context  上下文
+     * @param clientid 个推id
      */
     @Override
     public void onReceiveClientId(Context context, String clientid) {
-        Log.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
+        LogUtil.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
         Heartbeat.clientId = clientid;
     }
 
     /**
      * 处理透传消息
-     *
-     * @param context
-     * @param gtTransmitMessage
      */
     @Override
     public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
@@ -73,13 +89,10 @@ public class MyIntentService extends GTIntentService {
 
         String data = new String(payload);
         Gson gson = new Gson();
-        Log.e(TAG, "onReceiveMessageData: " + ";appid" + appid + ";taskid" + taskid + ";messageid" + messageid + ";payload" + payload + ";pkg" + pkg + ";cid" + cid);
-        Log.e(TAG, "onReceiveMessageData: data:" + data);
-
-        String realData = data;
-
-        Log.e(TAG, "onReceiveMessageData : realData=" + realData);
-        GeTuiBean geTuiBean = gson.fromJson(realData, GeTuiBean.class);
+        LogUtil.e(TAG, "onReceiveMessageData: " + ";appid" + appid + ";taskid" + taskid + ";messageid" + messageid + ";payload" + payload + ";pkg" + pkg + ";cid" + cid);
+        LogUtil.e(TAG, "onReceiveMessageData: data:" + data);
+        LogUtil.e(TAG, "onReceiveMessageData : realData=" + data);
+        GeTuiBean geTuiBean = gson.fromJson(data, GeTuiBean.class);
         String kind = geTuiBean.getKind();
         switch (kind) {
             case "clean":
@@ -87,12 +100,138 @@ public class MyIntentService extends GTIntentService {
                 startClean(gson, geTuiBean, kind);
                 break;
             case "statusType":
+                //申请初始化回调
                 statusType(gson, geTuiBean, kind);
                 break;
+            case "pushTimeRule":
+                LogUtil.d(TAG, "pushTimeRule: ");
+                //广告规则
+                changeAdRules(geTuiBean);
+                break;
+            //不需要更新广告了,而是更具规则来下载广告。
+//            case "push":
+//                LogUtil.d(TAG, "push: ");
+//                //更新广告
+//                String json = geTuiBean.getKind_data();
+//                if (json.equals("更新广告")) {
+//                    saveAd();
+//                }
+//                break;
+
         }
 
     }
 
+    private CompositeDisposable mDisposables;
+    protected ApiStores apiStores = ApiClient.retrofit().create(ApiStores.class);
+
+    protected void addSubscription(Observable observable, DisposableObserver observer) {
+        if (mDisposables == null) {
+            mDisposables = new CompositeDisposable();
+        }
+        observable
+                .unsubscribeOn(Schedulers.io())
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(observer);
+        mDisposables.add(observer);
+    }
+
+    /**
+     * 改变广告规则
+     *
+     * @param geTuiBean 广告规则数据
+     */
+    private void changeAdRules(GeTuiBean geTuiBean) {
+        String json = geTuiBean.getKind_data();
+        saveAdRules(json);
+    }
+
+    /**
+     * 保存广告id
+     */
+    private void saveAdRules(String id) {
+        LogUtil.d(TAG, "ad_id ->" + id);
+        Long lid = Long.valueOf(id);
+        Map<String, Long> params = new HashMap<>();
+        params.put("id", lid);
+        addSubscription(apiStores.getTimeRule(params), new ApiCallback<HttpResult<String>>() {
+
+            @Override
+            public void onSuccess(HttpResult<String> rule) {
+                String data = rule.getData();
+                //广告数据
+                ArrayList<GetAdBean> adBeans = Hawk.get("showAd", new ArrayList<GetAdBean>());
+
+                Gson gson = new Gson();
+                List<TimeRuleBean> list = gson.fromJson(data, new TypeToken<List<TimeRuleBean>>() {
+                }.getType());
+                //每个id对应的时间数
+                Map<String, String> adRulesMap = new HashMap<>();
+                for (int i = 0; i < adBeans.size(); i++) {
+                    GetAdBean getAdBean = adBeans.get(i);
+                    StringBuilder sb = new StringBuilder();
+                    for (int j = 0; j < list.size(); j++) {
+                        //每个规则里对应的广告
+                        List<String> ad = list.get(j).getAd();
+                        for (int k = 0; k < ad.size(); k++) {
+                            if (ad.get(k).equals(getAdBean.getId())) {
+                                sb.append(list.get(j).getTime() + "、");
+                                LogUtil.d(TAG, "list get get" + list.get(j).getName());
+                            }
+                        }
+                    }
+                    if (sb.length() > 0) {
+                        sb.deleteCharAt(sb.length() - 1);
+                    }
+                    LogUtil.e(TAG, "onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
+                    adRulesMap.put(getAdBean.getId(), sb.toString());
+                }
+                //保存对应的id对应的广告规则
+                Hawk.put("ad_rules_map", adRulesMap);
+                EventBus.getDefault().post(new ApiMessageEvent("pushTimeRule", null));
+
+                //发送设备id
+                deviceIdPostApi();
+            }
+
+            @Override
+            public void onFailure(String msg) {
+
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
+    /**
+     * 上传设备id,返回该id的的广告资源
+     */
+    private void deviceIdPostApi() {
+        Map<String, String> params = new HashMap<>();
+        params.put("clientId", Heartbeat.deviceId + "");
+        addSubscription(apiStores.uploadID(params), new ApiCallback<HttpResult<String>>() {
+
+            @Override
+            public void onSuccess(HttpResult<String> model) {
+                EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADADCID", model.getData()));
+            }
+
+            @Override
+            public void onFailure(String msg) {
+                LogUtil.e(TAG, msg);
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
     /**
      * 开始清洗
      *
@@ -101,47 +240,50 @@ public class MyIntentService extends GTIntentService {
      * @param kind
      */
     private void startClean(Gson gson, GeTuiBean geTuiBean, String kind) {
-        Log.e("home", "statusType: 开始清洗");
+        LogUtil.e("home", "statusType: 开始清洗");
     }
 
     /**
-     * 初始化回调
+     * 初始化申请连接服务器回调
      *
-     * @param gson
-     * @param baseBean
-     * @param kind
+     * @param gson     格式化
+     * @param baseBean 数据类
+     * @param kind     携带的数据
      */
     private void statusType(Gson gson, GeTuiBean baseBean, String kind) {
         String json = baseBean.getKind_data();
         String s = gson.fromJson(json, String.class);
-        if (s.equals("rejected")) {
-            //拒绝
-            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
-            Log.e("home", "statusType: 申请拒绝");
-        } else if (s.equals("agreed")) {
-            //申请通过
-            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
-            Log.e("home", "statusType: 申请通过");
-            SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
-        } else if (s.equals("agreed1")) {
-            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
-            Log.e("home", "statusType: 申请通过");
-            SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
-            // interService 不能弹出弹窗 在 service中弹出
-            EventBus.getDefault().post(new ApiMessageEvent(kind + "1", null));
-
+        switch (s) {
+            case "rejected":
+                //拒绝
+                SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
+                LogUtil.e("home", "statusType: 申请拒绝");
+                break;
+            case "agreed":
+                //申请通过
+                SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
+                LogUtil.e("home", "statusType: 申请通过");
+                SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
+                break;
+            case "agreed1":
+                SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
+                LogUtil.e("home", "statusType: 申请通过");
+                SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
+                // interService 不能弹出弹窗 在 service中弹出
+                EventBus.getDefault().post(new ApiMessageEvent(kind + "1", null));
+                break;
         }
         EventBus.getDefault().post(new ApiMessageEvent(kind, null));
     }
+
+
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void event(ApiMessageEvent messageEvent) {
     }
 
+
     /**
      * cid 离线上线通知
-     *
-     * @param context
-     * @param b
      */
     @Override
     public void onReceiveOnlineState(Context context, boolean b) {
@@ -150,9 +292,6 @@ public class MyIntentService extends GTIntentService {
 
     /**
      * 各种事件处理回执
-     *
-     * @param context
-     * @param gtCmdMessage
      */
     @Override
     public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
@@ -161,9 +300,6 @@ public class MyIntentService extends GTIntentService {
 
     /**
      * 通知到达,只有个推通道下发的通知会回调此方法
-     *
-     * @param context
-     * @param gtNotificationMessage
      */
     @Override
     public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
@@ -172,9 +308,6 @@ public class MyIntentService extends GTIntentService {
 
     /**
      * 通知点击,只有个推通道下发的通知会回调此方法
-     *
-     * @param context
-     * @param gtNotificationMessage
      */
     @Override
     public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {

+ 710 - 0
app/src/main/java/com/sunzee/service/MyService.java

@@ -0,0 +1,710 @@
+package com.sunzee.service;
+
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.IBinder;
+import android.os.SystemClock;
+import android.support.annotation.Nullable;
+import android.support.annotation.RequiresApi;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.orhanobut.hawk.Hawk;
+import com.sunzee.R;
+import com.sunzee.base.BaseApplication;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.HttpResult;
+import com.sunzee.model.domain.GetAdBean;
+import com.sunzee.model.domain.HeartbeatBean;
+import com.sunzee.model.domain.Name;
+import com.sunzee.model.domain.TimeRuleBean;
+import com.sunzee.model.message.ApiMessageEvent;
+import com.sunzee.model.message.DownLoadMessageEvent;
+import com.sunzee.receiver.Alarmreceiver;
+import com.sunzee.retrofit.ApiCallback;
+import com.sunzee.retrofit.ApiClient;
+import com.sunzee.retrofit.ApiStores;
+import com.sunzee.utils.FileUtil;
+import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.TimeUtil;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
+import com.wuxiaolong.androidutils.library.LogUtil;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import io.reactivex.Observable;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.disposables.CompositeDisposable;
+import io.reactivex.observers.DisposableObserver;
+import io.reactivex.schedulers.Schedulers;
+import okhttp3.RequestBody;
+
+public class MyService extends Service {
+    private static final String TAG = "MyService";
+    //心跳
+    private Timer timerHeartbeat;
+    private TimerTask taskHeartbeat;
+
+    @Nullable
+    @Override
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        Log.d(TAG, "MyServiceonCreate: ");
+        EventBus.getDefault().register(this);
+    }
+
+    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+        Log.e(TAG, "onStartCommand: 开始心跳3");
+        Bundle extras = null;
+        if (intent != null) {
+            extras = intent.getExtras();
+        }
+
+        if (extras != null) {
+
+            int heartbeat = extras.getInt("heartbeat");
+            if (heartbeat == 3) {
+                stopHeartbeat();
+                Log.w(TAG, "onStartCommand: 开始心跳" + heartbeat);
+                Log.e(TAG, "onStartCommand: 开始心跳1");
+                startHeartbeat();
+            }
+            int first = extras.getInt("first");
+            if (first == 4) {
+                //第一次启动心跳
+                checkHeartData();
+            }
+        }
+        //进程保活相关
+        flags = START_STICKY;
+
+        //启用前台服务,主要是startForeground()
+        String ns = Context.NOTIFICATION_SERVICE;
+
+        //获得通知管理器
+        NotificationManager manager1 = (NotificationManager) getSystemService(ns);
+
+        Notification.Builder builder = new Notification.Builder(getApplicationContext());
+        builder.setSmallIcon(R.drawable.login_logo);
+        builder.setTicker("服务正在运行");
+        builder.setContentTitle("服务正在运行");
+        builder.setContentText("服务正在运行");
+        builder.setWhen(System.currentTimeMillis()); //设置时间
+        Notification notification = builder.build();
+
+        //定义通知行为
+        manager1.notify(0, notification);
+
+        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
+        //读者可以修改此处的Minutes从而改变提醒间隔时间
+        //此处是设置每隔55分钟启动一次
+        //这是55分钟的毫秒数
+        int Minutes = 55 * 60 * 1000;
+        //SystemClock.elapsedRealtime()表示1970年1月1日0点至今所经历的时间
+        long triggerAtTime = SystemClock.elapsedRealtime() + Minutes;
+        //此处设置开启AlarmReceiver这个Service
+        Intent i = new Intent(this, Alarmreceiver.class);
+        PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
+        //ELAPSED_REALTIME_WAKEUP表示让定时任务的出发时间从系统开机算起,并且会唤醒CPU。
+        manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, pi);
+
+        return super.onStartCommand(intent, flags, startId);
+        //进程保活相关
+
+        //return START_STICKY ;
+    }
+
+    /**
+     * 开始心跳
+     */
+    private void startHeartbeat() {
+        Log.e(TAG, "startHeartbeat: 开始心跳");
+        timerHeartbeat = new Timer();
+        taskHeartbeat = new TimerTask() {
+            @Override
+            public void run() {
+                //经纬度不为0
+//                if (Heartbeat.latitude != 0 && Heartbeat.longitude != 0) {
+                //系统管理不为空
+                String managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
+                if (managerId != null && !TextUtils.isEmpty(managerId)) {
+                  //  sendHeart();
+                }
+
+            }
+        };
+        timerHeartbeat.schedule(taskHeartbeat, 1000, 1000 * 60 * 5);
+    }
+
+    /**
+     * 发送心跳
+     */
+    private void sendHeart() {
+        Heartbeat.managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
+        Heartbeat.lastUpdateTime = TimeUtil.getStrCurTime();
+        HeartbeatBean heartbeatBean = new HeartbeatBean();
+        heartbeatBean.setCabinetHd(Heartbeat.cabinetHd);
+        heartbeatBean.setCabinetTm(Heartbeat.cabinetTm);
+        heartbeatBean.setFurnaceSp("0");
+        heartbeatBean.setFurnaceTm(Heartbeat.furnaceTm);
+        heartbeatBean.setLastUpdateTime(Heartbeat.lastUpdateTime);
+        heartbeatBean.setLatitude(Heartbeat.latitude);
+        heartbeatBean.setLongitude(Heartbeat.longitude);
+        heartbeatBean.setManagerId(Heartbeat.managerId);
+        heartbeatBean.setOdorConcentration(Heartbeat.odorConcentration);
+        heartbeatBean.setCleaner(Heartbeat.cleaner);
+        heartbeatBean.setDisinfectant(Heartbeat.disinfectant);
+        heartbeatBean.setPeopleCounting(Heartbeat.peopleCounting);
+        int netType = (int) SharedPreferencesUtils.getParam(Name.NET_TYPE, -1);
+        if (netType == 0) {
+            Heartbeat.netWorkingMode = "4g";
+        } else if (netType == 1) {
+            Heartbeat.netWorkingMode = "wifi";
+        } else {
+            Heartbeat.netWorkingMode = "no";
+        }
+        heartbeatBean.setNetWorkingMode(Heartbeat.netWorkingMode);
+        heartbeatBean.setGtClientId(Heartbeat.clientId);
+        heartbeatBean.setClientId(Heartbeat.deviceId);
+        Gson gson = new Gson();
+        String json = gson.toJson(heartbeatBean);
+        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=utf-8"), json);
+        addSubscription(apiStores.heart(body), new ApiCallback<HttpResult<String>>() {
+            @Override
+            public void onSuccess(HttpResult<String> model) {
+                Log.d(TAG, "heartonSuccess: " + model);
+            }
+
+            @Override
+            public void onFailure(String msg) {
+                Log.d(TAG, "heartononFailure: " + msg);
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
+    /**
+     * 检测心跳数据以及开始心跳
+     */
+    private void checkHeartData() {
+        //系统管理不为空
+        Heartbeat.managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
+        if (Heartbeat.managerId != null && !TextUtils.isEmpty(Heartbeat.managerId)) {
+            Log.e(TAG, "checkHeartData: 开始心跳2");
+            startHeartbeat();
+            LogUtil.i(TAG + "系统管理id为" + Heartbeat.managerId);
+        } else {
+            LogUtil.i(TAG + "系统管理id为空");
+        }
+    }
+
+    /**
+     * 停止心跳
+     */
+    private void stopHeartbeat() {
+        if (timerHeartbeat != null) {
+            taskHeartbeat.cancel();
+            timerHeartbeat.cancel();
+            timerHeartbeat = null;
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        EventBus.getDefault().unregister(this);
+    }
+
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void event(ApiMessageEvent messageEvent) {
+        switch (messageEvent.getName()) {
+            case "statusType1":
+                //同步数据
+                //showSyncDialog();
+                break;
+            case "DOWNKOADADCID":
+                //上传设备id,返回该id的的广告资源
+                Log.d(TAG, "event: ");
+                downAdvertising((String) messageEvent.getData());
+                break;
+            default:
+                break;
+
+        }
+    }
+
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void event(DownLoadMessageEvent messageEvent) {
+        switch (messageEvent.getType()) {
+            case success:
+                //先下载B屏广告 再下载A屏广告 然后窗口消失
+                //下载成功
+                ToastUtil.showToast("下载成功");
+                Log.e(TAG, "event: 下载成功" + messageEvent.getData() + "index=" + currentIndex + " size-1=" + (getAdBeansBackup.size() - 1) + "  size" + getAdBeansBackup.size());
+                //只下载公司宣传视频
+                if (messageEvent.getScreenType() == 0) {
+                    if (currentIndex == corporationAdBeans.size() - 1) {
+                        Log.e(TAG, "event: A屏下载完成");
+                        //B屏广告下完
+//                        if (syncDialog != null) {
+//                            syncDialog.setAdState(R.string.sync_success);
+////                            syncDialog.dismiss();
+//                        }
+//不同的 删除本地文件(旧广告)
+                        for (int i = 0; i < allFileA.size(); i++) {
+                            File file = allFileA.get(i);
+                            if (file != null && file.exists()) {
+                                Log.e(TAG, "onNext:删除的A屏广告 " + file.getName());
+                                file.delete();
+
+                            }
+                        }
+                        getAdRuleId("1");
+                        Hawk.put("showAdA", getAdBeansA);
+                        //推送给购买页和制作页更新
+                        EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadAll, "", -1));
+                        return;
+                    }
+
+
+                } else if (messageEvent.getScreenType() == 1) {
+                    //B屏最后一个下载完 保存数据
+                    if (currentIndex == getAdBeansBackup.size() - 1) {
+                        currentIndex = 0;
+                        Hawk.put("showAd", getAdBeans);
+                        //全部默认显示 添加数据
+                        for (int i = 0; i < getAdBeans.size(); i++) {
+                            GetAdBean getAdBean = getAdBeans.get(i);
+                            if (getAdBean.getLocationType().equals("棉花糖宣传广告")) {
+                                showSugar.put(i, getAdBean);
+                            }
+                            if (getAdBean.getLocationType().equals("外接广告")) {
+                                showOut.put(i, getAdBean);
+                            }
+                        }
+                        Hawk.put("show_sugar", showSugar);
+                        Hawk.put("show_out", showOut);
+                        Log.d(TAG, "synAdSuccess:保存完成广告数据4" + getAdBeans.size());
+                        SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
+                        SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
+                        //不同的 删除本地文件(旧广告)
+                        for (int i = 0; i < allFile.size(); i++) {
+                            File file = allFile.get(i);
+                            if (file != null && file.exists()) {
+                                Log.e(TAG, "onNext:删除的B屏广告 " + file.getName());
+                                file.delete();
+
+                            }
+                        }
+                        //开始下载公司宣传视频
+                        currentIndex = 0;
+                        downLoadFile(currentIndex, "", corporationAdBeans);
+                        getAdBeansBackup.clear();
+                        return;
+                    }
+
+                }
+                if (messageEvent.getScreenType() == 1) {
+                    //开始下载B屏广告
+                    Log.e(TAG, "event: 开始下载B屏广告");
+                    currentIndex++;//下载成功一个
+                    if (currentIndex < getAdBeansBackup.size()) {
+                        downLoadFile(currentIndex, getAdBeansBackup.get(currentIndex).getAdType(), getAdBeansBackup);
+                    }
+                } else if (messageEvent.getScreenType() == 0) {
+                    //开始下载A屏广告
+                    Log.e(TAG, "event: 开始下载A屏广告");
+                    currentIndex++;//下载成功一个
+                    if (currentIndex < corporationAdBeans.size()) {
+                        downLoadFile(currentIndex, corporationAdBeans.get(currentIndex).getAdType(), corporationAdBeans);
+                    }
+                }
+
+                break;
+            case failed:
+                //下载失败
+                ToastUtil.showToast("下载失败" + messageEvent.getData());
+                Log.d(TAG, "event: 下载失败" + messageEvent.getData());
+                String strCurTime = TimeUtil.getStrCurTime();
+                Map<String, String> parms = new HashMap();
+                parms.put("clientId", Heartbeat.deviceId);
+                parms.put("pushUpdateTime", strCurTime);
+                addSubscription(apiStores.pushTimeUpdate(parms), new ApiCallback<HttpResult<String>>() {
+                    @Override
+                    public void onSuccess(HttpResult<String> model) {
+                        Log.e(TAG, "onNext: 上传失败成功 ");
+                    }
+
+                    @Override
+                    public void onFailure(String msg) {
+
+                    }
+
+                    @Override
+                    public void onFinish() {
+
+                    }
+                });
+                break;
+            default:
+                break;
+
+        }
+    }
+
+    //要显示的棉花糖广告<index,name>
+    private Map<Integer, GetAdBean> showSugar;
+    //要显示的外接广告<index,name>
+    private Map<Integer, GetAdBean> showOut;
+    //显示的数据
+    private ArrayList<GetAdBean> getAdBeans;
+    private ArrayList<GetAdBean> getAdBeansA;
+    //用于下载
+    private ArrayList<GetAdBean> getAdBeansBackup;
+    //公司宣传广告
+    private ArrayList<GetAdBean> corporationAdBeans;
+    //当前下载的索引
+    private static int currentIndex;
+    //下载成功后要删除的文件
+    private ArrayList<File> allFile;
+    private ArrayList<File> allFileA;
+
+    /**
+     * 上传设备id,返回该id的的广告资源
+     *
+     * @param s 要播放的数据
+     */
+    private void downAdvertising(String s) {
+        showSugar = Hawk.get("show_sugar", new HashMap<Integer, GetAdBean>());
+        showOut = Hawk.get("show_out", new HashMap<Integer, GetAdBean>());
+        getAdBeans = new ArrayList<>();
+        getAdBeansA = new ArrayList<>();
+        getAdBeansBackup = new ArrayList<>();
+        Gson gson = new Gson();
+        //广告实体
+        getAdBeans = gson.fromJson(s, new TypeToken<List<GetAdBean>>() {
+        }.getType());
+        getAdBeansBackup.addAll(getAdBeans);
+        //只有公司宣传广告
+        corporationAdBeans = new ArrayList<>();
+        List<GetAdBean> indexList = new ArrayList<>();
+        for (int i = 0; i < getAdBeansBackup.size(); i++) {
+            if (getAdBeansBackup.get(i).getScreenType() == 0) {
+                corporationAdBeans.add(getAdBeansBackup.get(i));
+                indexList.add(getAdBeansBackup.get(i));
+            }
+        }
+        for (int i = 0; i < indexList.size(); i++) {
+            getAdBeansBackup.remove(indexList.get(i));
+            getAdBeans.remove(indexList.get(i));
+        }
+        getAdBeansA.addAll(corporationAdBeans);
+        currentIndex = 0;
+        //全部默认显示 添加数据
+        for (int i = 0; i < getAdBeansBackup.size(); i++) {
+            showSugar.put(i, getAdBeansBackup.get(i));
+            showOut.put(i, getAdBeansBackup.get(i));
+        }
+        Hawk.put("show_sugar", showSugar);
+        Hawk.put("show_out", showOut);
+
+        getFilesDir();
+        LogUtil.d(TAG, "initView: " + getFilesDir().getName());
+        //本地的所有广告数据
+
+        File externalFilesDir = BaseApplication.getContext().getExternalFilesDir("");
+        if (externalFilesDir == null) {
+            externalFilesDir.mkdir();
+        }
+        if (!externalFilesDir.exists()) {
+            externalFilesDir.mkdirs();
+        }
+        //1 本地的所有广告数据
+        File[] allFiles = FileUtil.getAllFiles(Environment.getExternalStorageDirectory().getPath() + "/rightvideoimg/", "");
+        //A屏
+        File[] allFilesA = FileUtil.getAllFiles(Environment.getExternalStorageDirectory().getPath() + "/leftvideoimg/", "");
+        allFile = new ArrayList<>();
+        allFileA = new ArrayList<>();
+        List<File> files = Arrays.asList(allFilesA);
+        allFileA.addAll(files);
+        if (allFiles != null && allFiles.length >= 0) {
+
+            for (int i = 0; i < allFiles.length; i++) {
+                allFile.add(allFiles[i]);
+            }
+        }
+
+        //备份一个list用于删除
+        //另外一个用于显示
+        //相同 不下载(删除一个实体) 不删除本地文件
+
+        ArrayList<File> unDeleteFiles = new ArrayList<>();
+        if (allFiles != null) {
+            for (int i = 0; i < allFiles.length; i++) {
+                File file = allFiles[i];
+                String name = allFiles[i].getName();
+                LogUtil.d(TAG, "onNext: 本地的所有文件:" + name);
+                for (int j = 0; j < getAdBeansBackup.size(); j++) {
+                    GetAdBean getAdBean = getAdBeansBackup.get(j);
+                    String id = getAdBean.getId();
+                    //前缀名
+                    String caselsh = name.substring(0, name.lastIndexOf("."));
+                    if (id.equals(caselsh)) {
+                        //相同的删除url 不下载
+                        LogUtil.e(TAG, "onNext不下载的文件: " + name);
+//                                        timeDatas.remove(j);
+                        getAdBeansBackup.remove(j);
+                        //记住不删除的文件
+                        unDeleteFiles.add(file);
+                    }
+                }
+
+            }
+
+            for (int i = 0; i < unDeleteFiles.size(); i++) {
+                LogUtil.e(TAG, "onNext: unDeleteFiles name=" + unDeleteFiles.get(i).getName());
+            }
+
+
+            //只剩下删除的文件
+            allFile.removeAll(unDeleteFiles);
+        }
+
+        ArrayList<File> unDeleteFilesA = new ArrayList<>();
+        if (allFilesA != null) {
+            for (int i = 0; i < allFilesA.length; i++) {
+                File file = allFilesA[i];
+                String name = allFilesA[i].getName();
+                LogUtil.e(TAG, "onNext: A屏本地的所有文件:" + name);
+                //时间,用于判断唯一
+                //跟网络数据进行对比 如果id一样的不进行下载
+                for (int j = 0; j < corporationAdBeans.size(); j++) {
+                    GetAdBean getAdBean = corporationAdBeans.get(j);
+                    String id = getAdBean.getId();
+                    //前缀名
+                    String caselsh = name.substring(0, name.lastIndexOf("."));
+                    if (id.equals(caselsh)) {
+                        //相同的删除url 不下载
+                        LogUtil.e(TAG, "onNext不下载的文件: " + name);
+                        corporationAdBeans.remove(j);
+                        //记住不删除的文件
+                        unDeleteFilesA.add(file);
+                    }
+                }
+            }
+            //只剩下删除的文件
+            allFileA.removeAll(unDeleteFilesA);
+        }
+
+        //3 下载数据
+        if (getAdBeansBackup.size() <= 0) {
+            LogUtil.e(TAG, "onNext: 推送过来的B屏数据相同,不下载");
+            Hawk.put("showAd", getAdBeans);
+            //全部默认显示 添加数据
+            for (int i = 0; i < getAdBeans.size(); i++) {
+                showSugar.put(i, getAdBeans.get(i));
+                showOut.put(i, getAdBeans.get(i));
+            }
+            Hawk.put("show_sugar", showSugar);
+            Hawk.put("show_out", showOut);
+            LogUtil.d(TAG, "synAdSuccess:保存完成广告数据3" + getAdBeans.size());
+            SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
+            //todo
+//                            if (syncDialog != null) {
+//                                syncDiaLogUtil.setAdState(R.string.sync_success);
+//                                syncDiaLogUtil.dismiss();
+//                            }
+            if (corporationAdBeans.size() <= 0) {
+                LogUtil.e(TAG, "onNext: 推送过来的A屏数据相同,不下载");
+                Hawk.put("showAdA", getAdBeansA);
+                //todo
+//                if (syncDialog != null) {
+//                    syncDiaLogUtil.setAdState(R.string.sync_success);
+//                    getAdRuleId("1");
+//                }
+            } else {
+                downLoadFile(0, "", corporationAdBeans);
+            }
+            return;
+        }
+        downLoadFile(currentIndex, "", getAdBeansBackup);
+        //开始下载
+        LogUtil.e(TAG, "synProductSuccess:同步广告管理成功 ");
+        LogUtil.e(TAG, "synProductSuccess:全部同步成功 ");
+    }
+
+    private CompositeDisposable mDisposables;
+    protected ApiStores apiStores = ApiClient.retrofit().create(ApiStores.class);
+
+    protected void addSubscription(Observable observable, DisposableObserver observer) {
+        if (mDisposables == null) {
+            mDisposables = new CompositeDisposable();
+        }
+        observable
+                .unsubscribeOn(Schedulers.io())
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(observer);
+        mDisposables.add(observer);
+    }
+
+    /**
+     * 保存广告id
+     */
+    private void getAdRuleId(String id) {
+
+
+        Map<String, String> params = new HashMap<>();
+        params.put("clientId", Heartbeat.deviceId);
+
+        addSubscription(apiStores.synTimeRule(params), new ApiCallback<HttpResult<String>>() {
+            @Override
+            public void onSuccess(HttpResult<String> model) {
+                saveAdRules(model.getData());
+            }
+
+            @Override
+            public void onFailure(String msg) {
+
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+
+
+    }
+
+    /**
+     * 保存广告id
+     */
+    private void saveAdRules(String id) {
+        LogUtil.d(TAG, "ad_id ->" + id);
+        Long lid = Long.valueOf(id);
+        Map<String, Long> params = new HashMap<>();
+        params.put("id", lid);
+        addSubscription(apiStores.getTimeRule(params), new ApiCallback<HttpResult<String>>() {
+
+            @Override
+            public void onSuccess(HttpResult<String> rule) {
+                //广告数据
+                ArrayList<GetAdBean> adBeans = Hawk.get("showAd", new ArrayList<GetAdBean>());
+                Gson gson = new Gson();
+                List<TimeRuleBean> list = gson.fromJson(rule.getData(), new TypeToken<List<TimeRuleBean>>() {
+                }.getType());
+                //每个id对应的时间数
+                Map<String, String> adRulesMap = new HashMap<>();
+                for (int i = 0; i < adBeans.size(); i++) {
+                    GetAdBean getAdBean = adBeans.get(i);
+                    StringBuilder sb = new StringBuilder();
+                    for (int j = 0; j < list.size(); j++) {
+                        //每个规则里对应的广告
+                        List<String> ad = list.get(j).getAd();
+                        for (int k = 0; k < ad.size(); k++) {
+                            if (ad.get(k).equals(getAdBean.getId())) {
+                                sb.append(list.get(j).getTime() + "、");
+                            }
+                        }
+                    }
+                    if (sb.length() > 0) {
+                        sb.deleteCharAt(sb.length() - 1);
+                    }
+
+                    Log.e(TAG, "onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
+                    adRulesMap.put(getAdBean.getId(), sb.toString());
+                }
+                //保存对应的id对应的广告规则
+                Hawk.put("ad_rules_map", adRulesMap);
+
+//                if (syncDialog != null) {
+//                    syncDialog.setAdRuleState(R.string.sync_success);
+//                    syncDialog.dismiss();
+//                }
+            }
+
+            @Override
+            public void onFailure(String msg) {
+
+            }
+
+            @Override
+            public void onFinish() {
+
+            }
+        });
+    }
+
+    /**
+     * 下载文件
+     *
+     * @param index 下载索引 第几个
+     * @param type  没有
+     * @param datas 要下载数据列表
+     */
+    private void downLoadFile(int index, String type, ArrayList<GetAdBean> datas) {
+        //开始下载
+        Intent downloadApkIntent = new Intent(getApplicationContext(), DownServer.class);
+        Bundle bundle = new Bundle();
+        if (datas.size() <= 0) {
+            return;
+        }
+        GetAdBean getAdBean = datas.get(index);
+        String url = getAdBean.getUrl();
+        if (TextUtils.isEmpty(url)) {
+            //todo
+//            if (syncDialog != null) {
+//                syncDialog.setAdState(R.string.synchroniz_fail);
+//                syncDialog.dismiss();
+//            }
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.synchroniz_fail));
+            return;
+        }
+        String type1 = url.substring(url.lastIndexOf(".") + 1);
+        bundle.putString("downloadUrl", url);
+        bundle.putString("download_name", getAdBean.getName());
+        String time = TimeUtil.getNoTime(getAdBean.getCreateDate());
+        Log.d(TAG, "downLoadFile: time=" + time);
+        bundle.putString("title", getAdBean.getId());
+        Log.d(TAG, "downLoadFile: 开始下载" + getAdBean.getId());
+        bundle.putString("downloadtype", type1);
+        bundle.putInt("scrrentype", getAdBean.getScreenType());
+        downloadApkIntent.putExtra("download", bundle);
+        getApplicationContext().startService(downloadApkIntent);
+    }
+}

+ 203 - 0
app/src/main/java/com/sunzee/ui/activity/AdvertisingActivity.java

@@ -0,0 +1,203 @@
+package com.sunzee.ui.activity;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.annotation.Nullable;
+import android.text.format.DateFormat;
+import android.view.SurfaceView;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.sunzee.R;
+import com.sunzee.base.MvpActivity;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.message.ApiMessageEvent;
+import com.sunzee.model.message.DownLoadMessageEvent;
+import com.sunzee.mvp.advertising.AdvertisingPresenter;
+import com.sunzee.mvp.advertising.AdvertisingView;
+import com.sunzee.utils.GeTuiUtil;
+import com.sunzee.utils.LongClickUtils;
+import com.sunzee.utils.SimplePlayerUtils;
+import com.wuxiaolong.androidutils.library.LogUtil;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * 广告界面
+ */
+public class AdvertisingActivity extends MvpActivity<AdvertisingPresenter> implements AdvertisingView {
+
+
+    private static final String TAG = "AdvertisingActivity";
+    private SurfaceView mAdSurfaceView;
+    private SurfaceView mAdbSurfaceView;
+    private SimplePlayerUtils mRightsimplePlayer;
+    private SimplePlayerUtils mLeftsimplePlayer;
+    private ImageView mAdImageview;
+    private ImageView mAdbImageview;
+    private GeTuiUtil mGeTuiUtil;
+    private RelativeLayout mRlRoot;
+    private TextView mTvTime;
+    private MyHandler myHandler;
+    private TextView mTvEquipmentNo;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_advertising);
+        EventBus.getDefault().register(this);
+        mGeTuiUtil = new GeTuiUtil(this);
+        mGeTuiUtil.geTui();
+        initView();
+        initEvent();
+
+    }
+
+    private void initEvent() {
+        LongClickUtils.setLongClick(new Handler(), mRlRoot, 10, new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                Intent intent = new Intent(AdvertisingActivity.this, LoginActivity.class);
+                startActivity(intent);
+                finish();
+                return false;
+            }
+        });
+    }
+
+    private void initView() {
+        myHandler = new MyHandler();
+        mAdSurfaceView = findViewById(R.id.sf_cor_ad);
+        mAdImageview = findViewById(R.id.iv_cor_ad);
+        mAdbSurfaceView = findViewById(R.id.sf_cor_adb);
+        mAdbImageview = findViewById(R.id.iv_cor_adb);
+        mRlRoot = findViewById(R.id.rl_root);
+        mTvTime = findViewById(R.id.tv_time1);
+        mTvEquipmentNo = findViewById(R.id.tv_equipment_no1);
+        mTvEquipmentNo.setText(Heartbeat.deviceId != null ? Heartbeat.deviceId.substring(Heartbeat.deviceId.length() - 6) : "");
+        //1.初始化播放器
+        mRightsimplePlayer = new SimplePlayerUtils(mAdSurfaceView);
+        mRightsimplePlayer.setImageView(mAdImageview);
+        mLeftsimplePlayer = new SimplePlayerUtils(mAdbSurfaceView);
+        mLeftsimplePlayer.setImageView(mAdbImageview);
+        play();
+        startRefreshime();
+    }
+
+    private void play() {
+        mvpPresenter.play();
+    }
+
+
+    @Override
+    public void playLeft(ArrayList<File> playFileList) {
+        mLeftsimplePlayer.setFileData(playFileList);
+        mLeftsimplePlayer.playVideo();
+    }
+
+    @Override
+    public void playRight(ArrayList<File> playFile) {
+        mRightsimplePlayer.setFileData(playFile);
+        mRightsimplePlayer.playVideo();
+    }
+
+    @Override
+    public void updateTime(CharSequence sysTimeStr) {
+        mTvTime.setText(sysTimeStr);
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        mLeftsimplePlayer.onDestroy();
+        mRightsimplePlayer.onDestroy();
+
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        EventBus.getDefault().unregister(this);
+        myHandler.removeCallbacksAndMessages(null);
+        myHandler = null;
+        stopRefreshTime();
+    }
+
+    //个推相关
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void event(DownLoadMessageEvent messageEvent) {
+        switch (messageEvent.getType()) {
+            case downloadAll:
+                play();
+                break;
+            default:
+                break;
+
+        }
+    }
+
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void event(ApiMessageEvent messageEvent) {
+        switch (messageEvent.getName()) {
+            case "pushTimeRule":
+                //推送最新规则
+                LogUtil.e(TAG, "event: 接收到规则");
+                play();
+                break;
+        }
+    }
+
+    @Override
+    protected AdvertisingPresenter createPresenter() {
+        return new AdvertisingPresenter(this);
+    }
+
+    public class MyHandler extends Handler {
+
+        @Override
+        public void handleMessage(android.os.Message msg) {
+            switch (msg.what) {
+                case 1:
+                    long sysTime = System.currentTimeMillis();//获取系统时间
+                    CharSequence sysTimeStr = DateFormat.format("yyyy-MM-dd HH:mm:ss", sysTime);//时间显示格式
+                    mTvTime.setText(sysTimeStr);
+                    break;
+            }
+        }
+    }
+
+    private Timer timerGetTime;
+    private TimerTask timerGetTimerTak;
+
+    private void startRefreshime() {
+        timerGetTime = new Timer();
+        timerGetTimerTak = new TimerTask() {
+            @Override
+            public void run() {
+                myHandler.sendEmptyMessage(1);
+            }
+        };
+        timerGetTime.schedule(timerGetTimerTak, 0, 1000);
+    }
+
+    private void stopRefreshTime() {
+        if (timerGetTime != null) {
+            timerGetTime.cancel();
+            timerGetTime = null;
+        }
+        if (timerGetTimerTak != null) {
+            timerGetTimerTak.cancel();
+            timerGetTimerTak = null;
+        }
+    }
+}

+ 274 - 48
app/src/main/java/com/sunzee/ui/activity/HomeActivity.java

@@ -1,8 +1,14 @@
 package com.sunzee.ui.activity;
 
 import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
+import android.os.Environment;
 import android.support.annotation.NonNull;
+import android.support.annotation.RequiresApi;
 import android.support.design.widget.NavigationView;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -10,37 +16,54 @@ import android.text.TextUtils;
 import android.util.Log;
 import android.view.MenuItem;
 import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.sunzee.R;
 import com.sunzee.base.BaseFragment;
 import com.sunzee.base.MvpActivity;
-import com.sunzee.model.domain.Heartbeat;
+import com.sunzee.model.Heartbeat;
+import com.sunzee.model.domain.ApkInfoBean;
 import com.sunzee.model.domain.Name;
 import com.sunzee.model.message.ApiMessageEvent;
+import com.sunzee.model.message.DownLoadMessageEvent;
 import com.sunzee.mvp.home.HomePresenter;
 import com.sunzee.mvp.home.HomeView;
+import com.sunzee.service.DownPresenter;
+import com.sunzee.service.MyService;
 import com.sunzee.ui.dialog.ManagementSystemDialog;
+import com.sunzee.ui.dialog.NormalDialog;
+import com.sunzee.ui.dialog.ShutdownDialog;
 import com.sunzee.utils.FileUtil;
-import com.sunzee.utils.GeTuiUtil;
 import com.sunzee.utils.HomePagerSimpleFactory;
 import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
 
+import java.io.File;
 
-public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView {
+/**
+ * 后台首页 page
+ */
+public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView, View.OnClickListener, DownPresenter.ProgressUpdate {
 
     private NavigationView mNavigationView;
     private FragmentManager mFragmentManager;
-    private GeTuiUtil mGeTuiUtil;
+
     private TextView mTvConnectionSystem;
     private String systemId;
     private TextView mTvSystemId;
     private ManagementSystemDialog mManagementSystemDialog;
     private static final String TAG = "HomeActivity";
+    private TextView mTvVersion;
+    private TextView mTvUpdataAPK;
+    private LinearLayout mLlBlack;
+    private ImageView mIvShutownLogo;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -48,7 +71,6 @@ public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView
         setContentView(R.layout.activity_home);
         initView();
         initEvent();
-
     }
 
     @Override
@@ -57,12 +79,26 @@ public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView
         EventBus.getDefault().register(this);
     }
 
-    @Override
-    protected void onStop() {
-        super.onStop();
-        EventBus.getDefault().unregister(this);
+    private void initView() {
+        mNavigationView = findViewById(R.id.bnv_main_navigationbar);
+        mTvVersion = findViewById(R.id.tv_version);
+        mTvUpdataAPK = findViewById(R.id.tv_updatapk);
+        mLlBlack = findViewById(R.id.ll_black);
+        mIvShutownLogo = findViewById(R.id.iv_shutown_logo);
+        mNavigationView.setItemIconTintList(null);
+        mIvShutownLogo.setOnClickListener(this);
+        mFragmentManager = getSupportFragmentManager();
+        mTvConnectionSystem = findViewById(R.id.connection_system);
+        mTvSystemId = findViewById(R.id.tv_system_id);
+        String managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
+        if (managerId != null && !TextUtils.isEmpty(managerId)) {
+            cheeckConnectState(false);
+        }
+        DownPresenter downPresenter = DownPresenter.getInstance();
+        downPresenter.setProgressUpdate(this);
     }
 
+
     private void initEvent() {
         mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
             @Override
@@ -75,42 +111,103 @@ public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView
                 return true;
             }
         });
-        mTvConnectionSystem.setOnClickListener(new View.OnClickListener() {
+        mTvConnectionSystem.setOnClickListener(this);
+        mTvUpdataAPK.setOnClickListener(this);
+        mLlBlack.setOnClickListener(this);
+
+    }
+
+    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.connection_system:
+                //连接服务器
+                connectToServer();
+                break;
+            case R.id.tv_updatapk:
+                //检查更新
+                mvpPresenter.updataapk();
+                break;
+            case R.id.ll_black:
+                gotoAdvertisingActivity();
+                break;
+            case R.id.iv_shutown_logo:
+                showGuanjiDialog();
+                break;
+        }
+    }
+
+    private void gotoAdvertisingActivity() {
+        startActivity(new Intent(HomeActivity.this, AdvertisingActivity.class));
+        finish();
+    }
+
+    /**
+     * 连接服务器
+     */
+    private void connectToServer() {
+        if (mManagementSystemDialog == null) {
+            mManagementSystemDialog = new ManagementSystemDialog(HomeActivity.this);
+        }
+        mManagementSystemDialog.setCanceledOnTouchOutside(true);
+        mManagementSystemDialog.setListener(new ManagementSystemDialog.DialogClickListener() {
+
             @Override
-            public void onClick(View view) {
-                if (mManagementSystemDialog == null) {
-                    mManagementSystemDialog = new ManagementSystemDialog(HomeActivity.this);
-                }
-                mManagementSystemDialog.setCanceledOnTouchOutside(true);
-                mManagementSystemDialog.setListener(new ManagementSystemDialog.DialogClickListener() {
-                    @Override
-                    public void onClickListener(int type, String text) {
-                        switch (type) {
-                            case R.id.btn_apply:
-                                systemId = text;
-                                mvpPresenter.connectionSystem(text);
-                                SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 1);
-                                mTvSystemId.setText("连接申请中");
-                                mTvConnectionSystem.setVisibility(View.GONE);
-                                break;
+            public void onClickListener(int type, String text) {
+                switch (type) {
+                    case R.id.btn_apply:
+                        if (Heartbeat.clientId == null || Heartbeat.clientId.equals("")) {
+                            ToastUtil.showToast(UiUtil.getStringRes(R.string.idsb));
+                            return;
                         }
-                    }
-                });
-                mManagementSystemDialog.show();
+                        systemId = text;
+                        mvpPresenter.connectionSystem(text);
+                        SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 1);
+                        mTvSystemId.setText("连接申请中");
+                        mTvConnectionSystem.setVisibility(View.GONE);
+                        ToastUtil.showToast("连接申请中,请稍后!");
+                        break;
+                }
             }
         });
+        mManagementSystemDialog.show();
     }
 
     @Subscribe(threadMode = ThreadMode.MAIN)
     public void event(ApiMessageEvent messageEvent) {
         switch (messageEvent.getName()) {
             case "statusType":
-                //刷新界面
+                //刷新界面:心跳
                 cheeckConnectState(true);
                 break;
         }
     }
 
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void event(DownLoadMessageEvent messageEvent) {
+        switch (messageEvent.getType()) {
+            case downloadApkSuccess:
+                //下载成功安装
+                Intent intent = new Intent(Intent.ACTION_VIEW);
+                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                File file = new File(Environment.getExternalStorageDirectory().getPath() + "/apk/" + "mht.apk");
+                intent.setDataAndType(Uri.fromFile(new File(file.getAbsolutePath())),
+                        "application/vnd.android.package-archive");
+                startActivity(intent);
+                if (updateDialog != null) {
+                    updateDialog.dismiss();
+                }
+                break;
+            case downloadApkProcess:
+                //下载apk进度更新
+                break;
+            default:
+                break;
+        }
+    }
+
+
     /**
      * 检查连接状态并更新界面
      *
@@ -124,14 +221,22 @@ public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView
                 mTvSystemId.setVisibility(View.VISIBLE);
                 mTvSystemId.setText("已连接:" + param);
                 mTvConnectionSystem.setVisibility(View.GONE);
+                ToastUtil.showToast("连接成功");
             }
-            Log.e(TAG, "cheeckConnectState:连接成功: " + connectState);
             SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
             Heartbeat.deviceId = FileUtil.getDeviceId();
+            Log.d(TAG, "cheeckConnectState: " + isFrist);
+            if (isFrist) {
+                //开始心跳
+                Intent intent = new Intent(HomeActivity.this, MyService.class);
+                Bundle bundle = new Bundle();
+                bundle.putInt("heartbeat", 3);
+                intent.putExtras(bundle);
+                startService(intent);
+            }
         } else if (connectState == 1) {
             mTvSystemId.setText("连接申请中!!!");
             mTvConnectionSystem.setVisibility(View.GONE);
-            Log.e(TAG, "cheeckConnectState: 正在连接: " + connectState);
         } else if (connectState == 0) {
             mTvConnectionSystem.setVisibility(View.VISIBLE);
             mTvSystemId.setVisibility(View.GONE);
@@ -144,29 +249,150 @@ public class HomeActivity extends MvpActivity<HomePresenter> implements HomeView
         return fragment;
     }
 
-    private void initView() {
-        mNavigationView = findViewById(R.id.bnv_main_navigationbar);
-        mNavigationView.setItemIconTintList(null);
-        mFragmentManager = getSupportFragmentManager();
-        mGeTuiUtil = new GeTuiUtil(this);
-        mGeTuiUtil.geTui();
+    private void switchFragment(BaseFragment fragment) {
+        FragmentTransaction ftransaction = mFragmentManager.beginTransaction();
+        ftransaction.replace(R.id.fl_home_content, fragment);
+        ftransaction.commit();
+    }
 
-        mTvConnectionSystem = findViewById(R.id.connection_system);
-        mTvSystemId = findViewById(R.id.tv_system_id);
-        String managerId = (String) SharedPreferencesUtils.getParam(Name.SYSTEM_ID, "");
-        if (managerId != null && !TextUtils.isEmpty(managerId)) {
+    @Override
+    protected HomePresenter createPresenter() {
+        return new HomePresenter(this);
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        EventBus.getDefault().unregister(this);
+    }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+    }
+
+    @Override
+    public void initSuccess(String result) {
+        if (result.equals("设备申请中,请耐心等待")) {
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.connecting1));
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 1);
             cheeckConnectState(false);
+        } else if (result.equals("该设备已经初始化")) {
+            //连接成功
+            //在service进行同步
+            EventBus.getDefault().post(new ApiMessageEvent("statusType" + "1", null));
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
+            Log.e(TAG, "statusType: 申请通过");
+            SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
+            cheeckConnectState(false);
+            Heartbeat.deviceId = FileUtil.getDeviceId();
+        } else if (result.equals("找不到商家")) {
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
+        } else if (result.equals("设备商家类型错误")) {
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
+        } else {
+            SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
         }
     }
 
+    // 是否要更新
+    private boolean isUpdate;
+
     @Override
-    protected HomePresenter createPresenter() {
-        return new HomePresenter(this);
+    public void updataSuccess(ApkInfoBean apkInfoBean) {
+        //当前版本号
+        int versionCode = getVersionCode();
+        //下载的版本号
+        int version = apkInfoBean.getVersion();
+        if (version > versionCode) {
+            //更新
+            isUpdate = true;
+            showUpdateDialog(apkInfoBean.getVersionName(), isUpdate, version, apkInfoBean.getDownloadUrl(), apkInfoBean.getVersionInfo());
+        } else {
+            //不更新
+            isUpdate = false;
+            showUpdateDialog(apkInfoBean.getVersionName(), isUpdate, version, apkInfoBean.getDownloadUrl(), apkInfoBean.getVersionInfo());
+        }
     }
 
-    private void switchFragment(BaseFragment fragment) {
-        FragmentTransaction ftransaction = mFragmentManager.beginTransaction();
-        ftransaction.replace(R.id.fl_home_content, fragment);
-        ftransaction.commit();
+    /*
+     * 获取当前程序的版本号
+     */
+    private int getVersionCode() {
+        //获取packagemanager的实例
+        PackageManager packageManager = getPackageManager();
+        //getPackageName()是你当前类的包名,0代表是获取版本信息
+        PackageInfo packInfo = null;
+        try {
+            packInfo = packageManager.getPackageInfo(getPackageName(), 0);
+        } catch (PackageManager.NameNotFoundException e) {
+            e.printStackTrace();
+        }
+        return packInfo.versionCode;
+    }
+
+    //检查更新
+    private NormalDialog updateDialog;
+
+    /**
+     * 检查更新弹窗
+     *
+     * @param versionName 版本号
+     * @param isUpdate    是否要更新
+     * @param version     版本号
+     * @param url         下载地址
+     * @param versionInfo 更新内容
+     */
+    private void showUpdateDialog(String versionName, final boolean isUpdate, final int version, final String url, String versionInfo) {
+        if (updateDialog == null) {
+            updateDialog = new NormalDialog(HomeActivity.this);
+        }
+        updateDialog.setListener(new NormalDialog.DialogClickListener() {
+            @Override
+            public void onClickListener(int type) {
+                switch (type) {
+                    case R.id.btn_confirm:
+                        if (isUpdate) {
+                            //更新 下载
+                            mvpPresenter.downloadApk(url, version);
+                        } else {
+                            //不更新
+                            updateDialog.dismiss();
+                        }
+                        break;
+                    case R.id.btn_cancel:
+                        ToastUtil.showToast("取消");
+                        updateDialog.dismiss();
+                        break;
+                }
+            }
+        });
+        updateDialog.setUpdateContent(R.string.check_update, versionName, isUpdate, versionInfo);
+        updateDialog.show();
+    }
+
+    @Override
+    public void onProgressUpdate(double mDownload_so_far, double mDownload_all) {
+        if (updateDialog != null) {
+            updateDialog.setContent((int) ((mDownload_so_far / mDownload_all) * 100D));
+        }
+    }
+
+    private ShutdownDialog shutdownDialog;
+
+    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
+    private void showGuanjiDialog() {
+
+        if (shutdownDialog == null) {
+            shutdownDialog = new ShutdownDialog(HomeActivity.this);
+        }
+        shutdownDialog.setCanceledOnTouchOutside(true);
+        shutdownDialog.setListener(new ShutdownDialog.DialogClickListener() {
+            @Override
+            public void onClickListener(int type) {
+            }
+        });
+        shutdownDialog.setBtnText(R.string.guang_ji, R.string.guang_ji1, R.string.guan_ji_now, R.string.open_now);
+        shutdownDialog.show();
     }
 }

+ 87 - 0
app/src/main/java/com/sunzee/ui/activity/LoginActivity.java

@@ -0,0 +1,87 @@
+package com.sunzee.ui.activity;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.sunzee.R;
+import com.sunzee.base.MvpActivity;
+import com.sunzee.mvp.login.LoginPresenter;
+import com.sunzee.mvp.login.LoginView;
+import com.sunzee.utils.ToastUtil;
+
+/**
+ * 登录界面
+ */
+public class LoginActivity extends MvpActivity<LoginPresenter> implements LoginView, View.OnClickListener {
+
+    private EditText mEtUserName;
+    private EditText mEtUserPassword;
+    private TextView mTvUuserLogin;
+    private View mLlHideKeyMap;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_login);
+        initView();
+    }
+
+    private void initView() {
+        mEtUserName = findViewById(R.id.et_username);
+        mEtUserPassword = findViewById(R.id.et_userpassword);
+        mEtUserPassword.requestFocus();
+        mTvUuserLogin = findViewById(R.id.tv_userlogin);
+        mLlHideKeyMap = findViewById(R.id.ll_hidekeymap);
+        mTvUuserLogin.setOnClickListener(this);
+        mLlHideKeyMap.setOnClickListener(this);
+    }
+
+    @Override
+    protected LoginPresenter createPresenter() {
+        return new LoginPresenter(this);
+    }
+
+    @Override
+    public void loginSuccessful() {
+        ToastUtil.showToast("登录成功!");
+        Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
+        startActivity(intent);
+        finish();
+    }
+
+    @Override
+    public void loginUserFailed() {
+        ToastUtil.showToast("用户名或者密码错误,登录失败!!!");
+    }
+
+    @Override
+    public void inputEmpty() {
+        ToastUtil.showToast("请输入账户名或者密码!!");
+    }
+
+    @Override
+    public void laterInput(int time) {
+        ToastUtil.showToast("请在" + time + "秒后输入!");
+    }
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.ll_hidekeymap:
+                //隐藏键盘
+                InputMethodManager imm = (InputMethodManager)
+                        getSystemService(Context.INPUT_METHOD_SERVICE);
+                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+                break;
+            case R.id.tv_userlogin:
+                //登录功能,只需要提供字符串就可以进行一个判断。
+                mvpPresenter.login(mEtUserName.getText().toString().trim(), mEtUserPassword.getText().toString().trim());
+                break;
+        }
+    }
+}

+ 1 - 6
app/src/main/java/com/sunzee/ui/activity/MainActivity.java

@@ -5,21 +5,15 @@ import android.view.View;
 import android.widget.TextView;
 
 import com.google.gson.Gson;
-import com.google.gson.JsonParser;
 import com.sunzee.R;
 import com.sunzee.base.MvpActivity;
 import com.sunzee.model.EmailResult;
 import com.sunzee.mvp.main.MainPresenter;
 import com.sunzee.mvp.main.MainView;
-import com.sunzee.retrofit.ApiCallback;
-import com.sunzee.retrofit.ApiStores;
-import com.sunzee.retrofit.RetrofitCallback;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import retrofit2.Call;
-
 /**
  * 由Activity/Fragment实现View里方法,包含一个Presenter的引用
  */
@@ -32,6 +26,7 @@ public class MainActivity extends MvpActivity<MainPresenter> implements MainView
         setContentView(R.layout.activity_main);
         text = findViewById(R.id.text);
         initToolBarAsHome(getString(R.string.title));
+
     }
 
     @Override

+ 3 - 0
app/src/main/java/com/sunzee/ui/dialog/ManagementSystemDialog.java

@@ -11,6 +11,9 @@ import android.widget.Toast;
 
 import com.sunzee.R;
 
+/**
+ * 连接服务器的对话框
+ */
 public class ManagementSystemDialog extends Dialog {
     //在构造方法里提前加载了样式
     private Context context;//上下文

+ 190 - 0
app/src/main/java/com/sunzee/ui/dialog/NormalDialog.java

@@ -0,0 +1,190 @@
+package com.sunzee.ui.dialog;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Build;
+import android.support.annotation.RequiresApi;
+import android.support.v4.widget.TextViewCompat;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.sunzee.R;
+import com.sunzee.model.domain.Name;
+import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.UiUtil;
+
+/**
+ * @author whw
+ * @time 2019/3/13
+ * @Description 普通样式弹框
+ */
+public class NormalDialog extends Dialog implements View.OnClickListener {
+
+    public static final int OK = 2;
+    public static final int NO = 3;
+
+    private TextView tvTitle;
+    private TextView tvContent;
+    private Button btnConfirm;
+    private Button btnCancel;
+    private ImageView IvQrCode;
+    /**
+     * 中间进入进出动画(默认动画)
+     */
+    public static final int ANIM_CENTER_IN_OUT = 0;
+
+    public void setListener(DialogClickListener listener) {
+        this.listener = listener;
+    }
+
+    private DialogClickListener listener;
+
+
+    public NormalDialog(Context context) {
+        super(context, R.style.DialogBgD);//加载样式
+        setContentView(R.layout.dialog_normal);
+        initView();
+        this.setCanceledOnTouchOutside(false);
+    }
+
+    protected void initView() {
+        tvTitle = findViewById(R.id.tv_title);
+        tvContent = findViewById(R.id.tv_content);
+        btnConfirm = findViewById(R.id.btn_confirm);
+        btnCancel = findViewById(R.id.btn_cancel);
+        IvQrCode = findViewById(R.id.iv_qr_code);
+        btnConfirm.setOnClickListener(this);
+        btnCancel.setOnClickListener(this);
+
+    }
+
+    /**
+     * 设置文本
+     *
+     * @param title   标题
+     * @param content 内容
+     * @param btnText 按钮文字
+     */
+    public void setContent(int title, int content, int btnText) {
+
+        tvTitle.setText(title);
+        tvContent.setText(content);
+        btnConfirm.setText(btnText);
+    }
+
+
+    public void setContent(int title, int content) {
+        tvTitle.setText(title);
+        tvContent.setText(content);
+    }
+
+    /**
+     * set button text
+     *
+     * @param strIdTitle title text
+     * @param strId      shutdown text
+     * @param strid1     open text
+     */
+    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
+    public void setBtnText(int strIdTitle, int content, int strId, int strid1) {
+        tvTitle.setText(strIdTitle);
+        tvContent.setText(content);
+        btnConfirm.setText(strId);
+        btnCancel.setText(strid1);
+    //    btnCancel.setBackground(UiUtil.getDrawableRes(R.drawable.shape_btn_add));
+        btnCancel.setTextColor(UiUtil.getColorRes(R.color.white));
+    }
+
+    /**
+     * get the text of button
+     */
+    public String getBtnTextConfirm() {
+
+        return btnConfirm.getText().toString().trim();
+    }
+
+    /**
+     * get the text of buttonCancel
+     */
+    public String getBtnTextCancel() {
+
+        return btnCancel.getText().toString().trim();
+    }
+
+    /**
+     * 用于检查更新
+     *
+     * @param titleId     标题
+     * @param version     版本名
+     * @param isUpdate    是否要更新
+     * @param versionInfo 更新内容
+     */
+    public void setUpdateContent(int titleId, String version, boolean isUpdate, String versionInfo) {
+        tvTitle.setText(titleId);
+        if (isUpdate) {
+            //新版本 更新
+
+            tvContent.setText(UiUtil.getStringRes(R.string.have_update_content1) + version + "\n" + versionInfo);
+            btnConfirm.setText(R.string.update_now);
+        } else {
+            //不是 不更新
+            tvContent.setText(R.string.no_update);
+            btnConfirm.setText(R.string.confirm);
+        }
+
+    }
+
+    /**
+     * 设置文字
+     *
+     * @param text
+     */
+    public void setContent(String text) {
+        tvContent.setText(text);
+    }
+
+    /**
+     * 下载进度
+     */
+    public void setContent() {
+        tvContent.setText(UiUtil.getStringRes(R.string.download_now));
+    }
+
+    public void setContent(int size) {
+        tvContent.setText(UiUtil.getStringRes(R.string.download_now) + size + "%");
+    }
+
+    public void setBtnEgState() {
+        int param = (int) SharedPreferencesUtils.getParam(Name.LANGUAGE_TYPE, -1);
+        if (param == 2) {
+            btnCancel.setLines(1);
+            TextViewCompat.setAutoSizeTextTypeWithDefaults(btnCancel, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
+            btnConfirm.setLines(1);
+            TextViewCompat.setAutoSizeTextTypeWithDefaults(btnConfirm, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
+        }
+    }
+
+    @Override
+    public void onClick(View v) {
+
+        switch (v.getId()) {
+            case R.id.btn_cancel:
+                dismiss();
+                break;
+        }
+        listener.onClickListener(v.getId());
+
+    }
+
+    public void showCardImg() {
+        IvQrCode.setVisibility(View.VISIBLE);
+    }
+
+    public interface DialogClickListener {
+
+        void onClickListener(int type);
+
+    }
+}

+ 134 - 0
app/src/main/java/com/sunzee/ui/dialog/ShutdownDialog.java

@@ -0,0 +1,134 @@
+package com.sunzee.ui.dialog;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Build;
+import android.support.annotation.NonNull;
+import android.support.annotation.RequiresApi;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.sunzee.R;
+import com.sunzee.model.domain.Name;
+import com.sunzee.utils.SharedPreferencesUtils;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
+
+/**
+ * @author whw
+ * @time 2019/3/13
+ * @Description 普通样式弹框
+ */
+public class ShutdownDialog extends Dialog implements View.OnClickListener {
+
+    public static final int OK = 2;
+    public static final int NO = 3;
+    private final Context mContext;
+    private TextView tvTitle;
+    private TextView tvContent;
+    private Button btnConfirm;
+    private Button btnCancel;
+    private ImageView IvQrCode;
+
+    public void setListener(DialogClickListener listener) {
+        this.listener = listener;
+    }
+
+    private DialogClickListener listener;
+
+
+    public ShutdownDialog(@NonNull Context context) {
+        super(context, R.style.DialogBgD);//加载样式
+        mContext = context;
+        setContentView(R.layout.dialog_normal);
+        initView();
+    }
+
+    protected void initView() {
+        tvTitle = findViewById(R.id.tv_title);
+        tvContent = findViewById(R.id.tv_content);
+        btnConfirm = findViewById(R.id.btn_confirm);
+        btnCancel = findViewById(R.id.btn_cancel);
+        IvQrCode = findViewById(R.id.iv_qr_code);
+        btnConfirm.setOnClickListener(this);
+        btnCancel.setOnClickListener(this);
+
+        int param = (int) SharedPreferencesUtils.getParam(Name.LANGUAGE_TYPE, -1);
+        if (param != 1) {
+            btnCancel.setLines(1);
+            btnConfirm.setLines(1);
+        }
+    }
+
+    /**
+     * set button text
+     *
+     * @param strIdTitle title text
+     * @param strId      shutdown text
+     * @param strid1     open text
+     */
+    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
+    public void setBtnText(int strIdTitle, int content, int strId, int strid1) {
+        tvTitle.setText(strIdTitle);
+        tvContent.setText(content);
+        btnConfirm.setText(strId);
+        btnCancel.setText(strid1);
+        btnCancel.setTextColor(UiUtil.getColorRes(R.color.white));
+    }
+
+    /**
+     * get the text of button
+     */
+    public String getBtnTextConfirm() {
+
+        return btnConfirm.getText().toString().trim();
+    }
+
+    /**
+     * get the text of buttonCancel
+     */
+    public String getBtnTextCancel() {
+
+        return btnCancel.getText().toString().trim();
+    }
+
+
+    /**
+     * 设置文字
+     *
+     * @param text
+     */
+    public void setContent(String text) {
+        tvContent.setText(text);
+    }
+
+
+    @Override
+    public void onClick(View v) {
+        /**
+         * 1.如果==0,并且超過30秒
+         * ·我們需要重新開始,也就是可以開關機,也就是開
+         *
+         */
+        long openCloseFacility = (long) SharedPreferencesUtils.getParam("open_close_facility", (long) 0);
+        long data = System.currentTimeMillis() - openCloseFacility;
+        long shengyuData = openCloseFacility - System.currentTimeMillis();
+        if (openCloseFacility == 0 | data > 30000) {
+            listener.onClickListener(v.getId());
+//            new Thread(new CountDownThread()).start();
+            SharedPreferencesUtils.setParam("open_close_facility", System.currentTimeMillis());
+        } else {
+            ToastUtil.showToast(String.format(mContext.getString(R.string.no_continuous_oepn_close_chance), (30 - ((Math.abs(shengyuData) % (1000 * 60)) / 1000))));
+        }
+        return;
+
+    }
+
+    public interface DialogClickListener {
+
+        void onClickListener(int type);
+
+    }
+}

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/AlarmRecordFragment.java

@@ -11,8 +11,6 @@ import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
 import com.sunzee.mvp.alarmrecord.AlarmRecordPresenter;
 import com.sunzee.mvp.alarmrecord.AlarmRecordView;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 
 /**
  * 报警记录界面

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/DebugFragment.java

@@ -11,8 +11,6 @@ import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
 import com.sunzee.mvp.debug.DebugPresenter;
 import com.sunzee.mvp.debug.DebugView;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 
 /**
  * 调试页界面

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/GeneralParameterFragment.java

@@ -11,8 +11,6 @@ import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
 import com.sunzee.mvp.generalparameter.GeneralParameterPresenter;
 import com.sunzee.mvp.generalparameter.GeneralParameterView;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 
 /**
  * 通用参数界面

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/LanguageSetFragment.java

@@ -9,8 +9,6 @@ import android.view.ViewGroup;
 
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 import com.sunzee.mvp.languageset.LanguageSetPresenter;
 import com.sunzee.mvp.languageset.LanguageSetView;
 

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/OtherFragment.java

@@ -9,8 +9,6 @@ import android.view.ViewGroup;
 
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 import com.sunzee.mvp.other.OtherPresenter;
 import com.sunzee.mvp.other.OtherView;
 

+ 63 - 4
app/src/main/java/com/sunzee/ui/fragment/PasswordResetFragment.java

@@ -1,34 +1,64 @@
 package com.sunzee.ui.fragment;
 
+import android.annotation.SuppressLint;
+import android.content.Context;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 import com.sunzee.mvp.passwordreset.PasswordResetPresenter;
 import com.sunzee.mvp.passwordreset.PasswordResetView;
+import com.sunzee.utils.ToastUtil;
+import com.sunzee.utils.UiUtil;
 
 /**
  * 重置密码界面
  */
-public class PasswordResetFragment extends MvpFragment<PasswordResetPresenter> implements PasswordResetView {
+public class PasswordResetFragment extends MvpFragment<PasswordResetPresenter> implements PasswordResetView, View.OnClickListener {
+
+    private EditText mUsername;
+    private EditText mUserPassword;
+    private EditText mAgineUserPassword;
+    private TextView mTvLogin;
+    private LinearLayout mLoginGroup;
 
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         View inflate = inflater.inflate(R.layout.fragment_change_password, container, false);
+        initView(inflate);
+        initEvent();
         return inflate;
     }
 
+    private void initEvent() {
+        mTvLogin.setOnClickListener(this);
+        mLoginGroup.setOnClickListener(this);
+
+    }
+
+    private void initView(View inflate) {
+        mUsername = inflate.findViewById(R.id.et_username_changepass);
+        mUserPassword = inflate.findViewById(R.id.et_userpassword_changepass);
+        mAgineUserPassword = inflate.findViewById(R.id.et_agine_userpassword_changepass);
+        mTvLogin = inflate.findViewById(R.id.tv_login_chagepass);
+        mLoginGroup = inflate.findViewById(R.id.ll_logingroup);
+
+    }
+
     @Override
     protected PasswordResetPresenter createPresenter() {
-        return null;
+        return new PasswordResetPresenter(this);
     }
 
     @Override
@@ -40,4 +70,33 @@ public class PasswordResetFragment extends MvpFragment<PasswordResetPresenter> i
     public void hideLoading() {
 
     }
+
+    @Override
+    public void showResult(boolean success) {
+        if (success) {
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.modified_success));
+        } else {
+            ToastUtil.showToast(UiUtil.getStringRes(R.string.modified_failed));
+        }
+    }
+
+    private static final String TAG = "PasswordResetFragment";
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.tv_login_chagepass:
+                mvpPresenter.reset(mUsername.getText().toString().trim(),
+                        mUserPassword.getText().toString().trim(),
+                        mAgineUserPassword.getText().toString().trim());
+                break;
+            case R.id.ll_logingroup:
+                Log.d(TAG, "onClick: ");
+                //隐藏键盘
+                @SuppressLint("WrongConstant") InputMethodManager imm = (InputMethodManager)
+                        mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
+                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+                break;
+        }
+    }
 }

+ 1 - 3
app/src/main/java/com/sunzee/ui/fragment/ShowMaterialFragment.java

@@ -9,13 +9,11 @@ import android.view.ViewGroup;
 
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 import com.sunzee.mvp.showmaterial.ShowMaterialPresenter;
 import com.sunzee.mvp.showmaterial.ShowMaterialView;
 
 /**
- * 其他页界面
+ * 查看物料界面
  */
 public class ShowMaterialFragment extends MvpFragment<ShowMaterialPresenter> implements ShowMaterialView {
 

+ 0 - 2
app/src/main/java/com/sunzee/ui/fragment/StatisticsFragment.java

@@ -9,8 +9,6 @@ import android.view.ViewGroup;
 
 import com.sunzee.R;
 import com.sunzee.base.MvpFragment;
-import com.sunzee.mvp.homepage.HomePagePresenter;
-import com.sunzee.mvp.homepage.HomePageView;
 import com.sunzee.mvp.statistics.StatisticsPresenter;
 import com.sunzee.mvp.statistics.StatisticsView;
 

+ 48 - 0
app/src/main/java/com/sunzee/utils/DensityUtil.java

@@ -0,0 +1,48 @@
+package com.sunzee.utils;
+
+
+import com.sunzee.base.BaseApplication;
+
+/**
+ * 设备信息
+ * Created by MinKin
+ */
+public class DensityUtil {
+
+    public static float dp2px(float dpValue) {
+        float density = BaseApplication.getContext().getResources().getDisplayMetrics().density;
+        return density * dpValue + 0.5f;
+    }
+
+    public static float px2dp(float pxValue) {
+        float density = BaseApplication.getContext().getResources().getDisplayMetrics().density;
+        return pxValue / density + 0.5f;
+    }
+
+    public static int px2sp(float pxValue) {
+        float scaledDensity = BaseApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
+        return (int) (pxValue / scaledDensity + 0.5f);
+    }
+
+    public static int sp2px(float spValue) {
+        float scaledDensity = BaseApplication.getContext().getResources().getDisplayMetrics().scaledDensity;
+        return (int) (spValue * scaledDensity + 0.5f);
+    }
+
+    public static int getScreenWidth() {
+        return BaseApplication.getContext().getResources().getDisplayMetrics().widthPixels;
+    }
+
+    public static int getScreenHeight() {
+        return BaseApplication.getContext().getResources().getDisplayMetrics().heightPixels;
+    }
+
+    public static int getStatusBarHeight() {
+        int statusBarHeight = 0;
+        int resourceId = BaseApplication.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
+        if (resourceId > 0) {
+            statusBarHeight = BaseApplication.getContext().getResources().getDimensionPixelSize(resourceId);
+        }
+        return statusBarHeight;
+    }
+}

+ 20 - 26
app/src/main/java/com/sunzee/utils/FileUtil.java

@@ -3,10 +3,9 @@ package com.sunzee.utils;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.text.TextUtils;
-import android.util.Log;
-
 
 import com.sunzee.model.domain.Name;
+import com.wuxiaolong.androidutils.library.LogUtil;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -17,6 +16,7 @@ import java.io.InputStreamReader;
 import java.io.RandomAccessFile;
 import java.net.FileNameMap;
 import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -53,8 +53,8 @@ public class FileUtil {
             String _name = _file.getName();
             String filePath = _file.getAbsolutePath();//获取文件路径
             String fileName = _file.getName().substring(0, _name.length() - 4);//获取文件名
-            Log.d("LOGCAT", "fileName:" + fileName);
-            Log.d("LOGCAT", "FILEPATH:" + filePath);
+            LogUtil.d("LOGCAT", "fileName:" + fileName);
+            LogUtil.d("LOGCAT", "FILEPATH:" + filePath);
 
         }
         return files;
@@ -70,10 +70,7 @@ public class FileUtil {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
         BitmapFactory.decodeFile(filePath, options);
-        if (options.outWidth == -1) {
-            return false;
-        }
-        return true;
+        return options.outWidth != -1;
     }
 
 
@@ -101,10 +98,7 @@ public class FileUtil {
      */
     public static boolean isVedioFile(String fileName) {
         String mimeType = getMimeType(fileName);
-        if (!TextUtils.isEmpty(fileName) && mimeType.contains(PREFIX_VIDEO)) {
-            return true;
-        }
-        return false;
+        return !TextUtils.isEmpty(fileName) && mimeType.contains(PREFIX_VIDEO);
     }
 
 
@@ -114,7 +108,7 @@ public class FileUtil {
         String fileContent = getFileContent(file);
         if (file != null && !TextUtils.isEmpty(fileContent)) {
             //如果存在 直接获取
-            Log.e(TAG, "getDeviceId: " + fileContent);
+            LogUtil.e(TAG, "getDeviceId: " + fileContent);
             deviceId = fileContent.trim();
         } else {
             //不存在 先生成再获取
@@ -140,7 +134,7 @@ public class FileUtil {
             int j = random.nextInt(1000);
             randomText = randomText + j;
         }
-        deviceId = String.valueOf(l) + randomText;
+        deviceId = l + randomText;
         writeTxtToFile(deviceId, filePath, fileName);
     }
 
@@ -155,7 +149,7 @@ public class FileUtil {
         try {
             File file = new File(strFilePath);
             if (!file.exists()) {
-                Log.d("TestFile", "Create the file:" + strFilePath);
+                LogUtil.d("TestFile", "Create the file:" + strFilePath);
                 file.getParentFile().mkdirs();
                 file.createNewFile();
             }
@@ -164,7 +158,7 @@ public class FileUtil {
             raf.write(strContent.getBytes());
             raf.close();
         } catch (Exception e) {
-            Log.e("TestFile", "Error on write File:" + e);
+            LogUtil.e("TestFile", "Error on write File:" + e);
         }
     }
 
@@ -194,7 +188,7 @@ public class FileUtil {
                 file.mkdir();
             }
         } catch (Exception e) {
-            Log.i("error:", e + "");
+            LogUtil.i("error:", e + "");
         }
     }
 
@@ -206,16 +200,16 @@ public class FileUtil {
             if (file.getName().endsWith("txt")) {//文件格式为""文件
                 BufferedReader buffreader = null;
                 try {
-                    buffreader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+                    buffreader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
                     String line = "";
                     //分行读取
                     while ((line = buffreader.readLine()) != null) {
                         content += line + "\n";
                     }
-                } catch (java.io.FileNotFoundException e) {
-                    Log.d("TestFile", "The File doesn't not exist.");
+                } catch (FileNotFoundException e) {
+                    LogUtil.d("TestFile", "The File doesn't not exist.");
                 } catch (IOException e) {
-                    Log.d("TestFile", e.getMessage());
+                    LogUtil.d("TestFile", e.getMessage());
                 } finally {
                     try {
                         if (buffreader != null) {
@@ -283,22 +277,22 @@ public class FileUtil {
             for (File file : logFiles) {
                 SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
                 String nowDate = format.format(new Date(System.currentTimeMillis()));
-                //Log.d(TAG, "duibi: " + nowDate);
+                //LogUtil.d(TAG, "duibi: " + nowDate);
                 try {
                     String replace = file.getName().replace("-" + FileUtil.getDeviceId() + ".txt", "");
-                    Log.d(TAG, "pastDueLog: " + replace);
+                    LogUtil.d(TAG, "pastDueLog: " + replace);
                     Date dateFile = format.parse(replace);
                     Date dataNow = format.parse(nowDate);
                     long fileTime = dateFile.getTime();
                     long nowTime = dataNow.getTime();
                     if (nowTime - fileTime > SEVENT_DAYS) {
                         //如果超过7天,我们就进行删除指定的文件,否则就什么都不做。
-                        //Log.d(TAG, "duibi: "+fileTime);
+                        //LogUtil.d(TAG, "duibi: "+fileTime);
                         //删除
                         file.delete();
                     }
-                    //Log.d(TAG, "duibi: "+dataNow);
-                    //Log.d(TAG, "duibi: " + file.getName());
+                    //LogUtil.d(TAG, "duibi: "+dataNow);
+                    //LogUtil.d(TAG, "duibi: " + file.getName());
                 } catch (ParseException e) {
                     //604800000 7天
                     e.printStackTrace();

+ 73 - 0
app/src/main/java/com/sunzee/utils/LongClickUtils.java

@@ -0,0 +1,73 @@
+package com.sunzee.utils;
+
+import android.os.Handler;
+import android.view.MotionEvent;
+import android.view.View;
+
+/**
+ * @author whw
+ * @time 2019/3/6
+ * @Description 长按事件监听
+ */
+public class LongClickUtils {
+
+    private static final String TAG = "LongClickUtils";
+
+    /**
+     * 自定义时长的长按事件
+     *
+     * @param handler           外界handler(为了减少handler的泛滥使用,最好全局传handler引用,如果没有就直接传 new Handler())
+     * @param longClickView     被长按的视图(任意控件)
+     * @param delayMillis       长按时间,毫秒
+     * @param longClickListener 长按回调的返回事件
+     */
+    public static void setLongClick(final Handler handler, final View longClickView, final long delayMillis, final View.OnLongClickListener longClickListener) {
+        longClickView.setOnTouchListener(new View.OnTouchListener() {
+            private int TOUCH_MAX = 50;
+            private int mLastMotionX;
+            private int mLastMotionY;
+
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                int x = (int) event.getX();
+                int y = (int) event.getY();
+
+                switch (event.getAction()) {
+                    case MotionEvent.ACTION_UP:
+                        // 抬起时,移除已有Runnable回调,抬起就算长按了(不需要考虑用户是否长按了超过预设的时间)
+                        handler.removeCallbacks(r);
+                        break;
+                    case MotionEvent.ACTION_MOVE:
+                        if (Math.abs(mLastMotionX - x) > TOUCH_MAX
+                                || Math.abs(mLastMotionY - y) > TOUCH_MAX) {
+                            // 移动误差阈值
+                            // xy方向判断
+                            // 移动超过阈值,则表示移动了,就不是长按(看需求),移除 已有的Runnable回调
+                            handler.removeCallbacks(r);
+                        }
+                        break;
+                    case MotionEvent.ACTION_DOWN:
+                        // 每次按下重新计时
+                        // 按下前,先移除 已有的Runnable回调,防止用户多次单击导致多次回调长按事件的bug
+                        handler.removeCallbacks(r);
+                        mLastMotionX = x;
+                        mLastMotionY = y;
+                        // 按下时,开始计时
+                        handler.postDelayed(r, delayMillis);
+                        break;
+                }
+                return true;//onclick等其他事件不能用请改这里
+            }
+
+            private Runnable r = new Runnable() {
+                @Override
+                public void run() {
+                    if (longClickListener != null) {// 回调给用户,用户可能传null,需要判断null
+                        longClickListener.onLongClick(longClickView);
+                    }
+                }
+            };
+        });
+    }
+
+}

+ 0 - 1
app/src/main/java/com/sunzee/utils/SharedPreferencesUtils.java

@@ -23,7 +23,6 @@ public class SharedPreferencesUtils {
      * @param object
      */
     public static void setParam(String key, Object object) {
-
         String type = object.getClass().getSimpleName();
         SharedPreferences sp = BaseApplication.getContext().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
         SharedPreferences.Editor editor = sp.edit();

+ 285 - 0
app/src/main/java/com/sunzee/utils/TimeUtil.java

@@ -0,0 +1,285 @@
+package com.sunzee.utils;
+
+import android.text.format.Time;
+
+import com.sunzee.R;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @author whw
+ * @time 2019/4/9
+ * @Description 时间工具类
+ */
+public class TimeUtil {
+    /**
+     * 获取当前时间的年月日时分秒
+     * @return 字符串
+     */
+    public static String getStrCurTime(){
+        String time="";
+        long date = System.currentTimeMillis();
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date curDate = new Date(date);
+        time = formatter.format(curDate);
+        return time;
+    }
+
+    /**
+     *
+     * @param timeMillis
+     * @return 指定的时间
+     */
+    public static String getTime(long timeMillis){
+        String time="";
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date curDate = new Date(timeMillis);
+        time = formatter.format(curDate);
+        return time;
+    }
+
+    /**
+     *
+     * @param timeMillis
+     * @return 指定的没有格式的时间
+     */
+    public static String getNoTime(long timeMillis){
+        String time="";
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+        Date curDate = new Date(timeMillis);
+        time = formatter.format(curDate);
+        return time;
+    }
+
+    /**
+     *
+     * 判断时间相差几天
+     * @param startTime
+     * @param endTime
+     * @param format yyyy-MM-dd
+     * @return
+     */
+    public static long dateDiff(String startTime, String endTime, String format) {
+        // 按照传入的格式生成一个simpledateformate对象
+        SimpleDateFormat sd = new SimpleDateFormat(format);
+        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
+        long nh = 1000 * 60 * 60;// 一小时的毫秒数
+        long nm = 1000 * 60;// 一分钟的毫秒数
+        long ns = 1000;// 一秒钟的毫秒数
+        long diff;
+        long day = 0;
+        long hour = 0;
+        long min = 0;
+        long sec = 0;
+        try {
+            // 获得两个时间的毫秒时间差异
+            try {
+                diff = sd.parse(endTime).getTime()
+                        - sd.parse(startTime).getTime();
+                day = diff / nd;// 计算差多少天
+                hour = diff % nd / nh;// 计算差多少小时
+                min = diff % nd % nh / nm;// 计算差多少分钟
+                sec = diff % nd % nh % nm / ns;// 计算差多少秒
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+
+
+            // 输出结果
+            System.out.println("时间相差:" + day + "天" + hour + "小时" + min
+                    + "分钟" + sec + "秒。");
+            if (day>=1) {
+                return day;
+            }else {
+                if (day==0) {
+                    return 1;
+                }else {
+                    return 0;
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return 0;
+
+    }
+
+    /**
+     * 判断时间大小
+     * @param DATE1
+     * @param DATE2
+     * @return
+     */
+    public static boolean compare_date(String DATE1, String DATE2) {
+        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            Date dt1 = df.parse(DATE1);
+            Date dt2 = df.parse(DATE2);
+            if (dt1.getTime() > dt2.getTime()) {
+                System.out.println("dt1 在dt2前");
+                return true;
+            } else if (dt1.getTime() < dt2.getTime()) {
+                System.out.println("dt1在dt2后");
+                return false;
+            } else {
+                return true;
+            }
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return false;
+    }
+
+    /**
+     * 判断相差几个月
+     * @param startTime
+     * @param endTime
+     */
+    public static int mouthDiff(String startTime, String endTime)  {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+        String str1 = "2012-12";
+        String str2 = "2012-01";
+        Calendar bef = Calendar.getInstance();
+        Calendar aft = Calendar.getInstance();
+        try {
+            bef.setTime(sdf.parse(str1));
+            aft.setTime(sdf.parse(str2));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        int result = aft.get(Calendar.MONTH) - bef.get(Calendar.MONTH);
+        int month = (aft.get(Calendar.YEAR) - bef.get(Calendar.YEAR)) * 12;
+        return Math.abs(month + result);
+    }
+
+    /**
+     * 计算2个日期之间相差的  以年、月、日为单位,各自计算结果是多少
+     * 比如:2011-02-02 到  2017-03-02
+     *                                以年为单位相差为:6年
+     *                                以月为单位相差为:73个月
+     *                                以日为单位相差为:2220天
+     * @param fromDate
+     * @param toDate
+     * @return
+     */
+    public static int yearCompare(Date fromDate,Date toDate){
+        Calendar  from  =  Calendar.getInstance();
+        from.setTime(fromDate);
+        Calendar  to  =  Calendar.getInstance();
+        to.setTime(toDate);
+        //只要年月
+        int fromYear = from.get(Calendar.YEAR);
+        int fromMonth = from.get(Calendar.MONTH);
+
+        int toYear = to.get(Calendar.YEAR);
+        int toMonth = to.get(Calendar.MONTH);
+
+        int year = toYear  -  fromYear;
+        int month = toYear *  12  + toMonth  -  (fromYear  *  12  +  fromMonth);
+        int day = (int) ((to.getTimeInMillis()  -  from.getTimeInMillis())  /  (24  *  3600  *  1000));
+        return year;
+
+    }
+
+    //计算两个日期相差年数
+    public static int yearDateDiff(String startDate,String endDate) {
+        Calendar calBegin = Calendar.getInstance(); //获取日历实例
+        Calendar calEnd = Calendar.getInstance();
+        if (stringTodate(startDate, "yyyy")==null||stringTodate(startDate, "yyyy")==null){
+            return -100;
+        }
+        calBegin.setTime(stringTodate(startDate, "yyyy")); //字符串按照指定格式转化为日期
+        calEnd.setTime(stringTodate(endDate, "yyyy"));
+        return calEnd.get(Calendar.YEAR) - calBegin.get(Calendar.YEAR);
+
+    }
+
+    //字符串按照指定格式转化为日期
+    public static Date stringTodate(String dateStr, String formatStr) {
+        // 如果时间为空则默认当前时间
+        Date date = null;
+        SimpleDateFormat format = new SimpleDateFormat(formatStr);
+        if (dateStr != null && !dateStr.equals("")) {
+            String time = "";
+            try {
+                Date dateTwo = format.parse(dateStr);
+                time = format.format(dateTwo);
+                date = format.parse(time);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+
+        } else {
+            String timeTwo = format.format(new Date());
+            try {
+                date = format.parse(timeTwo);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+        }
+        return date;
+
+    }
+
+
+    /**
+     * 判断当前系统时间是否在指定时间的范围内
+     *
+     * @param beginHour
+     * 开始小时,例如22
+     * @param beginMin
+     * 开始小时的分钟数,例如30
+     * @param endHour
+     * 结束小时,例如 8
+     * @param endMin
+     * 结束小时的分钟数,例如0
+     * @return true表示在范围内,否则false
+     */
+    public static boolean isCurrentInTimeScope(int beginHour, int beginMin, int endHour, int endMin) {
+        boolean result = false;
+        final long aDayInMillis = 1000 * 60 * 60 * 24;
+        final long currentTimeMillis = System.currentTimeMillis();
+
+        Time now = new Time();
+        now.set(currentTimeMillis);
+
+        Time startTime = new Time();
+        startTime.set(currentTimeMillis);
+        startTime.hour = beginHour;
+        startTime.minute = beginMin;
+
+        Time endTime = new Time();
+        endTime.set(currentTimeMillis);
+        endTime.hour = endHour;
+        endTime.minute = endMin;
+
+        if (!startTime.before(endTime)) {
+// 跨天的特殊情况(比如22:00-8:00)
+            startTime.set(startTime.toMillis(true) - aDayInMillis);
+            result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime
+            Time startTimeInThisDay = new Time();
+            startTimeInThisDay.set(startTime.toMillis(true) + aDayInMillis);
+            if (!now.before(startTimeInThisDay)) {
+                result = true;
+            }
+        } else {
+// 普通情况(比如 8:00 - 14:00)
+            result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime
+        }
+        return result;
+    }
+
+    public static String getDur(int time){
+        String text="";
+        int i = time / 60;
+        int i1 = time % 60;
+        text=i+ UiUtil.getStringRes(R.string.minute) +i1+ UiUtil.getStringRes(R.string.second);
+        return text;
+    }
+}

+ 26 - 0
app/src/main/java/com/sunzee/utils/ToastUtil.java

@@ -0,0 +1,26 @@
+package com.sunzee.utils;
+
+import android.annotation.SuppressLint;
+import android.widget.Toast;
+
+import com.sunzee.base.BaseApplication;
+
+
+/**
+ * 吐司工具类
+ * Created By MinKin.
+ */
+public class ToastUtil {
+
+    private static Toast mToast;
+
+    @SuppressLint("ShowToast")
+    public static void showToast(String text) {
+        if (mToast == null) {
+            mToast = Toast.makeText(BaseApplication.getContext(), text, Toast.LENGTH_LONG);
+        } else {
+            mToast.setText(text);
+        }
+        mToast.show();
+    }
+}

+ 45 - 0
app/src/main/java/com/sunzee/utils/UiUtil.java

@@ -0,0 +1,45 @@
+package com.sunzee.utils;
+
+import android.graphics.drawable.Drawable;
+import android.support.v4.content.ContextCompat;
+
+import com.sunzee.base.BaseApplication;
+
+import java.lang.reflect.Field;
+
+/**
+ * 获取字符串、颜色
+ * Created By MinKin.
+ */
+public class UiUtil {
+
+    public static String getStringRes(int id) {
+        return BaseApplication.getContext().getResources().getString(id);
+    }
+
+    public static int getColorRes(int id) {
+        return ContextCompat.getColor(BaseApplication.getContext(), id);
+    }
+
+    public static String[] getStringArrayRes(int id) {
+        return BaseApplication.getContext().getResources().getStringArray(id);
+    }
+
+    public static Drawable getDrawableRes(int id) {
+        return BaseApplication.getContext().getResources().getDrawable(id);
+    }
+
+    public static float getDimensionRes(int id) {
+        return BaseApplication.getContext().getResources().getDimension(id);
+    }
+
+    public static int getResId(String variableName, Class<?> c) {
+        try {
+            Field idField = c.getDeclaredField(variableName);
+            return idField.getInt(idField);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return -1;
+        }
+    }
+}

+ 134 - 0
app/src/main/res/layout/activity_advertising.xml

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <FrameLayout
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"
+            android:layout_weight="1">
+
+            <ImageView
+                android:id="@+id/iv_cor_ad"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:visibility="gone" />
+
+            <SurfaceView
+                android:id="@+id/sf_cor_ad"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent" />
+        </FrameLayout>
+
+
+        <FrameLayout
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_gravity="center"
+            android:layout_weight="1">
+
+            <ImageView
+                android:id="@+id/iv_cor_adb"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:visibility="gone" />
+
+            <SurfaceView
+                android:id="@+id/sf_cor_adb"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent" />
+        </FrameLayout>
+    </LinearLayout>
+
+    <ImageView
+        android:layout_width="@dimen/dp_40"
+        android:layout_height="@dimen/dp_16"
+        android:layout_marginLeft="@dimen/dp_10"
+        android:layout_marginTop="@dimen/dp_6"
+        android:src="@drawable/login_logo" />
+
+    <LinearLayout
+        android:id="@+id/ll_service"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:background="@drawable/shape_system_btn_rounded_rectangle"
+        android:orientation="vertical"
+        android:textColor="#767988">
+
+        <TextView
+            android:id="@+id/tv_servicecontact"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginRight="@dimen/dp_5"
+            android:layout_marginBottom="@dimen/dp_1"
+            android:padding="@dimen/dp_2"
+            android:textColor="#767988"
+            android:textSize="@dimen/dp_5" />
+
+        <TextView
+            android:id="@+id/tv_serviceline"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="@dimen/dp_2"
+            android:textColor="#767988"
+            android:textSize="@dimen/dp_5" />
+
+    </LinearLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_root"
+        android:layout_width="wrap_content"
+        android:layout_height="@dimen/dp_40"
+        android:layout_alignParentRight="true">
+
+        <TextView
+            android:id="@+id/tv_time"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentLeft="true"
+            android:text="@string/current_time1"
+            android:textColor="@color/white"
+            android:textSize="@dimen/sp_8" />
+
+        <TextView
+            android:id="@+id/tv_time1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_toRightOf="@id/tv_time"
+            android:gravity="center_vertical"
+            android:text="2019-05-05 18:00:00"
+
+            android:textColor="@color/white"
+            android:textSize="@dimen/sp_8" />
+
+        <TextView
+            android:id="@+id/tv_equipment_no"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/tv_time"
+            android:layout_alignParentLeft="true"
+            android:text="@string/equipment_no"
+            android:textColor="@color/white"
+            android:textSize="@dimen/sp_8" />
+
+        <TextView
+            android:id="@+id/tv_equipment_no1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/tv_time"
+            android:layout_toRightOf="@id/tv_equipment_no"
+            android:gravity="center_vertical"
+            android:text="1234567856"
+            android:textColor="@color/white"
+            android:textSize="@dimen/sp_8" />
+    </RelativeLayout>
+</RelativeLayout>

+ 32 - 28
app/src/main/res/layout/activity_home.xml

@@ -16,38 +16,41 @@
         <android.support.design.widget.NavigationView
             android:id="@+id/bnv_main_navigationbar"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
+            android:layout_height="match_parent"
             android:background="@color/white"
-            android:paddingHorizontal="@dimen/dp_5"
+            android:paddingHorizontal="@dimen/dp_9"
             app:headerLayout="@layout/navigation_layout"
+            app:itemBackground="@color/white"
             app:itemTextAppearance="@style/Menu"
             app:menu="@menu/my_navigation_items"
             app:theme="@style/ItemHeight" />
 
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_alignParentBottom="true"
-            android:layout_marginLeft="@dimen/dp_4"
-            android:layout_marginBottom="@dimen/dp_3"
-            android:gravity="center_vertical"
-            android:padding="@dimen/dp_10">
-
-            <ImageView
-                android:layout_width="@dimen/dp_6"
-                android:layout_height="@dimen/dp_6"
-                android:layout_marginRight="@dimen/dp_8"
-                android:src="@drawable/back_icon" />
-
-            <TextView
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/black"
-                android:textColor="@color/gray"
-                android:textSize="@dimen/sp_6" />
-        </LinearLayout>
+
     </RelativeLayout>
 
+    <LinearLayout
+        android:id="@+id/ll_black"
+        android:layout_width="@dimen/dp_100"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_marginBottom="@dimen/dp_3"
+        android:gravity="center_vertical"
+        android:padding="@dimen/dp_10">
+
+        <ImageView
+            android:layout_width="@dimen/dp_8"
+            android:layout_height="@dimen/dp_8"
+            android:layout_marginLeft="@dimen/dp_4"
+            android:layout_marginRight="@dimen/dp_10"
+            android:src="@drawable/back_icon" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/black"
+            android:textColor="@color/gray"
+            android:textSize="@dimen/sp_6" />
+    </LinearLayout>
 
     <RelativeLayout
         android:id="@+id/rl_top"
@@ -70,6 +73,7 @@
             android:textSize="@dimen/dp_6" />
 
         <TextView
+            android:id="@+id/tv_updatapk"
             android:layout_width="wrap_content"
             android:layout_height="@dimen/dp_15"
             android:layout_centerVertical="true"
@@ -85,12 +89,12 @@
 
         <ImageView
             android:id="@+id/iv_shutown_logo"
-            android:layout_width="@dimen/dp_16"
-            android:layout_height="@dimen/dp_16"
+            android:layout_width="@dimen/dp_14"
+            android:layout_height="@dimen/dp_14"
             android:layout_alignParentRight="true"
             android:layout_centerVertical="true"
-            android:layout_marginLeft="@dimen/dp_8"
-            android:layout_marginRight="@dimen/dp_8"
+            android:layout_marginLeft="@dimen/dp_10"
+            android:layout_marginRight="@dimen/dp_10"
             android:src="@drawable/shutdown" />
 
         <TextView

+ 69 - 56
app/src/main/res/layout/activity_login.xml

@@ -3,70 +3,83 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
-
     <LinearLayout
-        android:layout_width="0dp"
-        android:layout_height="match_parent"
-        android:layout_marginLeft="@dimen/dp_46"
-        android:layout_weight="1"
-        android:orientation="vertical">
+        android:id="@+id/ll_hidekeymap"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
 
-        <ImageView
-            android:layout_width="@dimen/dp_100"
-            android:layout_height="@dimen/dp_40"
-            android:layout_marginTop="@dimen/dp_22"
-            android:src="@drawable/login_logo" />
+        <LinearLayout
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_marginLeft="@dimen/dp_46"
+            android:layout_weight="1"
+            android:orientation="vertical">
 
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/dp_20"
-            android:text="Hello,"
-            android:textColor="@color/logo_blue"
-            android:textSize="@dimen/sp_25" />
+            <ImageView
+                android:layout_width="@dimen/dp_100"
+                android:layout_height="@dimen/dp_40"
+                android:layout_marginTop="@dimen/dp_22"
+                android:src="@drawable/login_logo" />
 
-        <TextView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="Welcome to login"
-            android:textColor="@color/logo_blue"
-            android:textSize="@dimen/sp_25" />
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/dp_20"
+                android:text="Hello,"
+                android:textColor="@color/logo_blue"
+                android:textSize="@dimen/sp_25" />
 
-        <EditText
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/dp_20"
-            android:layout_marginRight="@dimen/dp_50"
-            android:paddingBottom="@dimen/dp_10"
-            android:hint="@string/input_use_name"
-            android:textColor="@color/gray"
-            android:textSize="@dimen/sp_10" />
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="Welcome to login"
+                android:textColor="@color/logo_blue"
+                android:textSize="@dimen/sp_25" />
 
-        <EditText
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="@dimen/dp_10"
-            android:layout_marginRight="@dimen/dp_50"
-            android:paddingBottom="@dimen/dp_10"
-            android:hint="@string/enter_password"
-            android:textColor="@color/gray"
-            android:textSize="@dimen/sp_10" />
+            <EditText
+                android:id="@+id/et_username"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/dp_20"
+                android:layout_marginRight="@dimen/dp_50"
+                android:hint="@string/input_use_name"
+                android:lines="1"
+                android:paddingBottom="@dimen/dp_10"
+                android:text="admin"
+                android:textColor="@color/gray"
+                android:textSize="@dimen/sp_10" />
 
-        <TextView
-            android:layout_width="@dimen/dp_110"
-            android:layout_height="@dimen/dp_25"
-            android:layout_marginTop="@dimen/dp_20"
-            android:background="@drawable/shape_login_rounded_rectangle"
-            android:gravity="center"
-            android:text="@string/login"
-            android:textColor="@color/white"
-            android:textSize="@dimen/sp_15" />
+            <EditText
+                android:id="@+id/et_userpassword"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/dp_10"
+                android:layout_marginRight="@dimen/dp_50"
+                android:hint="@string/enter_password"
+                android:lines="1"
+                android:paddingBottom="@dimen/dp_10"
+                android:textColor="@color/gray"
+                android:textColorHint="@color/gray"
+                android:textSize="@dimen/sp_10" />
 
-    </LinearLayout>
+            <TextView
+                android:id="@+id/tv_userlogin"
+                android:layout_width="@dimen/dp_110"
+                android:layout_height="@dimen/dp_25"
+                android:layout_marginTop="@dimen/dp_20"
+                android:background="@drawable/shape_login_rounded_rectangle"
+                android:gravity="center"
+                android:text="@string/login"
+                android:textColor="@color/white"
+                android:textSize="@dimen/sp_15" />
+
+        </LinearLayout>
 
-    <ImageView
+        <ImageView
+
+            android:layout_width="@dimen/dp_315"
+            android:layout_height="match_parent"
+            android:src="@drawable/login_leftlogo" />
+    </LinearLayout>
 
-        android:layout_width="@dimen/dp_315"
-        android:layout_height="match_parent"
-        android:src="@drawable/login_leftlogo" />
 </LinearLayout>

+ 1 - 2
app/src/main/res/layout/activity_main.xml

@@ -2,8 +2,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
-    tools:context="com.sunzee.ui.activity.MainActivity">
+    android:orientation="vertical">
 
     <include layout="@layout/toolbar" />
 

+ 1 - 0
app/src/main/res/layout/dialog_connect_server.xml

@@ -17,6 +17,7 @@
         android:textSize="@dimen/dp_10" />
 
     <EditText
+        android:text="2478"
         android:id="@+id/et_server_id"
         android:layout_width="@dimen/dp_162"
         android:layout_height="@dimen/dp_22"

+ 85 - 74
app/src/main/res/layout/fragment_change_password.xml

@@ -3,104 +3,115 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/shallowblue"
-    android:gravity="center"
-    android:padding="@dimen/dp_5"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:padding="@dimen/dp_5">
 
     <LinearLayout
-        android:gravity="center_horizontal"
-        android:background="@drawable/shape_password_rounded_rectangle"
-        android:layout_width="@dimen/dp_220"
-        android:layout_height="@dimen/dp_170">
+        android:id="@+id/ll_logingroup"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:gravity="center">
 
         <LinearLayout
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:gravity="right"
-            android:orientation="vertical">
+            android:layout_width="@dimen/dp_220"
+            android:layout_height="@dimen/dp_170"
+            android:background="@drawable/shape_password_rounded_rectangle"
+            android:gravity="center_horizontal">
 
             <LinearLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_marginTop="@dimen/dp_25"
-                android:gravity="center">
+                android:gravity="right"
+                android:orientation="vertical">
 
-                <TextView
+                <LinearLayout
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:layout_marginRight="@dimen/dp_8"
-                    android:text="@string/older_password"
-                    android:textColor="#767988"
-                    android:textSize="@dimen/sp_10" />
+                    android:layout_marginTop="@dimen/dp_25"
+                    android:gravity="center">
 
-                <EditText
-                    android:layout_width="@dimen/dp_120"
-                    android:layout_height="wrap_content"
-                    android:background="@drawable/shape_password_edit_rounded_rectangle"
-                    android:hint="@string/input_older_password"
-                    android:padding="@dimen/dp_5"
-                    android:textSize="@dimen/sp_7" />
-            </LinearLayout>
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginRight="@dimen/dp_8"
+                        android:text="@string/older_password"
+                        android:textColor="#767988"
+                        android:textSize="@dimen/sp_10" />
 
-            <LinearLayout
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginTop="@dimen/dp_20"
-                android:gravity="center">
+                    <EditText
+                        android:id="@+id/et_username_changepass"
+                        android:layout_width="@dimen/dp_120"
+                        android:layout_height="wrap_content"
+                        android:background="@drawable/shape_password_edit_rounded_rectangle"
+                        android:hint="@string/input_older_password"
+                        android:padding="@dimen/dp_5"
+                        android:textSize="@dimen/sp_7" />
+                </LinearLayout>
 
-                <TextView
+                <LinearLayout
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:layout_marginRight="@dimen/dp_8"
-                    android:text="@string/new_password"
-                    android:textColor="#767988"
-                    android:textSize="@dimen/sp_10" />
+                    android:layout_marginTop="@dimen/dp_20"
+                    android:gravity="center">
 
-                <EditText
-                    android:layout_width="@dimen/dp_120"
-                    android:layout_height="wrap_content"
-                    android:background="@drawable/shape_password_edit_rounded_rectangle"
-                    android:hint="@string/input_new_password"
-                    android:padding="@dimen/dp_5"
-                    android:textSize="@dimen/sp_7" />
-            </LinearLayout>
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginRight="@dimen/dp_8"
+                        android:text="@string/new_password"
+                        android:textColor="#767988"
+                        android:textSize="@dimen/sp_10" />
 
-            <LinearLayout
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_marginTop="@dimen/dp_20"
-                android:gravity="center">
+                    <EditText
+                        android:id="@+id/et_userpassword_changepass"
+                        android:layout_width="@dimen/dp_120"
+                        android:layout_height="wrap_content"
+                        android:background="@drawable/shape_password_edit_rounded_rectangle"
+                        android:hint="@string/input_new_password"
+                        android:padding="@dimen/dp_5"
+                        android:textSize="@dimen/sp_7" />
+                </LinearLayout>
 
-                <TextView
+                <LinearLayout
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
-                    android:layout_marginRight="@dimen/dp_8"
-                    android:text="@string/confirm_password"
-                    android:textColor="#767988"
-                    android:textSize="@dimen/sp_10" />
+                    android:layout_marginTop="@dimen/dp_20"
+                    android:gravity="center">
+
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginRight="@dimen/dp_8"
+                        android:text="@string/confirm_password"
+                        android:textColor="#767988"
+                        android:textSize="@dimen/sp_10" />
 
-                <EditText
-                    android:layout_width="@dimen/dp_120"
+                    <EditText
+                        android:id="@+id/et_agine_userpassword_changepass"
+                        android:layout_width="@dimen/dp_120"
+                        android:layout_height="wrap_content"
+                        android:background="@drawable/shape_password_edit_rounded_rectangle"
+                        android:hint="@string/input_confirm_password"
+                        android:padding="@dimen/dp_5"
+                        android:textSize="@dimen/sp_7" />
+                </LinearLayout>
+
+                <LinearLayout
+                    android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:background="@drawable/shape_password_edit_rounded_rectangle"
-                    android:hint="@string/input_confirm_password"
-                    android:padding="@dimen/dp_5"
-                    android:textSize="@dimen/sp_7" />
-            </LinearLayout>
+                    android:gravity="center_horizontal">
 
-            <LinearLayout
-                android:gravity="center_horizontal"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content">
-                <TextView
-                    android:layout_width="@dimen/dp_170"
-                    android:layout_height="@dimen/dp_20"
-                    android:layout_marginTop="@dimen/dp_10"
-                    android:background="@drawable/shape_password_bottom_rounded_rectangle"
-                    android:gravity="center"
-                    android:text="@string/modify"
-                    android:textColor="@color/white"
-                    android:textSize="@dimen/sp_10" />
+                    <TextView
+                        android:id="@+id/tv_login_chagepass"
+                        android:layout_width="@dimen/dp_170"
+                        android:layout_height="@dimen/dp_20"
+                        android:layout_marginTop="@dimen/dp_10"
+                        android:background="@drawable/shape_password_bottom_rounded_rectangle"
+                        android:gravity="center"
+                        android:text="@string/modify"
+                        android:textColor="@color/white"
+                        android:textSize="@dimen/sp_10" />
+                </LinearLayout>
             </LinearLayout>
         </LinearLayout>
     </LinearLayout>

+ 60 - 56
app/src/main/res/layout/fragment_home.xml

@@ -4,10 +4,10 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:paddingLeft="@dimen/dp_10"
-    android:paddingRight="@dimen/dp_10"
     android:background="@color/shallowblue"
-    android:orientation="vertical">
+    android:orientation="vertical"
+    android:paddingLeft="@dimen/dp_10"
+    android:paddingRight="@dimen/dp_10">
 
     <LinearLayout
         android:id="@+id/linearLayout3"
@@ -35,14 +35,14 @@
                 android:layout_marginBottom="@dimen/dp_2"
                 android:text="@string/total_cleaning_times_today"
                 android:textColor="@color/white"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="767W"
                 android:textColor="@color/white"
-                android:textSize="@dimen/dp_16" />
+                android:textSize="@dimen/dp_14" />
 
         </LinearLayout>
 
@@ -61,7 +61,7 @@
                 android:layout_height="wrap_content"
                 android:text="@string/random_cleaning_times_today"
                 android:textColor="#939494"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -69,7 +69,7 @@
                 android:layout_marginTop="@dimen/dp_13"
                 android:text="767W"
                 android:textColor="@color/logo_blue"
-                android:textSize="@dimen/dp_16" />
+                android:textSize="@dimen/dp_14" />
 
             <ImageView
                 android:layout_width="@dimen/dp_35"
@@ -95,7 +95,7 @@
                 android:layout_height="wrap_content"
                 android:text="@string/regular_cleaning_times_today"
                 android:textColor="@color/white"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -103,7 +103,7 @@
                 android:layout_marginTop="@dimen/dp_13"
                 android:text="767W"
                 android:textColor="@color/white"
-                android:textSize="@dimen/dp_16" />
+                android:textSize="@dimen/dp_14" />
 
             <ImageView
                 android:layout_width="@dimen/dp_35"
@@ -117,8 +117,8 @@
         <RelativeLayout
             android:layout_width="0dp"
             android:layout_height="@dimen/dp_55"
-            android:layout_marginTop="@dimen/dp_5"
             android:layout_marginLeft="@dimen/dp_5"
+            android:layout_marginTop="@dimen/dp_5"
             android:layout_marginBottom="@dimen/dp_5"
             android:layout_weight="1"
             android:background="@drawable/shape_home_bottom2_rectangle"
@@ -132,7 +132,7 @@
                 android:layout_marginBottom="@dimen/dp_2"
                 android:text="2020-04-20"
                 android:textColor="@color/gray"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -140,7 +140,7 @@
                 android:layout_marginTop="@dimen/dp_13"
                 android:text="10:35"
                 android:textColor="@color/logo_blue"
-                android:textSize="@dimen/dp_16" />
+                android:textSize="@dimen/dp_14" />
 
             <ImageView
                 android:layout_width="@dimen/dp_35"
@@ -170,7 +170,7 @@
             android:layout_height="wrap_content"
             android:text="@string/fault_today"
             android:textColor="@color/logo_blue"
-            android:textSize="@dimen/sp_10" />
+            android:textSize="@dimen/sp_7" />
 
         <LinearLayout
             android:layout_width="match_parent"
@@ -183,7 +183,7 @@
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="@dimen/dp_8"
                 android:text="@string/untreated"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -192,20 +192,20 @@
                 android:layout_marginRight="@dimen/dp_5"
                 android:text="24"
                 android:textColor="@color/bright_blue"
-                android:textSize="@dimen/sp_13" />
+                android:textSize="@dimen/sp_10" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/a"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="@dimen/dp_8"
                 android:text="@string/fault_today"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -214,20 +214,20 @@
                 android:layout_marginRight="@dimen/dp_5"
                 android:text="12"
                 android:textColor="@color/orange"
-                android:textSize="@dimen/sp_13" />
+                android:textSize="@dimen/sp_10" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/a"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="@dimen/dp_8"
                 android:text="@string/complete"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
 
             <TextView
                 android:layout_width="wrap_content"
@@ -236,13 +236,13 @@
                 android:layout_marginRight="@dimen/dp_5"
                 android:text="12"
                 android:textColor="#385AA8"
-                android:textSize="@dimen/sp_13" />
+                android:textSize="@dimen/sp_10" />
 
             <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/a"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_6" />
         </LinearLayout>
 
 
@@ -273,7 +273,7 @@
                 android:layout_marginRight="@dimen/dp_40"
                 android:text="@string/flow_people_today"
                 android:textColor="#3E5DA8"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <LinearLayout
                 android:layout_width="match_parent"
@@ -287,14 +287,14 @@
                     android:layout_marginTop="@dimen/dp_10"
                     android:text="7677W"
                     android:textColor="@color/orange"
-                    android:textSize="@dimen/dp_18" />
+                    android:textSize="@dimen/dp_16" />
 
                 <TextView
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_marginTop="@dimen/dp_5"
                     android:text="@string/traffic_was"
-                    android:textSize="@dimen/sp_8" />
+                    android:textSize="@dimen/sp_6" />
             </LinearLayout>
         </LinearLayout>
 
@@ -312,7 +312,7 @@
                 android:layout_marginRight="@dimen/dp_70"
                 android:text="@string/cleaning_method"
                 android:textColor="#3E5DA8"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <LinearLayout
                 android:layout_width="match_parent"
@@ -320,6 +320,7 @@
                 android:gravity="center">
 
                 <RelativeLayout
+                    android:id="@+id/rl_clear"
                     android:layout_width="@dimen/dp_80"
                     android:layout_height="match_parent"
                     android:layout_margin="@dimen/dp_5"
@@ -331,7 +332,7 @@
                         android:padding="@dimen/dp_5"
                         android:text="@string/start_cleaning"
                         android:textColor="@color/white"
-                        android:textSize="@dimen/dp_10" />
+                        android:textSize="@dimen/dp_8" />
 
                     <ImageView
                         android:layout_width="@dimen/dp_40"
@@ -353,7 +354,7 @@
                         android:padding="@dimen/dp_5"
                         android:text="@string/regular_cleaning"
                         android:textColor="@color/white"
-                        android:textSize="@dimen/dp_10" />
+                        android:textSize="@dimen/dp_8" />
 
                     <ImageView
                         android:layout_width="@dimen/dp_40"
@@ -384,7 +385,7 @@
                 android:layout_marginRight="@dimen/dp_70"
                 android:text="@string/environmental_testing"
                 android:textColor="#3E5DA8"
-                android:textSize="@dimen/sp_8" />
+                android:textSize="@dimen/sp_7" />
 
             <LinearLayout
                 android:layout_width="match_parent"
@@ -393,31 +394,35 @@
                 android:gravity="center">
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_28"
+                    android:layout_height="@dimen/dp_28"
+                    android:layout_marginRight="@dimen/dp_28"
+                    android:background="@drawable/shape_hollow_circle_wendu"
                     android:gravity="center"
-                    android:textSize="@dimen/sp_12"
                     android:text="40°"
-                    android:textColor="@color/bright_blue" />
+                    android:textColor="#ffd95e"
+                    android:textSize="@dimen/sp_8" />
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_28"
+                    android:layout_height="@dimen/dp_28"
+                    android:layout_marginRight="@dimen/dp_28"
+                    android:background="@drawable/shape_hollow_circle_shidu"
                     android:gravity="center"
-                    android:textSize="@dimen/sp_12"
                     android:text="40°"
-                    android:textColor="@color/bright_blue" />
+                    android:textColor="#437dff"
+                    android:textSize="@dimen/sp_8" />
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_28"
+                    android:layout_height="@dimen/dp_28"
+                    android:layout_marginLeft="@dimen/dp_5"
+                    android:layout_marginRight="@dimen/dp_5"
+                    android:background="@drawable/shape_hollow_circle_huanjing"
                     android:gravity="center"
                     android:text="40°"
-                    android:textSize="@dimen/sp_12"
-                    android:textColor="@color/bright_blue" />
+                    android:textColor="#57f3ff"
+                    android:textSize="@dimen/sp_8" />
 
             </LinearLayout>
 
@@ -428,31 +433,30 @@
                 android:gravity="center">
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_28"
+                    android:layout_height="@dimen/dp_28"
+                    android:layout_marginRight="@dimen/dp_30"
                     android:gravity="center"
                     android:text="@string/temperature"
                     android:textColor="@color/logo_blue"
-                    android:textSize="@dimen/sp_8" />
+                    android:textSize="@dimen/sp_6" />
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_28"
+                    android:layout_height="@dimen/dp_28"
+                    android:layout_marginRight="@dimen/dp_30"
                     android:gravity="center"
                     android:text="@string/humidity"
                     android:textColor="@color/logo_blue"
-                    android:textSize="@dimen/sp_8" />
+                    android:textSize="@dimen/sp_6" />
 
                 <TextView
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
+                    android:layout_width="@dimen/dp_40"
+                    android:layout_height="@dimen/dp_28"
                     android:gravity="center"
                     android:text="@string/environmental_comfort_index"
                     android:textColor="@color/logo_blue"
-                    android:textSize="@dimen/sp_8" />
+                    android:textSize="@dimen/sp_6" />
 
             </LinearLayout>
         </LinearLayout>

+ 3 - 3
app/src/main/res/layout/navigation_layout.xml

@@ -7,7 +7,7 @@
     android:orientation="vertical">
 
     <ImageView
-        android:layout_marginTop="@dimen/dp_10"
+        android:layout_marginTop="@dimen/dp_7"
         android:layout_width="@dimen/dp_50"
         android:layout_height="wrap_content"
         android:src="@drawable/login_logo" />
@@ -15,8 +15,8 @@
     <TextView
         android:layout_width="@dimen/dp_50"
         android:layout_height="@dimen/dp_50"
-        android:layout_marginTop="@dimen/dp_10"
-        android:layout_marginBottom="@dimen/dp_10"
+        android:layout_marginTop="@dimen/dp_7"
+        android:layout_marginBottom="@dimen/dp_5"
         android:background="@drawable/shape_user_round"
         android:gravity="center"
         android:text="A"