[Cleanup] Code Cleanup, Removed some unused methods

This commit is contained in:
Prathamesh More 2021-11-28 22:25:18 +05:30
parent 3df5a77ee8
commit 6ae4c3cae4
32 changed files with 122 additions and 301 deletions

View file

@ -37,6 +37,7 @@ object Constants {
const val IS_MUSIC = const val IS_MUSIC =
MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''" MediaStore.Audio.AudioColumns.IS_MUSIC + "=1" + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"
@Suppress("Deprecation")
val baseProjection = arrayOf( val baseProjection = arrayOf(
BaseColumns._ID, // 0 BaseColumns._ID, // 0
MediaStore.Audio.AudioColumns.TITLE, // 1 MediaStore.Audio.AudioColumns.TITLE, // 1

View file

@ -82,6 +82,7 @@ class LockScreenActivity : AbsMusicServiceActivity() {
} }
} }
@Suppress("Deprecation")
private fun lockScreenInit() { private fun lockScreenInit() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true) setShowWhenLocked(true)

View file

@ -172,7 +172,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
v.getGlobalVisibleRect(outRect) v.getGlobalVisibleRect(outRect)
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) { if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) {
v.clearFocus() v.clearFocus()
val imm = getSystemService<InputMethodManager>()?.hideSoftInputFromWindow(v.windowToken, 0) getSystemService<InputMethodManager>()?.hideSoftInputFromWindow(v.windowToken, 0)
} }
} }
} }

View file

@ -137,16 +137,6 @@ class SearchAdapter(
} }
} }
private fun getSongs(playlist: Playlist): List<Song> {
val songs = mutableListOf<Song>()
if (playlist is AbsSmartPlaylist) {
songs.addAll(playlist.getSongs())
} else {
songs.addAll(PlaylistSongsLoader.getPlaylistSongList(activity, playlist.id))
}
return songs
}
override fun getItemCount(): Int { override fun getItemCount(): Int {
return dataSet.size return dataSet.size
} }

View file

