From b99dcad12903595dc59e67c2121fb67a891c7b7a Mon Sep 17 00:00:00 2001 From: Konrad Renner Date: Mon, 14 Sep 2015 17:23:39 +0200 Subject: [PATCH] fixed change of icon colors if light toolbar background occurs --- .../org/kore/kolabnotes/android/Utils.java | 31 ++++++++++++++++++- .../android/fragment/DetailFragment.java | 2 +- .../android/fragment/OverviewFragment.java | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/kore/kolabnotes/android/Utils.java b/app/src/main/java/org/kore/kolabnotes/android/Utils.java index d644143..cd18f21 100755 --- a/app/src/main/java/org/kore/kolabnotes/android/Utils.java +++ b/app/src/main/java/org/kore/kolabnotes/android/Utils.java @@ -3,6 +3,7 @@ import android.accounts.Account; import android.accounts.AccountManager; import android.annotation.TargetApi; +import android.app.Activity; import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; @@ -16,12 +17,15 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.internal.widget.TintImageView; import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.util.Log; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.view.ViewOutlineProvider; +import android.view.ViewTreeObserver; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageButton; @@ -38,6 +42,8 @@ import org.kore.kolabnotes.android.widget.StickyNoteWidget; import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class Utils { @@ -323,8 +329,9 @@ public static final AccountIdentifier getAccountIdentifierWithName(Context conte return new AccountIdentifier(email,rootFolder); } - public static void setToolbarTextAndIconColor(Toolbar toolbar, boolean lightText){ + public static void setToolbarTextAndIconColor(final Activity activity, final Toolbar toolbar, final boolean lightText){ + setOverflowButtonColor(activity,lightText); if(lightText){ toolbar.setTitleTextColor(android.graphics.Color.WHITE); @@ -362,6 +369,28 @@ public static void setToolbarTextAndIconColor(Toolbar toolbar, boolean lightText } } + public static void setOverflowButtonColor(final Activity activity, final boolean lightColor){ + final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description); + final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); + final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); + + viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final ArrayList outViews = new ArrayList(); + decorView.findViewsWithText(outViews, overflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); + + if(outViews.isEmpty()){ + return; + } + + TintImageView overflow = (TintImageView)outViews.get(0); + overflow.setColorFilter(lightColor ? android.graphics.Color.WHITE : android.graphics.Color.BLACK); + decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + } + public static boolean useLightTextColor(Context context, Color colorOfNote){ if(colorOfNote == null){ return false; diff --git a/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java b/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java index 79aabf6..2e7fab5 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java +++ b/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java @@ -268,7 +268,7 @@ void setToolbarColor(){ toolbar.setBackgroundColor(getResources().getColor(R.color.theme_default_primary)); } - Utils.setToolbarTextAndIconColor(toolbar,lightText); + Utils.setToolbarTextAndIconColor(activity, toolbar,lightText); } void setHtml(String text){ diff --git a/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java b/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java index b430136..6a2d121 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java +++ b/app/src/main/java/org/kore/kolabnotes/android/fragment/OverviewFragment.java @@ -344,7 +344,7 @@ public void onResume(){ super.onResume(); toolbar.setNavigationIcon(R.drawable.drawer_icon); toolbar.setBackgroundColor(getResources().getColor(R.color.theme_default_primary)); - Utils.setToolbarTextAndIconColor(toolbar,true); + Utils.setToolbarTextAndIconColor(activity, toolbar,true); //displayBlankFragment(); Intent startIntent = getActivity().getIntent();