mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add color in entry edit
This commit is contained in:
@@ -46,6 +46,8 @@ abstract class TemplateAbstractView<
|
|||||||
|
|
||||||
protected var headerContainerView: ViewGroup
|
protected var headerContainerView: ViewGroup
|
||||||
protected var entryIconView: ImageView
|
protected var entryIconView: ImageView
|
||||||
|
protected var backgroundColorView: View
|
||||||
|
protected var foregroundColorView: View
|
||||||
protected var backgroundColorButton: ImageView
|
protected var backgroundColorButton: ImageView
|
||||||
protected var foregroundColorButton: ImageView
|
protected var foregroundColorButton: ImageView
|
||||||
private var titleContainerView: ViewGroup
|
private var titleContainerView: ViewGroup
|
||||||
@@ -59,6 +61,8 @@ abstract class TemplateAbstractView<
|
|||||||
|
|
||||||
headerContainerView = findViewById(R.id.template_header_container)
|
headerContainerView = findViewById(R.id.template_header_container)
|
||||||
entryIconView = findViewById(R.id.template_icon_button)
|
entryIconView = findViewById(R.id.template_icon_button)
|
||||||
|
backgroundColorView = findViewById(R.id.template_background_color)
|
||||||
|
foregroundColorView = findViewById(R.id.template_foreground_color)
|
||||||
backgroundColorButton = findViewById(R.id.template_background_color_button)
|
backgroundColorButton = findViewById(R.id.template_background_color_button)
|
||||||
foregroundColorButton = findViewById(R.id.template_foreground_color_button)
|
foregroundColorButton = findViewById(R.id.template_foreground_color_button)
|
||||||
titleContainerView = findViewById(R.id.template_title_container)
|
titleContainerView = findViewById(R.id.template_title_container)
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
package com.kunzisoft.keepass.view
|
package com.kunzisoft.keepass.view
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.PorterDuff
|
|
||||||
import android.graphics.PorterDuffColorFilter
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
|
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||||
|
import androidx.core.graphics.BlendModeCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.kunzisoft.keepass.R
|
import com.kunzisoft.keepass.R
|
||||||
import com.kunzisoft.keepass.database.element.DateInstant
|
import com.kunzisoft.keepass.database.element.DateInstant
|
||||||
import com.kunzisoft.keepass.database.element.Field
|
import com.kunzisoft.keepass.database.element.Field
|
||||||
import com.kunzisoft.keepass.database.element.icon.IconImage
|
import com.kunzisoft.keepass.database.element.icon.IconImage
|
||||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||||
import com.kunzisoft.keepass.database.element.template.*
|
import com.kunzisoft.keepass.database.element.template.TemplateAttribute
|
||||||
|
import com.kunzisoft.keepass.database.element.template.TemplateAttributeAction
|
||||||
|
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
|||||||
|
|
||||||
fun setIcon(iconImage: IconImage) {
|
fun setIcon(iconImage: IconImage) {
|
||||||
mEntryInfo?.icon = iconImage
|
mEntryInfo?.icon = iconImage
|
||||||
populateIconMethod?.invoke(entryIconView, iconImage)
|
refreshIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnBackgroundColorClickListener(onClickListener: OnClickListener) {
|
fun setOnBackgroundColorClickListener(onClickListener: OnClickListener) {
|
||||||
@@ -65,12 +67,20 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setBackgroundColor(color: Int?) {
|
fun setBackgroundColor(color: Int?) {
|
||||||
color?.let {
|
applyBackgroundColor(color)
|
||||||
backgroundColorButton.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
|
||||||
}
|
|
||||||
mEntryInfo?.backgroundColor = color
|
mEntryInfo?.backgroundColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun applyBackgroundColor(color: Int?) {
|
||||||
|
if (color != null) {
|
||||||
|
backgroundColorView.background.colorFilter = BlendModeColorFilterCompat
|
||||||
|
.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_ATOP)
|
||||||
|
backgroundColorView.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
backgroundColorView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setOnForegroundColorClickListener(onClickListener: OnClickListener) {
|
fun setOnForegroundColorClickListener(onClickListener: OnClickListener) {
|
||||||
foregroundColorButton.setOnClickListener(onClickListener)
|
foregroundColorButton.setOnClickListener(onClickListener)
|
||||||
}
|
}
|
||||||
@@ -80,12 +90,20 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setForegroundColor(color: Int?) {
|
fun setForegroundColor(color: Int?) {
|
||||||
color?.let {
|
applyForegroundColor(color)
|
||||||
foregroundColorButton.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
|
||||||
}
|
|
||||||
mEntryInfo?.foregroundColor = color
|
mEntryInfo?.foregroundColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun applyForegroundColor(color: Int?) {
|
||||||
|
if (color != null) {
|
||||||
|
foregroundColorView.background.colorFilter = BlendModeColorFilterCompat
|
||||||
|
.createBlendModeColorFilterCompat(color, BlendModeCompat.SRC_ATOP)
|
||||||
|
foregroundColorView.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
foregroundColorView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun preProcessTemplate() {
|
override fun preProcessTemplate() {
|
||||||
headerContainerView.isVisible = true
|
headerContainerView.isVisible = true
|
||||||
}
|
}
|
||||||
@@ -228,12 +246,8 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
|
|||||||
|
|
||||||
override fun populateViewsWithEntryInfo(showEmptyFields: Boolean): List<ViewField> {
|
override fun populateViewsWithEntryInfo(showEmptyFields: Boolean): List<ViewField> {
|
||||||
refreshIcon()
|
refreshIcon()
|
||||||
mEntryInfo?.backgroundColor?.let {
|
applyBackgroundColor(mEntryInfo?.backgroundColor)
|
||||||
backgroundColorButton.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
applyForegroundColor(mEntryInfo?.foregroundColor)
|
||||||
}
|
|
||||||
mEntryInfo?.foregroundColor?.let {
|
|
||||||
foregroundColorButton.colorFilter = PorterDuffColorFilter(it, PorterDuff.Mode.SRC_ATOP)
|
|
||||||
}
|
|
||||||
return super.populateViewsWithEntryInfo(showEmptyFields)
|
return super.populateViewsWithEntryInfo(showEmptyFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,28 +30,44 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="?attr/cardViewStyle">
|
style="?attr/cardViewStyle">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ImageView
|
<View
|
||||||
android:id="@+id/template_foreground_color_button"
|
android:id="@+id/template_background_color"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="36dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="36dp"
|
||||||
android:layout_margin="12dp"
|
android:layout_margin="9dp"
|
||||||
android:layout_gravity="top|start"
|
android:layout_gravity="top|end"
|
||||||
android:src="@drawable/ic_color_foreground_white_24dp"
|
android:background="@drawable/background_rounded_square" />
|
||||||
android:contentDescription="@string/content_description_entry_background_color"
|
<View
|
||||||
style="@style/KeepassDXStyle.ImageButton.Simple.Mini" />
|
android:id="@+id/template_foreground_color"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_margin="32dp"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:background="@drawable/background_rounded_square" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/template_background_color_button"
|
android:id="@+id/template_background_color_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="12dp"
|
|
||||||
android:layout_gravity="top|end"
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="3dp"
|
||||||
android:src="@drawable/ic_color_background_white_24dp"
|
android:src="@drawable/ic_color_background_white_24dp"
|
||||||
android:contentDescription="@string/content_description_entry_background_color"
|
android:contentDescription="@string/content_description_entry_background_color"
|
||||||
style="@style/KeepassDXStyle.ImageButton.Simple.Mini" />
|
style="@style/KeepassDXStyle.ImageButton.Simple.Mini" />
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/template_foreground_color_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="25dp"
|
||||||
|
android:src="@drawable/ic_color_foreground_white_24dp"
|
||||||
|
android:contentDescription="@string/content_description_entry_background_color"
|
||||||
|
style="@style/KeepassDXStyle.ImageButton.Simple.Mini" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@@ -65,8 +81,9 @@
|
|||||||
android:id="@+id/template_icon_button"
|
android:id="@+id/template_icon_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:elevation="8dp"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
android:src="@drawable/ic_blank_32dp"
|
android:src="@drawable/ic_blank_32dp"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:contentDescription="@string/content_description_entry_icon"/>
|
android:contentDescription="@string/content_description_entry_icon"/>
|
||||||
|
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
|
|||||||
Reference in New Issue
Block a user