In contact and chat lists use bitmap to show text avatar
This commit is contained in:
@@ -11,8 +11,6 @@ import android.widget.ArrayAdapter
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.Canvas
|
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ class CallListAdapter(private val ctx: Context, private val aor: String, private
|
|||||||
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
||||||
else
|
else
|
||||||
viewHolder.textAvatarView.text = ""
|
viewHolder.textAvatarView.text = ""
|
||||||
viewHolder.imageAvatarView.setImageBitmap(getBitmapFromView(viewHolder.textAvatarView))
|
viewHolder.imageAvatarView.setImageBitmap(Utils.bitmapFromView(viewHolder.textAvatarView))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val bitmap = BitmapFactory.decodeResource(ctx.resources, R.drawable.person_image)
|
val bitmap = BitmapFactory.decodeResource(ctx.resources, R.drawable.person_image)
|
||||||
@@ -80,6 +78,8 @@ class CallListAdapter(private val ctx: Context, private val aor: String, private
|
|||||||
viewHolder.directionsView.addView(dirView)
|
viewHolder.directionsView.addView(dirView)
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
if (count <= 3)
|
||||||
|
viewHolder.etcView.text = ""
|
||||||
|
|
||||||
val contactName = ContactsActivity.contactName(callRow.peerUri)
|
val contactName = ContactsActivity.contactName(callRow.peerUri)
|
||||||
if (contactName.startsWith("sip:"))
|
if (contactName.startsWith("sip:"))
|
||||||
@@ -102,12 +102,4 @@ class CallListAdapter(private val ctx: Context, private val aor: String, private
|
|||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBitmapFromView(view: View): Bitmap? {
|
|
||||||
val bitmap = Bitmap.createBitmap(view.layoutParams.width, view.layoutParams.height, Bitmap.Config.ARGB_8888)
|
|
||||||
val canvas = Canvas(bitmap)
|
|
||||||
view.layout(0, 0, view.layoutParams.width, view.layoutParams.height)
|
|
||||||
view.draw(canvas)
|
|
||||||
return bitmap
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.cardview.widget.CardView
|
|
||||||
import android.text.format.DateUtils.isToday
|
import android.text.format.DateUtils.isToday
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -20,8 +20,7 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList<Mess
|
|||||||
|
|
||||||
private class ViewHolder(view: View?) {
|
private class ViewHolder(view: View?) {
|
||||||
val textAvatarView = view?.findViewById(R.id.TextAvatar) as TextView
|
val textAvatarView = view?.findViewById(R.id.TextAvatar) as TextView
|
||||||
val cardAvatarView = view?.findViewById(R.id.CardAvatar) as CardView
|
val imageAvatarView = view?.findViewById(R.id.ImageAvatar) as ImageView
|
||||||
val cardImageAvatarView = view?.findViewById(R.id.ImageAvatar) as ImageView
|
|
||||||
val layoutView = view?.findViewById(R.id.chat) as LinearLayout
|
val layoutView = view?.findViewById(R.id.chat) as LinearLayout
|
||||||
val peerView = view?.findViewById(R.id.peer) as TextView
|
val peerView = view?.findViewById(R.id.peer) as TextView
|
||||||
val infoView = view?.findViewById(R.id.info) as TextView
|
val infoView = view?.findViewById(R.id.info) as TextView
|
||||||
@@ -50,20 +49,19 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList<Mess
|
|||||||
peer = contact.name
|
peer = contact.name
|
||||||
val avatarImage = contact.avatarImage
|
val avatarImage = contact.avatarImage
|
||||||
if (avatarImage != null) {
|
if (avatarImage != null) {
|
||||||
viewHolder.textAvatarView.visibility = View.GONE
|
viewHolder.imageAvatarView.setImageBitmap(avatarImage)
|
||||||
viewHolder.cardAvatarView.visibility = View.VISIBLE
|
|
||||||
viewHolder.cardImageAvatarView.setImageBitmap(avatarImage)
|
|
||||||
} else {
|
} else {
|
||||||
viewHolder.textAvatarView.visibility = View.VISIBLE
|
|
||||||
viewHolder.cardAvatarView.visibility = View.GONE
|
|
||||||
viewHolder.textAvatarView.background.setTint(contact.color)
|
viewHolder.textAvatarView.background.setTint(contact.color)
|
||||||
|
if (peer.isNotEmpty())
|
||||||
viewHolder.textAvatarView.text = "${peer[0]}"
|
viewHolder.textAvatarView.text = "${peer[0]}"
|
||||||
|
else
|
||||||
|
viewHolder.textAvatarView.text = ""
|
||||||
|
viewHolder.imageAvatarView.setImageBitmap(Utils.bitmapFromView(viewHolder.textAvatarView))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
peer = Utils.friendlyUri(message.peerUri, message.aor)
|
peer = Utils.friendlyUri(message.peerUri, message.aor)
|
||||||
viewHolder.textAvatarView.visibility = View.VISIBLE
|
val bitmap = BitmapFactory.decodeResource(ctx.resources, R.drawable.person_image)
|
||||||
viewHolder.cardAvatarView.visibility = View.GONE
|
viewHolder.imageAvatarView.setImageBitmap(bitmap)
|
||||||
viewHolder.textAvatarView.setBackgroundResource(R.drawable.person_image)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message.direction == R.drawable.arrow_down_green) ||
|
if ((message.direction == R.drawable.arrow_down_green) ||
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.cardview.widget.CardView
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@@ -31,7 +30,6 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
|
|
||||||
private class ViewHolder(view: View?) {
|
private class ViewHolder(view: View?) {
|
||||||
val textAvatarView = view?.findViewById(R.id.TextAvatar) as TextView
|
val textAvatarView = view?.findViewById(R.id.TextAvatar) as TextView
|
||||||
val cardAvatarView = view?.findViewById(R.id.CardAvatar) as CardView
|
|
||||||
val imageAvatarView = view?.findViewById(R.id.ImageAvatar) as ImageView
|
val imageAvatarView = view?.findViewById(R.id.ImageAvatar) as ImageView
|
||||||
val nameView = view?.findViewById(R.id.contactName) as TextView
|
val nameView = view?.findViewById(R.id.contactName) as TextView
|
||||||
val actionView = view?.findViewById(R.id.edit) as ImageButton
|
val actionView = view?.findViewById(R.id.edit) as ImageButton
|
||||||
@@ -55,19 +53,14 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
|
|
||||||
val avatarImage = contact.avatarImage
|
val avatarImage = contact.avatarImage
|
||||||
if (avatarImage != null) {
|
if (avatarImage != null) {
|
||||||
viewHolder.textAvatarView.visibility = View.GONE
|
|
||||||
viewHolder.cardAvatarView.visibility = View.VISIBLE
|
|
||||||
viewHolder.imageAvatarView.visibility = View.VISIBLE
|
|
||||||
viewHolder.imageAvatarView.setImageBitmap(avatarImage)
|
viewHolder.imageAvatarView.setImageBitmap(avatarImage)
|
||||||
} else {
|
} else {
|
||||||
viewHolder.textAvatarView.visibility = View.VISIBLE
|
|
||||||
viewHolder.cardAvatarView.visibility = View.GONE
|
|
||||||
viewHolder.imageAvatarView.visibility = View.GONE
|
|
||||||
viewHolder.textAvatarView.background.setTint(contact.color)
|
viewHolder.textAvatarView.background.setTint(contact.color)
|
||||||
if (contact.name.isNotEmpty())
|
if (contact.name.isNotEmpty())
|
||||||
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
||||||
else
|
else
|
||||||
viewHolder.textAvatarView.text = ""
|
viewHolder.textAvatarView.text = ""
|
||||||
|
viewHolder.imageAvatarView.setImageBitmap(Utils.bitmapFromView(viewHolder.textAvatarView))
|
||||||
}
|
}
|
||||||
|
|
||||||
viewHolder.nameView.text = contact.name
|
viewHolder.nameView.text = contact.name
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.Intent
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Bitmap.createScaledBitmap
|
import android.graphics.Bitmap.createScaledBitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.*
|
import android.net.*
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
@@ -711,4 +712,13 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun bitmapFromView(view: View): Bitmap? {
|
||||||
|
val bitmap = Bitmap.createBitmap(view.layoutParams.width, view.layoutParams.height, Bitmap.Config.ARGB_8888)
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
view.layout(0, 0, view.layoutParams.width, view.layoutParams.height)
|
||||||
|
view.draw(canvas)
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
android:text="" />
|
android:text="" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="5dp"
|
||||||
android:paddingStart="0dp"
|
android:paddingStart="0dp"
|
||||||
android:paddingEnd="5dp"
|
android:paddingEnd="6dp"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:lines="2"
|
android:lines="2"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:gravity="center" >
|
android:gravity="center"
|
||||||
|
android:visibility="gone" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:gravity="center" >
|
android:gravity="center"
|
||||||
|
android:visibility="gone" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
|
|||||||
Reference in New Issue
Block a user