@ -28,12 +28,6 @@ fun List<SongEntity>.toSongs(): List<Song> {
} }
} }
fun List<Song>.toSongs(playlistId: Long): List<SongEntity> {
return map {
it.toSongEntity(playlistId)
}
}
fun Song.toHistoryEntity(timePlayed: Long): HistoryEntity { fun Song.toHistoryEntity(timePlayed: Long): HistoryEntity {
return HistoryEntity( return HistoryEntity(
id = id, id = id,

View file

@ -3,13 +3,9 @@ package code.name.monkey.retromusic.extensions
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Environment
import android.provider.DocumentsContract
import androidx.activity.result.ActivityResult import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import java.io.File
import java.io.OutputStream import java.io.OutputStream
fun Fragment.createNewFile( fun Fragment.createNewFile(

View file

@ -17,9 +17,7 @@ class PlaylistPreviewFetcher(val context: Context, private val playlistPreview:
val bitmap = val bitmap =
AutoGeneratedPlaylistBitmap.getBitmap( AutoGeneratedPlaylistBitmap.getBitmap(
context, context,
playlistPreview.songs.shuffled(), playlistPreview.songs.shuffled()
true,
false
) )
callback.onDataReady(bitmap) callback.onDataReady(bitmap)
} catch (e: Exception) { } catch (e: Exception) {

View file

@ -92,11 +92,11 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
public abstract Fragment getItem(int position); public abstract Fragment getItem(int position);
@Override @Override
public void startUpdate(ViewGroup container) {} public void startUpdate(@NonNull ViewGroup container) {}
@NonNull @NonNull
@Override @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 // If we already have this item instantiated, there is nothing
// to do. This can happen when we are restoring the entire pager // to do. This can happen when we are restoring the entire pager
// from its saved state, where the fragment manager has already // from its saved state, where the fragment manager has already
@ -132,7 +132,7 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
} }
@Override @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; Fragment fragment = (Fragment) object;
if (mCurTransaction == null) { if (mCurTransaction == null) {
@ -152,23 +152,21 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
} }
@Override @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; Fragment fragment = (Fragment) object;
if (fragment != mCurrentPrimaryItem) { if (fragment != mCurrentPrimaryItem) {
if (mCurrentPrimaryItem != null) { if (mCurrentPrimaryItem != null) {
mCurrentPrimaryItem.setMenuVisibility(false); mCurrentPrimaryItem.setMenuVisibility(false);
mCurrentPrimaryItem.setUserVisibleHint(false); mCurrentPrimaryItem.setUserVisibleHint(false);
} }
if (fragment != null) { fragment.setMenuVisibility(true);
fragment.setMenuVisibility(true); fragment.setUserVisibleHint(true);
fragment.setUserVisibleHint(true);
}
mCurrentPrimaryItem = fragment; mCurrentPrimaryItem = fragment;
} }
} }
@Override @Override
public void finishUpdate(ViewGroup container) { public void finishUpdate(@NonNull ViewGroup container) {
if (mCurTransaction != null) { if (mCurTransaction != null) {
mCurTransaction.commitAllowingStateLoss(); mCurTransaction.commitAllowingStateLoss();
mCurTransaction = null; mCurTransaction = null;
@ -177,7 +175,7 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
} }
@Override @Override
public boolean isViewFromObject(View view, Object object) { public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return ((Fragment) object).getView() == view; return ((Fragment) object).getView() == view;
} }

View file

@ -40,8 +40,6 @@ abstract class WrappedAsyncTaskLoader<D>
if (!isReset) { if (!isReset) {
this.mData = data this.mData = data
super.deliverResult(data) super.deliverResult(data)
} else {
// An asynchronous query came in while the loader is stopped
} }
} }

View file

@ -75,6 +75,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Random; import java.util.Random;
import code.name.monkey.appthemehelper.util.VersionUtils;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.LockScreenActivity; import code.name.monkey.retromusic.activities.LockScreenActivity;
import code.name.monkey.retromusic.appwidgets.AppWidgetBig; import code.name.monkey.retromusic.appwidgets.AppWidgetBig;
@ -1155,7 +1156,7 @@ public class MusicService extends MediaBrowserServiceCompat
playback.setNextDataSource(getTrackUri(Objects.requireNonNull(getSongAt(nextPosition)))); playback.setNextDataSource(getTrackUri(Objects.requireNonNull(getSongAt(nextPosition))));
} }
this.nextPosition = nextPosition; this.nextPosition = nextPosition;
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
} }
@ -1591,11 +1592,8 @@ public class MusicService extends MediaBrowserServiceCompat
mediaButtonIntent.setComponent(mediaButtonReceiverComponentName); mediaButtonIntent.setComponent(mediaButtonReceiverComponentName);
PendingIntent mediaButtonReceiverPendingIntent; PendingIntent mediaButtonReceiverPendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent,
mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_MUTABLE); VersionUtils.INSTANCE.hasMarshmallow() ? PendingIntent.FLAG_IMMUTABLE : 0);
} else {
mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
}
mediaSession = new MediaSessionCompat( mediaSession = new MediaSessionCompat(
this, this,
@ -1604,9 +1602,6 @@ public class MusicService extends MediaBrowserServiceCompat
mediaButtonReceiverPendingIntent); mediaButtonReceiverPendingIntent);
MediaSessionCallback mediasessionCallback = MediaSessionCallback mediasessionCallback =
new MediaSessionCallback(getApplicationContext(), this); new MediaSessionCallback(getApplicationContext(), this);
mediaSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setCallback(mediasessionCallback); mediaSession.setCallback(mediasessionCallback);
mediaSession.setActive(true); mediaSession.setActive(true);
mediaSession.setMediaButtonReceiver(mediaButtonReceiverPendingIntent); mediaSession.setMediaButtonReceiver(mediaButtonReceiverPendingIntent);

View file

