From 772eae7a4c7ed87dc6a1cf55d187738e2a98e3c2 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Fri, 17 Mar 2023 19:30:06 +0100 Subject: [PATCH] Revert "Make linter happy: use try-with-resources" Those require higher API levels. Added comment. This reverts commit 84e78e4bdafb4a5d7b7fd4a4f36fb965e5ed4b45. --- src/org/kde/kdeconnect/Helpers/SMSHelper.java | 19 +++++++++++-------- .../SftpPlugin/SftpSettingsFragment.java | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/org/kde/kdeconnect/Helpers/SMSHelper.java b/src/org/kde/kdeconnect/Helpers/SMSHelper.java index 19069028..f557f091 100644 --- a/src/org/kde/kdeconnect/Helpers/SMSHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SMSHelper.java @@ -658,14 +658,17 @@ public class SMSHelper { attachments.add(new Attachment(partID, contentType, encodedThumbnail, fileName)); } else if (MimeType.isTypeVideo(contentType)) { String fileName = data.substring(data.lastIndexOf('/') + 1); - try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) { - retriever.setDataSource(context, ContentUris.withAppendedId(getMMSPartUri(), partID)); - Bitmap videoThumbnail = retriever.getFrameAtTime(); - String encodedThumbnail = SmsMmsUtils.bitMapToBase64( - Bitmap.createScaledBitmap(videoThumbnail, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, true) - ); - attachments.add(new Attachment(partID, contentType, encodedThumbnail, fileName)); - }; + + // Can't use try-with-resources since MediaMetadataRetriever's close method was only added in API 29 + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + retriever.setDataSource(context, ContentUris.withAppendedId(getMMSPartUri(), partID)); + Bitmap videoThumbnail = retriever.getFrameAtTime(); + + String encodedThumbnail = SmsMmsUtils.bitMapToBase64( + Bitmap.createScaledBitmap(videoThumbnail, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, true) + ); + + attachments.add(new Attachment(partID, contentType, encodedThumbnail, fileName)); } else if (MimeType.isTypeAudio(contentType)) { String fileName = data.substring(data.lastIndexOf('/') + 1); diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java index 73e8482f..4b8570dd 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpSettingsFragment.java @@ -89,10 +89,10 @@ public class SftpSettingsFragment public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { super.onCreatePreferences(savedInstanceState, rootKey); - int colorAccent; - try (TypedArray ta = requireContext().obtainStyledAttributes(new int[]{R.attr.colorAccent})) { - colorAccent = ta.getColor(0, 0); - } + // Can't use try-with-resources since TypedArray's close method was only added in API 31 + TypedArray ta = requireContext().obtainStyledAttributes(new int[]{R.attr.colorAccent}); + int colorAccent = ta.getColor(0, 0); + ta.recycle(); storageInfoList = getStorageInfoList(requireContext(), plugin);