liuzhenxing1118 7 сар өмнө
parent
commit
0acd9b76ce

+ 14 - 10
app/src/main/java/com/xplora/xponboarding/Activity/QRActivity.java

@@ -1,5 +1,6 @@
 package com.xplora.xponboarding.Activity;
 
+import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
@@ -33,17 +34,20 @@ public class QRActivity extends BaseActivatedActivity {
         ImageView qrIv = findViewById(R.id.qr);
         Button button = findViewById(R.id.mTestActivited);
 
-        textView.setText(R.string.qrcode_scan);
+        String ticket = DataManager.getTicket();
+        boolean isTicketOK = ticket.length() > 0;
+        String host = "https://sgp.tecanswer.com/w/";
+        String content = host + "?" + "t=" + ticket;
+        int color = isTicketOK ? Color.BLACK : getColor(R.color.xp_red);
+        qrIv.setImageBitmap(QRCodeUtil.createQRCodeBitmapEx(content, 240, 240, color));
 
-        String host = "https://start.myxplora.com/";
-        String qr = "qr=" + DataManager.getIMEI();
-        String c = "c=sikey";
-        String t = "t=" + "X6";
-        String bt = "bt=" + DataManager.getBTMac();
-        String content = host + "?" + qr + "&" + c + "&" + t + "&" + bt;
-        //content = Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
-        //Log.d(TAG, "initView: qr content:" + content);
-        qrIv.setImageBitmap(QRCodeUtil.createQRCodeBitmap(content, 240, 240));
+        //如果 ticket 是空的,二维码标红
+        if (isTicketOK) {
+            textView.setText(R.string.qrcode_scan);
+        } else {
+            textView.setText(R.string.qrcode_error);
+            textView.setTextColor(getColor(R.color.xp_red));
+        }
 
         if (Macros.DEBUG) {
             button.setVisibility(View.VISIBLE);

+ 8 - 0
app/src/main/java/com/xplora/xponboarding/Data/DataManager.java

@@ -32,6 +32,14 @@ public class DataManager extends Application {
         sContext = getApplicationContext();
     }
 
+    public static String getTicket() {
+        String value = Settings.System.getString(sContext.getContentResolver(), "sk_tk");
+        if (value == null)
+            value = "";
+        Log.d(TAG, "getTicket: " + value);
+        return value;
+    }
+
     public static String getTimeFormat() {
         if (Macros.DEBUG) {
             return mTimeFormat;

+ 17 - 3
app/src/main/java/com/xplora/xponboarding/Utils/QRCodeUtil.java

@@ -28,7 +28,20 @@ public class QRCodeUtil {
                 height,
                 "UTF-8",
                 null,
-                1
+                1,
+                Color.BLACK
+        );
+    }
+
+    public static Bitmap createQRCodeBitmapEx(String content, int width, int height, int defaultColor) {
+        return createQRCodeBitmap(
+                content,
+                width,
+                height,
+                "UTF-8",
+                null,
+                1,
+                defaultColor
         );
     }
 
@@ -49,7 +62,8 @@ public class QRCodeUtil {
             int height,
             String character_set,
             String error_correction,
-            int margin
+            int margin,
+            int defaultColor
     ) {
         /* 1.参数合法性判断  */
         if (TextUtils.isEmpty(content)) { // 字符串内容判空
@@ -76,7 +90,7 @@ public class QRCodeUtil {
             for (int y = 0; y < height; y++) {
                 for (int x = 0; x < width; x++) {
                     if (bitMatrix.get(x, y)) {
-                        pixels[y * width + x] = Color.BLACK; // 黑色色块像素设置
+                        pixels[y * width + x] = defaultColor; // 黑色色块像素设置
                     } else {
                         pixels[y * width + x] = Color.WHITE; // 白色色块像素设置
                     }

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

@@ -15,7 +15,6 @@
         android:layout_marginTop="30dp"
         />
 
-
     <TextView
         android:id="@+id/content"
         android:layout_width="wrap_content"
@@ -34,11 +33,12 @@
 
     <Button
         android:id="@+id/mTestActivited"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
+        android:layout_width="90dp"
+        android:layout_height="35dp"
         android:layout_alignParentEnd="true"
         android:layout_alignParentBottom="true"
         android:text="Activited"
+        android:textSize="12sp"
         android:visibility="gone"
         />
 

+ 1 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -22,6 +22,7 @@
     <string name="sim_unactivated_content">请在使用SIM卡之前激活它,您可以向SIM卡提供商寻求激活支持</string>
     <string name="qr_code">二维码</string>
     <string name="qrcode_scan">使用应用程序扫描二维码以激活或连接手表</string>
+    <string name="qrcode_error">发生错误,请确保手表插卡并连接网络</string>
     <string name="qrcode_install_sim">请先安装SIM卡</string>
     <string name="restart">重新启动</string>
     <string name="sim_input_error_3">您输入了错误的PIN码\n 3次\n请使用手机解锁SIM卡</string>

+ 1 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -22,6 +22,7 @@
     <string name="sim_unactivated_content">使用前請先啟動您的SIM卡,您可以向您的SIM卡提供者尋求啟動支援</string>
     <string name="qr_code">QR 圖碼</string>
     <string name="qrcode_scan">使用App掃描二維碼啟動或連接手錶</string>
+    <string name="qrcode_error">發生錯誤,請確保手錶插卡並連接網絡</string>
     <string name="qrcode_install_sim">請先安裝SIM卡</string>
     <string name="restart">重新啟動</string>
     <string name="sim_input_error_3">您已輸入錯誤 PIN 碼 \n 3 次 \n 請使用您的手機解鎖 SIM 卡</string>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -10,4 +10,5 @@
 
     <color name="transparent">#00FFFFFF</color>
     <color name="xp_yellow">#FFFFC34B</color>
+    <color name="xp_red">#FFFF0000</color>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -21,6 +21,7 @@
     <string name="sim_unactivated_content">Please activate your SIM card before using it, you can ask your SIM provider for activation support</string>
     <string name="qr_code">QR code</string>
     <string name="qrcode_scan">Use App to scan QR code to activate or connect watch</string>
+    <string name="qrcode_error">An error has occurred, please ensure that the watch is inserted into the card and connected to the network</string>
     <string name="qrcode_install_sim">Please install a SIM card first</string>
     <string name="restart">Restart</string>
     <string name="sim_input_error_3">You\'ve input wrong PIN \n 3 times \n Please use your phone to unlock the SIM card</string>