From 6ae4c3cae45461131037ff56d208e924b4ae03f2 Mon Sep 17 00:00:00 2001 From: Prathamesh More Date: Sun, 28 Nov 2021 22:25:18 +0530 Subject: [PATCH] [Cleanup] Code Cleanup, Removed some unused methods --- .../code/name/monkey/retromusic/Constants.kt | 1 + .../activities/LockScreenActivity.kt | 1 + .../activities/base/AbsBaseActivity.kt | 2 +- .../retromusic/adapter/SearchAdapter.kt | 10 -- .../monkey/retromusic/db/SongExtension.kt | 6 - .../retromusic/extensions/IntentExtensions.kt | 4 - .../playlistPreview/PlaylistPreviewFetcher.kt | 4 +- .../misc/CustomFragmentStatePagerAdapter.java | 18 ++- .../retromusic/misc/WrappedAsyncTaskLoader.kt | 2 - .../retromusic/service/MusicService.java | 13 +- .../notification/PlayingNotificationImpl.kt | 8 +- .../transform/HorizontalFlipTransformation.kt | 32 ++--- .../transform/NormalPageTransformer.kt | 48 +++---- .../transform/VerticalFlipTransformation.kt | 32 ++--- .../name/monkey/retromusic/util/AppRater.kt | 22 ---- .../util/AutoGeneratedPlaylistBitmap.java | 118 +----------------- .../monkey/retromusic/util/BitmapEditor.java | 13 +- .../monkey/retromusic/util/ImageUtil.java | 2 - .../retromusic/util/PackageValidator.kt | 1 + .../monkey/retromusic/util/PlaylistsUtil.java | 14 +-- .../retromusic/util/RetroColorUtil.java | 2 +- .../retromusic/util/SwipeAndDragHelper.java | 24 ++-- .../name/monkey/retromusic/util/ViewUtil.kt | 5 - .../util/color/NotificationColorUtil.java | 6 +- .../retromusic/views/BreadCrumbLayout.java | 1 + .../views/RetroShapeableImageView.kt | 2 - .../name/monkey/retromusic/views/SeekArc.java | 4 +- .../views/StatusBarMarginFrameLayout.java | 1 - .../retromusic/views/WidthFitSquareLayout.kt | 19 +-- .../main/res/layout/list_item_color_view.xml | 2 +- .../util/TextInputLayoutUtil.kt | 2 - .../util/ToolbarContentTintHelper.java | 4 +- 32 files changed, 122 insertions(+), 301 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/Constants.kt b/app/src/main/java/code/name/monkey/retromusic/Constants.kt index fdfb31e5..153c1275 100644 --- a/app/src/main/java/code/name/monkey/retromusic/Constants.kt +++ b/app/src/main/java/code/name/monkey/retromusic/Constants.kt @@ -37,6 +37,7 @@ object Constants { const val IS_MUSIC = MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''" + @Suppress("Deprecation") val baseProjection = arrayOf( BaseColumns._ID, // 0 MediaStore.Audio.AudioColumns.TITLE, // 1 diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt index 621bc177..ba026cdb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt @@ -82,6 +82,7 @@ class LockScreenActivity : AbsMusicServiceActivity() { } } + @Suppress("Deprecation") private fun lockScreenInit() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { setShowWhenLocked(true) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsBaseActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsBaseActivity.kt index 2106fcae..d84c84b9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsBaseActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsBaseActivity.kt @@ -172,7 +172,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() { v.getGlobalVisibleRect(outRect) if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) { v.clearFocus() - val imm = getSystemService()?.hideSoftInputFromWindow(v.windowToken, 0) + getSystemService()?.hideSoftInputFromWindow(v.windowToken, 0) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/SearchAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/SearchAdapter.kt index 01c86c36..d7fb4e1f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/SearchAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/SearchAdapter.kt @@ -137,16 +137,6 @@ class SearchAdapter( } } - private fun getSongs(playlist: Playlist): List { - val songs = mutableListOf() - if (playlist is AbsSmartPlaylist) { - songs.addAll(playlist.getSongs()) - } else { - songs.addAll(PlaylistSongsLoader.getPlaylistSongList(activity, playlist.id)) - } - return songs - } - override fun getItemCount(): Int { return dataSet.size } diff --git a/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt b/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt index b6d9f40d..4a3705de 100644 --- a/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt +++ b/app/src/main/java/code/name/monkey/retromusic/db/SongExtension.kt @@ -28,12 +28,6 @@ fun List.toSongs(): List { } } -fun List.toSongs(playlistId: Long): List { - return map { - it.toSongEntity(playlistId) - } -} - fun Song.toHistoryEntity(timePlayed: Long): HistoryEntity { return HistoryEntity( id = id, diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/IntentExtensions.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/IntentExtensions.kt index 3c1f3988..5622f007 100644 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/IntentExtensions.kt +++ b/app/src/main/java/code/name/monkey/retromusic/extensions/IntentExtensions.kt @@ -3,13 +3,9 @@ package code.name.monkey.retromusic.extensions import android.app.Activity import android.content.Intent import android.net.Uri -import android.os.Environment -import android.provider.DocumentsContract import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts -import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment -import java.io.File import java.io.OutputStream fun Fragment.createNewFile( diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/playlistPreview/PlaylistPreviewFetcher.kt b/app/src/main/java/code/name/monkey/retromusic/glide/playlistPreview/PlaylistPreviewFetcher.kt index 0b18f6e0..07a2ec4b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/playlistPreview/PlaylistPreviewFetcher.kt +++ b/app/src/main/java/code/name/monkey/retromusic/glide/playlistPreview/PlaylistPreviewFetcher.kt @@ -17,9 +17,7 @@ class PlaylistPreviewFetcher(val context: Context, private val playlistPreview: val bitmap = AutoGeneratedPlaylistBitmap.getBitmap( context, - playlistPreview.songs.shuffled(), - true, - false + playlistPreview.songs.shuffled() ) callback.onDataReady(bitmap) } catch (e: Exception) { diff --git a/app/src/main/java/code/name/monkey/retromusic/misc/CustomFragmentStatePagerAdapter.java b/app/src/main/java/code/name/monkey/retromusic/misc/CustomFragmentStatePagerAdapter.java index 9ee76bb0..c1de399a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/misc/CustomFragmentStatePagerAdapter.java +++ b/app/src/main/java/code/name/monkey/retromusic/misc/CustomFragmentStatePagerAdapter.java @@ -92,11 +92,11 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter { public abstract Fragment getItem(int position); @Override - public void startUpdate(ViewGroup container) {} + public void startUpdate(@NonNull ViewGroup container) {} @NonNull @Override - public Object instantiateItem(ViewGroup container, int position) { + public Object instantiateItem(@NonNull ViewGroup container, int position) { // If we already have this item instantiated, there is nothing // to do. This can happen when we are restoring the entire pager // from its saved state, where the fragment manager has already @@ -132,7 +132,7 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter { } @Override - public void destroyItem(ViewGroup container, int position, Object object) { + public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) { Fragment fragment = (Fragment) object; if (mCurTransaction == null) { @@ -152,23 +152,21 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter { } @Override - public void setPrimaryItem(ViewGroup container, int position, Object object) { + public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) { Fragment fragment = (Fragment) object; if (fragment != mCurrentPrimaryItem) { if (mCurrentPrimaryItem != null) { mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setUserVisibleHint(false); } - if (fragment != null) { - fragment.setMenuVisibility(true); - fragment.setUserVisibleHint(true); - } + fragment.setMenuVisibility(true); + fragment.setUserVisibleHint(true); mCurrentPrimaryItem = fragment; } } @Override - public void finishUpdate(ViewGroup container) { + public void finishUpdate(@NonNull ViewGroup container) { if (mCurTransaction != null) { mCurTransaction.commitAllowingStateLoss(); mCurTransaction = null; @@ -177,7 +175,7 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter { } @Override - public boolean isViewFromObject(View view, Object object) { + public boolean isViewFromObject(@NonNull View view, @NonNull Object object) { return ((Fragment) object).getView() == view; } diff --git a/app/src/main/java/code/name/monkey/retromusic/misc/WrappedAsyncTaskLoader.kt b/app/src/main/java/code/name/monkey/retromusic/misc/WrappedAsyncTaskLoader.kt index b798cc52..7c596c5f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/misc/WrappedAsyncTaskLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/misc/WrappedAsyncTaskLoader.kt @@ -40,8 +40,6 @@ abstract class WrappedAsyncTaskLoader if (!isReset) { this.mData = data super.deliverResult(data) - } else { - // An asynchronous query came in while the loader is stopped } } diff --git a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java index 9ede65f9..0647dbc2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/MusicService.java @@ -75,6 +75,7 @@ import java.util.List; import java.util.Objects; import java.util.Random; +import code.name.monkey.appthemehelper.util.VersionUtils; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.activities.LockScreenActivity; import code.name.monkey.retromusic.appwidgets.AppWidgetBig; @@ -1155,7 +1156,7 @@ public class MusicService extends MediaBrowserServiceCompat playback.setNextDataSource(getTrackUri(Objects.requireNonNull(getSongAt(nextPosition)))); } this.nextPosition = nextPosition; - } catch (Exception e) { + } catch (Exception ignored) { } } } @@ -1591,11 +1592,8 @@ public class MusicService extends MediaBrowserServiceCompat mediaButtonIntent.setComponent(mediaButtonReceiverComponentName); PendingIntent mediaButtonReceiverPendingIntent; - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { - mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_MUTABLE); - } else { - mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); - } + mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, + VersionUtils.INSTANCE.hasMarshmallow() ? PendingIntent.FLAG_IMMUTABLE : 0); mediaSession = new MediaSessionCompat( this, @@ -1604,9 +1602,6 @@ public class MusicService extends MediaBrowserServiceCompat mediaButtonReceiverPendingIntent); MediaSessionCallback mediasessionCallback = new MediaSessionCallback(getApplicationContext(), this); - mediaSession.setFlags( - MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS - | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mediasessionCallback); mediaSession.setActive(true); mediaSession.setMediaButtonReceiver(mediaButtonReceiverPendingIntent); diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt index 552c82ae..3cca67a2 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl.kt @@ -70,15 +70,11 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent { action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel) action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP val clickIntent = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.getActivity( + PendingIntent.getActivity( service, 0, action, if (VersionUtils.hasMarshmallow()) PendingIntent.FLAG_IMMUTABLE - else 0 + else 0 or PendingIntent.FLAG_UPDATE_CURRENT ) - } else { - PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT) - } val serviceName = ComponentName(service, MusicService::class.java) val intent = Intent(ACTION_QUIT) diff --git a/app/src/main/java/code/name/monkey/retromusic/transform/HorizontalFlipTransformation.kt b/app/src/main/java/code/name/monkey/retromusic/transform/HorizontalFlipTransformation.kt index 94004b6b..f96a2109 100644 --- a/app/src/main/java/code/name/monkey/retromusic/transform/HorizontalFlipTransformation.kt +++ b/app/src/main/java/code/name/monkey/retromusic/transform/HorizontalFlipTransformation.kt @@ -31,21 +31,23 @@ class HorizontalFlipTransformation : ViewPager.PageTransformer { } - if (position < -1) { // [-Infinity,-1) - // This page is way off-screen to the left. - page.alpha = 0f - - } else if (position <= 0) { // [-1,0] - page.alpha = 1f - page.rotationX = 180 * (1 - abs(position) + 1) - - } else if (position <= 1) { // (0,1] - page.alpha = 1f - page.rotationX = -180 * (1 - abs(position) + 1) - - } else { // (1,+Infinity] - // This page is way off-screen to the right. - page.alpha = 0f + when { + position < -1 -> { // [-Infinity,-1) + // This page is way off-screen to the left. + page.alpha = 0f + } + position <= 0 -> { // [-1,0] + page.alpha = 1f + page.rotationX = 180 * (1 - abs(position) + 1) + } + position <= 1 -> { // (0,1] + page.alpha = 1f + page.rotationX = -180 * (1 - abs(position) + 1) + } + else -> { // (1,+Infinity] + // This page is way off-screen to the right. + page.alpha = 0f + } } } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/transform/NormalPageTransformer.kt b/app/src/main/java/code/name/monkey/retromusic/transform/NormalPageTransformer.kt index eac68e8a..aeada031 100644 --- a/app/src/main/java/code/name/monkey/retromusic/transform/NormalPageTransformer.kt +++ b/app/src/main/java/code/name/monkey/retromusic/transform/NormalPageTransformer.kt @@ -29,32 +29,36 @@ class NormalPageTransformer : ViewPager.PageTransformer { val pageWidth = view.width val pageHeight = view.height - if (position < -1) { // [-Infinity,-1) - // This page is way off-screen to the left. - view.alpha = 1f - view.scaleY = 0.7f - } else if (position <= 1) { // [-1,1] - // Modify the default slide transition to shrink the page as well - val scaleFactor = max(MIN_SCALE, 1 - abs(position)) - val vertMargin = pageHeight * (1 - scaleFactor) / 2 - val horzMargin = pageWidth * (1 - scaleFactor) / 2 - if (position < 0) { - view.translationX = horzMargin - vertMargin / 2 - } else { - view.translationX = -horzMargin + vertMargin / 2 + when { + position < -1 -> { // [-Infinity,-1) + // This page is way off-screen to the left. + view.alpha = 1f + view.scaleY = 0.7f } + position <= 1 -> { // [-1,1] + // Modify the default slide transition to shrink the page as well + val scaleFactor = max(MIN_SCALE, 1 - abs(position)) + val vertMargin = pageHeight * (1 - scaleFactor) / 2 + val horzMargin = pageWidth * (1 - scaleFactor) / 2 + if (position < 0) { + view.translationX = horzMargin - vertMargin / 2 + } else { + view.translationX = -horzMargin + vertMargin / 2 + } - // Scale the page down (between MIN_SCALE and 1) - view.scaleX = scaleFactor - view.scaleY = scaleFactor + // Scale the page down (between MIN_SCALE and 1) + view.scaleX = scaleFactor + view.scaleY = scaleFactor - // Fade the page relative to its size. - //view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); + // Fade the page relative to its size. + //view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); - } else { // (1,+Infinity] - // This page is way off-screen to the right. - view.alpha = 1f - view.scaleY = 0.7f + } + else -> { // (1,+Infinity] + // This page is way off-screen to the right. + view.alpha = 1f + view.scaleY = 0.7f + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/transform/VerticalFlipTransformation.kt b/app/src/main/java/code/name/monkey/retromusic/transform/VerticalFlipTransformation.kt index 25df95c8..dba0946b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/transform/VerticalFlipTransformation.kt +++ b/app/src/main/java/code/name/monkey/retromusic/transform/VerticalFlipTransformation.kt @@ -31,22 +31,24 @@ class VerticalFlipTransformation : ViewPager.PageTransformer { } - if (position < -1) { // [-Infinity,-1) - // This page is way off-screen to the left. - page.alpha = 0f - - } else if (position <= 0) { // [-1,0] - page.alpha = 1f - page.rotationY = 180 * (1 - abs(position) + 1) - - } else if (position <= 1) { // (0,1] - page.alpha = 1f - page.rotationY = -180 * (1 - abs(position) + 1) - - } else { // (1,+Infinity] - // This page is way off-screen to the right. - page.alpha = 0f + when { + position < -1 -> { // [-Infinity,-1) + // This page is way off-screen to the left. + page.alpha = 0f + } + position <= 0 -> { // [-1,0] + page.alpha = 1f + page.rotationY = 180 * (1 - abs(position) + 1) + } + position <= 1 -> { // (0,1] + page.alpha = 1f + page.rotationY = -180 * (1 - abs(position) + 1) + } + else -> { // (1,+Infinity] + // This page is way off-screen to the right. + page.alpha = 0f + } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt b/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt index 83237739..64a4302a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt @@ -79,26 +79,4 @@ object AppRater { } } } - - private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) { - MaterialAlertDialogBuilder(context) - .setTitle("Rate this App") - .setMessage("If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!") - .setPositiveButton(R.string.app_name) { _, _ -> - context.startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse("market://details?id=${context.packageName}") - ) - ) - editor.putBoolean(DO_NOT_SHOW_AGAIN, true) - editor.commit() - } - .setNeutralButton("Not now", null) - .setNegativeButton("No thanks") { _, _ -> - editor.putBoolean(DO_NOT_SHOW_AGAIN, true) - editor.commit() - } - .show() - } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/AutoGeneratedPlaylistBitmap.java b/app/src/main/java/code/name/monkey/retromusic/util/AutoGeneratedPlaylistBitmap.java index d6243d46..b0efcd62 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/AutoGeneratedPlaylistBitmap.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/AutoGeneratedPlaylistBitmap.java @@ -3,11 +3,6 @@ package code.name.monkey.retromusic.util; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.RectF; -import android.util.Log; import androidx.annotation.NonNull; @@ -20,19 +15,12 @@ import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.model.Song; public class AutoGeneratedPlaylistBitmap { - private static final String TAG = "AutoGeneratedPB"; - /* - public static Bitmap getBitmapWithCollectionFrame(Context context, List songPlaylist, boolean round, boolean blur) { - Bitmap bitmap = getBitmap(context,songPlaylist,round,blur); - int w = bitmap.getWidth(); - Bitmap ret = Bitmap.createBitmap(w,w,Bitmap.Config.ARGB_8888); - } - */ public static Bitmap getBitmap( - Context context, List songPlaylist, boolean round, boolean blur) { - if (songPlaylist == null || songPlaylist.isEmpty()) return getDefaultBitmap(context, round); - if (songPlaylist.size() == 1) return getBitmapWithAlbumId(context, songPlaylist.get(0).getAlbumId()); + Context context, List songPlaylist) { + if (songPlaylist == null || songPlaylist.isEmpty()) return getDefaultBitmap(context); + if (songPlaylist.size() == 1) + return getBitmapWithAlbumId(context, songPlaylist.get(0).getAlbumId()); List albumID = new ArrayList<>(); for (Song song : songPlaylist) { if (!albumID.contains(song.getAlbumId())) albumID.add(song.getAlbumId()); @@ -46,102 +34,6 @@ public class AutoGeneratedPlaylistBitmap { return MergedImageUtils.INSTANCE.joinImages(art); } - private static Bitmap getBitmapCollection(ArrayList art, boolean round) { - long start = System.currentTimeMillis(); - // lấy kích thước là kích thước của bitmap lớn nhất - int max_width = art.get(0).getWidth(); - for (Bitmap b : art) if (max_width < b.getWidth()) max_width = b.getWidth(); - Bitmap bitmap = Bitmap.createBitmap(max_width, max_width, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - Paint paint = new Paint(); - paint.setAntiAlias(false); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(max_width / 100); - paint.setColor(0xffffffff); - switch (art.size()) { - case 2: - canvas.drawBitmap(art.get(1), null, new Rect(0, 0, max_width, max_width), null); - canvas.drawBitmap( - art.get(0), null, new Rect(-max_width / 2, 0, max_width / 2, max_width), null); - canvas.drawLine(max_width / 2, 0, max_width / 2, max_width, paint); - break; - case 3: - canvas.drawBitmap( - art.get(0), null, new Rect(-max_width / 4, 0, 3 * max_width / 4, max_width), null); - canvas.drawBitmap( - art.get(1), null, new Rect(max_width / 2, 0, max_width, max_width / 2), null); - canvas.drawBitmap( - art.get(2), null, new Rect(max_width / 2, max_width / 2, max_width, max_width), null); - canvas.drawLine(max_width / 2, 0, max_width / 2, max_width, paint); - canvas.drawLine(max_width / 2, max_width / 2, max_width, max_width / 2, paint); - break; - case 4: - canvas.drawBitmap(art.get(0), null, new Rect(0, 0, max_width / 2, max_width / 2), null); - canvas.drawBitmap( - art.get(1), null, new Rect(max_width / 2, 0, max_width, max_width / 2), null); - canvas.drawBitmap( - art.get(2), null, new Rect(0, max_width / 2, max_width / 2, max_width), null); - canvas.drawBitmap( - art.get(3), null, new Rect(max_width / 2, max_width / 2, max_width, max_width), null); - canvas.drawLine(max_width / 2, 0, max_width / 2, max_width, paint); - canvas.drawLine(0, max_width / 2, max_width, max_width / 2, paint); - break; - // default: canvas.drawBitmap(art.get(0),null,new Rect(0,0,max_width,max_width),null); - default: - - // độ rộng của des bitmap - float w = (float) (Math.sqrt(2) / 2 * max_width); - float b = (float) (max_width / Math.sqrt(5)); - // khoảng cách định nghĩa, dùng để tính vị trí tâm của 4 bức hình xung quanh - float d = (float) (max_width * (0.5f - 1 / Math.sqrt(10))); - float deg = 45; - - for (int i = 0; i < 5; i++) { - canvas.save(); - switch (i) { - case 0: - canvas.translate(max_width / 2, max_width / 2); - canvas.rotate(deg); - // b = (float) (max_width*Math.sqrt(2/5f)); - canvas.drawBitmap(art.get(0), null, new RectF(-b / 2, -b / 2, b / 2, b / 2), null); - break; - case 1: - canvas.translate(d, 0); - canvas.rotate(deg); - canvas.drawBitmap(art.get(i), null, new RectF(-w / 2, -w / 2, w / 2, w / 2), null); - paint.setAntiAlias(true); - canvas.drawLine(w / 2, -w / 2, w / 2, w / 2, paint); - break; - case 2: - canvas.translate(max_width, d); - canvas.rotate(deg); - canvas.drawBitmap(art.get(i), null, new RectF(-w / 2, -w / 2, w / 2, w / 2), null); - paint.setAntiAlias(true); - canvas.drawLine(-w / 2, w / 2, w / 2, w / 2, paint); - break; - case 3: - canvas.translate(max_width - d, max_width); - canvas.rotate(deg); - canvas.drawBitmap(art.get(i), null, new RectF(-w / 2, -w / 2, w / 2, w / 2), null); - paint.setAntiAlias(true); - canvas.drawLine(-w / 2, -w / 2, -w / 2, w / 2, paint); - break; - case 4: - canvas.translate(0, max_width - d); - canvas.rotate(deg); - canvas.drawBitmap(art.get(i), null, new RectF(-w / 2, -w / 2, w / 2, w / 2), null); - paint.setAntiAlias(true); - canvas.drawLine(-w / 2, -w / 2, w / 2, -w / 2, paint); - break; - } - canvas.restore(); - } - } - Log.d(TAG, "getBitmapCollection: smalltime = " + (System.currentTimeMillis() - start)); - if (round) return BitmapEditor.getRoundedCornerBitmap(bitmap, bitmap.getWidth() / 40); - else return bitmap; - } - private static Bitmap getBitmapWithAlbumId(@NonNull Context context, Long id) { try { return Glide.with(context) @@ -154,7 +46,7 @@ public class AutoGeneratedPlaylistBitmap { } } - public static Bitmap getDefaultBitmap(@NonNull Context context, boolean round) { + public static Bitmap getDefaultBitmap(@NonNull Context context) { return BitmapFactory.decodeResource(context.getResources(), R.drawable.default_album_art); } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/BitmapEditor.java b/app/src/main/java/code/name/monkey/retromusic/util/BitmapEditor.java index fac5bae2..8cde4762 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/BitmapEditor.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/BitmapEditor.java @@ -594,7 +594,7 @@ public final class BitmapEditor { /** * getResizedBitmap method is used to Resized the Image according to custom width and height * - * @param image + * @param image image to be resized * @param newHeight (new desired height) * @param newWidth (new desired Width) * @return image (new resized image) @@ -609,22 +609,21 @@ public final class BitmapEditor { // onTap the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate the new Bitmap - Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height, matrix, false); - return resizedBitmap; + return Bitmap.createBitmap(image, 0, 0, width, height, matrix, false); } public static boolean TrueIfBitmapBigger(Bitmap bitmap, int size) { int sizeBitmap = - (bitmap.getHeight() > bitmap.getWidth()) ? bitmap.getHeight() : bitmap.getWidth(); + Math.max(bitmap.getHeight(), bitmap.getWidth()); return sizeBitmap > size; } - public static Bitmap GetRoundedBitmapWithBlurShadow( + public static Bitmap getRoundedBitmapWithBlurShadow( Bitmap original, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) { int original_width = original.getWidth(); - int orginal_height = original.getHeight(); + int original_height = original.getHeight(); int bitmap_width = original_width + paddingLeft + paddingRight; - int bitmap_height = orginal_height + paddingTop + paddingBottom; + int bitmap_height = original_height + paddingTop + paddingBottom; Bitmap bitmap = Bitmap.createBitmap(bitmap_width, bitmap_height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ImageUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/ImageUtil.java index 8ef4da13..df569eb6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/ImageUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/ImageUtil.java @@ -25,13 +25,11 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.media.ExifInterface; -import android.os.Build; import androidx.annotation.ColorInt; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import java.io.File; import java.io.FileOutputStream; diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PackageValidator.kt b/app/src/main/java/code/name/monkey/retromusic/util/PackageValidator.kt index 76a56584..3d300c10 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PackageValidator.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/PackageValidator.kt @@ -191,6 +191,7 @@ class PackageValidator( * * @return [PackageInfo] for the package name or null if it's not found. */ + @Suppress("Deprecation") @SuppressLint("PackageManagerGetSignatures") private fun getPackageInfo(callingPackage: String): PackageInfo? = packageManager.getPackageInfo(callingPackage, diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java index 5e6872a0..02862550 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PlaylistsUtil.java @@ -166,8 +166,8 @@ public class PlaylistsUtil { Toast.LENGTH_SHORT) .show(); } - } catch (SecurityException ignored) { - ignored.printStackTrace(); + } catch (SecurityException exception) { + exception.printStackTrace(); } } @@ -234,13 +234,13 @@ public class PlaylistsUtil { for (int i = 0; i < selectionArgs.length; i++) { selectionArgs[i] = String.valueOf(songs.get(i).getIdInPlayList()); } - String selection = MediaStore.Audio.Playlists.Members._ID + " in ("; - //noinspection unused - for (String selectionArg : selectionArgs) selection += "?, "; - selection = selection.substring(0, selection.length() - 2) + ")"; + StringBuilder selection = new StringBuilder(MediaStore.Audio.Playlists.Members._ID + " in ("); + + for (String selectionArg : selectionArgs) selection.append("?, "); + selection = new StringBuilder(selection.substring(0, selection.length() - 2) + ")"); try { - context.getContentResolver().delete(uri, selection, selectionArgs); + context.getContentResolver().delete(uri, selection.toString(), selectionArgs); } catch (SecurityException ignored) { } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java index cc4aea66..096c2d78 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/RetroColorUtil.java @@ -42,7 +42,7 @@ public class RetroColorUtil { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); - hsv[1] = (hsv[1] / 1 * ratio) + (0.2f * (1.0f - ratio)); + hsv[1] = (hsv[1] * ratio) + (0.2f * (1.0f - ratio)); return Color.HSVToColor(hsv); } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/SwipeAndDragHelper.java b/app/src/main/java/code/name/monkey/retromusic/util/SwipeAndDragHelper.java index 589f8d4b..92c8be03 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/SwipeAndDragHelper.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/SwipeAndDragHelper.java @@ -29,22 +29,22 @@ public class SwipeAndDragHelper extends ItemTouchHelper.Callback { } @Override - public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; return makeMovementFlags(dragFlags, 0); } @Override public boolean onMove( - RecyclerView recyclerView, - RecyclerView.ViewHolder viewHolder, - RecyclerView.ViewHolder target) { + @NonNull RecyclerView recyclerView, + RecyclerView.ViewHolder viewHolder, + RecyclerView.ViewHolder target) { contract.onViewMoved(viewHolder.getLayoutPosition(), target.getLayoutPosition()); return true; } @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {} + public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {} @Override public boolean isLongPressDragEnabled() { @@ -53,13 +53,13 @@ public class SwipeAndDragHelper extends ItemTouchHelper.Callback { @Override public void onChildDraw( - Canvas c, - RecyclerView recyclerView, - RecyclerView.ViewHolder viewHolder, - float dX, - float dY, - int actionState, - boolean isCurrentlyActive) { + @NonNull Canvas c, + @NonNull RecyclerView recyclerView, + @NonNull RecyclerView.ViewHolder viewHolder, + float dX, + float dY, + int actionState, + boolean isCurrentlyActive) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth()); viewHolder.itemView.setAlpha(alpha); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt index c4e1a176..d582452e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt @@ -76,11 +76,6 @@ object ViewUtil { ) } - fun setProgressDrawable(indicator: CircularProgressIndicator, newColor: Int) { - indicator.setIndicatorColor(newColor) - indicator.trackColor = ColorUtil.withAlpha(newColor, 0.2f) - } - fun hitTest(v: View, x: Int, y: Int): Boolean { val tx = (v.translationX + 0.5f).toInt() val ty = (v.translationY + 0.5f).toInt() diff --git a/app/src/main/java/code/name/monkey/retromusic/util/color/NotificationColorUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/color/NotificationColorUtil.java index 03f8afd4..83d2a8f7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/color/NotificationColorUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/color/NotificationColorUtil.java @@ -353,11 +353,7 @@ public class NotificationColorUtil { public static int resolvePrimaryColor(Context context, int backgroundColor) { boolean useDark = shouldUseDark(backgroundColor); - if (useDark) { - return ContextCompat.getColor(context, android.R.color.primary_text_light); - } else { - return ContextCompat.getColor(context, android.R.color.primary_text_light); - } + return ContextCompat.getColor(context, android.R.color.primary_text_light); } public static int resolveSecondaryColor(Context context, int backgroundColor) { diff --git a/app/src/main/java/code/name/monkey/retromusic/views/BreadCrumbLayout.java b/app/src/main/java/code/name/monkey/retromusic/views/BreadCrumbLayout.java index b35840f6..4b492a85 100644 --- a/app/src/main/java/code/name/monkey/retromusic/views/BreadCrumbLayout.java +++ b/app/src/main/java/code/name/monkey/retromusic/views/BreadCrumbLayout.java @@ -399,6 +399,7 @@ public class BreadCrumbLayout extends HorizontalScrollView implements View.OnCli return file.getPath().equals("/") ? "root" : file.getName(); } + @NonNull @Override public String toString() { return "Crumb{" + "file=" + file + ", scrollPos=" + scrollPos + '}'; diff --git a/app/src/main/java/code/name/monkey/retromusic/views/RetroShapeableImageView.kt b/app/src/main/java/code/name/monkey/retromusic/views/RetroShapeableImageView.kt index 686814b4..18939a3e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/views/RetroShapeableImageView.kt +++ b/app/src/main/java/code/name/monkey/retromusic/views/RetroShapeableImageView.kt @@ -31,8 +31,6 @@ class RetroShapeableImageView @JvmOverloads constructor( init { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.RetroShapeableImageView, defStyle, -1) - val cornerSize = typedArray.getDimension(R.styleable.RetroShapeableImageView_retroCornerSize, 0f) - val circleShape = typedArray.getBoolean(R.styleable.RetroShapeableImageView_circleShape, false) addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> val radius = width / 2f shapeAppearanceModel = ShapeAppearanceModel().withCornerSize(radius) diff --git a/app/src/main/java/code/name/monkey/retromusic/views/SeekArc.java b/app/src/main/java/code/name/monkey/retromusic/views/SeekArc.java index 8fb46c7d..8bc646d5 100644 --- a/app/src/main/java/code/name/monkey/retromusic/views/SeekArc.java +++ b/app/src/main/java/code/name/monkey/retromusic/views/SeekArc.java @@ -452,8 +452,8 @@ public class SeekArc extends View { return; } - progress = (progress > mMax) ? mMax : progress; - progress = (progress < 0) ? 0 : progress; + progress = Math.min(progress, mMax); + progress = Math.max(progress, 0); mProgress = progress; if (mOnSeekArcChangeListener != null) { diff --git a/app/src/main/java/code/name/monkey/retromusic/views/StatusBarMarginFrameLayout.java b/app/src/main/java/code/name/monkey/retromusic/views/StatusBarMarginFrameLayout.java index 51c3acf8..452807b8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/views/StatusBarMarginFrameLayout.java +++ b/app/src/main/java/code/name/monkey/retromusic/views/StatusBarMarginFrameLayout.java @@ -15,7 +15,6 @@ package code.name.monkey.retromusic.views; import android.content.Context; -import android.os.Build; import android.util.AttributeSet; import android.view.WindowInsets; import android.widget.FrameLayout; diff --git a/app/src/main/java/code/name/monkey/retromusic/views/WidthFitSquareLayout.kt b/app/src/main/java/code/name/monkey/retromusic/views/WidthFitSquareLayout.kt index b6bd9f70..01bd0da6 100755 --- a/app/src/main/java/code/name/monkey/retromusic/views/WidthFitSquareLayout.kt +++ b/app/src/main/java/code/name/monkey/retromusic/views/WidthFitSquareLayout.kt @@ -17,20 +17,11 @@ import android.content.Context import android.util.AttributeSet import android.widget.FrameLayout -class WidthFitSquareLayout : FrameLayout { - constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) - constructor( - context: Context, attrs: AttributeSet?, - defStyleAttr: Int - ) : super(context, attrs, defStyleAttr) - - constructor( - context: Context, attrs: AttributeSet?, - defStyleAttr: Int, - defStyleRes: Int - ) : super(context, attrs, defStyleAttr, defStyleRes) - +class WidthFitSquareLayout @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = -1 +) : FrameLayout(context, attrs, defStyleAttr) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { super.onMeasure(widthMeasureSpec, widthMeasureSpec) } diff --git a/app/src/main/res/layout/list_item_color_view.xml b/app/src/main/res/layout/list_item_color_view.xml index fcb9facf..7a591826 100644 --- a/app/src/main/res/layout/list_item_color_view.xml +++ b/app/src/main/res/layout/list_item_color_view.xml @@ -69,7 +69,7 @@ android:orientation="vertical" app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" /> -