diff --git a/app/build.gradle b/app/build.gradle index 5820abf23..83f9bf1b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { minSdk 21 targetSdk 34 - versionName "12.1-240719-axi" + versionName "12.1-240725-axi" versionCode = 314 // Generate native debug symbols to allow Google Play to symbolicate our native crashes diff --git a/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java b/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java index 94cfa77cf..8d6b8de1e 100755 --- a/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java +++ b/app/src/main/java/com/limelight/computers/ComputerDatabaseManager.java @@ -1,6 +1,7 @@ package com.limelight.computers; import java.io.ByteArrayInputStream; +import java.io.File; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; @@ -23,7 +24,7 @@ import org.json.JSONObject; public class ComputerDatabaseManager { - private static final String COMPUTER_DB_NAME = "computers4.db"; + public static final String COMPUTER_DB_NAME = "computers4.db"; private static final String COMPUTER_TABLE_NAME = "Computers"; private static final String COMPUTER_UUID_COLUMN_NAME = "UUID"; private static final String COMPUTER_NAME_COLUMN_NAME = "ComputerName"; @@ -55,6 +56,12 @@ public ComputerDatabaseManager(Context c) { initializeDb(c); } + public ComputerDatabaseManager(Context context, File file){ + computerDb=SQLiteDatabase.openDatabase(file.getPath(), + null, SQLiteDatabase.OPEN_READONLY); + } + + public void close() { computerDb.close(); } diff --git a/app/src/main/java/com/limelight/preferences/StreamSettings.java b/app/src/main/java/com/limelight/preferences/StreamSettings.java index 7341372ab..1234c3f55 100755 --- a/app/src/main/java/com/limelight/preferences/StreamSettings.java +++ b/app/src/main/java/com/limelight/preferences/StreamSettings.java @@ -23,9 +23,7 @@ import android.support.v4.content.FileProvider; import android.text.InputFilter; import android.text.InputType; -import android.text.Spanned; import android.text.TextUtils; -import android.text.method.NumberKeyListener; import android.util.DisplayMetrics; import android.util.Range; import android.view.Display; @@ -45,14 +43,16 @@ import com.limelight.R; import com.limelight.binding.input.virtual_controller.keyboard.KeyBoardControllerConfigurationLoader; import com.limelight.binding.video.MediaCodecHelper; +import com.limelight.computers.ComputerDatabaseManager; +import com.limelight.nvstream.http.ComputerDetails; import com.limelight.utils.Dialog; import com.limelight.utils.FileUriUtils; import com.limelight.utils.UiHelper; import org.json.JSONObject; import java.io.File; -import java.text.DecimalFormat; import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.Map; public class StreamSettings extends Activity { @@ -709,6 +709,18 @@ public boolean onPreferenceClick(Preference preference) { return false; } }); + + findPreference("import_computers_data_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + startActivityForResult(intent, READ_DATABASE_REQUEST_CODE); + return false; + } + }); + findPreference("import_special_button_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { @@ -745,6 +757,25 @@ public boolean onPreferenceClick(Preference preference) { } }); + findPreference("export_computers_data_file").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + File dataFile=new File(getActivity().getDatabasePath(ComputerDatabaseManager.COMPUTER_DB_NAME).getPath()); + if(!dataFile.exists()){ + return false; + } + Uri uri; + Intent intent = new Intent(Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + String authority= BuildConfig.APPLICATION_ID+".fileprovider"; + uri= FileProvider.getUriForFile(getActivity(),authority,dataFile); + intent.putExtra(Intent.EXTRA_STREAM, uri); + intent.setType("*/*"); + startActivity(Intent.createChooser(intent,"保存数据文件")); + return false; + } + }); + findPreference("pref_axi_test").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override @@ -807,6 +838,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } int READ_REQUEST_CODE=1001; int READ_REQUEST_SPECIAL_CODE=1002; + + int READ_DATABASE_REQUEST_CODE=1003; + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -853,6 +887,32 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { e.printStackTrace(); Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show(); } + return; + } + + if (requestCode == READ_DATABASE_REQUEST_CODE && resultCode == Activity.RESULT_OK &&data.getData()!=null) { + try { + Uri uri = data.getData(); + File dataBaseFile= null; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + dataBaseFile = FileUriUtils.uriToFileApiQ(uri,getActivity()); + }else{ + String displayName = System.currentTimeMillis() + Math.round((Math.random() + 1) * 1000)+".db"; + dataBaseFile=new File(getActivity().getCacheDir().getAbsolutePath(), displayName); + FileUriUtils.copyUriToInternalStorage(getActivity(),uri,dataBaseFile); + } + ComputerDatabaseManager importManager=new ComputerDatabaseManager(getActivity(),dataBaseFile); + List importComputers=importManager.getAllComputers(); + ComputerDatabaseManager manager=new ComputerDatabaseManager(getActivity()); + for (ComputerDetails computer : importComputers) { + manager.updateComputer(computer); + } + Toast.makeText(getActivity(),"导入成功,重新打开APP生效!",Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + e.printStackTrace(); + Toast.makeText(getActivity(),"出错啦~"+e.getMessage(),Toast.LENGTH_SHORT).show(); + } + return; } } diff --git a/app/src/main/java/com/limelight/utils/FileUriUtils.java b/app/src/main/java/com/limelight/utils/FileUriUtils.java index 8c2e6e05e..62f6193f9 100755 --- a/app/src/main/java/com/limelight/utils/FileUriUtils.java +++ b/app/src/main/java/com/limelight/utils/FileUriUtils.java @@ -1,8 +1,12 @@ package com.limelight.utils; +import android.content.ContentResolver; import android.content.Context; import android.net.Uri; - +import android.os.Build; +import android.os.FileUtils; +import android.support.annotation.RequiresApi; +import android.webkit.MimeTypeMap; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -99,4 +103,66 @@ public static boolean writerFileString(File file, String content) { } return true; } + + @RequiresApi(api = Build.VERSION_CODES.Q) + public static File uriToFileApiQ(Uri uri, Context context) { + File file = null; + if (uri == null) return file; + //android10以上转换 + if (uri.getScheme().equals(ContentResolver.SCHEME_FILE)) { + file = new File(uri.getPath()); + } else if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { + //把文件复制到沙盒目录 + ContentResolver contentResolver = context.getContentResolver(); + String displayName = System.currentTimeMillis() + Math.round((Math.random() + 1) * 1000) + + "." + MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(uri)); + try { + InputStream is = contentResolver.openInputStream(uri); + File cache = new File(context.getCacheDir().getAbsolutePath(), displayName); + FileOutputStream fos = new FileOutputStream(cache); + FileUtils.copy(is, fos); + file = cache; + fos.close(); + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return file; + } + + public static void copyUriToInternalStorage(Context context, Uri uri, File destFile) { + InputStream inputStream = null; + OutputStream outputStream = null; + try { + // 从Uri获取输入流 + inputStream = context.getContentResolver().openInputStream(uri); + if (inputStream == null) { + return; + } + + // 创建目标文件 + outputStream = new FileOutputStream(destFile); + + // 缓冲区大小 + byte[] buffer = new byte[1024]; + int length; + while ((length = inputStream.read(buffer)) > 0) { + outputStream.write(buffer, 0, length); + } + + outputStream.flush(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 关闭输入流和输出流 + try { + if (inputStream != null) inputStream.close(); + if (outputStream != null) outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index ce51306b9..5a0376107 100755 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -465,8 +465,6 @@ android:text="%" android:title="屏幕灵敏度调整Y轴" /> - checkbox_enable_touch_sensitivity_rotation_auto - + + + + + \ No newline at end of file