@ -70,15 +70,11 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel) action.putExtra(MainActivity.EXPAND_PANEL, PreferenceUtil.isExpandPanel)
action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP action.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
val clickIntent = val clickIntent =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { PendingIntent.getActivity(
PendingIntent.getActivity(
service, 0, action, if (VersionUtils.hasMarshmallow()) service, 0, action, if (VersionUtils.hasMarshmallow())
PendingIntent.FLAG_IMMUTABLE 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 serviceName = ComponentName(service, MusicService::class.java)
val intent = Intent(ACTION_QUIT) val intent = Intent(ACTION_QUIT)

View file

@ -31,21 +31,23 @@ class HorizontalFlipTransformation : ViewPager.PageTransformer {
} }
if (position < -1) { // [-Infinity,-1) when {
// This page is way off-screen to the left. position < -1 -> { // [-Infinity,-1)
page.alpha = 0f // This page is way off-screen to the left.
page.alpha = 0f
} else if (position <= 0) { // [-1,0] }
page.alpha = 1f position <= 0 -> { // [-1,0]
page.rotationX = 180 * (1 - abs(position) + 1) page.alpha = 1f
page.rotationX = 180 * (1 - abs(position) + 1)
} else if (position <= 1) { // (0,1] }
page.alpha = 1f position <= 1 -> { // (0,1]
page.rotationX = -180 * (1 - abs(position) + 1) page.alpha = 1f
page.rotationX = -180 * (1 - abs(position) + 1)
} else { // (1,+Infinity] }
// This page is way off-screen to the right. else -> { // (1,+Infinity]
page.alpha = 0f // This page is way off-screen to the right.
page.alpha = 0f
}
} }
} }
} }

View file

@ -29,32 +29,36 @@ class NormalPageTransformer : ViewPager.PageTransformer {
val pageWidth = view.width val pageWidth = view.width
val pageHeight = view.height val pageHeight = view.height
if (position < -1) { // [-Infinity,-1) when {
// This page is way off-screen to the left. position < -1 -> { // [-Infinity,-1)
view.alpha = 1f // This page is way off-screen to the left.
view.scaleY = 0.7f view.alpha = 1f
} else if (position <= 1) { // [-1,1] view.scaleY = 0.7f
// 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
} }
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) // Scale the page down (between MIN_SCALE and 1)
view.scaleX = scaleFactor view.scaleX = scaleFactor
view.scaleY = scaleFactor view.scaleY = scaleFactor
// Fade the page relative to its size. // Fade the page relative to its size.
//view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA)); //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. else -> { // (1,+Infinity]
view.alpha = 1f // This page is way off-screen to the right.
view.scaleY = 0.7f view.alpha = 1f
view.scaleY = 0.7f
}
} }
} }

View file

@ -31,22 +31,24 @@ class VerticalFlipTransformation : ViewPager.PageTransformer {
} }
if (position < -1) { // [-Infinity,-1) when {
// This page is way off-screen to the left. position < -1 -> { // [-Infinity,-1)
page.alpha = 0f // This page is way off-screen to the left.
page.alpha = 0f
} else if (position <= 0) { // [-1,0] }
page.alpha = 1f position <= 0 -> { // [-1,0]
page.rotationY = 180 * (1 - abs(position) + 1) page.alpha = 1f
page.rotationY = 180 * (1 - abs(position) + 1)
} else if (position <= 1) { // (0,1] }
page.alpha = 1f position <= 1 -> { // (0,1]
page.rotationY = -180 * (1 - abs(position) + 1) page.alpha = 1f
page.rotationY = -180 * (1 - abs(position) + 1)
} else { // (1,+Infinity] }
// This page is way off-screen to the right. else -> { // (1,+Infinity]
page.alpha = 0f // This page is way off-screen to the right.
page.alpha = 0f
}
} }

View file

@ -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()
}
} }

View file

