show a nicer placeholder for contacts without image
This commit is contained in:
parent
0efae2f760
commit
75b54e1d18
|
@ -1,11 +1,14 @@
|
||||||
package com.simplemobiletools.contacts.pro.activities
|
package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Paint
|
||||||
import android.graphics.drawable.BitmapDrawable
|
import android.graphics.drawable.BitmapDrawable
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.provider.ContactsContract.CommonDataKinds.*
|
import android.provider.ContactsContract.CommonDataKinds.*
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.DataSource
|
import com.bumptech.glide.load.DataSource
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
@ -16,7 +19,10 @@ import com.bumptech.glide.request.RequestOptions
|
||||||
import com.bumptech.glide.request.target.Target
|
import com.bumptech.glide.request.target.Target
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
import com.simplemobiletools.commons.extensions.getContrastColor
|
||||||
|
import com.simplemobiletools.commons.extensions.getNameLetter
|
||||||
|
import com.simplemobiletools.commons.extensions.realScreenSize
|
||||||
|
import com.simplemobiletools.commons.helpers.letterBackgroundColors
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
import com.simplemobiletools.contacts.pro.extensions.sendEmailIntent
|
import com.simplemobiletools.contacts.pro.extensions.sendEmailIntent
|
||||||
|
@ -31,7 +37,7 @@ abstract class ContactActivity : SimpleActivity() {
|
||||||
protected var currentContactPhotoPath = ""
|
protected var currentContactPhotoPath = ""
|
||||||
|
|
||||||
fun showPhotoPlaceholder(photoView: ImageView) {
|
fun showPhotoPlaceholder(photoView: ImageView) {
|
||||||
val placeholder = BitmapDrawable(resources, SimpleContactsHelper(this).getContactLetterIcon(contact?.getNameToDisplay() ?: "A"))
|
val placeholder = BitmapDrawable(resources, getBigLetterPlaceholder(contact?.getNameToDisplay() ?: "A"))
|
||||||
photoView.setImageDrawable(placeholder)
|
photoView.setImageDrawable(placeholder)
|
||||||
currentContactPhotoPath = ""
|
currentContactPhotoPath = ""
|
||||||
contact?.photo = null
|
contact?.photo = null
|
||||||
|
@ -158,4 +164,35 @@ abstract class ContactActivity : SimpleActivity() {
|
||||||
Event.TYPE_BIRTHDAY -> R.string.birthday
|
Event.TYPE_BIRTHDAY -> R.string.birthday
|
||||||
else -> R.string.other
|
else -> R.string.other
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getBigLetterPlaceholder(name: String): Bitmap {
|
||||||
|
val letter = name.getNameLetter()
|
||||||
|
val height = resources.getDimension(R.dimen.top_contact_image_height).toInt()
|
||||||
|
val bitmap = Bitmap.createBitmap(realScreenSize.x, height, Bitmap.Config.ARGB_8888)
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
val view = TextView(this)
|
||||||
|
view.layout(0, 0, bitmap.width, bitmap.height)
|
||||||
|
|
||||||
|
val circlePaint = Paint().apply {
|
||||||
|
color = letterBackgroundColors[Math.abs(name.hashCode()) % letterBackgroundColors.size].toInt()
|
||||||
|
isAntiAlias = true
|
||||||
|
style = Paint.Style.FILL
|
||||||
|
}
|
||||||
|
|
||||||
|
val wantedTextSize = bitmap.height / 2f
|
||||||
|
val textPaint = Paint().apply {
|
||||||
|
color = circlePaint.color.getContrastColor()
|
||||||
|
isAntiAlias = true
|
||||||
|
textAlign = Paint.Align.CENTER
|
||||||
|
textSize = wantedTextSize
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.drawPaint(circlePaint)
|
||||||
|
|
||||||
|
val xPos = canvas.width / 2f
|
||||||
|
val yPos = canvas.height / 2 - (textPaint.descent() + textPaint.ascent()) / 2
|
||||||
|
canvas.drawText(letter, xPos, yPos, textPaint)
|
||||||
|
view.draw(canvas)
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,6 @@ class ViewContactActivity : ContactActivity() {
|
||||||
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
contact_photo.background = ColorDrawable(0)
|
contact_photo.background = ColorDrawable(0)
|
||||||
contact_photo_bottom_shadow.beVisible()
|
contact_photo_bottom_shadow.beVisible()
|
||||||
contact_photo_divider.beInvisible()
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/contact_scrollview"
|
android:id="@+id/contact_scrollview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
android:id="@+id/contact_scrollview"
|
android:id="@+id/contact_scrollview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
android:id="@+id/contact_photo"
|
android:id="@+id/contact_photo"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/top_contact_image_height"
|
android:layout_height="@dimen/top_contact_image_height"
|
||||||
|
android:layout_marginBottom="@dimen/normal_margin"
|
||||||
android:src="@drawable/ic_person_vector" />
|
android:src="@drawable/ic_person_vector" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
@ -30,15 +32,6 @@
|
||||||
android:background="@drawable/gradient_background"
|
android:background="@drawable/gradient_background"
|
||||||
android:contentDescription="@null" />
|
android:contentDescription="@null" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/contact_photo_divider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1px"
|
|
||||||
android:layout_below="@+id/contact_photo"
|
|
||||||
android:layout_marginBottom="@dimen/normal_margin"
|
|
||||||
android:background="@color/divider_grey"
|
|
||||||
android:importantForAccessibility="no" />
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/contact_toggle_favorite"
|
android:id="@+id/contact_toggle_favorite"
|
||||||
android:layout_width="@dimen/contact_actions_size"
|
android:layout_width="@dimen/contact_actions_size"
|
||||||
|
@ -101,7 +94,7 @@
|
||||||
android:id="@+id/contact_name_image"
|
android:id="@+id/contact_name_image"
|
||||||
android:layout_width="@dimen/contact_icons_size"
|
android:layout_width="@dimen/contact_icons_size"
|
||||||
android:layout_height="@dimen/contact_icons_size"
|
android:layout_height="@dimen/contact_icons_size"
|
||||||
android:layout_below="@+id/contact_photo_divider"
|
android:layout_below="@+id/contact_photo"
|
||||||
android:layout_marginStart="@dimen/normal_margin"
|
android:layout_marginStart="@dimen/normal_margin"
|
||||||
android:paddingTop="@dimen/medium_margin"
|
android:paddingTop="@dimen/medium_margin"
|
||||||
android:paddingEnd="@dimen/small_margin"
|
android:paddingEnd="@dimen/small_margin"
|
||||||
|
@ -112,7 +105,7 @@
|
||||||
android:id="@+id/contact_prefix"
|
android:id="@+id/contact_prefix"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/contact_photo_divider"
|
android:layout_below="@+id/contact_photo"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_toEndOf="@+id/contact_name_image"
|
android:layout_toEndOf="@+id/contact_name_image"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
|
|
Loading…
Reference in New Issue