From 15e37eef38a9e27178078022a5ffbc03f3ab0003 Mon Sep 17 00:00:00 2001 From: Sanjeev <> Date: Sat, 2 Sep 2023 18:16:49 +0530 Subject: [PATCH 1/4] resolve sect tflite file --- .../ModelManagementFragment.java | 75 ++++++++++++++----- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java index 4ae357ef1..08b0f90b6 100644 --- a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java +++ b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java @@ -1,13 +1,16 @@ package org.openbot.modelManagement; import android.app.Activity; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.database.Cursor; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.Uri; import android.os.Bundle; import android.os.Environment; +import android.provider.OpenableColumns; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -63,8 +66,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { Intent intent = result.getData(); // Handle the Intent List files = Utils.getSelectedFilesFromResult(intent); - - String fileName = new File(files.get(0).getPath()).getName(); + String fileName = getFileNameFromUri(files.get(0)); if (FileUtils.checkFileExistence(requireActivity(), fileName)) { AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); builder.setTitle(R.string.file_available_title); @@ -110,6 +112,37 @@ public void handleOnBackPressed() { requireActivity().getOnBackPressedDispatcher().addCallback(onBackPressedCallback); } + /** + * Extracts the file name from a given Uri. + * + * @param uri The Uri from which to extract the file name. + * @return The extracted file name, or null if not found. + */ + private String getFileNameFromUri(Uri uri) { + String fileName = null; + if (uri.getScheme().equals("content")) { + // If the Uri uses the content:// scheme, use a ContentResolver to get the file name + ContentResolver contentResolver = requireActivity().getContentResolver(); + Cursor cursor = contentResolver.query(uri, null, null, null, null); + if (cursor != null) { + try { + if (cursor.moveToFirst()) { + int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); + if (displayNameIndex != -1) { + fileName = cursor.getString(displayNameIndex); + } + } + } finally { + cursor.close(); + } + } + } else if (uri.getScheme().equals("file")) { + // If the Uri uses the file:// scheme, directly extract the file name + fileName = new File(uri.getPath()).getName(); + } + return fileName; + } + private void processModelFromStorage(List files, String fileName) { Model item = @@ -147,24 +180,28 @@ private void processModelFromStorage(List files, String fileName) { private void openPicker() { - Intent i = new Intent(requireActivity(), BackHandlingFilePickerActivity.class); - // This works if you defined the intent filter - // Intent i = new Intent(Intent.ACTION_GET_CONTENT); - - // Set these depending on your use case. These are the defaults. - i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); - i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); - i.putExtra(BackHandlingFilePickerActivity.EXTRA_MODE, BackHandlingFilePickerActivity.MODE_FILE); - - // Configure initial directory by specifying a String. - // You could specify a String like "/storage/emulated/0/", but that can - // dangerous. Always use Android's API calls to get paths to the SD-card or - // internal memory. - i.putExtra( - BackHandlingFilePickerActivity.EXTRA_START_PATH, - Environment.getExternalStorageDirectory().getPath()); +// Intent i = new Intent(requireActivity(), BackHandlingFilePickerActivity.class); +// // This works if you defined the intent filter +// // Intent i = new Intent(Intent.ACTION_GET_CONTENT); +// +// // Set these depending on your use case. These are the defaults. +// i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); +// i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); +// i.putExtra(BackHandlingFilePickerActivity.EXTRA_MODE, BackHandlingFilePickerActivity.MODE_FILE); +// +// // Configure initial directory by specifying a String. +// // You could specify a String like "/storage/emulated/0/", but that can +// // dangerous. Always use Android's API calls to get paths to the SD-card or +// // internal memory. +// i.putExtra( +// BackHandlingFilePickerActivity.EXTRA_START_PATH, +// Environment.getExternalStorageDirectory().getPath()); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("application/octet-stream"); // Specify the MIME type for TFLite files + intent.addCategory(Intent.CATEGORY_OPENABLE); + + mStartForResult.launch(intent); - mStartForResult.launch(i); } @Nullable From b95cac3c7089cf3a577072e22df9a4f49ff4378d Mon Sep 17 00:00:00 2001 From: Sanjeev <> Date: Mon, 4 Sep 2023 11:20:09 +0530 Subject: [PATCH 2/4] remove file chooser fragment --- android/robot/src/main/AndroidManifest.xml | 11 ---- .../BackHandlingFilePickerActivity.java | 45 --------------- .../BackHandlingFilePickerFragment.java | 57 ------------------- .../ModelManagementFragment.java | 18 ------ 4 files changed, 131 deletions(-) delete mode 100644 android/robot/src/main/java/org/openbot/modelManagement/BackHandlingFilePickerActivity.java delete mode 100644 android/robot/src/main/java/org/openbot/modelManagement/BackHandlingFilePickerFragment.java diff --git a/android/robot/src/main/AndroidManifest.xml b/android/robot/src/main/AndroidManifest.xml index fa508b963..3a1a4090e 100755 --- a/android/robot/src/main/AndroidManifest.xml +++ b/android/robot/src/main/AndroidManifest.xml @@ -69,17 +69,6 @@ - - - - - - - getFragment( - final String startPath, - final int mode, - final boolean allowMultiple, - final boolean allowDirCreate, - final boolean allowExistingFile, - final boolean singleClick) { - - // startPath is allowed to be null. - // In that case, default folder should be SD-card and not "/" - String path = - (startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath()); - - currentFragment = new BackHandlingFilePickerFragment(); - currentFragment.setArgs( - path, mode, allowMultiple, allowDirCreate, allowExistingFile, singleClick); - return currentFragment; - } - - /** Override the back-button. */ - @Override - public void onBackPressed() { - // If at top most level, normal behaviour - if (currentFragment.isBackTop()) { - super.onBackPressed(); - } else { - // Else go up - currentFragment.goUp(); - } - } -} diff --git a/android/robot/src/main/java/org/openbot/modelManagement/BackHandlingFilePickerFragment.java b/android/robot/src/main/java/org/openbot/modelManagement/BackHandlingFilePickerFragment.java deleted file mode 100644 index c78bd6e49..000000000 --- a/android/robot/src/main/java/org/openbot/modelManagement/BackHandlingFilePickerFragment.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.openbot.modelManagement; - -import androidx.annotation.NonNull; -import com.nononsenseapps.filepicker.FilePickerFragment; -import java.io.File; - -public class BackHandlingFilePickerFragment extends FilePickerFragment { - - /** - * For consistency, the top level the back button checks against should be the start path. But it - * will fall back on /. - */ - public File getBackTop() { - return getPath(getArguments().getString(KEY_START_PATH, "/")); - } - - /** @return true if the current path is the startpath or / */ - public boolean isBackTop() { - return 0 == compareFiles(mCurrentPath, getBackTop()) - || 0 == compareFiles(mCurrentPath, new File("/")); - } - - /** Go up on level, same as pressing on "..". */ - public void goUp() { - mCurrentPath = getParent(mCurrentPath); - mCheckedItems.clear(); - mCheckedVisibleViewHolders.clear(); - refresh(mCurrentPath); - } - - // File extension to filter on - private static final String EXTENSION = ".tflite"; - - /** - * @param file - * @return The file extension. If file has no extension, it returns null. - */ - private String getExtension(@NonNull File file) { - String path = file.getPath(); - int i = path.lastIndexOf("."); - if (i < 0) { - return null; - } else { - return path.substring(i); - } - } - - @Override - protected boolean isItemVisible(final File file) { - boolean ret = super.isItemVisible(file); - if (ret && !isDir(file) && (mode == MODE_FILE || mode == MODE_FILE_AND_DIR)) { - String ext = getExtension(file); - return EXTENSION.equalsIgnoreCase(ext); - } - return ret; - } -} diff --git a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java index 08b0f90b6..f71baa9b7 100644 --- a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java +++ b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java @@ -179,29 +179,11 @@ private void processModelFromStorage(List files, String fileName) { } private void openPicker() { - -// Intent i = new Intent(requireActivity(), BackHandlingFilePickerActivity.class); -// // This works if you defined the intent filter -// // Intent i = new Intent(Intent.ACTION_GET_CONTENT); -// -// // Set these depending on your use case. These are the defaults. -// i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); -// i.putExtra(BackHandlingFilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false); -// i.putExtra(BackHandlingFilePickerActivity.EXTRA_MODE, BackHandlingFilePickerActivity.MODE_FILE); -// -// // Configure initial directory by specifying a String. -// // You could specify a String like "/storage/emulated/0/", but that can -// // dangerous. Always use Android's API calls to get paths to the SD-card or -// // internal memory. -// i.putExtra( -// BackHandlingFilePickerActivity.EXTRA_START_PATH, -// Environment.getExternalStorageDirectory().getPath()); Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/octet-stream"); // Specify the MIME type for TFLite files intent.addCategory(Intent.CATEGORY_OPENABLE); mStartForResult.launch(intent); - } @Nullable From fe4048042fb4e7eec3610cbf7e1958fbb6bed8a9 Mon Sep 17 00:00:00 2001 From: Sanjeev <> Date: Mon, 4 Sep 2023 11:59:06 +0530 Subject: [PATCH 3/4] modes file over write --- ios/OpenBot/OpenBot/models/modes.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/ios/OpenBot/OpenBot/models/modes.swift b/ios/OpenBot/OpenBot/models/modes.swift index 48c1694d8..3f519d768 100644 --- a/ios/OpenBot/OpenBot/models/modes.swift +++ b/ios/OpenBot/OpenBot/models/modes.swift @@ -10,5 +10,4 @@ public struct ModeItem { var label: String; var icon: UIImage; var identifier: String; - var color: UIColor; } From 46a956c6dd4d72cb0c839bead6b5ac6bce3c5b7e Mon Sep 17 00:00:00 2001 From: Sanjeev <> Date: Fri, 15 Sep 2023 18:33:45 +0530 Subject: [PATCH 4/4] model management issue solved --- .../openbot/modelManagement/ModelManagementFragment.java | 1 + .../src/main/java/org/openbot/tflite/DetectorDefault.java | 7 ++++++- .../src/main/java/org/openbot/tflite/DetectorYoloV4.java | 7 ++++++- .../src/main/java/org/openbot/tflite/DetectorYoloV5.java | 8 +++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java index f71baa9b7..1cb2ce755 100644 --- a/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java +++ b/android/robot/src/main/java/org/openbot/modelManagement/ModelManagementFragment.java @@ -337,6 +337,7 @@ public void onModelDelete(Model mItem) { adapter.notifyItemChanged(index); } FileUtils.updateModelConfig(requireActivity(), masterList); + requireActivity().runOnUiThread(() -> adapter.setItems(loadModelList(binding.modelSpinner.getSelectedItem().toString()))); }); builder.setNegativeButton("Cancel", (dialog, id) -> {}); AlertDialog dialog = builder.create(); diff --git a/android/robot/src/main/java/org/openbot/tflite/DetectorDefault.java b/android/robot/src/main/java/org/openbot/tflite/DetectorDefault.java index 9f083ec2d..96164c45d 100755 --- a/android/robot/src/main/java/org/openbot/tflite/DetectorDefault.java +++ b/android/robot/src/main/java/org/openbot/tflite/DetectorDefault.java @@ -108,7 +108,12 @@ protected void addPixelValue(int pixelValue) { @Override protected void runInference() { Object[] inputArray = {imgData}; - tflite.runForMultipleInputsOutputs(inputArray, outputMap); + try { + tflite.runForMultipleInputsOutputs(inputArray, outputMap); + } + catch(Exception e){ + System.out.println("Error Occurred: " + e); + } } @Override diff --git a/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV4.java b/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV4.java index 4269b992c..65df0c279 100644 --- a/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV4.java +++ b/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV4.java @@ -82,7 +82,12 @@ protected void addPixelValue(int pixelValue) { @Override protected void runInference() { Object[] inputArray = {imgData}; - tflite.runForMultipleInputsOutputs(inputArray, outputMap); + try { + tflite.runForMultipleInputsOutputs(inputArray, outputMap); + } + catch(Exception e){ + System.out.println("Error Occurred: " + e); + } } @Override diff --git a/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV5.java b/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV5.java index b020bf299..aa9113da3 100644 --- a/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV5.java +++ b/android/robot/src/main/java/org/openbot/tflite/DetectorYoloV5.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.graphics.RectF; + import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -102,7 +103,12 @@ protected void addPixelValue(int pixelValue) { @Override protected void runInference() { Object[] inputArray = {imgData}; - tflite.runForMultipleInputsOutputs(inputArray, outputMap); + try { + tflite.runForMultipleInputsOutputs(inputArray, outputMap); + } + catch(Exception e){ + System.out.println("Error Occurred: " + e); + } } @Override