diff options
author | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-09-17 20:12:43 +0200 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart-ext@mousquetaires.com> | 2022-09-20 09:04:47 +0200 |
commit | f44d0f7c4a6db30e4bd29c07c56f2998c7874b51 (patch) | |
tree | e3dda2fc8b13063f423249fa44a19fedcd4f548d /app/src/main/java/foundation/e/privacycentralapp/common | |
parent | 837e4ffac7d9d2c26e474e3c69847fac43e5d577 (diff) | |
download | advanced-privacy-f44d0f7c4a6db30e4bd29c07c56f2998c7874b51.tar.gz |
256 : Add tooltip info about apps lists.
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/common')
-rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt new file mode 100644 index 0000000..a5c576c --- /dev/null +++ b/app/src/main/java/foundation/e/privacycentralapp/common/TextViewHelpers.kt @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package foundation.e.privacycentralapp.common + +import android.content.Context +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ImageSpan +import android.widget.TextView +import androidx.annotation.StringRes +import androidx.appcompat.content.res.AppCompatResources +import androidx.appcompat.widget.TooltipCompat +import foundation.e.privacycentralapp.R + +fun setToolTipForAsterisk( + textView: TextView, + @StringRes textId: Int, + @StringRes tooltipTextId: Int) { + textView.text = asteriskAsInfoIconSpannable(textView.context, textId) + TooltipCompat.setTooltipText(textView, textView.context.getString(tooltipTextId)) + + textView.setOnClickListener { it.performLongClick() } +} + +private fun asteriskAsInfoIconSpannable(context: Context, @StringRes textId: Int): Spannable { + val spannable = SpannableString(context.getString(textId)) + val index = spannable.lastIndexOf("*") + if (index != -1) { + AppCompatResources.getDrawable(context, R.drawable.ic_info_16dp)?.let { + it.setBounds(0, 0, it.intrinsicWidth, it.intrinsicHeight) + spannable.setSpan( + ImageSpan(it), + index, + index + 1, + Spannable.SPAN_INCLUSIVE_INCLUSIVE + ) + } + } + return spannable +}
\ No newline at end of file |