From d28b99149b0335a1f5f02396af794fabf723136e Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 22 Sep 2017 15:00:12 +0800 Subject: [PATCH] removed unused code --- twidere/build.gradle | 5 +- .../twidere/util/TwidereColorUtils.java | 8 ++-- .../twidere/util/TwidereMathUtils.java | 47 ------------------- .../twidere/view/HeaderDrawerLayout.java | 7 +-- .../mariotaku/ktextension/NumberExtensions.kt | 15 +++++- .../fragment/media/ImagePageFragment.kt | 7 ++- 6 files changed, 29 insertions(+), 60 deletions(-) delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/util/TwidereMathUtils.java diff --git a/twidere/build.gradle b/twidere/build.gradle index f244fbe5e..87403c117 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -127,9 +127,11 @@ android { exclude 'META-INF/INDEX.LIST' exclude 'META-INF/maven/**' exclude 'META-INF/*.kotlin_module' - exclude 'kotlin/*.kotlin_builtins' + exclude 'kotlin/**.kotlin_builtins' exclude 'org/osmdroid/**.png' + exclude 'javax/annotation/**.java' exclude 'generated-sources/**' + exclude 'jsr305_annotations/**' exclude 'sdk-version.​txt' exclude 'build-data.properties' } @@ -155,7 +157,6 @@ dependencies { // START Non-FOSS component googleImplementation "com.google.android.gms:play-services-maps:${libVersions['PlayServices']}" googleImplementation "com.google.android.gms:play-services-auth:${libVersions['PlayServices']}" - googleImplementation "com.google.android.gms:play-services-ads:${libVersions['PlayServices']}" googleImplementation "com.google.maps.android:android-maps-utils:${libVersions['MapsUtils']}" googleImplementation "com.anjlab.android.iab.v3:library:${libVersions['IABv3']}" googleImplementation "com.dropbox.core:dropbox-core-sdk:${libVersions['DropboxCoreSdk']}" diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereColorUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereColorUtils.java index cf1d42901..515deec28 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereColorUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereColorUtils.java @@ -27,6 +27,8 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; +import kotlin.ranges.RangesKt; + /** * Created by mariotaku on 15/1/8. */ @@ -94,9 +96,9 @@ public class TwidereColorUtils { public static int YIQToColor(int alpha, int[] yiq) { - final int r = TwidereMathUtils.clamp((yiq[0] * 1000 + yiq[1] * 956 + yiq[2] * 620) / 1000, 0, 255); - final int g = TwidereMathUtils.clamp((yiq[0] * 1000 - yiq[1] * 272 - yiq[2] * 647) / 1000, 0, 255); - final int b = TwidereMathUtils.clamp((yiq[0] * 1000 - yiq[1] * 1108 + yiq[2] * 1705) / 1000, 0, 255); + final int r = RangesKt.coerceIn((yiq[0] * 1000 + yiq[1] * 956 + yiq[2] * 620) / 1000, 0, 255); + final int g = RangesKt.coerceIn((yiq[0] * 1000 - yiq[1] * 272 - yiq[2] * 647) / 1000, 0, 255); + final int b = RangesKt.coerceIn((yiq[0] * 1000 - yiq[1] * 1108 + yiq[2] * 1705) / 1000, 0, 255); return Color.argb(alpha, r, g, b); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereMathUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwidereMathUtils.java deleted file mode 100644 index 6f953aeee..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwidereMathUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.util; - -public class TwidereMathUtils { - - private TwidereMathUtils() { - } - - public static int clamp(final int num, final int bound1, final int bound2) { - final int max = Math.max(bound1, bound2), min = Math.min(bound1, bound2); - return Math.max(Math.min(num, max), min); - } - - // Returns the next power of two. - // Returns the input if it is already power of 2. - // Throws IllegalArgumentException if the input is <= 0 or - // the answer overflows. - public static int nextPowerOf2(int n) { - if (n <= 0 || n > 1 << 30) throw new IllegalArgumentException("n is invalid: " + n); - n -= 1; - n |= n >> 16; - n |= n >> 8; - n |= n >> 4; - n |= n >> 2; - n |= n >> 1; - return n + 1; - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/HeaderDrawerLayout.java b/twidere/src/main/java/org/mariotaku/twidere/view/HeaderDrawerLayout.java index 688b0edba..89f465b58 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/HeaderDrawerLayout.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/HeaderDrawerLayout.java @@ -36,7 +36,8 @@ import android.view.ViewGroup; import android.widget.OverScroller; import org.mariotaku.twidere.R; -import org.mariotaku.twidere.util.TwidereMathUtils; + +import kotlin.ranges.RangesKt; /** * Custom ViewGroup for user profile page like Google+ but with tab swipe @@ -284,7 +285,7 @@ public class HeaderDrawerLayout extends ViewGroup { private void offsetHeaderBy(int dy) { final int prevTop = mContainer.getTop(); - final int clampedDy = TwidereMathUtils.clamp(prevTop + dy, getHeaderTopMinimum(), getHeaderTopMaximum()) - prevTop; + final int clampedDy = RangesKt.coerceIn(prevTop + dy, getHeaderTopMinimum(), getHeaderTopMaximum()) - prevTop; mContainer.offsetTopAndBottom(clampedDy); } @@ -421,7 +422,7 @@ public class HeaderDrawerLayout extends ViewGroup { mDrawer.scrollByCallback(-dy); } mScrollingHeaderByHelper = true; - return TwidereMathUtils.clamp(top, min, max); + return RangesKt.coerceIn(top, min, max); } private boolean isScrollingHeaderByHelper() { diff --git a/twidere/src/main/kotlin/org/mariotaku/ktextension/NumberExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/ktextension/NumberExtensions.kt index af41952b9..63c0a6e20 100644 --- a/twidere/src/main/kotlin/org/mariotaku/ktextension/NumberExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/ktextension/NumberExtensions.kt @@ -43,4 +43,17 @@ operator fun Long.contains(i: Long): Boolean = (this and i) == i fun Number.toLocalizedString(locale: Locale = Locale.getDefault()): String { val nf = NumberFormat.getInstance(locale) return nf.format(this) -} \ No newline at end of file +} + +val Int.nextPowerOf2: Int + get() { + var n = this + if (n <= 0 || n > 1 shl 30) throw IllegalArgumentException("n is invalid: " + n) + n -= 1 + n = n or (n shr 16) + n = n or (n shr 8) + n = n or (n shr 4) + n = n or (n shr 2) + n = n or (n shr 1) + return n + 1 + } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt index 20a8e009a..52e447b8d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/media/ImagePageFragment.kt @@ -28,13 +28,13 @@ import android.os.Bundle import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder +import org.mariotaku.ktextension.nextPowerOf2 import org.mariotaku.mediaviewer.library.CacheDownloadLoader import org.mariotaku.mediaviewer.library.subsampleimageview.SubsampleImageViewerFragment import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.activity.MediaViewerActivity import org.mariotaku.twidere.model.ParcelableMedia import org.mariotaku.twidere.model.UserKey -import org.mariotaku.twidere.util.TwidereMathUtils import org.mariotaku.twidere.util.UriUtils import org.mariotaku.twidere.util.media.MediaExtra import java.io.IOException @@ -156,10 +156,9 @@ class ImagePageFragment : SubsampleImageViewerFragment() { val dm = context.resources.displayMetrics val targetSize = Math.min(1024, Math.max(dm.widthPixels, dm.heightPixels)) val sizeRatio = Math.ceil(Math.max(o.outHeight, o.outWidth) / targetSize.toDouble()) - o.inSampleSize = TwidereMathUtils.nextPowerOf2(Math.max(1.0, sizeRatio).toInt()) + o.inSampleSize = Math.max(1.0, sizeRatio).toInt().nextPowerOf2 o.inJustDecodeBounds = false - val bitmap = decodeBitmap(cr, uri, o) ?: throw IOException() - return bitmap + return decodeBitmap(cr, uri, o) ?: throw IOException() } return super.decode(context, uri) }