mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-05-02 15:45:42 -04:00
Android: Add Start File to main activity menu
This commit is contained in:
parent
e22c7608e3
commit
076d3d3479
@ -40,7 +40,6 @@ public final class FileUtil {
|
|||||||
} else return volumePath;
|
} else return volumePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
private static String getVolumePath(final String volumeId, Context context) {
|
private static String getVolumePath(final String volumeId, Context context) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;
|
||||||
@ -91,4 +90,41 @@ public final class FileUtil {
|
|||||||
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
||||||
else return File.separator;
|
else return File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String getFullPathFromUri(@Nullable final Uri treeUri, Context con) {
|
||||||
|
if (treeUri == null) return null;
|
||||||
|
String volumePath = getVolumePath(getVolumeIdFromUri(treeUri), con);
|
||||||
|
if (volumePath == null) return File.separator;
|
||||||
|
if (volumePath.endsWith(File.separator))
|
||||||
|
volumePath = volumePath.substring(0, volumePath.length() - 1);
|
||||||
|
|
||||||
|
String documentPath = getDocumentPathFromUri(treeUri);
|
||||||
|
if (documentPath.endsWith(File.separator))
|
||||||
|
documentPath = documentPath.substring(0, documentPath.length() - 1);
|
||||||
|
|
||||||
|
if (documentPath.length() > 0) {
|
||||||
|
if (documentPath.startsWith(File.separator))
|
||||||
|
return volumePath + documentPath;
|
||||||
|
else
|
||||||
|
return volumePath + File.separator + documentPath;
|
||||||
|
} else return volumePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
private static String getVolumeIdFromUri(final Uri treeUri) {
|
||||||
|
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||||
|
final String[] split = docId.split(":");
|
||||||
|
if (split.length > 0) return split[0];
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
private static String getDocumentPathFromUri(final Uri treeUri) {
|
||||||
|
final String docId = DocumentsContract.getDocumentId(treeUri);
|
||||||
|
final String[] split = docId.split(":");
|
||||||
|
if ((split.length >= 2) && (split[1] != null)) return split[1];
|
||||||
|
else return File.separator;
|
||||||
|
}
|
||||||
}
|
}
|
@ -49,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private static final int REQUEST_EXTERNAL_STORAGE_PERMISSIONS = 1;
|
private static final int REQUEST_EXTERNAL_STORAGE_PERMISSIONS = 1;
|
||||||
private static final int REQUEST_ADD_DIRECTORY_TO_GAME_LIST = 2;
|
private static final int REQUEST_ADD_DIRECTORY_TO_GAME_LIST = 2;
|
||||||
private static final int REQUEST_IMPORT_BIOS_IMAGE = 3;
|
private static final int REQUEST_IMPORT_BIOS_IMAGE = 3;
|
||||||
|
private static final int REQUEST_START_FILE = 4;
|
||||||
|
|
||||||
private GameList mGameList;
|
private GameList mGameList;
|
||||||
private ListView mGameListView;
|
private ListView mGameListView;
|
||||||
@ -160,6 +161,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startEmulation(null, true);
|
startEmulation(null, true);
|
||||||
} else if (id == R.id.action_start_bios) {
|
} else if (id == R.id.action_start_bios) {
|
||||||
startEmulation(null, false);
|
startEmulation(null, false);
|
||||||
|
} else if (id == R.id.action_start_file) {
|
||||||
|
startStartFile();
|
||||||
} else if (id == R.id.action_add_game_directory) {
|
} else if (id == R.id.action_add_game_directory) {
|
||||||
startAddGameDirectory();
|
startAddGameDirectory();
|
||||||
} else if (id == R.id.action_scan_for_new_games) {
|
} else if (id == R.id.action_scan_for_new_games) {
|
||||||
@ -177,16 +180,24 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String getPathFromUri(Uri uri) {
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
String path = FileUtil.getFullPathFromUri(uri, this);
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
if (path.length() < 5) {
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle("Error")
|
||||||
|
.setMessage("Failed to get path for the selected file. Please make sure the file is in internal/external storage.\n\n" +
|
||||||
|
"Tap the overflow button in the directory selector.\nSelect \"Show Internal Storage\".\n" +
|
||||||
|
"Tap the menu button and select your device name or SD card.")
|
||||||
|
.setPositiveButton("OK", (dialog, button) -> {})
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
switch (requestCode) {
|
return path;
|
||||||
case REQUEST_ADD_DIRECTORY_TO_GAME_LIST: {
|
}
|
||||||
if (resultCode != RESULT_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Uri treeUri = data.getData();
|
private String getPathFromTreeUri(Uri treeUri) {
|
||||||
String path = FileUtil.getFullPathFromTreeUri(treeUri, this);
|
String path = FileUtil.getFullPathFromTreeUri(treeUri, this);
|
||||||
if (path.length() < 5) {
|
if (path.length() < 5) {
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
@ -197,9 +208,25 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
.setPositiveButton("OK", (dialog, button) -> {})
|
.setPositiveButton("OK", (dialog, button) -> {})
|
||||||
.create()
|
.create()
|
||||||
.show();
|
.show();
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
switch (requestCode) {
|
||||||
|
case REQUEST_ADD_DIRECTORY_TO_GAME_LIST: {
|
||||||
|
if (resultCode != RESULT_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String path = getPathFromTreeUri(data.getData());
|
||||||
|
if (path == null)
|
||||||
|
return;
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
Set<String> currentValues = prefs.getStringSet("GameList/RecursivePaths", null);
|
Set<String> currentValues = prefs.getStringSet("GameList/RecursivePaths", null);
|
||||||
if (currentValues == null)
|
if (currentValues == null)
|
||||||
@ -221,6 +248,18 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
onImportBIOSImageResult(data.getData());
|
onImportBIOSImageResult(data.getData());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case REQUEST_START_FILE: {
|
||||||
|
if (resultCode != RESULT_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String path = getPathFromUri(data.getData());
|
||||||
|
if (path == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
startEmulation(path, shouldResumeStateByDefault());
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +308,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startStartFile() {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
intent.setType("*/*");
|
||||||
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
startActivityForResult(Intent.createChooser(intent, "Choose Disc Image"), REQUEST_START_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean doBIOSCheck() {
|
private boolean doBIOSCheck() {
|
||||||
if (AndroidHostInterface.getInstance().hasAnyBIOSImages())
|
if (AndroidHostInterface.getInstance().hasAnyBIOSImages())
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/action_resume"
|
android:id="@+id/action_resume"
|
||||||
android:title="Resume Last Session" />
|
android:title="Resume Last Session" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_start_file"
|
||||||
|
android:title="Start File" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_start_bios"
|
android:id="@+id/action_start_bios"
|
||||||
android:title="Start BIOS" />
|
android:title="Start BIOS" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user