|
@@ -1,5 +1,6 @@
|
|
|
package com.example.administrator.wingcool_gt9_apk;
|
|
|
|
|
|
+import android.Manifest;
|
|
|
import android.app.Activity;
|
|
|
import android.app.PendingIntent;
|
|
|
import android.content.Context;
|
|
@@ -24,6 +25,7 @@ import android.os.Message;
|
|
|
import android.os.SystemClock;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.text.Editable;
|
|
@@ -85,7 +87,7 @@ public class Config extends AppCompatActivity
|
|
|
private Button mSendCfg;
|
|
|
private byte[] mBytes = new byte[1024];
|
|
|
private byte[] mSendData = new byte[1024];
|
|
|
- private String[] mConfigShow = new String[189];
|
|
|
+ private String[] mConfigShow = new String[512];
|
|
|
|
|
|
private Context mAlertContext;
|
|
|
|
|
@@ -1277,7 +1279,7 @@ public class Config extends AppCompatActivity
|
|
|
mCfg8100 = viewcfgram.findViewById(R.id.cfg8100);
|
|
|
}
|
|
|
//===============================各view中的元素初始化结束===============================================//
|
|
|
-/*
|
|
|
+ /*
|
|
|
@Override
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
switch (parent.getId()){
|
|
@@ -1297,7 +1299,8 @@ public class Config extends AppCompatActivity
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
}
|
|
|
-*/
|
|
|
+ */
|
|
|
+ /*
|
|
|
public List<String> loadFile(String fileName){
|
|
|
List<String> lists = new ArrayList<>();
|
|
|
try {
|
|
@@ -1312,28 +1315,48 @@ public class Config extends AppCompatActivity
|
|
|
lists.add(line);
|
|
|
}
|
|
|
instream.close();
|
|
|
- //editdetail.setText(buffreader.toString()); //buffer.toString())就是读出的内容字符
|
|
|
- //mShow.setText(inputreader.toString());
|
|
|
+ edit_search.setText(buffreader.toString()); //buffer.toString())就是读出的内容字符
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- //Log.e(TAG, "****Load " + fileName + " Error****");
|
|
|
+ edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
}
|
|
|
return lists;
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
if (requestCode == 1) {
|
|
|
- Uri uri = data.getData();
|
|
|
- //Toast.makeText(this, "文件路径:" + uri.getPath().toString(), Toast.LENGTH_SHORT).show();
|
|
|
- edit_search.setText(uri.getPath().toString());
|
|
|
- //loadFile(uri.getPath().toString());
|
|
|
- ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
- .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
|
|
|
+
|
|
|
+ int permission_write = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
+ int permission_read = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
+
|
|
|
+ if ((permission_write != PackageManager.PERMISSION_GRANTED)
|
|
|
+ ||(permission_read != PackageManager.PERMISSION_GRANTED))
|
|
|
+ {
|
|
|
+
|
|
|
+ ActivityCompat.requestPermissions(Config.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
+ android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
|
|
|
+ }
|
|
|
|
|
|
StringBuffer buffer = new StringBuffer();
|
|
|
try {
|
|
|
- FileInputStream fis = new FileInputStream(uri.getPath().toString());
|
|
|
+
|
|
|
+ File dir = Environment.getExternalStorageDirectory();
|
|
|
+ //Uri uri = data.getData();
|
|
|
+
|
|
|
+ edit_search.setText(dir.getPath() + "/GT9110H_wingcool_config.cfg");
|
|
|
+
|
|
|
+ //File dir = Environment.getExternalStorageDirectory();
|
|
|
+ File dataFile = new File(dir.getPath(),"GT9110H_wingcool_config.cfg");
|
|
|
+ FileInputStream fis = new FileInputStream(dataFile);
|
|
|
+ //byte[] bytes = new byte[fis.available()];
|
|
|
+ //fis.read(bytes);
|
|
|
+ //fis.close();
|
|
|
+ //String str = new String(bytes,"utf-8");
|
|
|
+ //edit_search.setText(str);
|
|
|
+
|
|
|
+ //FileInputStream fis = new FileInputStream(uri.getPath().toString());
|
|
|
InputStreamReader isr = new InputStreamReader(fis,"UTF-8");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
|
|
|
Reader in = new BufferedReader(isr);
|
|
|
int ch;
|
|
@@ -1744,26 +1767,45 @@ public class Config extends AppCompatActivity
|
|
|
edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
+ Uri uri = data.getData();
|
|
|
File file = new File(uri.getPath());
|
|
|
+
|
|
|
+ edit_search.setText(uri.getPath().toString());
|
|
|
+ //loadFile(uri.getPath().toString());
|
|
|
+ ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
+ .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
|
|
|
+
|
|
|
+
|
|
|
String str = null;
|
|
|
try {
|
|
|
InputStream is = new FileInputStream(file);
|
|
|
InputStreamReader input = new InputStreamReader(is, "UTF-8");
|
|
|
BufferedReader reader = new BufferedReader(input);
|
|
|
while ((str = reader.readLine()) != null) {
|
|
|
- editdetail.setText(str);
|
|
|
- //editdetail.append("\n");
|
|
|
+ edit_search.setText(str);
|
|
|
}
|
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
+ //e.printStackTrace();
|
|
|
+ edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- */
|
|
|
+ */
|
|
|
+ /*
|
|
|
+ Uri uri = data.getData();
|
|
|
+ File file = new File(uri.getPath());
|
|
|
+
|
|
|
+ edit_search.setText(uri.getPath().toString());
|
|
|
+
|
|
|
+ ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
|
+ .Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
|
|
|
+
|
|
|
+ loadFile(uri.getPath().toString());
|
|
|
+ */
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -3992,7 +4034,18 @@ public class Config extends AppCompatActivity
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
|
|
|
+ //权限已成功申请
|
|
|
+ }else{
|
|
|
+ //用户拒绝授权
|
|
|
+ Toast.makeText(this,"无法获取SD卡读写权限", Toast.LENGTH_SHORT).show();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
break;
|
|
|
}
|
|
|
}
|