소스 검색

<增加初始化界面>

weizhengliang 4 년 전
부모
커밋
034d6777c7
18개의 변경된 파일401개의 추가작업 그리고 8개의 파일을 삭제
  1. 9 0
      callingbed/build.gradle
  2. 4 0
      callingbed/src/main/AndroidManifest.xml
  3. 0 4
      callingbed/src/main/java/com/wdkl/app/ncs/callingbed/activity/CallingbedActivity.kt
  4. 92 0
      callingbed/src/main/java/com/wdkl/app/ncs/callingbed/activity/InitActivity.kt
  5. 3 0
      callingbed/src/main/java/com/wdkl/app/ncs/callingbed/di/CallingbedComponent.kt
  6. 154 0
      callingbed/src/main/java/com/wdkl/app/ncs/callingbed/helper/NetHelper.java
  7. 30 0
      callingbed/src/main/java/com/wdkl/app/ncs/callingbed/helper/ReflectHelper.java
  8. 36 0
      callingbed/src/main/res/layout/init_lay.xml
  9. BIN
      callingbed/src/main/res/mipmap-hdpi/msg_network.png
  10. BIN
      callingbed/src/main/res/mipmap-mdpi/msg_network.png
  11. BIN
      callingbed/src/main/res/mipmap-xhdpi/msg_network.png
  12. 1 1
      callingbed/src/main/res/values/strings.xml
  13. 3 0
      middleware/src/main/code/com/wdkl/ncs/android/middleware/api/CallingbedApi.kt
  14. 2 0
      middleware/src/main/code/com/wdkl/ncs/android/middleware/di/PresenterComponent.kt
  15. 13 0
      middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/contract/callingbed/InitActivityContract.kt
  16. 3 2
      middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/presenter/callingbed/CallingbedActivityPresenter.kt
  17. 50 0
      middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/presenter/callingbed/InitActivityPresenter.kt
  18. 1 1
      welcome/src/main/code/com/wdkl/ncs/android/component/welcome/activity/WelcomeActivity.kt

+ 9 - 0
callingbed/build.gradle

