Просмотр исходного кода

1.启动页配置
2.打包证书创建

hanwenjie 1 год назад
Родитель
Сommit
aed33eeb14

+ 66 - 16
app/src/main/java/com/info666/app/infraredRemote/MainActivity.java

@@ -41,28 +41,51 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
     private Handler handler;
 
+    private boolean isDebug = false;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         sp = getSharedPreferences("config", Context.MODE_PRIVATE);
+        //初始化试图
+        this.initView();
+        //初始化app参数
+        this.initApp();
+    }
+
+    public void initView(){
         etUrl = findViewById(R.id.et_url);
         btnNext = findViewById(R.id.bt_next);
         btnNext.setOnClickListener(this);
         findViewById(R.id.bt_qrc).setOnClickListener(this);
         etUrl.setText(sp.getString("url","http://ccvadmin.info666.com/ljshxyqy/"));
         handler = new Handler(this);
-        this.initApp();
+        if(isDebug){
+            findViewById(R.id.ll_welcome).setVisibility(View.GONE);
+            findViewById(R.id.et_url).setVisibility(View.VISIBLE);
+            findViewById(R.id.ll_mt).setVisibility(View.VISIBLE);
+            findViewById(R.id.bt_next).setVisibility(View.VISIBLE);
+            findViewById(R.id.bt_qrc).setVisibility(View.VISIBLE);
+        }
     }
 
     public void initApp(){
         new Thread(()->{
-            String result = HttpUtil.get("http://api.info666.com/api/api/v1/appConfig/getAppConfig");
-            JSONObject jsonObject = JSONObject.parseObject(result);
-            JSONArray jsonArray = jsonObject.getJSONArray("data");
             Message message = new Message();
-            message.obj = jsonArray.getJSONObject(0).toJSONString();
-            handler.sendMessage(message);
+            try {
+                String result = HttpUtil.get("http://api.info666.com/api/api/v1/appConfig/getAppConfig",10 * 1000);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                JSONArray jsonArray = jsonObject.getJSONArray("data");
+                message.what = 200;
+                message.obj = jsonArray.getJSONObject(0).toJSONString();
+            }catch (Exception e){
+                message.what = 500;
+            }finally {
+                handler.sendMessage(message);
+            }
+
+
         }).start();
     }
 
@@ -74,18 +97,25 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
             if(null == url || url.length() == 0){
                 return;
             }
-            SharedPreferences.Editor editor = sp.edit();
-            editor.putString("url",url);
-            editor.commit();
-            Intent intent = new Intent(this, InfraredRemoteActivity.class);
-            startActivity(intent);
-            MainActivity.this.finish();
+            this.goInfraredRemote(url);
         } else if(v.getId() == R.id.bt_qrc){
             Intent intent = new Intent(this, MyCaptureActivity.class);
             startActivityForResult(intent,Activity.RESULT_FIRST_USER);
         }
     }
 
+    /**
+     * 打开红外页面
+     */
+    public void goInfraredRemote(String appUrl){
+        SharedPreferences.Editor editor = sp.edit();
+        editor.putString("url",appUrl);
+        editor.commit();
+        Intent intent = new Intent(this, InfraredRemoteActivity.class);
+        startActivity(intent);
+        MainActivity.this.finish();
+    }
+
     @Override
     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
@@ -97,15 +127,30 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
     @Override
     public boolean handleMessage(@NonNull Message msg) {
-        Log.d("handleMessage",msg.obj.toString());
+        Log.d("handleMessage",msg.obj + "");
         try {
+            if(msg.what == 500){
+                new AlertDialog.Builder(this)
+                        .setTitle(String.format("提示"))
+                        .setMessage("网络连接异常,请重试")
+                        .setPositiveButton("确定", (dialog, which) -> {
+                            MainActivity.this.finish();
+                        })
+                        .setCancelable(false)
+                        .create()
+                        .show();
+                return false;
+            }
             JSONObject appData = JSON.parseObject(msg.obj.toString());
             appData = JSON.parseObject(appData.getString("data"));
             int appVersion = appData.getInteger("appVersion");
             String downLoadUrl = appData.getString("downLoadUrl");
+            String appUrl = appData.getString("appUrl");
             int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
             if(appVersion > versionCode){
-                this.updateApp(downLoadUrl);
+                this.updateApp(downLoadUrl,appUrl);
+            }else{
+                this.goInfraredRemote(appUrl);
             }
         } catch (PackageManager.NameNotFoundException e) {
             throw new RuntimeException(e);
@@ -113,7 +158,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         return false;
     }
 
-    public void updateApp(String downLoadUrl){
+    public void updateApp(final String downLoadUrl,final String appUrl){
         new AlertDialog.Builder(this)
             .setTitle(String.format("提示"))
             .setMessage("有新版本需要更新")
@@ -122,8 +167,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                 Intent it = new Intent(Intent.ACTION_VIEW,uri);
                 MainActivity.this.startActivity(it);
                 dialog.dismiss();
+                MainActivity.this.finish();
+            })
+            .setNegativeButton("暂不升级", (dialog, which) -> {
+                this.goInfraredRemote(appUrl);
+                dialog.dismiss();
             })
-            .setNegativeButton("暂不升级", (dialog, which) -> dialog.dismiss())
+            .setCancelable(false)
             .create()
             .show();
     }

+ 30 - 0
app/src/main/res/layout/activity_main.xml

@@ -4,15 +4,43 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:background="@color/white"
     tools:context=".MainActivity">
 
     <LinearLayout
+        android:id="@+id/ll_welcome"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="220dp"
+        android:paddingRight="50dp"
+        android:paddingLeft="50dp"
+        android:orientation="vertical">
+
+        <ImageView
+            android:layout_width="match_parent"
+            android:layout_height="150dp"
+            android:scaleType="centerInside"
+            android:src="@mipmap/ic_icon"/>
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="40dp"
+            android:textSize="20dp"
+            android:gravity="center_horizontal"
+            android:fontFamily="sans-serif-medium"
+            android:text="@string/app_name"/>
+
+    </LinearLayout>
+
+    <LinearLayout
         android:id="@+id/ll_mt"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_centerInParent="true"
         android:paddingRight="50dp"
         android:paddingLeft="50dp"
+        android:visibility="gone"
         android:orientation="vertical">
 
         <LinearLayout
@@ -42,6 +70,7 @@
         android:layout_centerHorizontal="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:visibility="gone"
         android:text="打开"></Button>
 
     <Button
@@ -51,6 +80,7 @@
         android:layout_centerHorizontal="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:visibility="gone"
         android:text="扫码"></Button>
 
 </RelativeLayout>

BIN
app/src/main/res/mipmap-xxhdpi/ic_icon.jpg


BIN
keyStore/key.jks