@ -3,11 +3,6 @@ package code.name.monkey.retromusic.util;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; 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; import androidx.annotation.NonNull;
@ -20,19 +15,12 @@ import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.model.Song; import code.name.monkey.retromusic.model.Song;
public class AutoGeneratedPlaylistBitmap { public class AutoGeneratedPlaylistBitmap {
private static final String TAG = "AutoGeneratedPB";
/*
public static Bitmap getBitmapWithCollectionFrame(Context context, List<Song> 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( public static Bitmap getBitmap(
Context context, List<Song> songPlaylist, boolean round, boolean blur) { Context context, List<Song> songPlaylist) {
if (songPlaylist == null || songPlaylist.isEmpty()) return getDefaultBitmap(context, round); if (songPlaylist == null || songPlaylist.isEmpty()) return getDefaultBitmap(context);
if (songPlaylist.size() == 1) return getBitmapWithAlbumId(context, songPlaylist.get(0).getAlbumId()); if (songPlaylist.size() == 1)
return getBitmapWithAlbumId(context, songPlaylist.get(0).getAlbumId());
List<Long> albumID = new ArrayList<>(); List<Long> albumID = new ArrayList<>();
for (Song song : songPlaylist) { for (Song song : songPlaylist) {
if (!albumID.contains(song.getAlbumId())) albumID.add(song.getAlbumId()); if (!albumID.contains(song.getAlbumId())) albumID.add(song.getAlbumId());
@ -46,102 +34,6 @@ public class AutoGeneratedPlaylistBitmap {
return MergedImageUtils.INSTANCE.joinImages(art); return MergedImageUtils.INSTANCE.joinImages(art);
} }
private static Bitmap getBitmapCollection(ArrayList<Bitmap> art, boolean round) {
long start = System.currentTimeMillis();
// lấy kích thước 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) { private static Bitmap getBitmapWithAlbumId(@NonNull Context context, Long id) {
try { try {
return Glide.with(context) 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); return BitmapFactory.decodeResource(context.getResources(), R.drawable.default_album_art);
} }
} }

View file

@ -594,7 +594,7 @@ public final class BitmapEditor {
/** /**
* getResizedBitmap method is used to Resized the Image according to custom width and height * 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 newHeight (new desired height)
* @param newWidth (new desired Width) * @param newWidth (new desired Width)
* @return image (new resized image) * @return image (new resized image)
@ -609,22 +609,21 @@ public final class BitmapEditor {
// onTap the bit map // onTap the bit map
matrix.postScale(scaleWidth, scaleHeight); matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap // recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(image, 0, 0, width, height, matrix, false); return Bitmap.createBitmap(image, 0, 0, width, height, matrix, false);
return resizedBitmap;
} }
public static boolean TrueIfBitmapBigger(Bitmap bitmap, int size) { public static boolean TrueIfBitmapBigger(Bitmap bitmap, int size) {
int sizeBitmap = int sizeBitmap =
(bitmap.getHeight() > bitmap.getWidth()) ? bitmap.getHeight() : bitmap.getWidth(); Math.max(bitmap.getHeight(), bitmap.getWidth());
return sizeBitmap > size; return sizeBitmap > size;
} }
public static Bitmap GetRoundedBitmapWithBlurShadow( public static Bitmap getRoundedBitmapWithBlurShadow(
Bitmap original, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) { Bitmap original, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) {
int original_width = original.getWidth(); int original_width = original.getWidth();
int orginal_height = original.getHeight(); int original_height = original.getHeight();
int bitmap_width = original_width + paddingLeft + paddingRight; 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); Bitmap bitmap = Bitmap.createBitmap(bitmap_width, bitmap_height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(); Paint paint = new Paint();

View file

@ -25,13 +25,11 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.ExifInterface; import android.media.ExifInterface;
import android.os.Build;
import androidx.annotation.ColorInt; import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;

View file

@ -191,6 +191,7 @@ class PackageValidator(
* *
* @return [PackageInfo] for the package name or null if it's not found. * @return [PackageInfo] for the package name or null if it's not found.
*/ */
@Suppress("Deprecation")
@SuppressLint("PackageManagerGetSignatures") @SuppressLint("PackageManagerGetSignatures")
private fun getPackageInfo(callingPackage: String): PackageInfo? = private fun getPackageInfo(callingPackage: String): PackageInfo? =
packageManager.getPackageInfo(callingPackage, packageManager.getPackageInfo(callingPackage,

View file

@ -166,8 +166,8 @@ public class PlaylistsUtil {
Toast.LENGTH_SHORT) Toast.LENGTH_SHORT)
.show(); .show();
} }
} catch (SecurityException ignored) { } catch (SecurityException exception) {
ignored.printStackTrace(); exception.printStackTrace();
} }
} }
@ -234,13 +234,13 @@ public class PlaylistsUtil {
for (int i = 0; i < selectionArgs.length; i++) { for (int i = 0; i < selectionArgs.length; i++) {
selectionArgs[i] = String.valueOf(songs.get(i).getIdInPlayList()); selectionArgs[i] = String.valueOf(songs.get(i).getIdInPlayList());
} }
String selection = MediaStore.Audio.Playlists.Members._ID + " in ("; StringBuilder selection = new StringBuilder(MediaStore.Audio.Playlists.Members._ID + " in (");
//noinspection unused
for (String selectionArg : selectionArgs) selection += "?, "; for (String selectionArg : selectionArgs) selection.append("?, ");
selection = selection.substring(0, selection.length() - 2) + ")"; selection = new StringBuilder(selection.substring(0, selection.length() - 2) + ")");
try { try {
context.getContentResolver().delete(uri, selection, selectionArgs); context.getContentResolver().delete(uri, selection.toString(), selectionArgs);
} catch (SecurityException ignored) { } catch (SecurityException ignored) {
} }
} }

