From 51e54a0ee3574315c84fbc9ec830fc50a096f306 Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Sun, 29 Oct 2017 19:50:24 +0100 Subject: [PATCH] Update TravisCI script --- .travis.yml | 4 +- README.md | 2 +- .../net/gsantner/opoc/util/ContextUtils.java | 38 ++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 290583af9..b4204f729 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ env: global: - ANDROID_HOME=$HOME/android-sdk matrix: - - TASK="lintFlavorDefaultDebug --stacktrace" - - TASK="build check --stacktrace" + - TASK="clean lintFlavorDefaultDebug --stacktrace" + - TASK="clean build check -x lint --stacktrace" script: "./gradlew --no-daemon --parallel $TASK" diff --git a/README.md b/README.md index e6ebe813b..4f766f6f5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![GitHub release](https://img.shields.io/github/tag/gsantner/memetastic.svg)](https://github.com/gsantner/memetastic/releases) [![Donate](https://img.shields.io/badge/donate-bitcoin-orange.svg)](https://gsantner.github.io/#donate) [![Donate LiberaPay](https://img.shields.io/badge/donate-liberapay-orange.svg)](https://liberapay.com/gsantner/donate) -[![CircleCI](https://circleci.com/gh/gsantner/memetastic.svg?style=shield)](https://circleci.com/gh/gsantner/memetastic) +[![Build Status](https://travis-ci.org/gsantner/memetastic.svg?branch=master)](https://travis-ci.org/gsantner/memetastic) [![Translate - with Stringlate](https://img.shields.io/badge/stringlate-translate-green.svg)](https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgithub.com%2Fgsantner%2Fmemetastic.git&name=MemeTastic&web=https%3A%2F%2Fgithub.com%2Fgsantner%2Fmemetastic) [![Chat - Matrix](https://img.shields.io/badge/chat-on%20matrix-blue.svg)](https://matrix.to/#/#memetastic:matrix.org) [![Chat - FreeNode IRC](https://img.shields.io/badge/chat-on%20irc-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/?nick=memetastic-anon|?#memetastic) diff --git a/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java index 3083cb0ad..a27c33610 100644 --- a/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/ContextUtils.java @@ -29,6 +29,7 @@ import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; @@ -37,6 +38,7 @@ import android.net.NetworkInfo; import android.net.Uri; import android.os.Build; +import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; @@ -52,7 +54,10 @@ import android.text.Spanned; import android.text.TextUtils; import android.text.method.LinkMovementMethod; +import android.text.style.ForegroundColorSpan; import android.util.DisplayMetrics; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.widget.ImageView; @@ -65,11 +70,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.lang.reflect.Method; import java.util.Locale; import static android.graphics.Bitmap.CompressFormat; -@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt"}) +@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt", "ConstantConditions", "UnusedReturnValue"}) public class ContextUtils { //######################## //## Members, Constructors @@ -322,7 +328,7 @@ public void setAppLanguage(String androidLocaleString) { } // Find out if color above the given color should be light or dark. true if light - public boolean shouldColorOnTopBeLight(int colorOnBottomInt) { + public boolean shouldColorOnTopBeLight(@ColorInt int colorOnBottomInt) { return 186 > (((0.299 * Color.red(colorOnBottomInt)) + ((0.587 * Color.green(colorOnBottomInt)) + (0.114 * Color.blue(colorOnBottomInt))))); @@ -510,4 +516,32 @@ public Bitmap getBitmapFromDrawable(int drawableId) { } return bitmap; } + + public ContextUtils tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) { + for (int i = 0; i < menu.size(); i++) { + MenuItem item = menu.getItem(i); + Drawable drawable = item.getIcon(); + if (drawable != null) { + drawable.mutate(); + drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN); + } + if (item.hasSubMenu() && recurse) { + tintMenuItems(item.getSubMenu(), recurse, iconColor); + } + } + return this; + } + + @SuppressLint("PrivateApi") + public ContextUtils setSubMenuIconsVisiblity(Menu menu, boolean visible) { + if (menu.getClass().getSimpleName().equals("MenuBuilder")) { + try { + Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE); + m.setAccessible(true); + m.invoke(menu, visible); + } catch (Exception ignored) { + } + } + return this; + } }