فهرست منبع

修改读取cfg文件的方法,
1. 启动一个文件选择器来让用户选择要访问的文件或者目录
2. 在 `onActivityResult` 方法中处理文件选择器的结果
3. 使用 `ContentResolver` 和 `Uri` 来读取文件的内容
目前内外部文件都统一一个方法获取文件内容

robbin 1 سال پیش
والد
کامیت
af77add9b5

+ 1 - 1
.idea/misc.xml

@@ -29,7 +29,7 @@
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
   <component name="ProjectType">
     <option name="id" value="Android" />
   </component>

+ 1 - 1
app/build.gradle

@@ -14,7 +14,7 @@ android {
         variant ->
             variant.outputs.all{
                 //´Ë´¦Ö¸¶¨Éú³ÉµÄapkÎļþÃû
-                outputFileName = "WingCoolAPK_V2.4.0_20240315.apk"
+                outputFileName = "WingCoolAPK_V2.4.1_20240320.apk"
             }
     }
     lintOptions {

+ 48 - 15
app/src/main/java/com/example/administrator/wingcool_gt9_apk/Config.java

@@ -490,18 +490,18 @@ public class Config extends AppCompatActivity
         edit_text = (EditText) findViewById(R.id.editsearch);
 
         //选择本地文件
-        btnLocalFileButton = (Button) findViewById(R.id.localfile);
-        btnLocalFileButton.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                //ActivityCompat.requestPermissions(  Config.this, new String[]{android
-                //        .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
-                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
-                intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
-                intent.addCategory(Intent.CATEGORY_OPENABLE);
-                startActivityForResult(intent, 2);
-            }
-        });
+        //btnLocalFileButton = (Button) findViewById(R.id.localfile);
+        //btnLocalFileButton.setOnClickListener(new View.OnClickListener() {
+        //    @Override
+        //    public void onClick(View v) {
+        //        //ActivityCompat.requestPermissions(  Config.this, new String[]{android
+        //        //        .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
+        //        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+        //        intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
+        //        intent.addCategory(Intent.CATEGORY_OPENABLE);
+        //        startActivityForResult(intent, 2);
+        //    }
+        //});
 
         //选择U盘文件
         btnUDiskFileButton = (Button) findViewById(R.id.udiskfile);
@@ -510,7 +510,7 @@ public class Config extends AppCompatActivity
             public void onClick(View v) {
                 //ActivityCompat.requestPermissions(  Config.this, new String[]{android
                 //        .Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
-                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                 intent.setType("*/*");//设置类型,我这里是任意类型,任意后缀的可以这样写。
                 intent.addCategory(Intent.CATEGORY_OPENABLE);
                 startActivityForResult(intent, 1);
@@ -1678,7 +1678,7 @@ public class Config extends AppCompatActivity
     }
     */
 
-    protected void onActivityResult ( int requestCode, int resultCode, Intent data){
+    protected void onActivityResult ( int requestCode, int resultCode, Intent resultData){
         if (resultCode == Activity.RESULT_OK) {
 
             int permission_write = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
@@ -1692,6 +1692,38 @@ public class Config extends AppCompatActivity
                         android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
             }
 
+            String configString = "";
+
+            if (requestCode == 1 && resultCode == Activity.RESULT_OK) {  //U 盘 文 件
+
+                Uri uri = null;
+                if (resultData != null){
+                    uri = resultData.getData();
+                }
+
+                try {
+                    InputStream inputStream = getContentResolver().openInputStream(uri);
+                    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+                    String line;
+                    StringBuilder stringBuilder = new StringBuilder();
+
+                    while ((line = reader.readLine()) != null){
+                        stringBuilder.append(line);
+                    }
+
+                    reader.close();
+
+                    configString = stringBuilder.toString();
+
+                    //edit_search.setText(fileData);
+                    edit_search.setText(uri.getPath());
+
+                } catch (IOException c) {
+                    edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
+                    return;
+                }
+            }
+            /*
             StringBuffer buffer = new StringBuffer();
             String configString = "";
             Uri uri = data.getData();
@@ -1786,7 +1818,7 @@ public class Config extends AppCompatActivity
                     return;
                 }
             }  //end of else if (requestCode == 2)
-
+            */
     /*
                 Uri uri = data.getData();
                 File file = new File(uri.getPath());
@@ -1856,6 +1888,7 @@ public class Config extends AppCompatActivity
             }
 
             ReadCfgRam(stringCfgArr);
+
         }  //end of if (resultCode == Activity.RESULT_OK)
     }
 

+ 0 - 12
app/src/main/res/layout-hdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land-hdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land-mdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land-xhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land-xxhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land-xxxhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-land/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-mdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-xhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-xxhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout-xxxhdpi/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 0 - 12
app/src/main/res/layout/activity_config.xml

@@ -50,18 +50,6 @@
                     android:padding="5dp"
                     android:singleLine="true" />
 
-                <Button
-                    android:id="@+id/localfile"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:layout_margin="5dp"
-                    android:layout_weight="65"
-                    android:text="@string/localfile"
-                    android:textSize="18dp"
-                    android:textAllCaps="false"
-                    app:layout_constraintEnd_toEndOf="parent"
-                    app:layout_constraintTop_toTopOf="parent" />
-
                 <Button
                     android:id="@+id/udiskfile"
                     android:layout_width="match_parent"

+ 2 - 2
app/src/main/res/values-en/strings.xml

@@ -24,7 +24,7 @@
     <string name="chooseconfig">choose config</string>
     <string name="invalidfile">Invalid filename or file not found</string>
     <string name="localfile">Local File</string>
-    <string name="udiskfile">U Disk File</string>
+    <string name="udiskfile">Choose a file</string>
     <string name="cfgaddr">addr</string>
     <string name="nameandformat">please type the name and format of file</string>
     <string name="nopermission">Do not have the read and write permission on the SD card</string>
@@ -106,7 +106,7 @@
     <string name="companyaddr">Address:Room 2008, Chuangxingda Business Building, No.36 Liuxian 3rd Road, Baoan District, Shenzhen</string>
     <string name="telephonenum">Telephone:186 8896 1937</string>
     <string name="emailaddr">Email:max@wingcool.cn</string>
-    <string name="version">APK Version:v2.4.0_20240315-Release Version</string>
+    <string name="version">APK Version:v2.4.1_20240320-Debug Version</string>
 
     <!-- other -->
     <string name="app_name">WingCoolAPK</string>

+ 2 - 2
app/src/main/res/values/strings.xml

@@ -24,7 +24,7 @@
     <string name="chooseconfig">选择配置文件</string>
     <string name="invalidfile">无效的文件名或找不到文件</string>
     <string name="localfile">本地文件</string>
-    <string name="udiskfile">U盘文件</string>
+    <string name="udiskfile">选择文件</string>
     <string name="cfgaddr">地址</string>
     <string name="nameandformat">请输入文件名及文件格式</string>
     <string name="nopermission">无法获取SD卡读写权限</string>
@@ -106,7 +106,7 @@
     <string name="companyaddr">地址:深圳市宝安区留仙三路 36 号创兴达商务大厦 2008 室</string>
     <string name="telephonenum">电话:186 8896 1937</string>
     <string name="emailaddr">邮箱:max@wingcool.cn</string>
-    <string name="version">APK版本:v2.4.0_20240315-发布版本</string>
+    <string name="version">APK版本:v2.4.1_20240320-Debug版本</string>
 
     <!-- other -->
     <string name="app_name">WingCoolAPK</string>