View file

@ -42,7 +42,7 @@ public class RetroColorUtil {
float[] hsv = new float[3]; float[] hsv = new float[3];
Color.colorToHSV(color, hsv); 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); return Color.HSVToColor(hsv);
} }

View file

@ -29,22 +29,22 @@ public class SwipeAndDragHelper extends ItemTouchHelper.Callback {
} }
@Override @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; int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
return makeMovementFlags(dragFlags, 0); return makeMovementFlags(dragFlags, 0);
} }
@Override @Override
public boolean onMove( public boolean onMove(
RecyclerView recyclerView, @NonNull RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder viewHolder,
RecyclerView.ViewHolder target) { RecyclerView.ViewHolder target) {
contract.onViewMoved(viewHolder.getLayoutPosition(), target.getLayoutPosition()); contract.onViewMoved(viewHolder.getLayoutPosition(), target.getLayoutPosition());
return true; return true;
} }
@Override @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {} public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {}
@Override @Override
public boolean isLongPressDragEnabled() { public boolean isLongPressDragEnabled() {
@ -53,13 +53,13 @@ public class SwipeAndDragHelper extends ItemTouchHelper.Callback {
@Override @Override
public void onChildDraw( public void onChildDraw(
Canvas c, @NonNull Canvas c,
RecyclerView recyclerView, @NonNull RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder viewHolder,
float dX, float dX,
float dY, float dY,
int actionState, int actionState,
boolean isCurrentlyActive) { boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth()); float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth());
viewHolder.itemView.setAlpha(alpha); viewHolder.itemView.setAlpha(alpha);

View file

@ -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 { fun hitTest(v: View, x: Int, y: Int): Boolean {
val tx = (v.translationX + 0.5f).toInt() val tx = (v.translationX + 0.5f).toInt()
val ty = (v.translationY + 0.5f).toInt() val ty = (v.translationY + 0.5f).toInt()

View file

@ -353,11 +353,7 @@ public class NotificationColorUtil {
public static int resolvePrimaryColor(Context context, int backgroundColor) { public static int resolvePrimaryColor(Context context, int backgroundColor) {
boolean useDark = shouldUseDark(backgroundColor); boolean useDark = shouldUseDark(backgroundColor);
if (useDark) { return ContextCompat.getColor(context, android.R.color.primary_text_light);
return ContextCompat.getColor(context, android.R.color.primary_text_light);
} else {
return ContextCompat.getColor(context, android.R.color.primary_text_light);
}
} }
public static int resolveSecondaryColor(Context context, int backgroundColor) { public static int resolveSecondaryColor(Context context, int backgroundColor) {

View file

@ -399,6 +399,7 @@ public class BreadCrumbLayout extends HorizontalScrollView implements View.OnCli
return file.getPath().equals("/") ? "root" : file.getName(); return file.getPath().equals("/") ? "root" : file.getName();
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return "Crumb{" + "file=" + file + ", scrollPos=" + scrollPos + '}'; return "Crumb{" + "file=" + file + ", scrollPos=" + scrollPos + '}';

View file

@ -31,8 +31,6 @@ class RetroShapeableImageView @JvmOverloads constructor(
init { init {
val typedArray = val typedArray =
context.obtainStyledAttributes(attrs, R.styleable.RetroShapeableImageView, defStyle, -1) 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 { _, _, _, _, _, _, _, _, _ -> addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
val radius = width / 2f val radius = width / 2f
shapeAppearanceModel = ShapeAppearanceModel().withCornerSize(radius) shapeAppearanceModel = ShapeAppearanceModel().withCornerSize(radius)

View file

@ -452,8 +452,8 @@ public class SeekArc extends View {
return; return;
} }
progress = (progress > mMax) ? mMax : progress; progress = Math.min(progress, mMax);
progress = (progress < 0) ? 0 : progress; progress = Math.max(progress, 0);
mProgress = progress; mProgress = progress;
if (mOnSeekArcChangeListener != null) { if (mOnSeekArcChangeListener != null) {

View file

@ -15,7 +15,6 @@
package code.name.monkey.retromusic.views; package code.name.monkey.retromusic.views;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.WindowInsets; import android.view.WindowInsets;
import android.widget.FrameLayout; import android.widget.FrameLayout;

View file

@ -17,20 +17,11 @@ import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.FrameLayout import android.widget.FrameLayout
class WidthFitSquareLayout : FrameLayout { class WidthFitSquareLayout @JvmOverloads constructor(
constructor(context: Context) : super(context) context: Context,
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) attrs: AttributeSet? = null,
constructor( defStyleAttr: Int = -1
context: Context, attrs: AttributeSet?, ) : FrameLayout(context, attrs, defStyleAttr) {
defStyleAttr: Int
) : super(context, attrs, defStyleAttr)
constructor(
context: Context, attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec) super.onMeasure(widthMeasureSpec, widthMeasureSpec)
} }

View file

@ -69,7 +69,7 @@
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" /> app:layout_constraintGuide_begin="@dimen/list_pref_guideline_begin" />
<code.name.monkey.appthemehelper.common.prefs.BorderCircleView xmlns:android="http://schemas.android.com/apk/res/android" <code.name.monkey.appthemehelper.common.prefs.BorderCircleView
android:id="@+id/circle" android:id="@+id/circle"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"

View file

@ -4,8 +4,6 @@ import android.content.res.ColorStateList
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import java.lang.reflect.Field
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
*/ */

View file

@ -244,14 +244,14 @@ public final class ToolbarContentTintHelper {
} }
@Override @Override
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { public void onCloseMenu(@NonNull MenuBuilder menu, boolean allMenusAreClosing) {
if (mParentCb != null) { if (mParentCb != null) {
mParentCb.onCloseMenu(menu, allMenusAreClosing); mParentCb.onCloseMenu(menu, allMenusAreClosing);
} }
} }
@Override @Override
public boolean onOpenSubMenu(MenuBuilder subMenu) { public boolean onOpenSubMenu(@NonNull MenuBuilder subMenu) {
InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor); InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor);
return mParentCb != null && mParentCb.onOpenSubMenu(subMenu); return mParentCb != null && mParentCb.onOpenSubMenu(subMenu);
} }