- More work on avatars.
This commit is contained in:
@ -2,6 +2,8 @@ package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.CardView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -19,18 +21,27 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList<Call
|
||||
val callRow = rows[position]
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val rowView = inflater.inflate(R.layout.call_row, parent, false)
|
||||
val avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
val avatarBackground = avatarView.background as GradientDrawable
|
||||
val textAvatarView = rowView.findViewById(R.id.TextAvatar) as TextView
|
||||
val cardAvatarView = rowView.findViewById(R.id.CardAvatar) as CardView
|
||||
val cardImageAvatarView = rowView.findViewById(R.id.CardImageAvatar) as ImageView
|
||||
val contact = ContactsActivity.findContact(callRow.peerUri)
|
||||
val peer: String
|
||||
if (contact != null) {
|
||||
peer = contact.name
|
||||
avatarBackground.setColor(contact.color)
|
||||
val avatarImage = contact.avatarImage
|
||||
if (avatarImage != null) {
|
||||
textAvatarView.visibility = View.GONE
|
||||
cardAvatarView.visibility = View.VISIBLE
|
||||
cardImageAvatarView.setImageBitmap(avatarImage)
|
||||
} else {
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||
textAvatarView.text = "${contact.name[0]}"
|
||||
}
|
||||
} else {
|
||||
peer = Utils.friendlyUri(callRow.peerUri, callRow.aor)
|
||||
avatarBackground.setColor(Utils.randomColor())
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
textAvatarView.setBackgroundResource(R.drawable.person_image)
|
||||
}
|
||||
avatarView.text = "${peer[0]}"
|
||||
val directions = rowView.findViewById(R.id.directions) as LinearLayout
|
||||
var count = 1
|
||||
for (d in callRow.directions) {
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.CardView
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.*
|
||||
|
||||
import java.util.*
|
||||
import java.text.DateFormat
|
||||
@ -24,21 +21,31 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
|
||||
val message = rows[position]
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val rowView = inflater.inflate(R.layout.chat_row, parent, false)
|
||||
val avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
val avatarBackground = avatarView.background as GradientDrawable
|
||||
val textAvatarView = rowView.findViewById(R.id.TextAvatar) as TextView
|
||||
val cardAvatarView = rowView.findViewById(R.id.CardAvatar) as CardView
|
||||
val cardImageAvatarView = rowView.findViewById(R.id.ImageAvatar) as ImageView
|
||||
val layout = rowView.findViewById(R.id.chat) as LinearLayout
|
||||
val lp = layout.layoutParams as RelativeLayout.LayoutParams
|
||||
lp.setMargins(10, 10, 10, 10)
|
||||
val peer: String
|
||||
val contact = ContactsActivity.findContact(message.peerUri)
|
||||
val peer: String
|
||||
if (contact != null) {
|
||||
peer = contact.name
|
||||
avatarBackground.setColor(contact.color)
|
||||
val avatarImage = contact.avatarImage
|
||||
if (avatarImage != null) {
|
||||
textAvatarView.visibility = View.GONE
|
||||
cardAvatarView.visibility = View.VISIBLE
|
||||
cardImageAvatarView.setImageBitmap(avatarImage)
|
||||
} else {
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||
textAvatarView.text = "${peer[0]}"
|
||||
}
|
||||
} else {
|
||||
peer = Utils.friendlyUri(message.peerUri, message.aor)
|
||||
avatarBackground.setColor(Utils.randomColor())
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
textAvatarView.setBackgroundResource(R.drawable.person_image)
|
||||
}
|
||||
avatarView.text = "${peer[0]}"
|
||||
if (message.direction == R.drawable.arrow_down_green) {
|
||||
layout.setBackgroundResource(R.drawable.message_in_bg)
|
||||
} else {
|
||||
|
||||
@ -22,7 +22,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
|
||||
lateinit var textAvatarView: TextView
|
||||
lateinit var cardAvatarView: CardView
|
||||
lateinit var imageAvatarView: ImageView
|
||||
lateinit var cardImageAvatarView: ImageView
|
||||
lateinit var nameView: EditText
|
||||
lateinit var uriView: EditText
|
||||
|
||||
@ -38,9 +38,9 @@ class ContactActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_contact)
|
||||
|
||||
textAvatarView = findViewById(R.id.Avatar) as TextView
|
||||
textAvatarView = findViewById(R.id.TextAvatar) as TextView
|
||||
cardAvatarView = findViewById(R.id.CardAvatar) as CardView
|
||||
imageAvatarView = findViewById(R.id.ImageAvatar) as ImageView
|
||||
cardImageAvatarView = findViewById(R.id.ImageAvatar) as ImageView
|
||||
nameView = findViewById(R.id.Name) as EditText
|
||||
uriView = findViewById(R.id.Uri) as EditText
|
||||
|
||||
@ -82,42 +82,38 @@ class ContactActivity : AppCompatActivity() {
|
||||
|
||||
textAvatarView.setOnClickListener { _ ->
|
||||
|
||||
color = Utils.randomColor()
|
||||
showTextAvatar(textAvatarView.text.toString(), color)
|
||||
newAvatar = "text"
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
}
|
||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
||||
|
||||
}
|
||||
|
||||
textAvatarView.setOnLongClickListener { _ ->
|
||||
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
}
|
||||
|
||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
||||
|
||||
color = Utils.randomColor()
|
||||
showTextAvatar(textAvatarView.text.toString(), color)
|
||||
newAvatar = "text"
|
||||
true
|
||||
|
||||
}
|
||||
|
||||
cardAvatarView.setOnClickListener { _ ->
|
||||
|
||||
color = Utils.randomColor()
|
||||
showTextAvatar(nameView.text.toString(), color)
|
||||
newAvatar = "text"
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
}
|
||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
||||
|
||||
}
|
||||
|
||||
cardAvatarView.setOnLongClickListener { _ ->
|
||||
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
}
|
||||
|
||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
||||
|
||||
color = Utils.randomColor()
|
||||
showTextAvatar(nameView.text.toString(), color)
|
||||
newAvatar = "text"
|
||||
true
|
||||
|
||||
}
|
||||
@ -225,7 +221,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
"image" -> {
|
||||
contact.avatarImage = (imageAvatarView.drawable as BitmapDrawable).bitmap
|
||||
contact.avatarImage = (cardImageAvatarView.drawable as BitmapDrawable).bitmap
|
||||
Utils.deleteFile(File(BaresipService.filesPath, "${contact.id}.png"))
|
||||
File(BaresipService.filesPath, "tmp.png")
|
||||
.renameTo(File(BaresipService.filesPath, "${contact.id}.png"))
|
||||
@ -264,18 +260,13 @@ class ContactActivity : AppCompatActivity() {
|
||||
private fun showTextAvatar(name: String, color: Int) {
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
imageAvatarView.visibility = View.GONE
|
||||
(textAvatarView.background as GradientDrawable).setColor(color)
|
||||
if (name.isNotEmpty())
|
||||
textAvatarView.text = "${name[0]}"
|
||||
else
|
||||
textAvatarView.text = ""
|
||||
textAvatarView.text = "${name[0]}"
|
||||
}
|
||||
|
||||
private fun showImageAvatar(image: Bitmap) {
|
||||
textAvatarView.visibility = View.GONE
|
||||
cardAvatarView.visibility = View.VISIBLE
|
||||
imageAvatarView.visibility = View.VISIBLE
|
||||
imageAvatarView.setImageBitmap(image)
|
||||
cardImageAvatarView.setImageBitmap(image)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,16 +7,17 @@ import android.content.Intent
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.CardView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
import java.util.*
|
||||
|
||||
class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<Contact>,
|
||||
@ -24,16 +25,30 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
ArrayAdapter<Contact>(cxt, R.layout.contact_row, rows) {
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val row = rows[position]
|
||||
val contact = rows[position]
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
||||
val avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
val background = avatarView.background as GradientDrawable
|
||||
background.setColor(row.color)
|
||||
if (row.name.length > 0)
|
||||
avatarView.text = "${row.name[0]}"
|
||||
val textAvatarView = rowView.findViewById(R.id.TextAvatar) as TextView
|
||||
val cardAvatarView = rowView.findViewById(R.id.CardAvatar) as CardView
|
||||
val imageAvatarView = rowView.findViewById(R.id.ImageAvatar) as ImageView
|
||||
val avatarImage = contact.avatarImage
|
||||
if (avatarImage != null) {
|
||||
textAvatarView.visibility = View.GONE
|
||||
cardAvatarView.visibility = View.VISIBLE
|
||||
imageAvatarView.visibility = View.VISIBLE
|
||||
imageAvatarView.setImageBitmap(avatarImage)
|
||||
} else {
|
||||
textAvatarView.visibility = View.VISIBLE
|
||||
cardAvatarView.visibility = View.GONE
|
||||
imageAvatarView.visibility = View.GONE
|
||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||
if (contact.name.isNotEmpty())
|
||||
textAvatarView.text = "${contact.name[0]}"
|
||||
else
|
||||
textAvatarView.text = ""
|
||||
}
|
||||
val nameView = rowView.findViewById(R.id.contactName) as TextView
|
||||
nameView.text = row.name
|
||||
nameView.text = contact.name
|
||||
nameView.textSize = 20f
|
||||
nameView.setPadding(6, 6, 0, 6)
|
||||
if (aor != "") {
|
||||
@ -75,7 +90,6 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
val contact = Contact.contacts()[position]
|
||||
val id = contact.id
|
||||
val avatarFile = File(BaresipService.filesPath, "$id.img")
|
||||
if (avatarFile.exists()) {
|
||||
|
||||
BIN
app/src/main/person-web.png
Normal file
BIN
app/src/main/person-web.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
app/src/main/res/drawable/person_image.png
Normal file
BIN
app/src/main/res/drawable/person_image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@ -13,6 +13,7 @@
|
||||
android:id="@+id/account"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center_horizontal" >
|
||||
</TextView>
|
||||
|
||||
|
||||
@ -11,14 +11,13 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Avatar"
|
||||
android:id="@+id/TextAvatar"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="96dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/circle"
|
||||
android:textSize="72sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:gravity="center" >
|
||||
@ -34,7 +33,7 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ImageAvatar"
|
||||
android:layout_height="90dp"
|
||||
android:layout_height="96dp"
|
||||
android:layout_width="96dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop" >
|
||||
|
||||
@ -1,34 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/historyRow"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:descendantFocusability="blocksDescendants" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/avatar"
|
||||
android:id="@+id/TextAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/circle"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:gravity="center" >
|
||||
</TextView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/CardAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:elevation="12dp"
|
||||
app:cardCornerRadius="18dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/CardImageAvatar"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="36dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageView>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/directions"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginStart="41dp"
|
||||
android:layout_centerVertical="true" >
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -1,30 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/chats_row"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/avatar"
|
||||
android:id="@+id/TextAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginTop="10dp"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/circle"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:gravity="center" >
|
||||
</TextView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/CardAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:elevation="12dp"
|
||||
app:cardCornerRadius="18dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ImageAvatar"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="36dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageView>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/chat"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/avatar" >
|
||||
android:layout_marginStart="42dp" >
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
|
||||
@ -1,31 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/contactRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/avatar"
|
||||
android:id="@+id/TextAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/circle"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:gravity="center" >
|
||||
</TextView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/CardAvatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:elevation="12dp"
|
||||
app:cardCornerRadius="18dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ImageAvatar"
|
||||
android:layout_height="36dp"
|
||||
android:layout_width="36dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageView>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contactName"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginStart="41dp"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginBottom="6dp">
|
||||
</TextView>
|
||||
|
||||
@ -10,4 +10,5 @@
|
||||
<color name="colorGrayLight">#e0e0e0</color>
|
||||
<color name="colorAccent">#b00020</color>
|
||||
<color name="colorBaresip">#0ca1fd</color>
|
||||
<color name="colorWhite">#ffffff</color>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user