mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-02-19 06:30:55 +00:00
Correctly set the filename from chooser activity
This commit is contained in:
parent
57d1e95cce
commit
dfc09e87bb
@ -14,6 +14,7 @@ package org.deadc0de.apple2ix;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@ -21,6 +22,8 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.provider.DocumentsContract;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.provider.OpenableColumns;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -58,6 +61,34 @@ public class Apple2DiskChooserActivity extends AppCompatActivity {
|
||||
return pfd;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getFileNameFromUri(Context ctx, Uri uri) {
|
||||
|
||||
String fileName = null;
|
||||
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
throw new RuntimeException("SDK Version not allowed access");
|
||||
}
|
||||
|
||||
if (!DocumentsContract.isDocumentUri(ctx, uri)) {
|
||||
throw new RuntimeException("Not a Document URI for " + uri);
|
||||
}
|
||||
|
||||
ContentResolver resolver = ctx.getContentResolver();
|
||||
|
||||
Cursor returnCursor = resolver.query(uri, null, null, null, null);
|
||||
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
returnCursor.moveToFirst();
|
||||
fileName = returnCursor.getString(nameIndex);
|
||||
|
||||
} catch (Throwable t) {
|
||||
Log.e(TAG, "OOPS, could not get filename from URI ( " + uri + " ) : " + t);
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBoolean("ran", true);
|
||||
@ -142,6 +173,7 @@ public class Apple2DiskChooserActivity extends AppCompatActivity {
|
||||
|
||||
if (chosenUri != null) {
|
||||
chosenPfd = openFileDescriptorFromUri(this, chosenUri);
|
||||
chosenFileName = getFileNameFromUri(this, chosenUri);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +189,7 @@ public class Apple2DiskChooserActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void finish() {
|
||||
sDiskChooserIsChoosing.set(false);
|
||||
String name = chosenUri == null ? "" : chosenUri.toString();
|
||||
String name = chosenFileName == null ? (chosenUri == null ? "" : chosenUri.toString()) : chosenFileName;
|
||||
if (sDisksCallback != null) {
|
||||
sDisksCallback.onDisksChosen(new DiskArgs(name, chosenUri, chosenPfd));
|
||||
}
|
||||
@ -168,6 +200,8 @@ public class Apple2DiskChooserActivity extends AppCompatActivity {
|
||||
|
||||
private ParcelFileDescriptor chosenPfd;
|
||||
|
||||
private String chosenFileName;
|
||||
|
||||
private static final String TAG = "A2DiskChooserActivity";
|
||||
|
||||
private static final int EDIT_REQUEST_CODE = 44;
|
||||
|
Loading…
x
Reference in New Issue
Block a user