-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* model picker from storage implementation * autopilot check * dialog to check whether model already exists
- Loading branch information
Showing
11 changed files
with
340 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
android/app/src/main/java/org/openbot/ai/BackHandlingFilePickerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.openbot.ai; | ||
|
||
import android.os.Environment; | ||
import com.nononsenseapps.filepicker.AbstractFilePickerFragment; | ||
import com.nononsenseapps.filepicker.FilePickerActivity; | ||
import java.io.File; | ||
|
||
public class BackHandlingFilePickerActivity extends FilePickerActivity { | ||
|
||
/** Need access to the fragment */ | ||
BackHandlingFilePickerFragment currentFragment; | ||
|
||
/** Return a copy of the new fragment and set the variable above. */ | ||
@Override | ||
protected AbstractFilePickerFragment<File> 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(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
android/app/src/main/java/org/openbot/ai/BackHandlingFilePickerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.openbot.ai; | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.