@@ -35,6 +35,8 @@ android {
         }
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+        buildConfigField "String", "BUILD_TIME", getDate()
     }
 
     lintOptions {
@@ -50,6 +52,13 @@ android {
 
 }
 
+//获取编译日期
+String getDate() {
+    Date date = new Date();
+    String dates = "\""+date.format("yyyy年MM月dd日", TimeZone.getTimeZone("UTC"))+"\"";
+    return dates;
+}
+
 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

+ 4 - 0
callingbed/src/main/AndroidManifest.xml

@@ -10,6 +10,10 @@
         android:label="@string/app_name"
         android:supportsRtl="true" >
 
+        <activity android:name=".activity.InitActivity"
+            android:screenOrientation="landscape"
+            android:launchMode="singleTask"/>
+
         <activity android:name=".activity.CallingbedActivity"
             android:screenOrientation="landscape"
             android:launchMode="singleTask"/>

+ 0 - 4
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/activity/CallingbedActivity.kt

@@ -522,16 +522,12 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, CallingbedMa
         runOnUiThread {
             when (state) {
                 SipStatus.REGISTERING -> {
-                    //netOff = false
                     view_title_layout_tv_point.setBackgroundResource(R.color.yellow_color)
                 }
                 SipStatus.REGISTERFAIL -> {
-                    //netOff = true
-                    //handler.sendEmptyMessageDelayed(RESET_ETHE, 120000)
                     view_title_layout_tv_point.setBackgroundResource(R.color.red_color)
                 }
                 SipStatus.REGISTERCOM -> {
-                    //netOff = false
                     view_title_layout_tv_point.setBackgroundResource(R.color.green)
                 }
             }

+ 92 - 0
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/activity/InitActivity.kt

@@ -0,0 +1,92 @@
+package com.wdkl.app.ncs.callingbed.activity
+
+import com.enation.javashop.android.jrouter.external.annotation.Router
+import com.enation.javashop.net.engine.model.NetState
+import com.wdkl.app.ncs.callingbed.BuildConfig
+import com.wdkl.app.ncs.callingbed.R
+import com.wdkl.app.ncs.callingbed.databinding.InitLayBinding
+import com.wdkl.app.ncs.callingbed.helper.NetHelper
+import com.wdkl.app.ncs.callingbed.helper.ReflectHelper
+import com.wdkl.app.ncs.callingbed.launch.CallingbedLaunch
+import com.wdkl.ncs.android.lib.base.BaseActivity
+import com.wdkl.ncs.android.lib.utils.showMessage
+import com.wdkl.ncs.android.lib.vo.filter
+import com.wdkl.ncs.android.middleware.logic.contract.callingbed.InitActivityContract
+import com.wdkl.ncs.android.middleware.logic.presenter.callingbed.InitActivityPresenter
+import kotlinx.android.synthetic.main.init_lay.*
+import serialporttest.utils.SerialPortUtil
+
+@Router(path = "/callingbed/init")
+class InitActivity :BaseActivity<InitActivityPresenter, InitLayBinding>(), InitActivityContract.View {
+
+    val sdk_version = android.os.Build.VERSION.SDK_INT
+    val product_name = ReflectHelper.getProperty("ro.product.name", "null")
+
+    override fun getLayId(): Int {
+        return R.layout.init_lay
+    }
+
+    override fun bindDagger() {
+        CallingbedLaunch.component.inject(this)
+    }
+
+    override fun init() {
+        updateInitInfo("")
+    }
+
+    override fun bindEvent() {
+        //
+    }
+
+    override fun destory() {
+        //
+    }
+
+    //数据加载错误
+    override fun onError(message: String, type: Int) {
+        dismissDialog()
+        showMessage(message)
+    }
+
+    //数据加载完成
+    override fun complete(message: String, type: Int) {
+        dismissDialog()
+
+    }
+
+    //开始获取数据
+    override fun start() {
+        showDialog()
+    }
+
+    //网络监听
+    override fun networkMonitor(state: NetState) {
+        state.filter(onMobile = {
+
+        },onWifi = {
+
+        },offline = {
+
+        })
+    }
+
+    override fun setDeviceInfo() {
+        //
+    }
+
+    fun updateInitInfo(err: String) {
+        val macStr = "MAC地址: " + NetHelper.getInstance().macAddress
+        val ipStr = ", IP地址: " + NetHelper.getInstance().localIP
+        tv_init_msg.setText(macStr + ipStr + "\r\nError: " + err + getAppInfo())
+    }
+
+    fun getAppInfo(): String {
+        val str = ("\r\nApp名称: " + getString(R.string.javashop_app_name)
+                + "\r\nAPP版本号: V" + BuildConfig.VERSION_NAME
+                + "\r\n设备ID: " + SerialPortUtil.KEY_ID + "    NCS-中央服务器系列"
+                + "\r\n发布日期:" + BuildConfig.BUILD_TIME
+                + "\r\nSDK版本: " + sdk_version + ", 平台: " + product_name)
+
+        return str
+    }
+}

+ 3 - 0
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/di/CallingbedComponent.kt

@@ -1,6 +1,7 @@
 package com.wdkl.app.ncs.callingbed.di
 
 import com.wdkl.app.ncs.callingbed.activity.CallingbedActivity
+import com.wdkl.app.ncs.callingbed.activity.InitActivity
 import com.wdkl.app.ncs.callingbed.fragment.*
 import com.wdkl.ncs.android.middleware.di.ApplicationComponent
 import dagger.Component
@@ -9,6 +10,8 @@ import dagger.Component
 interface CallingbedComponent {
     fun inject(activity: CallingbedActivity)
 
+    fun inject(activity: InitActivity)
+
     fun inject(activity: MainFragment)
 
     fun inject(activity: DoctorOrderFragment)

+ 154 - 0
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/helper/NetHelper.java

@@ -1,7 +1,9 @@
 package com.wdkl.app.ncs.callingbed.helper;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.net.ConnectivityManager;
+import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.text.TextUtils;
 
@@ -12,6 +14,13 @@ import org.greenrobot.eventbus.EventBus;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -311,4 +320,149 @@ public class NetHelper {
 
         return -1;
     }
+
+    /**
+     * 得到MAC
+     *
+     * @return String
+     */
+    public String getMacAddress() {
+        String mac = "";
+        try {
+            mac = getLocalMacAddressFromIp();
+            if (TextUtils.isEmpty(mac)) {
+                mac = getNetworkMac();
+            }
+            if (TextUtils.isEmpty(mac)) {
+                mac = tryGetWifiMac();
+            }
+        } catch (Exception e) {
+        }
+        return mac;
+    }
+
+    public String tryGetWifiMac() {
+        String mac;
+        WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+        WifiInfo wi = wm.getConnectionInfo();
+        if (wi == null || wi.getMacAddress() == null) {
+            mac = null;
+        }
+        if ("02:00:00:00:00:00".equals(wi.getMacAddress().trim())) {
+            mac = null;
+        } else {
+            mac = wi.getMacAddress().trim();
+        }
+        return mac;
+    }
+
+    /**
+     * 通过网络接口获取
+     *
+     * @return
+     */
+    public static String getNetworkMac() {
+        try {
+            List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
+            for (NetworkInterface nif : all) {
+                // if (!nif.getName().equalsIgnoreCase("wlan0") && !nif.getName().equalsIgnoreCase("eth0") && !nif.getName().equalsIgnoreCase("eth1"))
+                if (!nif.getName().equalsIgnoreCase("eth0") && !nif.getName().equalsIgnoreCase("eth1") && !nif.getName().equalsIgnoreCase("eth2"))
+                    continue;
+                byte[] macBytes = nif.getHardwareAddress();
+                if (macBytes == null) {
+                    return null;
+                }
+                StringBuilder res1 = new StringBuilder();
+                for (byte b : macBytes) {
+                    res1.append(String.format("%02X:", b));
+                }
+                if (res1.length() > 0) {
+                    res1.deleteCharAt(res1.length() - 1);
+                }
+                return res1.toString();
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 根据IP地址获取MAC地址
+     *
+     * @return
+     */
+    @SuppressLint("NewApi")
+    public String getLocalMacAddressFromIp() {
+        String strMacAddr = null;
+        try {
+            // 获得IpD地址
+            InetAddress ip = getLocalInetAddress();
+            byte[] b = NetworkInterface.getByInetAddress(ip)
+                    .getHardwareAddress();
+            StringBuffer buffer = new StringBuffer();
+            for (int i = 0; i < b.length; i++) {
+                if (i != 0) {
+                    buffer.append(':');
+                }
+                String str = Integer.toHexString(b[i] & 0xFF);
+                buffer.append(str.length() == 1 ? 0 + str : str);
+            }
+            strMacAddr = buffer.toString().toUpperCase();
+
+        } catch (Exception e) {
+
+        }
+
+        return strMacAddr;
+    }
+
+    public InetAddress getLocalInetAddress() {
+        InetAddress ip = null;
+        try {
+            // 列举
+            Enumeration<NetworkInterface> en_netInterface = NetworkInterface
+                    .getNetworkInterfaces();
+            while (en_netInterface.hasMoreElements()) {// 是否还有元素
+                NetworkInterface ni = en_netInterface
+                        .nextElement();// 得到下一个元素
+                Enumeration<InetAddress> en_ip = ni.getInetAddresses();// 得到一个ip地址的列举
+                while (en_ip.hasMoreElements()) {
+                    ip = en_ip.nextElement();
+                    if (!ip.isLoopbackAddress()
+                            && ip.getHostAddress().indexOf(":") == -1)
+                        break;
+                    else
+                        ip = null;
+                }
+
+                if (ip != null) {
+                    break;
+                }
+            }
+        } catch (SocketException e) {
+
+            e.printStackTrace();
+        }
+
+
+        return ip;
+    }
+
+    public String getLocalIP() {
+        try {
+            for (Enumeration<NetworkInterface> enNetI = NetworkInterface.getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
+                NetworkInterface netI = enNetI.nextElement();
+                for (Enumeration<InetAddress> enumIpAddr = netI.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
+                    InetAddress inetAddress = enumIpAddr.nextElement();
+                    if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
+                        return inetAddress.getHostAddress();
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
 }

+ 30 - 0
callingbed/src/main/java/com/wdkl/app/ncs/callingbed/helper/ReflectHelper.java

@@ -0,0 +1,30 @@
+package com.wdkl.app.ncs.callingbed.helper;
+
+import java.lang.reflect.Method;
+
+public class ReflectHelper {
+
+    public static String getProperty(String key, String defaultValue) {
+        String value = defaultValue;
+        try {
+            Class<?> c = Class.forName("android.os.SystemProperties");
+            Method get = c.getMethod("get", String.class, String.class);
+            value = (String)(get.invoke(c, key, defaultValue));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return value;
+
+    }
+
+    public static void setProperty(String key, String value) {
+        try {
+            Class<?> c = Class.forName("android.os.SystemProperties");
+            Method set = c.getMethod("set", String.class, String.class);
+            set.invoke(c, key, value);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 36 - 0
callingbed/src/main/res/layout/init_lay.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout>
+    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:id="@+id/activity_init_layout_rl"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageView
+            android:id="@+id/iv_net_err"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:layout_centerHorizontal="true"
+            android:src="@mipmap/msg_network" />
+
+        <Button
+            android:id="@+id/btn_init_refresh"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:layout_below="@id/iv_net_err"
+            android:layout_centerHorizontal="true"
+            android:text="重新加载"/>
+
+        <TextView
+            android:id="@+id/tv_init_msg"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:layout_below="@id/btn_init_refresh"
+            android:layout_centerHorizontal="true"
+            android:text="正在初始化"
+            android:textSize="24sp" />
+
+    </RelativeLayout>
+</layout>

BIN
callingbed/src/main/res/mipmap-hdpi/msg_network.png


BIN
callingbed/src/main/res/mipmap-mdpi/msg_network.png


BIN
callingbed/src/main/res/mipmap-xhdpi/msg_network.png


+ 1 - 1
callingbed/src/main/res/values/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">Callingbed</string>
+    <string name="app_name"></string>
     <string name="local_sip">4000360960</string>
     <string name="target_sip">4000348830</string>
 </resources>

+ 3 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/api/CallingbedApi.kt

@@ -9,4 +9,7 @@ interface CallingbedApi {
 
     @GET("/ncs/customer/{customer_id}")
     fun getBedData(@Path("customer_id") customerId :Int): Observable<ResponseBody>
+
+    @GET("/ncs/device/{device_mac}")
+    fun getDeviceInfo(@Path("device_mac") deviceMac :String): Observable<ResponseBody>
 }

+ 2 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/di/PresenterComponent.kt

@@ -55,6 +55,8 @@ interface PresenterComponent {
     //5寸分机
     fun inject(presenter: CallingbedActivityPresenter)
 
+    fun inject(presenter: InitActivityPresenter)
+
     fun inject(presenter: MainFragmentPresenter)
 
     fun inject(presenter: DoctorOrderFragmentPresenter)

+ 13 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/contract/callingbed/InitActivityContract.kt

@@ -0,0 +1,13 @@
+package com.wdkl.ncs.android.middleware.logic.contract.callingbed
+
+import com.wdkl.ncs.android.lib.base.BaseContract
+
+interface InitActivityContract {
+    interface View : BaseContract.BaseView {
+        fun setDeviceInfo()
+    }
+
+    interface Presenter : BaseContract.BasePresenter {
+        fun loadDeviceInfo(mac: String)
+    }
+}

+ 3 - 2
middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/presenter/callingbed/CallingbedActivityPresenter.kt

@@ -16,12 +16,13 @@ import io.reactivex.disposables.Disposable
 import javax.inject.Inject
 
 class CallingbedActivityPresenter @Inject constructor() :RxPresenter<CallingbedActivityContract.View>(), CallingbedActivityContract.Presenter {
+
     override fun bindDagger() {
         MiddlewareDaggerComponent.component.inject(this)
     }
 
     @Inject
-    protected lateinit var callingbed2Api: CallingbedApi
+    protected lateinit var callingbedApi: CallingbedApi
 
     private val observer = object :ConnectionObserver<Any>() {
         override fun onStartWithConnection() {
@@ -43,7 +44,7 @@ class CallingbedActivityPresenter @Inject constructor() :RxPresenter<CallingbedA
     }
 
     override fun loadData(bedId: Int) {
-        callingbed2Api.getBedData(bedId)
+        callingbedApi.getBedData(bedId)
                 .map {
                     var gson = GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create()
                     var customerInfoVO = gson.fromJson(it.getJsonString(), CustomerInfoVO::class.java)

+ 50 - 0
middleware/src/main/code/com/wdkl/ncs/android/middleware/logic/presenter/callingbed/InitActivityPresenter.kt

@@ -0,0 +1,50 @@
+package com.wdkl.ncs.android.middleware.logic.presenter.callingbed
+
+import com.enation.javashop.net.engine.plugin.connection.ConnectionQuality
+import com.enation.javashop.net.engine.plugin.exception.ExceptionHandle
+import com.enation.javashop.net.engine.utils.ThreadFromUtils
+import com.wdkl.ncs.android.lib.base.RxPresenter
+import com.wdkl.ncs.android.lib.utils.ConnectionObserver
+import com.wdkl.ncs.android.middleware.api.CallingbedApi
+import com.wdkl.ncs.android.middleware.di.MiddlewareDaggerComponent
+import com.wdkl.ncs.android.middleware.logic.contract.callingbed.InitActivityContract
+import io.reactivex.disposables.Disposable
+import javax.inject.Inject
+
+class InitActivityPresenter @Inject constructor() : RxPresenter<InitActivityContract.View>(), InitActivityContract.Presenter {
+
+    override fun bindDagger() {
+        MiddlewareDaggerComponent.component.inject(this)
+    }
+
+    @Inject
+    protected lateinit var initDeviceApi: CallingbedApi
+
+    private val observer = object : ConnectionObserver<Any>() {
+        override fun onStartWithConnection() {
+            providerView().start()
+        }
+
+        override fun onNextWithConnection(result: Any, connectionQuality: ConnectionQuality) {
+            providerView().complete("")
+            providerView().setDeviceInfo()
+        }
+
+        override fun onErrorWithConnection(error: ExceptionHandle.ResponeThrowable, connectionQuality: ConnectionQuality) {
+            providerView().onError(error.customMessage)
+        }
+
+        override fun attachSubscribe(var1: Disposable) {
+            addDisposable(var1)
+        }
+    }
+
+    override fun loadDeviceInfo(mac: String) {
+        initDeviceApi.getDeviceInfo(mac)
+                .map {
+                    //
+                }
+                .compose(ThreadFromUtils.defaultSchedulers())
+                .subscribe(observer)
+    }
+}

+ 1 - 1
welcome/src/main/code/com/wdkl/ncs/android/component/welcome/activity/WelcomeActivity.kt

@@ -92,7 +92,7 @@ class WelcomeActivity :BaseActivity<WelcomePresenter, ActivityWelcomeBinding>(),
     override fun toHome() {
         AppTool.Time.delay(200) {
             //push("/home/main")
-            push("/callingbed/main")
+            push("/callingbed/init")
             finish()
         }
     }