From 78af79cd4f182ba60d93906332c1e91a211a83aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 5 May 2016 11:02:26 +0100 Subject: [PATCH 1/5] checkstyle: enable OneTopLevelClass The only remaining error was ClipboardCompat, which was unnecessarily exposing three top-level classes. Make the two implementation classes be nested, private and static. --- .../fdroid/fdroid/compat/ClipboardCompat.java | 51 +++++++++---------- config/checkstyle/checkstyle.xml | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/compat/ClipboardCompat.java b/app/src/main/java/org/fdroid/fdroid/compat/ClipboardCompat.java index fd79497bb..808acacd1 100644 --- a/app/src/main/java/org/fdroid/fdroid/compat/ClipboardCompat.java +++ b/app/src/main/java/org/fdroid/fdroid/compat/ClipboardCompat.java @@ -17,34 +17,33 @@ public abstract class ClipboardCompat { return new OldClipboard(); } -} + @TargetApi(11) + private static class HoneycombClipboard extends ClipboardCompat { -@TargetApi(11) -class HoneycombClipboard extends ClipboardCompat { + private final ClipboardManager manager; - private final ClipboardManager manager; - - HoneycombClipboard(Context context) { - this.manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - } - - @Override - public String getText() { - CharSequence text = null; - if (manager.hasPrimaryClip()) { - ClipData data = manager.getPrimaryClip(); - if (data.getItemCount() > 0) { - text = data.getItemAt(0).getText(); - } + HoneycombClipboard(Context context) { + this.manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + } + + @Override + public String getText() { + CharSequence text = null; + if (manager.hasPrimaryClip()) { + ClipData data = manager.getPrimaryClip(); + if (data.getItemCount() > 0) { + text = data.getItemAt(0).getText(); + } + } + return text != null ? text.toString() : null; + } + } + + private static class OldClipboard extends ClipboardCompat { + + @Override + public String getText() { + return null; } - return text != null ? text.toString() : null; - } -} - -class OldClipboard extends ClipboardCompat { - - @Override - public String getText() { - return null; } } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index fb2da6279..8bb944a11 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -62,7 +62,7 @@ - + From 6ce94a22d3271bc24143a7decf0fa2e78eb23b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 5 May 2016 11:07:40 +0100 Subject: [PATCH 2/5] Never suppress UnusedDeclaration on TAG fields Remove the ones that weren't used at all. They can be added back if they're ever actually used. Moreover, one of them was even named incorrectly. --- app/src/main/java/org/fdroid/fdroid/Utils.java | 1 - .../main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java | 3 --- .../org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java | 3 --- 3 files changed, 7 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/Utils.java b/app/src/main/java/org/fdroid/fdroid/Utils.java index fa6148ece..955ffa960 100644 --- a/app/src/main/java/org/fdroid/fdroid/Utils.java +++ b/app/src/main/java/org/fdroid/fdroid/Utils.java @@ -71,7 +71,6 @@ import java.util.zip.Adler32; public final class Utils { - @SuppressWarnings("UnusedDeclaration") private static final String TAG = "Utils"; private static final int BUFFER_SIZE = 4096; diff --git a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java index 8c37d6833..009a0399b 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java +++ b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapAppsView.java @@ -227,9 +227,6 @@ public class SwapAppsView extends ListView implements private class AppListAdapter extends CursorAdapter { - @SuppressWarnings("UnusedDeclaration") - private static final String TAG = "AppListAdapter"; - private class ViewHolder { private final LocalBroadcastManager localBroadcastManager; diff --git a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 0040019ae..a1585a512 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -656,9 +656,6 @@ public class SwapWorkflowActivity extends AppCompatActivity { public static final int TYPE_COMPLETE = 1; public static final int TYPE_ERROR = 2; - @SuppressWarnings("UnusedDeclaration") - private static final String TAG = "UpdateAsyncTask"; - @NonNull protected final Set selectedApps; From 1192468015b47ffb2b406ace5e552261eccd2140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 5 May 2016 11:53:20 +0100 Subject: [PATCH 3/5] Do not ellipsize description on Android 2.X For some reason, even when showing the entire description some words at the end of lines and paragraphs still get cut off. This results in little parts of the description being completely inaccessible. Ellipsizing is just cosmetic, so ditch it on 2.X altogether. I tested and proved that this fixes the issue with an android-10 x86 emulator, after reproducing the bug. Keep the ellipsizing on newer versions, as it doesn't misbehave on those. Fixes #510. --- app/src/main/java/org/fdroid/fdroid/AppDetails.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/AppDetails.java b/app/src/main/java/org/fdroid/fdroid/AppDetails.java index c29e6ae36..34455797f 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppDetails.java +++ b/app/src/main/java/org/fdroid/fdroid/AppDetails.java @@ -33,6 +33,7 @@ import android.content.pm.PackageManager; import android.database.ContentObserver; import android.graphics.Bitmap; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; @@ -1112,7 +1113,10 @@ public class AppDetails extends AppCompatActivity { viewMorePermissions.setText(getString(R.string.less)); } else { description.setMaxLines(MAX_LINES); - description.setEllipsize(TextUtils.TruncateAt.MARQUEE); + if (Build.VERSION.SDK_INT > 10) { + // ellipsizing doesn't work properly here on 2.X + description.setEllipsize(TextUtils.TruncateAt.MARQUEE); + } viewMorePermissions.setText(R.string.more); } viewAllDescription ^= true; @@ -1133,7 +1137,10 @@ public class AppDetails extends AppCompatActivity { // If description has more than five lines if (description.getLineCount() > MAX_LINES) { description.setMaxLines(MAX_LINES); - description.setEllipsize(TextUtils.TruncateAt.MARQUEE); + if (Build.VERSION.SDK_INT > 10) { + // ellipsizing doesn't work properly here on 2.X + description.setEllipsize(TextUtils.TruncateAt.MARQUEE); + } description.setOnClickListener(expanderDescription); viewAllDescription = true; From a9c73dd278d4a4d52501b27c65e33f56fd246cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 5 May 2016 12:05:42 +0100 Subject: [PATCH 4/5] Avoid NPE in getNotificationTitle See the following crash reported via ACRA: java.lang.NullPointerException at org.fdroid.fdroid.net.DownloaderService.getNotificationTitle(DownloaderService.java:188) at org.fdroid.fdroid.net.DownloaderService.createNotification(DownloaderService.java:167) at org.fdroid.fdroid.net.DownloaderService.handleIntent(DownloaderService.java:274) at org.fdroid.fdroid.net.DownloaderService$ServiceHandler.handleMessage(DownloaderService.java:107) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.os.HandlerThread.run(HandlerThread.java:61) I'm not sure what the source of the null App was (could be that we couldn't access the DB for some reason, or perhaps that somehow the app wasn't in it anymore). In any case, it doesn't hurt to double check here. If the app is null, simply fall back to the title without the app name. --- .../java/org/fdroid/fdroid/net/DownloaderService.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java index f29b880e8..d483d36e4 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/DownloaderService.java @@ -181,15 +181,14 @@ public class DownloaderService extends Service { * message. */ private String getNotificationTitle(@Nullable String packageName) { - String title; if (packageName != null) { - App app = AppProvider.Helper.findByPackageName( + final App app = AppProvider.Helper.findByPackageName( getContentResolver(), packageName, new String[]{AppProvider.DataColumns.NAME}); - title = getString(R.string.downloading_apk, app.name); - } else { - title = getString(R.string.downloading); + if (app != null) { + return getString(R.string.downloading_apk, app.name); + } } - return title; + return getString(R.string.downloading); } public static PendingIntent createAppDetailsIntent(@NonNull Context context, int requestCode, @Nullable String packageName) { From 2ed7c925f7a82765a24a6d7405dc69ac04aa14cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 6 May 2016 00:58:48 +0100 Subject: [PATCH 5/5] gradle: bump Android plugin to 2.1.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e4f43b486..e02ad215c 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.0.0' + classpath 'com.android.tools.build:gradle:2.1.0' classpath files('libs/gradle-witness.jar') } }