Replayce adapterposition to layoutposition

This commit is contained in:
h4h13 2020-04-16 23:43:12 +05:30
parent 43a33a63eb
commit d87c95b7b2
14 changed files with 342 additions and 199 deletions

View file

@ -49,7 +49,7 @@ class GenreAdapter(
inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) { inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
override fun onClick(v: View?) { override fun onClick(v: View?) {
super.onClick(v) super.onClick(v)
val genre = dataSet[adapterPosition] val genre = dataSet[layoutPosition]
NavigationUtil.goToGenre(activity, genre) NavigationUtil.goToGenre(activity, genre)
} }
} }

View file

@ -113,7 +113,7 @@ class SearchAdapter(
menu?.visibility = View.VISIBLE menu?.visibility = View.VISIBLE
menu?.setOnClickListener(object : SongMenuHelper.OnClickSongMenu(activity) { menu?.setOnClickListener(object : SongMenuHelper.OnClickSongMenu(activity) {
override val song: Song override val song: Song
get() = dataSet!![adapterPosition] as Song get() = dataSet!![layoutPosition] as Song
}) })
} else { } else {
menu?.visibility = View.GONE menu?.visibility = View.GONE
@ -130,7 +130,7 @@ class SearchAdapter(
} }
override fun onClick(v: View?) { override fun onClick(v: View?) {
val item = dataSet!![adapterPosition] val item = dataSet!![layoutPosition]
when (itemViewType) { when (itemViewType) {
ALBUM -> { ALBUM -> {
val options = ActivityOptions.makeSceneTransitionAnimation( val options = ActivityOptions.makeSceneTransitionAnimation(

View file

@ -146,7 +146,7 @@ class SongFileAdapter(
init { init {
if (menu != null && callbacks != null) { if (menu != null && callbacks != null) {
menu?.setOnClickListener { v -> menu?.setOnClickListener { v ->
val position = adapterPosition val position = layoutPosition
if (isPositionInRange(position)) { if (isPositionInRange(position)) {
callbacks.onFileMenuClicked(dataSet[position], v) callbacks.onFileMenuClicked(dataSet[position], v)
} }
@ -158,7 +158,7 @@ class SongFileAdapter(
} }
override fun onClick(v: View?) { override fun onClick(v: View?) {
val position = adapterPosition val position = layoutPosition
if (isPositionInRange(position)) { if (isPositionInRange(position)) {
if (isInQuickSelectMode) { if (isInQuickSelectMode) {
toggleChecked(position) toggleChecked(position)
@ -169,7 +169,7 @@ class SongFileAdapter(
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
val position = adapterPosition val position = layoutPosition
return isPositionInRange(position) && toggleChecked(position) return isPositionInRange(position) && toggleChecked(position)
} }

View file

@ -97,9 +97,9 @@ class AlbumFullWidthAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${dataSet[adapterPosition].id}" "${activity.getString(R.string.transition_album_art)}_${dataSet[layoutPosition].id}"
) )
NavigationUtil.goToAlbumOptions(activity, dataSet[adapterPosition].id, activityOptions) NavigationUtil.goToAlbumOptions(activity, dataSet[layoutPosition].id, activityOptions)
} }
} }
} }

View file

@ -144,21 +144,21 @@ class ArtistAdapter(
override fun onClick(v: View?) { override fun onClick(v: View?) {
super.onClick(v) super.onClick(v)
if (isInQuickSelectMode) { if (isInQuickSelectMode) {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
} else { } else {
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_artist_image)}_${dataSet[adapterPosition].id}" "${activity.getString(R.string.transition_artist_image)}_${dataSet[layoutPosition].id}"
) )
NavigationUtil.goToArtistOptions( NavigationUtil.goToArtistOptions(
activity, dataSet[adapterPosition].id, activityOptions activity, dataSet[layoutPosition].id, activityOptions
) )
} }
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
return super.onLongClick(v) return super.onLongClick(v)
} }
} }

View file

@ -33,6 +33,7 @@ import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist
import code.name.monkey.retromusic.util.AutoGeneratedPlaylistBitmap import code.name.monkey.retromusic.util.AutoGeneratedPlaylistBitmap
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.RetroColorUtil
import java.util.* import java.util.*
class PlaylistAdapter( class PlaylistAdapter(
@ -89,7 +90,7 @@ class PlaylistAdapter(
} else { } else {
holder.menu?.show() holder.menu?.show()
} }
PlaylistBitmapLoader(this, holder, playlist).execute() //PlaylistBitmapLoader(this, holder, playlist).execute()
} }
private fun getIconRes(playlist: Playlist): Drawable { private fun getIconRes(playlist: Playlist): Drawable {
@ -182,7 +183,7 @@ class PlaylistAdapter(
} }
menu?.setOnClickListener { view -> menu?.setOnClickListener { view ->
val playlist = dataSet[adapterPosition] val playlist = dataSet[layoutPosition]
val popupMenu = PopupMenu(activity, view) val popupMenu = PopupMenu(activity, view)
popupMenu.inflate( popupMenu.inflate(
if (itemViewType == SMART_PLAYLIST) R.menu.menu_item_smart_playlist if (itemViewType == SMART_PLAYLIST) R.menu.menu_item_smart_playlist
@ -202,7 +203,7 @@ class PlaylistAdapter(
} }
} }
PlaylistMenuHelper.handleMenuClick( PlaylistMenuHelper.handleMenuClick(
activity, dataSet[adapterPosition], item activity, dataSet[layoutPosition], item
) )
} }
popupMenu.show() popupMenu.show()
@ -216,15 +217,15 @@ class PlaylistAdapter(
override fun onClick(v: View?) { override fun onClick(v: View?) {
if (isInQuickSelectMode) { if (isInQuickSelectMode) {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
} else { } else {
val playlist = dataSet[adapterPosition] val playlist = dataSet[layoutPosition]
NavigationUtil.goToPlaylistNew(activity, playlist) NavigationUtil.goToPlaylistNew(activity, playlist)
} }
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
return true return true
} }
} }
@ -243,6 +244,13 @@ class PlaylistAdapter(
override fun onPostExecute(result: Bitmap?) { override fun onPostExecute(result: Bitmap?) {
super.onPostExecute(result) super.onPostExecute(result)
viewHolder.image?.setImageBitmap(result) viewHolder.image?.setImageBitmap(result)
val color = RetroColorUtil.getColor(
RetroColorUtil.generatePalette(
result
),
ATHUtil.resolveColor(adapter.activity, R.attr.colorSurface)
)
viewHolder.paletteColorContainer?.setBackgroundColor(color)
} }
} }

View file

@ -55,19 +55,19 @@ abstract class AbsOffsetSongAdapter(
override // could also return null, just to be safe return empty song override // could also return null, just to be safe return empty song
val song: Song val song: Song
get() = if (itemViewType == OFFSET_ITEM) Song.emptySong else dataSet[adapterPosition - 1] get() = if (itemViewType == OFFSET_ITEM) Song.emptySong else dataSet[layoutPosition - 1]
override fun onClick(v: View?) { override fun onClick(v: View?) {
if (isInQuickSelectMode && itemViewType != OFFSET_ITEM) { if (isInQuickSelectMode && itemViewType != OFFSET_ITEM) {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
} else { } else {
MusicPlayerRemote.openQueue(dataSet, adapterPosition - 1, true) MusicPlayerRemote.openQueue(dataSet, layoutPosition - 1, true)
} }
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
if (itemViewType == OFFSET_ITEM) return false if (itemViewType == OFFSET_ITEM) return false
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
return true return true
} }
} }

View file

@ -158,7 +158,7 @@ class PlayingQueueAdapter(
override fun onSongMenuItemClick(item: MenuItem): Boolean { override fun onSongMenuItemClick(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.action_remove_from_playing_queue -> { R.id.action_remove_from_playing_queue -> {
removeFromQueue(adapterPosition) removeFromQueue(layoutPosition)
return true return true
} }
} }

View file

@ -150,7 +150,7 @@ open class SongAdapter(
open inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) { open inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
protected open var songMenuRes = SongMenuHelper.MENU_RES protected open var songMenuRes = SongMenuHelper.MENU_RES
protected open val song: Song protected open val song: Song
get() = dataSet[adapterPosition] get() = dataSet[layoutPosition]
init { init {
setImageTransitionName(activity.getString(R.string.transition_album_art)) setImageTransitionName(activity.getString(R.string.transition_album_art))
@ -186,14 +186,14 @@ open class SongAdapter(
override fun onClick(v: View?) { override fun onClick(v: View?) {
if (isInQuickSelectMode) { if (isInQuickSelectMode) {
toggleChecked(adapterPosition) toggleChecked(layoutPosition)
} else { } else {
MusicPlayerRemote.openQueue(dataSet, adapterPosition, true) MusicPlayerRemote.openQueue(dataSet, layoutPosition, true)
} }
} }
override fun onLongClick(v: View?): Boolean { override fun onLongClick(v: View?): Boolean {
return toggleChecked(adapterPosition) return toggleChecked(layoutPosition)
} }
} }

View file

@ -40,14 +40,14 @@ class PlaylistsFragment :
} }
override fun createLayoutManager(): GridLayoutManager { override fun createLayoutManager(): GridLayoutManager {
return GridLayoutManager(activity, 2) return GridLayoutManager(requireContext(), 1)
} }
override fun createAdapter(): PlaylistAdapter { override fun createAdapter(): PlaylistAdapter {
return PlaylistAdapter( return PlaylistAdapter(
mainActivity, mainActivity,
ArrayList(), ArrayList(),
R.layout.item_card, R.layout.item_list,
mainActivity mainActivity
) )
} }

View file

@ -48,6 +48,8 @@ public class AutoGeneratedPlaylistBitmap {
if (bitmap != null) art.add(bitmap); if (bitmap != null) art.add(bitmap);
if (art.size() == 6) break; if (art.size() == 6) break;
} }
return MergedImageUtils.INSTANCE.joinImages(art);
/*
long start3 = System.currentTimeMillis() - start2 - start; long start3 = System.currentTimeMillis() - start2 - start;
Bitmap ret; Bitmap ret;
@ -71,7 +73,7 @@ public class AutoGeneratedPlaylistBitmap {
return BitmapEditor.GetRoundedBitmapWithBlurShadow(context, ret, w / 24, w / 24, w / 24, w / 24, 0, 200, w / 40, 1); return BitmapEditor.GetRoundedBitmapWithBlurShadow(context, ret, w / 24, w / 24, w / 24, w / 24, 0, 200, w / 40, 1);
Log.d(TAG, "getBitmap: time = " + (System.currentTimeMillis() - start) + ", start2 = " + start2 + ", start3 = " + start3); Log.d(TAG, "getBitmap: time = " + (System.currentTimeMillis() - start) + ", start2 = " + start2 + ", start3 = " + start3);
return ret; return ret;*/
} }
private static Bitmap getBitmapCollection(ArrayList<Bitmap> art, boolean round) { private static Bitmap getBitmapCollection(ArrayList<Bitmap> art, boolean round) {
@ -177,14 +179,6 @@ public class AutoGeneratedPlaylistBitmap {
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
/* try {
return Picasso.get().load(Util.getAlbumArtUri(id)).get();
} catch (Exception e) {
return null;
}*/
// return ImageLoader.getInstance().loadImageSync(Util.getAlbumArtUri(song.albumId).toString());
} }
public static Bitmap getDefaultBitmap(@NonNull Context context, boolean round) { public static Bitmap getDefaultBitmap(@NonNull Context context, boolean round) {

View file

@ -291,8 +291,8 @@ public final class BitmapEditor {
return (bitmap); return (bitmap);
} }
public static boolean PerceivedBrightness( int will_White, int[] c)
{ public static boolean PerceivedBrightness(int will_White, int[] c) {
double TBT = Math.sqrt(c[0] * c[0] * .241 + c[1] * c[1] * .691 + c[2] * c[2] * .068); double TBT = Math.sqrt(c[0] * c[0] * .241 + c[1] * c[1] * .691 + c[2] * c[2] * .068);
// Log.d("themee",TBT+""); // Log.d("themee",TBT+"");
return (TBT > will_White) ? false : true; return (TBT > will_White) ? false : true;
@ -324,6 +324,7 @@ public final class BitmapEditor {
r, g, b r, g, b
}; };
} }
public static Bitmap updateSat(Bitmap src, float settingSat) { public static Bitmap updateSat(Bitmap src, float settingSat) {
int w = src.getWidth(); int w = src.getWidth();
@ -342,21 +343,22 @@ public final class BitmapEditor {
canvasResult = null; canvasResult = null;
return bitmapResult; return bitmapResult;
} }
/** /**
* Stack Blur v1.0 from * Stack Blur v1.0 from
* http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html * http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
* Java Author: Mario Klingemann <mario at quasimondo.com> * Java Author: Mario Klingemann <mario at quasimondo.com>
* http://incubator.quasimondo.com * http://incubator.quasimondo.com
* * <p>
* created Feburary 29, 2004 * created Feburary 29, 2004
* Android port : Yahel Bouaziz <yahel at kayenko.com> * Android port : Yahel Bouaziz <yahel at kayenko.com>
* http://www.kayenko.com * http://www.kayenko.com
* ported april 5th, 2012 * ported april 5th, 2012
* * <p>
* This is A compromise between Gaussian Blur and Box blur * This is A compromise between Gaussian Blur and Box blur
* It creates much better looking blurs than Box Blur, but is * It creates much better looking blurs than Box Blur, but is
* 7x faster than my Gaussian Blur implementation. * 7x faster than my Gaussian Blur implementation.
* * <p>
* I called it Stack Blur because this describes best how this * I called it Stack Blur because this describes best how this
* filter works internally: it creates A kind of moving stack * filter works internally: it creates A kind of moving stack
* of colors whilst scanning through the image. Thereby it * of colors whilst scanning through the image. Thereby it
@ -365,7 +367,7 @@ public final class BitmapEditor {
* colors on the topmost layer of the stack are either added on * colors on the topmost layer of the stack are either added on
* or reduced by one, depending on if they are on the right or * or reduced by one, depending on if they are on the right or
* on the x side of the stack. * on the x side of the stack.
* * <p>
* If you are using this algorithm in your code please add * If you are using this algorithm in your code please add
* the following line: * the following line:
* Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com> * Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>
@ -381,13 +383,11 @@ public final class BitmapEditor {
afterscaleSentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false); // tạo bitmap scaled afterscaleSentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false); // tạo bitmap scaled
bitmap = afterscaleSentBitmap.copy(afterscaleSentBitmap.getConfig(), true); bitmap = afterscaleSentBitmap.copy(afterscaleSentBitmap.getConfig(), true);
afterscaleSentBitmap.recycle(); afterscaleSentBitmap.recycle();
} } else {
else {
bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); // đơn giản chỉ copy bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); // đơn giản chỉ copy
} }
if (radius < 1) { if (radius < 1) {
return (sentBitmap.copy(sentBitmap.getConfig(), true)); return (sentBitmap.copy(sentBitmap.getConfig(), true));
} }
@ -609,12 +609,15 @@ public final class BitmapEditor {
return output; return output;
} }
/** 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
* @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)
* */ */
public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) { public static Bitmap getResizedBitmap(Bitmap image, int newHeight, int newWidth) {
int width = image.getWidth(); int width = image.getWidth();
int height = image.getHeight(); int height = image.getHeight();
@ -629,12 +632,13 @@ public final class BitmapEditor {
matrix, false); matrix, false);
return resizedBitmap; return resizedBitmap;
} }
public static boolean TrueIfBitmapBigger(Bitmap bitmap, int size)
{ public static boolean TrueIfBitmapBigger(Bitmap bitmap, int size) {
int sizeBitmap = (bitmap.getHeight() > bitmap.getWidth()) ? bitmap.getHeight() : bitmap.getWidth(); int sizeBitmap = (bitmap.getHeight() > bitmap.getWidth()) ? bitmap.getHeight() : bitmap.getWidth();
if (sizeBitmap > size) return true; if (sizeBitmap > size) return true;
return false; return false;
} }
public static Bitmap GetRoundedBitmapWithBlurShadow(Bitmap original, int paddingTop, int paddingBottom, int paddingLeft, int paddingRight) { public static Bitmap GetRoundedBitmapWithBlurShadow(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 orginal_height = original.getHeight();
@ -690,15 +694,15 @@ public final class BitmapEditor {
bitmap.recycle(); bitmap.recycle();
return end_bitmap; return end_bitmap;
} }
public static void setBitmapforImageView(ImageView imv,Bitmap apply)
{ public static void setBitmapforImageView(ImageView imv, Bitmap apply) {
Bitmap old = ((BitmapDrawable) imv.getDrawable()).getBitmap(); Bitmap old = ((BitmapDrawable) imv.getDrawable()).getBitmap();
imv.setImageBitmap(apply); imv.setImageBitmap(apply);
if (old != null) if (old != null)
old.recycle(); old.recycle();
} }
public static Bitmap getBlurredWithGoodPerformance(Bitmap bitmap,int scale,int radius,int saturation)
{ public static Bitmap getBlurredWithGoodPerformance(Bitmap bitmap, int scale, int radius, int saturation) {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap1 = getResizedBitmap(bitmap, 50, 50); Bitmap bitmap1 = getResizedBitmap(bitmap, 50, 50);
Bitmap updateSatBitmap = updateSat(bitmap1, saturation); Bitmap updateSatBitmap = updateSat(bitmap1, saturation);
@ -708,6 +712,7 @@ public final class BitmapEditor {
bitmap1.recycle(); bitmap1.recycle();
return blurredBitmap; return blurredBitmap;
} }
static public Path RoundedRect(float left, float top, float right, float bottom, float rx, float ry, boolean conformToOriginalPost) { static public Path RoundedRect(float left, float top, float right, float bottom, float rx, float ry, boolean conformToOriginalPost) {
Path path = new Path(); Path path = new Path();
if (rx < 0) rx = 0; if (rx < 0) rx = 0;
@ -729,8 +734,7 @@ public final class BitmapEditor {
path.rLineTo(0, ry); path.rLineTo(0, ry);
path.rLineTo(width, 0); path.rLineTo(width, 0);
path.rLineTo(0, -ry); path.rLineTo(0, -ry);
} } else {
else {
path.rQuadTo(0, ry, rx, ry);//bottom-x corner path.rQuadTo(0, ry, rx, ry);//bottom-x corner
path.rLineTo(widthMinusCorners, 0); path.rLineTo(widthMinusCorners, 0);
@ -743,8 +747,8 @@ public final class BitmapEditor {
return path; return path;
} }
public static int mixTwoColors( int color1, int color2, float amount )
{ public static int mixTwoColors(int color1, int color2, float amount) {
final byte ALPHA_CHANNEL = 24; final byte ALPHA_CHANNEL = 24;
final byte RED_CHANNEL = 16; final byte RED_CHANNEL = 16;
final byte GREEN_CHANNEL = 8; final byte GREEN_CHANNEL = 8;
@ -763,8 +767,8 @@ public final class BitmapEditor {
return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL; return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
} }
public static Bitmap getBlurredWithGoodPerformance(Context context,Bitmap bitmap,int scale,int radius,float saturation)
{ public static Bitmap getBlurredWithGoodPerformance(Context context, Bitmap bitmap, int scale, int radius, float saturation) {
Bitmap bitmap1 = getResizedBitmap(bitmap, 150, 150); Bitmap bitmap1 = getResizedBitmap(bitmap, 150, 150);
Bitmap updateSatBimap = updateSat(bitmap1, saturation); Bitmap updateSatBimap = updateSat(bitmap1, saturation);
Bitmap blurredBitmap = BlurBitmapWithRenderScript(context, updateSatBimap, radius); Bitmap blurredBitmap = BlurBitmapWithRenderScript(context, updateSatBimap, radius);
@ -773,8 +777,7 @@ public final class BitmapEditor {
return blurredBitmap; return blurredBitmap;
} }
public static Bitmap getBlurredBimapWithRenderScript(Context context, Bitmap bitmapOriginal,float radius) public static Bitmap getBlurredBimapWithRenderScript(Context context, Bitmap bitmapOriginal, float radius) {
{
//define this only once if blurring multiple times //define this only once if blurring multiple times
RenderScript rs = RenderScript.create(context); RenderScript rs = RenderScript.create(context);
@ -788,6 +791,7 @@ public final class BitmapEditor {
output.copyTo(bitmapOriginal); output.copyTo(bitmapOriginal);
return bitmapOriginal; return bitmapOriginal;
} }
public static Bitmap BlurBitmapWithRenderScript(Context context, Bitmap bitmap, float radius) { public static Bitmap BlurBitmapWithRenderScript(Context context, Bitmap bitmap, float radius) {
//Let's create an empty bitmap with the same size of the bitmap we want to blur //Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
@ -838,8 +842,8 @@ public final class BitmapEditor {
drawable.draw(canvas); drawable.draw(canvas);
return bitmap; return bitmap;
} }
public static Bitmap changeBitmapColor(Bitmap sourceBitmap, int color)
{ public static Bitmap changeBitmapColor(Bitmap sourceBitmap, int color) {
Bitmap resultBitmap = sourceBitmap.copy(sourceBitmap.getConfig(), true); Bitmap resultBitmap = sourceBitmap.copy(sourceBitmap.getConfig(), true);
Paint paint = new Paint(); Paint paint = new Paint();
ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN); ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
@ -850,10 +854,8 @@ public final class BitmapEditor {
} }
/** /**
*
* @param mode * @param mode
* @return * @return 0 : CLEAR
* 0 : CLEAR
* <br> 1 : SRC * <br> 1 : SRC
* <br> 2 : DST * <br> 2 : DST
* <br> 3 : SRC_OVER * <br> 3 : SRC_OVER
@ -872,45 +874,61 @@ public final class BitmapEditor {
* <br>16 : DARKEN * <br>16 : DARKEN
* <br>17 : LIGHTEN * <br>17 : LIGHTEN
*/ */
public static PorterDuff.Mode getPorterMode(int mode) public static PorterDuff.Mode getPorterMode(int mode) {
{
switch (mode) { switch (mode) {
default: default:
case 0: return PorterDuff.Mode.CLEAR; case 0:
case 1: return PorterDuff.Mode.SRC; return PorterDuff.Mode.CLEAR;
case 2: return PorterDuff.Mode.DST; case 1:
case 3: return PorterDuff.Mode.SRC_OVER; return PorterDuff.Mode.SRC;
case 4: return PorterDuff.Mode.DST_OVER; case 2:
case 5: return PorterDuff.Mode.SRC_IN; return PorterDuff.Mode.DST;
case 6: return PorterDuff.Mode.DST_IN; case 3:
case 7: return PorterDuff.Mode.SRC_OUT; return PorterDuff.Mode.SRC_OVER;
case 8: return PorterDuff.Mode.DST_OUT; case 4:
case 9: return PorterDuff.Mode.SRC_ATOP; return PorterDuff.Mode.DST_OVER;
case 10: return PorterDuff.Mode.DST_ATOP; case 5:
case 11: return PorterDuff.Mode.XOR; return PorterDuff.Mode.SRC_IN;
case 16: return PorterDuff.Mode.DARKEN; case 6:
case 17: return PorterDuff.Mode.LIGHTEN; return PorterDuff.Mode.DST_IN;
case 13: return PorterDuff.Mode.MULTIPLY; case 7:
case 14: return PorterDuff.Mode.SCREEN; return PorterDuff.Mode.SRC_OUT;
case 12: return PorterDuff.Mode.ADD; case 8:
case 15: return PorterDuff.Mode.OVERLAY; return PorterDuff.Mode.DST_OUT;
case 9:
return PorterDuff.Mode.SRC_ATOP;
case 10:
return PorterDuff.Mode.DST_ATOP;
case 11:
return PorterDuff.Mode.XOR;
case 16:
return PorterDuff.Mode.DARKEN;
case 17:
return PorterDuff.Mode.LIGHTEN;
case 13:
return PorterDuff.Mode.MULTIPLY;
case 14:
return PorterDuff.Mode.SCREEN;
case 12:
return PorterDuff.Mode.ADD;
case 15:
return PorterDuff.Mode.OVERLAY;
} }
} }
public static void applyNewColor4Bitmap(Context context,int[] idBitmaps,ImageView[] imageViews,int color,float alpha)
{ public static void applyNewColor4Bitmap(Context context, int[] idBitmaps, ImageView[] imageViews, int color, float alpha) {
android.content.res.Resources resource = context.getResources(); android.content.res.Resources resource = context.getResources();
int size = idBitmaps.length; int size = idBitmaps.length;
Bitmap usingBitmap, resultBitmap; Bitmap usingBitmap, resultBitmap;
for(int i=0;i<size;i++) for (int i = 0; i < size; i++) {
{
usingBitmap = BitmapFactory.decodeResource(resource, idBitmaps[i]); usingBitmap = BitmapFactory.decodeResource(resource, idBitmaps[i]);
resultBitmap = changeBitmapColor(usingBitmap, color); resultBitmap = changeBitmapColor(usingBitmap, color);
imageViews[i].setImageBitmap(resultBitmap); imageViews[i].setImageBitmap(resultBitmap);
imageViews[i].setAlpha(alpha); imageViews[i].setAlpha(alpha);
} }
} }
public static void applyNewColor4Bitmap(Context context,int idBitmap,ImageView applyView,int color,float alpha)
{ public static void applyNewColor4Bitmap(Context context, int idBitmap, ImageView applyView, int color, float alpha) {
android.content.res.Resources resource = context.getResources(); android.content.res.Resources resource = context.getResources();
Bitmap usingBitmap = BitmapFactory.decodeResource(resource, idBitmap); Bitmap usingBitmap = BitmapFactory.decodeResource(resource, idBitmap);
@ -919,6 +937,7 @@ public final class BitmapEditor {
applyView.setAlpha(alpha); applyView.setAlpha(alpha);
} }
public static Bitmap getBitmapFromView(View view) { public static Bitmap getBitmapFromView(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap); Canvas c = new Canvas(bitmap);
@ -926,6 +945,7 @@ public final class BitmapEditor {
view.draw(c); view.draw(c);
return bitmap; return bitmap;
} }
public static Bitmap getBitmapFromView(View view, int left, int top, int right, int bottom) { public static Bitmap getBitmapFromView(View view, int left, int top, int right, int bottom) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap); Canvas c = new Canvas(bitmap);
@ -933,14 +953,14 @@ public final class BitmapEditor {
view.draw(c); view.draw(c);
return bitmap; return bitmap;
} }
public static Bitmap getBackgroundBitmapAViewWithParent(View childView,View parentView)
{ public static Bitmap getBackgroundBitmapAViewWithParent(View childView, View parentView) {
int[] pos_child = new int[2]; int[] pos_child = new int[2];
childView.getLocationOnScreen(pos_child); childView.getLocationOnScreen(pos_child);
return getBitmapFromView(parentView, pos_child[0], pos_child[1], parentView.getRight(), parentView.getBottom()); return getBitmapFromView(parentView, pos_child[0], pos_child[1], parentView.getRight(), parentView.getBottom());
} }
public static Bitmap getBackgroundBlurAViewWithParent(Activity activity,View childView,View parentView)
{ public static Bitmap getBackgroundBlurAViewWithParent(Activity activity, View childView, View parentView) {
Bitmap b1 = getBackgroundBitmapAViewWithParent(childView, parentView); Bitmap b1 = getBackgroundBitmapAViewWithParent(childView, parentView);
Bitmap b2 = getBlurredWithGoodPerformance(activity, b1, 1, 8, 2); Bitmap b2 = getBlurredWithGoodPerformance(activity, b1, 1, 8, 2);
b1.recycle(); b1.recycle();

View file

@ -0,0 +1,121 @@
package code.name.monkey.retromusic.util
import android.graphics.*
import com.bumptech.glide.util.Util.assertBackgroundThread
internal object MergedImageUtils {
private const val IMAGE_SIZE = 1600
private const val PARTS = 3
private const val DEGREES = 9f
fun joinImages(list: List<Bitmap>): Bitmap {
assertBackgroundThread()
val arranged = arrangeBitmaps(list.shuffled())
val mergedImage = create(
arranged,
IMAGE_SIZE,
PARTS
)
val finalImage = rotate(
mergedImage,
IMAGE_SIZE,
DEGREES
)
mergedImage.recycle()
return finalImage
}
private fun arrangeBitmaps(list: List<Bitmap>): List<Bitmap> {
return when {
list.size == 1 -> {
val item = list[0]
listOf(item, item, item, item, item, item, item, item, item)
}
list.size == 2 -> {
val item1 = list[0]
val item2 = list[1]
listOf(item1, item2, item1, item2, item1, item2, item1, item2, item1)
}
list.size == 3 -> {
val item1 = list[0]
val item2 = list[1]
val item3 = list[2]
listOf(item1, item2, item3, item3, item1, item2, item2, item3, item1)
}
list.size == 4 -> {
val item1 = list[0]
val item2 = list[1]
val item3 = list[2]
val item4 = list[3]
listOf(item1, item2, item3, item4, item1, item2, item3, item4, item1)
}
list.size < 9 -> { // 5 to 8
val item1 = list[0]
val item2 = list[1]
val item3 = list[2]
val item4 = list[3]
val item5 = list[4]
listOf(item1, item2, item3, item4, item5, item2, item3, item4, item1)
}
else -> list // case 9
}
}
private fun create(images: List<Bitmap>, imageSize: Int, parts: Int): Bitmap {
val result = Bitmap.createBitmap(imageSize, imageSize, Bitmap.Config.ARGB_8888)
val canvas = Canvas(result)
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
val onePartSize = imageSize / parts
images.forEachIndexed { i, bitmap ->
val bit = Bitmap.createScaledBitmap(bitmap, onePartSize, onePartSize, true)
canvas.drawBitmap(
bit,
(onePartSize * (i % parts)).toFloat(),
(onePartSize * (i / parts)).toFloat(),
paint
)
bit.recycle()
}
paint.color = Color.WHITE
paint.strokeWidth = 10f
val oneThirdSize = (IMAGE_SIZE / 3).toFloat()
val twoThirdSize = (IMAGE_SIZE / 3 * 2).toFloat()
// vertical lines
canvas.drawLine(oneThirdSize, 0f, oneThirdSize, imageSize.toFloat(), paint)
canvas.drawLine(twoThirdSize, 0f, twoThirdSize, imageSize.toFloat(), paint)
// horizontal lines
canvas.drawLine(0f, oneThirdSize, imageSize.toFloat(), oneThirdSize, paint)
canvas.drawLine(0f, twoThirdSize, imageSize.toFloat(), twoThirdSize, paint)
return result
}
private fun rotate(bitmap: Bitmap, imageSize: Int, degrees: Float): Bitmap {
val matrix = Matrix()
matrix.postRotate(degrees)
val rotated = Bitmap.createBitmap(bitmap, 0, 0, imageSize, imageSize, matrix, true)
bitmap.recycle()
val cropStart = imageSize * 25 / 100
val cropEnd: Int = (cropStart * 1.5).toInt()
val cropped = Bitmap.createBitmap(
rotated,
cropStart,
cropStart,
imageSize - cropEnd,
imageSize - cropEnd
)
rotated.recycle()
return cropped
}
}

View file

@ -36,7 +36,7 @@ public class SwipeAndDragHelper extends ItemTouchHelper.Callback {
@Override @Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
contract.onViewMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); contract.onViewMoved(viewHolder.getLayoutPosition(), target.getLayoutPosition());
return true; return true;
} }