Skip to content

Commit

Permalink
fixed change of icon colors if light toolbar background occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
konradrenner committed Sep 14, 2015
1 parent 353efce commit b99dcad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion app/src/main/java/org/kore/kolabnotes/android/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<View> outViews = new ArrayList<View>();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b99dcad

Please sign in to comment.