mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Colorize entry view
This commit is contained in:
@@ -36,6 +36,9 @@ import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.graphics.BlendModeColorFilterCompat
|
||||
import androidx.core.graphics.BlendModeCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
import com.kunzisoft.keepass.R
|
||||
@@ -99,9 +102,10 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
}
|
||||
|
||||
private var mIcon: IconImage? = null
|
||||
private var mIconColor: Int = 0
|
||||
private var mColorAccent: Int = 0
|
||||
private var mControlColor: Int = 0
|
||||
private var molorPrimary: Int = 0
|
||||
private var mColorPrimary: Int = 0
|
||||
private var mColorBackground: Int = 0
|
||||
private var mBackgroundColor: Int? = null
|
||||
private var mForegroundColor: Int? = null
|
||||
|
||||
@@ -129,16 +133,19 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
collapsingToolbarLayout?.title = " "
|
||||
toolbar?.title = " "
|
||||
|
||||
// Retrieve the textColor to tint the icon
|
||||
val taIconColor = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
|
||||
mIconColor = taIconColor.getColor(0, Color.BLACK)
|
||||
taIconColor.recycle()
|
||||
val taColorControl = theme.obtainStyledAttributes(intArrayOf(R.attr.colorControlNormal))
|
||||
mControlColor = taColorControl.getColor(0, Color.BLACK)
|
||||
taColorControl.recycle()
|
||||
// Retrieve the textColor to tint the toolbar
|
||||
val taColorAccent = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
|
||||
val taControlColor = theme.obtainStyledAttributes(intArrayOf(R.attr.toolbarColorControl))
|
||||
val taColorPrimary = theme.obtainStyledAttributes(intArrayOf(R.attr.colorPrimary))
|
||||
molorPrimary = taColorPrimary.getColor(0, Color.BLACK)
|
||||
val taColorBackground = theme.obtainStyledAttributes(intArrayOf(android.R.attr.windowBackground))
|
||||
mColorAccent = taColorAccent.getColor(0, Color.BLACK)
|
||||
mControlColor = taControlColor.getColor(0, Color.BLACK)
|
||||
mColorPrimary = taColorPrimary.getColor(0, Color.BLACK)
|
||||
mColorBackground = taColorBackground.getColor(0, Color.BLACK)
|
||||
taColorAccent.recycle()
|
||||
taControlColor.recycle()
|
||||
taColorPrimary.recycle()
|
||||
taColorBackground.recycle()
|
||||
|
||||
// Get Entry from UUID
|
||||
try {
|
||||
@@ -183,10 +190,8 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
// Assign history dedicated view
|
||||
historyView?.visibility = if (entryIsHistory) View.VISIBLE else View.GONE
|
||||
if (entryIsHistory) {
|
||||
val taColorAccent = theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
|
||||
collapsingToolbarLayout?.contentScrim =
|
||||
ColorDrawable(taColorAccent.getColor(0, Color.BLACK))
|
||||
taColorAccent.recycle()
|
||||
ColorDrawable(mColorAccent)
|
||||
}
|
||||
|
||||
val entryInfo = entryInfoHistory.entryInfo
|
||||
@@ -201,9 +206,6 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
}
|
||||
// Assign title icon
|
||||
mIcon = entryInfo.icon
|
||||
titleIconView?.let { iconView ->
|
||||
mIconDrawableFactory?.assignDatabaseIcon(iconView, entryInfo.icon, mIconColor)
|
||||
}
|
||||
// Assign title text
|
||||
val entryTitle =
|
||||
if (entryInfo.title.isNotEmpty()) entryInfo.title else UuidUtil.toHexString(entryInfo.id)
|
||||
@@ -272,13 +274,6 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
super.onDatabaseRetrieved(database)
|
||||
|
||||
mEntryViewModel.loadDatabase(database)
|
||||
|
||||
// Assign title icon
|
||||
mIcon?.let { icon ->
|
||||
titleIconView?.let { iconView ->
|
||||
mIconDrawableFactory?.assignDatabaseIcon(iconView, icon, mIconColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDatabaseActionFinished(
|
||||
@@ -325,8 +320,24 @@ class EntryActivity : DatabaseLockActivity() {
|
||||
}
|
||||
|
||||
private fun applyToolbarColors() {
|
||||
appBarLayout?.setBackgroundColor(mBackgroundColor ?: molorPrimary)
|
||||
collapsingToolbarLayout?.contentScrim = ColorDrawable(mBackgroundColor ?: molorPrimary)
|
||||
appBarLayout?.setBackgroundColor(mBackgroundColor ?: mColorPrimary)
|
||||
collapsingToolbarLayout?.contentScrim = ColorDrawable(mBackgroundColor ?: mColorPrimary)
|
||||
val backgroundDarker = if (mBackgroundColor != null) {
|
||||
ColorUtils.blendARGB(mBackgroundColor!!, Color.BLACK, 0.1f)
|
||||
} else {
|
||||
mColorBackground
|
||||
}
|
||||
titleIconView?.background?.colorFilter = BlendModeColorFilterCompat
|
||||
.createBlendModeColorFilterCompat(backgroundDarker, BlendModeCompat.SRC_IN)
|
||||
mIcon?.let { icon ->
|
||||
titleIconView?.let { iconView ->
|
||||
mIconDrawableFactory?.assignDatabaseIcon(
|
||||
iconView,
|
||||
icon,
|
||||
mForegroundColor ?: mColorAccent
|
||||
)
|
||||
}
|
||||
}
|
||||
toolbar?.changeControlColor(mForegroundColor ?: mControlColor)
|
||||
collapsingToolbarLayout?.changeTitleColor(mForegroundColor ?: mControlColor)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<attr name="cardBackgroundTransparentColor" format="reference|color" />
|
||||
<attr name="iconPreferenceColor" format="reference|color" />
|
||||
<attr name="textColorInverse" format="reference|color" />
|
||||
<attr name="toolbarColorControl" format="reference|color" />
|
||||
|
||||
<attr name="educationCircleColor" format="reference|color" />
|
||||
<attr name="educationTextColor" format="reference|color" />
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<dimen name="image_button_margin">8dp</dimen>
|
||||
<dimen name="image_list_margin_vertical">22dp</dimen>
|
||||
<dimen name="image_list_margin_horizontal">8dp</dimen>
|
||||
<dimen name="image_list_margin_vertical_back">15dp</dimen>
|
||||
<dimen name="image_preview_height">144dp</dimen>
|
||||
<dimen name="button_margin">6dp</dimen>
|
||||
<dimen name="card_view_margin_horizontal">10dp</dimen>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<item name="android:textColorPrimary">@color/cyan_lightest</item>
|
||||
<item name="android:textColorHintInverse">@color/cyan_lightest</item>
|
||||
<item name="android:windowBackground">@color/white_darkest</item>
|
||||
<item name="toolbarColorControl">@color/grey_light</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Clear</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Clear</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Clear</item>
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<item name="android:textColorPrimary">@color/green_light</item>
|
||||
<item name="android:textColorHintInverse">@color/green_light</item>
|
||||
<item name="android:windowBackground">@color/white</item>
|
||||
<item name="toolbarColorControl">@color/grey_light</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.White</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.White</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.White</item>
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
<item name="android:textColorPrimary">@color/purple_lighter</item>
|
||||
<item name="android:textColorHintInverse">@color/purple_lighter</item>
|
||||
<item name="android:windowBackground">@color/black_purple_dark</item>
|
||||
<item name="toolbarColorControl">@color/white</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Purple.Dark</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Purple.Dark</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Purple.Dark</item>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<item name="android:textColorPrimary">@color/blue_light</item>
|
||||
<item name="android:textColorHintInverse">@color/blue_lighter</item>
|
||||
<item name="android:windowBackground">@color/white_dark</item>
|
||||
<item name="toolbarColorControl">@color/white</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Blue</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Blue</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Blue</item>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<item name="android:textColorPrimary">@color/red</item>
|
||||
<item name="android:textColorHintInverse">@color/red_lighter</item>
|
||||
<item name="android:windowBackground">@color/white_dark</item>
|
||||
<item name="toolbarColorControl">@color/white</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Red</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Red</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Red</item>
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
|
||||
<!-- Toolbar -->
|
||||
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
|
||||
<item name="toolbarColorControl">@color/white</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Light</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Light</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Light</item>
|
||||
@@ -141,6 +142,7 @@
|
||||
|
||||
<!-- Toolbar -->
|
||||
<item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
|
||||
<item name="toolbarColorControl">@color/white</item>
|
||||
<item name="toolbarAppearance">@style/KeepassDXStyle.Toolbar.Night</item>
|
||||
<item name="toolbarHomeAppearance">@style/KeepassDXStyle.Toolbar.Home.Night</item>
|
||||
<item name="toolbarSpecialAppearance">@style/KeepassDXStyle.Toolbar.Special.Night</item>
|
||||
|
||||
Reference in New Issue
Block a user