Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Commit

Permalink
set item icon color
Browse files Browse the repository at this point in the history
  • Loading branch information
sugtao4423 committed Aug 6, 2019
1 parent 6d77ae0 commit bf30af7
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sugtao4423.mhwitemdataeditor

import android.content.Context
import android.graphics.*
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -31,7 +32,7 @@ class ItemListAdapter(private val context: Context) : RecyclerView.Adapter<ItemL
}
val item = data[position]

holder.itemIcon.setImageResource(ItemDataUtils.getItemIconRes(item))
holder.itemIcon.setImageBitmap(getMaskedImage(item))
holder.itemName.text = ItemDataUtils.getItemName(context, item)
holder.itemDetail.text = context.getString(R.string.item_detail, item.id, item.carry, numberFormat.format(item.sell), numberFormat.format(item.buy))

Expand All @@ -40,6 +41,21 @@ class ItemListAdapter(private val context: Context) : RecyclerView.Adapter<ItemL
}
}

private fun getMaskedImage(itemData: ItemData): Bitmap {
val colorImage = BitmapFactory.decodeResource(context.resources, ItemDataUtils.getItemIconColorRes(itemData))
val itemImage = BitmapFactory.decodeResource(context.resources, ItemDataUtils.getItemIconRes(itemData))

val masked = Bitmap.createBitmap(itemImage.width, itemImage.height, Bitmap.Config.ARGB_8888)
Canvas(masked).apply {
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_IN)

drawBitmap(colorImage, 0f, 0f, null)
drawBitmap(itemImage, 0f, 0f, paint)
}
return masked
}

override fun getItemCount(): Int {
return data.size
}
Expand Down

0 comments on commit bf30af7

Please sign in to comment.