use try with resources. remove unused methods

This commit is contained in:
Daniel Gultsch 2022-02-23 11:37:48 +01:00
parent 3534c619fb
commit 48f8c1a6a0

View file

@ -186,11 +186,6 @@ public class FileBackend {
return paint; return paint;
} }
private static String getTakePhotoPath() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
+ "/Camera/";
}
public static Uri getUriForUri(Context context, Uri uri) { public static Uri getUriForUri(Context context, Uri uri) {
if ("file".equals(uri.getScheme())) { if ("file".equals(uri.getScheme())) {
return getUriForFile(context, new File(uri.getPath())); return getUriForFile(context, new File(uri.getPath()));
@ -474,19 +469,6 @@ public class FileBackend {
return bitmap; return bitmap;
} }
private void createNoMedia(File diretory) {
final File noMedia = new File(diretory, ".nomedia");
if (!noMedia.exists()) {
try {
if (!noMedia.createNewFile()) {
Log.d(Config.LOGTAG, "created nomedia file " + noMedia.getAbsolutePath());
}
} catch (Exception e) {
Log.d(Config.LOGTAG, "could not create nomedia file");
}
}
}
public void updateMediaScanner(File file) { public void updateMediaScanner(File file) {
updateMediaScanner(file, null); updateMediaScanner(file, null);
} }
@ -724,28 +706,18 @@ public class FileBackend {
copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri); copyFileToPrivateStorage(mXmppConnectionService.getFileBackend().getFile(message), uri);
} }
private String getExtensionFromUri(Uri uri) { private String getExtensionFromUri(final Uri uri) {
String[] projection = {MediaStore.MediaColumns.DATA}; final String[] projection = {MediaStore.MediaColumns.DATA};
String filename = null; String filename = null;
Cursor cursor; try (final Cursor cursor =
try {
cursor =
mXmppConnectionService mXmppConnectionService
.getContentResolver() .getContentResolver()
.query(uri, projection, null, null, null); .query(uri, projection, null, null, null)) {
} catch (IllegalArgumentException e) { if (cursor != null && cursor.moveToFirst()) {
cursor = null;
}
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
filename = cursor.getString(0); filename = cursor.getString(0);
} }
} catch (Exception e) { } catch (final SecurityException | IllegalArgumentException e) {
filename = null; filename = null;
} finally {
cursor.close();
}
} }
if (filename == null) { if (filename == null) {
final List<String> segments = uri.getPathSegments(); final List<String> segments = uri.getPathSegments();
@ -753,7 +725,7 @@ public class FileBackend {
filename = segments.get(segments.size() - 1); filename = segments.get(segments.size() - 1);
} }
} }
int pos = filename == null ? -1 : filename.lastIndexOf('.'); final int pos = filename == null ? -1 : filename.lastIndexOf('.');
return pos > 0 ? filename.substring(pos + 1) : null; return pos > 0 ? filename.substring(pos + 1) : null;
} }