mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2026-08-01 14:19:12 -06:00
Replace getFileName implementation in Tools, use it ImportControlActivity
This commit is contained in:
parent
d789f1251e
commit
641402c251
2 changed files with 9 additions and 28 deletions
|
|
@ -71,7 +71,7 @@ public class ImportControlActivity extends Activity {
|
|||
finishAndRemoveTask();
|
||||
return;
|
||||
}
|
||||
mEditText.setText(getNameFromURI(mUriData));
|
||||
mEditText.setText(trimFileName(Tools.getFileName(this, mUriData)));
|
||||
mHasIntentChanged = false;
|
||||
|
||||
//Import and verify thread
|
||||
|
|
@ -193,15 +193,4 @@ public class ImportControlActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
public String getNameFromURI(Uri uri) {
|
||||
Cursor c = getContentResolver().query(uri, null, null, null, null);
|
||||
if(c == null) return uri.getLastPathSegment(); // idk myself but it happens on asus file manager
|
||||
c.moveToFirst();
|
||||
int columnIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if(columnIndex == -1) return uri.getLastPathSegment();
|
||||
String fileName = c.getString(columnIndex);
|
||||
c.close();
|
||||
return trimFileName(fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -846,22 +846,14 @@ public final class Tools {
|
|||
}
|
||||
|
||||
public static String getFileName(Context ctx, Uri uri) {
|
||||
String result = null;
|
||||
if (uri.getScheme().equals("content")) {
|
||||
try (Cursor cursor = ctx.getContentResolver().query(uri, null, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result = uri.getPath();
|
||||
int cut = result.lastIndexOf('/');
|
||||
if (cut != -1) {
|
||||
result = result.substring(cut + 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
Cursor c = ctx.getContentResolver().query(uri, null, null, null, null);
|
||||
if(c == null) return uri.getLastPathSegment(); // idk myself but it happens on asus file manager
|
||||
c.moveToFirst();
|
||||
int columnIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if(columnIndex == -1) return uri.getLastPathSegment();
|
||||
String fileName = c.getString(columnIndex);
|
||||
c.close();
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/** Swap the main fragment with another */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue