|
@@ -105,7 +105,8 @@ public class Config extends AppCompatActivity
|
|
|
private StringBuffer mStringBuffer = new StringBuffer();
|
|
|
private Context mContext;
|
|
|
|
|
|
- private Button search_button;
|
|
|
+ private Button btnLocalFileButton; //本地文件按钮
|
|
|
+ private Button btnUDiskFileButton; //U盘文件按钮
|
|
|
private TextView edit_search;
|
|
|
private EditText edit_text;
|
|
|
|
|
@@ -485,11 +486,26 @@ public class Config extends AppCompatActivity
|
|
|
mSendCfg = (Button) findViewById(R.id.sendcfg);
|
|
|
mShow = (TextView) findViewById(R.id.show);
|
|
|
|
|
|
- search_button = (Button) findViewById(R.id.searchbutton);
|
|
|
edit_search = (TextView) findViewById(R.id.editsearch);
|
|
|
edit_text = (EditText) findViewById(R.id.editsearch);
|
|
|
|
|
|
- search_button.setOnClickListener(new View.OnClickListener() {
|
|
|
+ //选择本地文件
|
|
|
+ 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);
|
|
|
+ btnUDiskFileButton.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
//ActivityCompat.requestPermissions( Config.this, new String[]{android
|
|
@@ -1664,22 +1680,67 @@ public class Config extends AppCompatActivity
|
|
|
|
|
|
protected void onActivityResult ( int requestCode, int resultCode, Intent data){
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
+
|
|
|
+ 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();
|
|
|
+ String configString = "";
|
|
|
+ Uri uri = data.getData();
|
|
|
+
|
|
|
if (requestCode == 1) {
|
|
|
|
|
|
- int permission_write = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
- int permission_read = ContextCompat.checkSelfPermission(Config.this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
|
|
+ byte[] filebuffer;
|
|
|
+ int len;
|
|
|
+ try {
|
|
|
+
|
|
|
+ String fileString = "";
|
|
|
+ File storage = new File("/storage");
|
|
|
+ File[] files = storage.listFiles();
|
|
|
+ for (final File file : files) {
|
|
|
+ if (file.canRead()) {
|
|
|
+ if (!file.getName().equals(Environment.getExternalStorageDirectory().getName())) {
|
|
|
+ //满足该条件的文件夹就是u盘在手机上的目录
|
|
|
+ fileString = (file.getPath()+"/GT9110H_wingcool_config.cfg");
|
|
|
+ fileString = fileString.replaceAll(":", "/"); //将:改为/,以防某些系统文件目录读出是:
|
|
|
+ edit_search.setText(fileString);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if ((permission_write != PackageManager.PERMISSION_GRANTED)
|
|
|
- ||(permission_read != PackageManager.PERMISSION_GRANTED))
|
|
|
- {
|
|
|
+ buffer = new StringBuffer();
|
|
|
+ //String storageState = Environment.getExternalStorageState();
|
|
|
+ //if (storageState.equals(Environment.MEDIA_MOUNTED)) {
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(fileString);
|
|
|
+ filebuffer = new byte[1024];
|
|
|
+ len = fileInputStream.read(filebuffer);
|
|
|
+ while (len > 0) {
|
|
|
+ buffer.append(new String(filebuffer, 0, len));
|
|
|
+ len = fileInputStream.read(filebuffer);
|
|
|
+ }
|
|
|
+ fileInputStream.close();
|
|
|
+ //}
|
|
|
|
|
|
- ActivityCompat.requestPermissions(Config.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
- android.Manifest.permission.READ_EXTERNAL_STORAGE}, 3);
|
|
|
+ configString = buffer.toString();
|
|
|
+
|
|
|
+ } catch (IOException ex) {
|
|
|
+
|
|
|
+ //edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
+ edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
|
|
|
+ return;
|
|
|
}
|
|
|
+ }
|
|
|
+ else if (requestCode == 2) {
|
|
|
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
try {
|
|
|
-
|
|
|
File dir = Environment.getExternalStorageDirectory();
|
|
|
//Uri uri = data.getData();
|
|
|
File dataFile;
|
|
@@ -1688,12 +1749,12 @@ public class Config extends AppCompatActivity
|
|
|
|
|
|
//File dir = Environment.getExternalStorageDirectory();
|
|
|
dataFile = new File(dir.getPath(), "GT9110H_wingcool_config.cfg");
|
|
|
- }else if (byProductType == GT7){ //GT7
|
|
|
+ } else if (byProductType == GT7) { //GT7
|
|
|
edit_search.setText(dir.getPath() + "/GT738x_wingcool_config.cfg");
|
|
|
|
|
|
//File dir = Environment.getExternalStorageDirectory();
|
|
|
dataFile = new File(dir.getPath(), "GT738x_wingcool_config.cfg");
|
|
|
- }else{ //other
|
|
|
+ } else { //other
|
|
|
edit_search.setText(dir.getPath() + "/GTxxxx_wingcool_config.cfg");
|
|
|
|
|
|
//File dir = Environment.getExternalStorageDirectory();
|
|
@@ -1708,49 +1769,23 @@ public class Config extends AppCompatActivity
|
|
|
//edit_search.setText(str);
|
|
|
|
|
|
//FileInputStream fis = new FileInputStream(uri.getPath().toString());
|
|
|
- InputStreamReader isr = new InputStreamReader(fis,"UTF-8");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
|
|
|
+ InputStreamReader isr = new InputStreamReader(fis, "UTF-8");//文件编码Unicode,UTF-8,ASCII,GB2312,Big5
|
|
|
Reader in = new BufferedReader(isr);
|
|
|
int ch;
|
|
|
while ((ch = in.read()) > -1) {
|
|
|
- buffer.append((char)ch);
|
|
|
+ buffer.append((char) ch);
|
|
|
}
|
|
|
in.close();
|
|
|
- String configString;
|
|
|
- configString = buffer.toString();
|
|
|
- //mShow.setText(configString.toString());
|
|
|
|
|
|
- //value = value.trim(); //去除空格
|
|
|
- configString = configString.replaceAll("0x", ""); //0x转换为没有
|
|
|
- //editdetail.setText(configString.toString()); //buffer.toString())就是读出的内容字符
|
|
|
+ configString = buffer.toString();
|
|
|
|
|
|
- String[] stringCfgArr = configString.split(",");
|
|
|
- //byte bcfgarr[] = new byte[188];
|
|
|
+ } catch (IOException c) {
|
|
|
|
|
|
- int i;
|
|
|
- for (i = 0; i < 186; i++){
|
|
|
- mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
|
|
|
- }
|
|
|
- if (byProductType == GT7) {
|
|
|
- for (; i < 444; i++) {
|
|
|
- mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
|
|
|
- }
|
|
|
- }
|
|
|
+ edit_search.setText(uri.getPath() + "——" + getResources().getString(R.string.invalidfile));
|
|
|
|
|
|
- if (byProductType == GT9) {
|
|
|
- ReadCfgSample(mBytes);
|
|
|
- ReadCfgModuleSwitch(mBytes);
|
|
|
- ReadCfgNormalSetting(mBytes);
|
|
|
- ReadCfgChannelSetting(mBytes);
|
|
|
- ReadCfgPenSetting(mBytes);
|
|
|
- ReadCfgPlamRestrain(mBytes);
|
|
|
- ReadCfgKeySetting(mBytes);
|
|
|
- ReadCfgHoppingSetting(mBytes);
|
|
|
- }
|
|
|
-
|
|
|
- ReadCfgRam(stringCfgArr);
|
|
|
- } catch (IOException e) {
|
|
|
- edit_search.setText(getResources().getString(R.string.invalidfile));
|
|
|
+ return;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
Uri uri = data.getData();
|
|
@@ -1791,9 +1826,37 @@ public class Config extends AppCompatActivity
|
|
|
|
|
|
loadFile(uri.getPath().toString());
|
|
|
*/
|
|
|
+
|
|
|
+ //value = value.trim(); //去除空格
|
|
|
+ configString = configString.replaceAll("0x", ""); //0x转换为没有
|
|
|
+ //editdetail.setText(configString.toString()); //buffer.toString())就是读出的内容字符
|
|
|
+
|
|
|
+ String[] stringCfgArr = configString.split(",");
|
|
|
+ //byte bcfgarr[] = new byte[188];
|
|
|
+
|
|
|
+ int i;
|
|
|
+ for (i = 0; i < 186; i++){
|
|
|
+ mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
|
|
|
+ }
|
|
|
+ if (byProductType == GT7) {
|
|
|
+ for (; i < 444; i++) {
|
|
|
+ mBytes[i] = (byte) Integer.parseInt(stringCfgArr[i], 16);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ if (byProductType == GT9) {
|
|
|
+ ReadCfgSample(mBytes);
|
|
|
+ ReadCfgModuleSwitch(mBytes);
|
|
|
+ ReadCfgNormalSetting(mBytes);
|
|
|
+ ReadCfgChannelSetting(mBytes);
|
|
|
+ ReadCfgPenSetting(mBytes);
|
|
|
+ ReadCfgPlamRestrain(mBytes);
|
|
|
+ ReadCfgKeySetting(mBytes);
|
|
|
+ ReadCfgHoppingSetting(mBytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ ReadCfgRam(stringCfgArr);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void initListener() {
|