From 1118c4450b4b14976c08c0d09c3860f4c47d8af3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 21 Apr 2018 20:38:14 +0200 Subject: [PATCH] fix text size in snackbars --- .../ui/ConversationsOverviewFragment.java | 8 ++++--- .../ui/ShareLocationActivity.java | 2 ++ .../conversations/utils/ThemeHelper.java | 21 ++++++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java index 8761a4710..701e9a83b 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsOverviewFragment.java @@ -58,6 +58,7 @@ import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.PendingActionHelper; import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.ScrollState; +import eu.siacs.conversations.utils.ThemeHelper; import static android.support.v7.widget.helper.ItemTouchHelper.LEFT; import static android.support.v7.widget.helper.ItemTouchHelper.RIGHT; @@ -133,7 +134,7 @@ public class ConversationsOverviewFragment extends XmppFragment { activity.xmppConnectionService.archiveConversation(c); } }); - Snackbar.make(binding.list, title, 5000) + final Snackbar snackbar = Snackbar.make(binding.list, title, 5000) .setAction(R.string.undo, v -> { pendingActionHelper.undo(); Conversation c = swipedConversation.pop(); @@ -158,8 +159,9 @@ public class ConversationsOverviewFragment extends XmppFragment { break; } } - }) - .show(); + }); + ThemeHelper.fixTextSize(snackbar); + snackbar.show(); } }; diff --git a/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java index f85d0cc80..734fb7dda 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareLocationActivity.java @@ -22,6 +22,7 @@ import eu.siacs.conversations.databinding.ActivityShareLocationBinding; import eu.siacs.conversations.ui.util.LocationHelper; import eu.siacs.conversations.ui.widget.Marker; import eu.siacs.conversations.ui.widget.MyLocation; +import eu.siacs.conversations.utils.ThemeHelper; public class ShareLocationActivity extends LocationActivity implements LocationListener { @@ -71,6 +72,7 @@ public class ShareLocationActivity extends LocationActivity implements LocationL startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); + ThemeHelper.fixTextSize(this.snackBar); this.binding.shareButton.setOnClickListener(view -> { final Intent result = new Intent(); diff --git a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java index a5f17765b..0214b7f6e 100644 --- a/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/ThemeHelper.java @@ -29,13 +29,18 @@ package eu.siacs.conversations.utils; -import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; +import android.content.res.TypedArray; import android.preference.PreferenceManager; import android.support.annotation.StyleRes; +import android.support.design.widget.Snackbar; +import android.util.Log; +import android.util.TypedValue; +import android.widget.TextView; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.ui.SettingsActivity; @@ -66,4 +71,18 @@ public class ThemeHelper { return false; } } + + public static void fixTextSize(Snackbar snackbar) { + TypedArray typedArray = snackbar.getContext().obtainStyledAttributes(new int[]{R.attr.TextSizeBody1}); + final float size = typedArray.getDimension(0,0f); + typedArray.recycle(); + if (size != 0f) { + final TextView text = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text); + final TextView action = snackbar.getView().findViewById(android.support.design.R.id.snackbar_action); + if (text != null && action != null) { + text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + action.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + } + } + } }