support avatars shape customization
This commit is contained in:
parent
7ef0e53892
commit
21658d20d0
|
@ -64,7 +64,6 @@ dependencies {
|
|||
implementation 'de.measite.minidns:minidns-hla:0.2.4'
|
||||
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
|
||||
implementation 'org.whispersystems:signal-protocol-java:2.6.2'
|
||||
implementation 'com.makeramen:roundedimageview:2.3.0'
|
||||
implementation "com.wefika:flowlayout:0.4.1"
|
||||
//noinspection GradleDependency
|
||||
implementation('com.github.natario1:Transcoder:v0.9.1') {
|
||||
|
|
71
src/main/java/eu/siacs/conversations/ui/widget/AvatarView.kt
Normal file
71
src/main/java/eu/siacs/conversations/ui/widget/AvatarView.kt
Normal file
|
@ -0,0 +1,71 @@
|
|||
package eu.siacs.conversations.ui.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.graphics.Outline
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewOutlineProvider
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import eu.siacs.conversations.R
|
||||
|
||||
class AvatarView : AppCompatImageView {
|
||||
private var currentShape: String = ""
|
||||
|
||||
private val preferencesListener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ -> invalidateShape() }
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
invalidateShape()
|
||||
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(preferencesListener)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(preferencesListener)
|
||||
}
|
||||
|
||||
private fun invalidateShape() {
|
||||
val shape = PreferenceManager.getDefaultSharedPreferences(context).getString("avatar_shape", context.getString(R.string.avatar_shape))
|
||||
|
||||
if (shape == currentShape) {
|
||||
return
|
||||
}
|
||||
|
||||
when {
|
||||
shape == "oval" -> {
|
||||
clipToOutline = true
|
||||
outlineProvider = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
outline.setOval(0, 0, view.width, view.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
shape == "rounded_square" -> {
|
||||
clipToOutline = true
|
||||
outlineProvider = object : ViewOutlineProvider() {
|
||||
override fun getOutline(view: View, outline: Outline) {
|
||||
val maxRadius = minOf(view.width, view.height) / 2f
|
||||
val radius = minOf(context.resources.getDimension(R.dimen.avatar_corners_radius), maxRadius)
|
||||
outline.setRoundRect(0, 0, view.width, view.height, radius)
|
||||
}
|
||||
}
|
||||
}
|
||||
shape == "square" -> {
|
||||
clipToOutline = false
|
||||
outlineProvider = ViewOutlineProvider.BACKGROUND
|
||||
}
|
||||
}
|
||||
|
||||
currentShape = shape!!
|
||||
}
|
||||
}
|
|
@ -10,13 +10,12 @@
|
|||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/account_image"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:contentDescription="@string/account_image_description"
|
||||
app:riv_corner_radius="6dp" />
|
||||
android:contentDescription="@string/account_image_description" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -35,12 +35,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/card_padding_regular">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/details_contact_badge"
|
||||
android:layout_width="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_height="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_alignParentTop="true"
|
||||
app:riv_corner_radius="8dp"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -39,14 +39,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/card_padding_regular">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/avater"
|
||||
android:layout_width="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_height="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="@dimen/avatar_item_distance"
|
||||
android:contentDescription="@string/account_image_description"
|
||||
app:riv_corner_radius="8dp" />
|
||||
android:contentDescription="@string/account_image_description" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -40,11 +40,10 @@
|
|||
android:gravity="center_vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/muc_pm_counterpart_avatar"
|
||||
android:layout_width="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_height="@dimen/avatar_on_details_screen_size"
|
||||
app:riv_corner_radius="8dp"
|
||||
android:layout_marginEnd="@dimen/avatar_item_distance"/>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -97,12 +96,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="32dp">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/your_photo"
|
||||
android:layout_width="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_height="@dimen/avatar_on_details_screen_size"
|
||||
android:layout_alignParentStart="true"
|
||||
app:riv_corner_radius="8dp"
|
||||
android:layout_marginEnd="@dimen/avatar_item_distance"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginRight="@dimen/avatar_item_distance" />
|
||||
|
|
|
@ -8,13 +8,12 @@
|
|||
android:background="?selectableItemBackground"
|
||||
android:padding="@dimen/list_padding">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/contact_photo"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="6dp"/>
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -19,13 +19,12 @@
|
|||
android:orientation="horizontal"
|
||||
android:padding="8dp">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/conversation_image"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="8dp" />
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -43,6 +42,7 @@
|
|||
android:paddingRight="4dp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:textAppearance="@style/TextAppearance.Conversations.Subhead" />
|
||||
|
||||
<RelativeLayout
|
||||
|
|
|
@ -22,15 +22,14 @@
|
|||
android:alpha="0"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/message_photo"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:translationY="-2dp"
|
||||
android:scaleType="fitXY"
|
||||
app:riv_corner_radius="6dp" />
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/message_box"
|
||||
|
|
|
@ -22,15 +22,14 @@
|
|||
android:alpha="0"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/message_photo"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:translationY="-2dp"
|
||||
android:scaleType="fitXY"
|
||||
app:riv_corner_radius="6dp" />
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/message_box"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
android:text="@string/load_more_messages"
|
||||
android:textColor="?colorAccent"/>
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/message_photo"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
|
@ -27,8 +27,7 @@
|
|||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="-1.5dp"
|
||||
android:padding="0dp"
|
||||
android:scaleType="fitXY"
|
||||
app:riv_corner_radius="4dp"/>
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/status_message"
|
||||
|
|
|
@ -9,13 +9,12 @@
|
|||
android:background="?selectableItemBackground"
|
||||
android:padding="@dimen/list_padding">
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:scaleType="centerCrop"
|
||||
app:riv_corner_radius="6dp" />
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
android:layout_height="match_parent"
|
||||
android:padding="2dp"
|
||||
android:background="?selectableItemBackground">
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
<eu.siacs.conversations.ui.widget.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/black54"
|
||||
app:riv_corner_radius="6dp"
|
||||
android:scaleType="centerInside"/>
|
||||
</eu.siacs.conversations.ui.widget.SquareFrameLayout>
|
||||
</layout>
|
||||
|
|
|
@ -89,6 +89,18 @@
|
|||
<item>SEND_LOCATION</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="avatars_shape">
|
||||
<item>@string/avater_shape_rounded_square</item>
|
||||
<item>@string/avater_shape_oval</item>
|
||||
<item>@string/avater_shape_square</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="avatars_shape_values">
|
||||
<item>rounded_square</item>
|
||||
<item>oval</item>
|
||||
<item>square</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="picture_compression_values">
|
||||
<item>never</item>
|
||||
<item>auto</item>
|
||||
|
|
|
@ -54,4 +54,5 @@
|
|||
<string name="default_push_account">none</string>
|
||||
<bool name="always_full_timestamps">false</bool>
|
||||
<bool name="skip_image_editor_screen">false</bool>
|
||||
<string name="avatar_shape">rounded_square</string>
|
||||
</resources>
|
||||
|
|
|
@ -78,4 +78,6 @@
|
|||
<dimen name="activity_margin">16dp</dimen>
|
||||
|
||||
<dimen name="colorpicker_hue_width">30dp</dimen>
|
||||
|
||||
<dimen name="avatar_corners_radius">8dp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -599,6 +599,8 @@
|
|||
<string name="pref_theme_dark">Dark</string>
|
||||
<string name="pref_show_navigation_bar">Show navigation bar</string>
|
||||
<string name="pref_show_navigation_bar_summary">Use alternative navigation way via navigation bar on the bottom of the screen</string>
|
||||
<string name="pref_avatars_shape">Avatars shape</string>
|
||||
<string name="pref_avatar_shape_summary">Allows you to select avatars shape globally</string>
|
||||
<string name="pref_use_green_background">Green Background</string>
|
||||
<string name="pref_use_green_background_summary">Use green background for received messages</string>
|
||||
<string name="pref_always_show_full_timestamps">Show full timestamps</string>
|
||||
|
@ -1099,4 +1101,7 @@
|
|||
<string name="delete_background_failed">Couldn\'t remove background image</string>
|
||||
<string name="delete_background_success">Background image removed</string>
|
||||
<string name="no_background_set">No custom background set</string>
|
||||
<string name="avater_shape_oval">Oval</string>
|
||||
<string name="avater_shape_rounded_square">Rounded Square</string>
|
||||
<string name="avater_shape_square">Square</string>
|
||||
</resources>
|
||||
|
|
|
@ -183,6 +183,13 @@
|
|||
android:key="show_nav_bar"
|
||||
android:summary="@string/pref_show_navigation_bar_summary"
|
||||
android:title="@string/pref_show_navigation_bar" />
|
||||
<ListPreference
|
||||
android:defaultValue="@string/avatar_shape"
|
||||
android:key="avatar_shape"
|
||||
android:entries="@array/avatars_shape"
|
||||
android:entryValues="@array/avatars_shape_values"
|
||||
android:summary="@string/pref_avatar_shape_summary"
|
||||
android:title="@string/pref_avatars_shape" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="@bool/use_green_background"
|
||||
android:key="use_green_background"
|
||||
|
|
Loading…
Reference in a new issue