1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Update opoc license headers

This commit is contained in:
Gregor Santner 2018-03-12 00:05:53 +01:00
parent 6cac47763c
commit 43a2ad25bc
9 changed files with 177 additions and 163 deletions

View file

@ -693,10 +693,10 @@ public class MainActivity extends ThemedActivity
} }
} }
final boolean darkBg = ContextUtils.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor()); ContextUtils cu = ContextUtils.get();
ContextUtils.get() final boolean darkBg = cu.get().shouldColorOnTopBeLight(AppSettings.get().getPrimaryColor());
.tintMenuItems(menu, true, ContextCompat.getColor(this, darkBg ? R.color.white : R.color.black)) cu.tintMenuItems(menu, true, ContextCompat.getColor(this, darkBg ? R.color.white : R.color.black));
.setSubMenuIconsVisiblity(menu, true); cu.setSubMenuIconsVisiblity(menu, true);
return true; return true;
} }

View file

@ -71,7 +71,7 @@ public class BadgeDrawable extends Drawable {
Rect bounds = getBounds(); Rect bounds = getBounds();
float width = bounds.right - bounds.left; float width = bounds.right - bounds.left;
float height = bounds.bottom - bounds.top; float height = bounds.bottom - bounds.top;
float oneDp = ContextUtils.get().dp2px(1); float oneDp = ContextUtils.get().convertDpToPx(1);
// Position the badge in the top-right quadrant of the icon. // Position the badge in the top-right quadrant of the icon.
float radius = ((Math.max(width, height) / 2)) / 2; float radius = ((Math.max(width, height) / 2)) / 2;

View file

@ -1,20 +1,15 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2016-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
/* /*
* Get updates:
* https://github.com/gsantner/onePieceOfCode/blob/master/java/SimpleMarkdownParser.java
* Apply to TextView:
* See https://github.com/gsantner/onePieceOfCode/blob/master/android/ContextUtils.java
* Parses most common markdown tags. Only inline tags are supported, multiline/block syntax * Parses most common markdown tags. Only inline tags are supported, multiline/block syntax
* is not supported (citation, multiline code, ..). This is intended to stay as easy as possible. * is not supported (citation, multiline code, ..). This is intended to stay as easy as possible.
* *

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2017-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
/* /*
* Requires: * Requires:

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2016-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
package net.gsantner.opoc.util; package net.gsantner.opoc.util;
import android.app.Activity; import android.app.Activity;

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ---------------------------------------------------------------------------- *
* Gregor Santner <gsantner.net> wrote this file. You can do whatever
* you want with this stuff. If we meet some day, and you think this stuff is
* worth it, you can buy me a coke in return. Provided as is without any kind
* of warranty. No attribution required. - Gregor Santner
* *
* License of this file: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2017-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
/* /*
* Place adblock hosts file in raw: src/main/res/raw/adblock_domains__xyz.txt * Place adblock hosts file in raw: src/main/res/raw/adblock_domains__xyz.txt

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2016-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
/* /*
* This is a wrapper for settings based on SharedPreferences * This is a wrapper for settings based on SharedPreferences

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2016-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
package net.gsantner.opoc.util; package net.gsantner.opoc.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -20,7 +19,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -46,19 +44,17 @@ import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.AppCompatButton;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.gsantner.opoc.format.markdown.SimpleMarkdownParser; import net.gsantner.opoc.format.markdown.SimpleMarkdownParser;
@ -69,11 +65,14 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.graphics.Bitmap.CompressFormat; import static android.graphics.Bitmap.CompressFormat;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt", "ConstantConditions", "UnusedReturnValue"}) @SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "ObsoleteSdkInt", "deprecation", "SpellCheckingInspection"})
public class ContextUtils { public class ContextUtils {
//######################## //########################
//## Members, Constructors //## Members, Constructors
@ -155,7 +154,7 @@ public class ContextUtils {
public void openWebpageInExternalBrowser(final String url) { public void openWebpageInExternalBrowser(final String url) {
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
try { try {
_context.startActivity(intent); _context.startActivity(intent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
@ -220,7 +219,7 @@ public class ContextUtils {
rstr(strResBitcoinMessage), rstr(strResBitcoinMessage)); rstr(strResBitcoinMessage), rstr(strResBitcoinMessage));
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(btcUri)); intent.setData(Uri.parse(btcUri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
try { try {
_context.startActivity(intent); _context.startActivity(intent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
@ -257,36 +256,43 @@ public class ContextUtils {
return sb.toString(); return sb.toString();
} }
@SuppressLint("RestrictedApi") /**
@SuppressWarnings("RestrictedApi") * Get internet connection state - the permission ACCESS_NETWORK_STATE is required
public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) { *
button.setSupportBackgroundTintList(ColorStateList.valueOf( * @return True if internet connection available
rcolor(resColor) */
));
}
@SuppressLint("MissingPermission") // ACCESS_NETWORK_STATE required
public boolean isConnectedToInternet() { public boolean isConnectedToInternet() {
ConnectivityManager con = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); try {
NetworkInfo activeNetInfo = con == null ? null : con.getActiveNetworkInfo(); ConnectivityManager con = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
return activeNetInfo != null && activeNetInfo.isConnectedOrConnecting(); @SuppressLint("MissingPermission") NetworkInfo activeNetInfo =
con == null ? null : con.getActiveNetworkInfo();
return activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
} catch (Exception ignored) {
throw new RuntimeException("Error: Developer forgot to declare a permission");
}
} }
public boolean isConnectedToInternet(@Nullable @StringRes Integer warnMessageStringRes) { public boolean isAppInstalled(String packageName) {
final boolean result = isConnectedToInternet(); PackageManager pm = _context.getApplicationContext().getPackageManager();
if (!result && warnMessageStringRes != null) try {
Toast.makeText(_context, _context.getString(warnMessageStringRes), Toast.LENGTH_SHORT).show(); pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
return result; } catch (PackageManager.NameNotFoundException e) {
return false;
}
} }
public void restartApp(Class classToStartupWith) { public void restartApp(Class classToStart) {
Intent restartIntent = new Intent(_context, classToStartupWith); Intent inte = new Intent(_context, classToStart);
PendingIntent restartIntentP = PendingIntent.getActivity(_context, 555, PendingIntent inteP = PendingIntent.getActivity(_context, 555, inte, PendingIntent.FLAG_CANCEL_CURRENT);
restartIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) _context.getSystemService(Context.ALARM_SERVICE); AlarmManager mgr = (AlarmManager) _context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, restartIntentP); if (mgr != null) {
System.exit(0); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, inteP);
} else {
inte.addFlags(FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(inte);
}
Runtime.getRuntime().exit(0);
} }
public String loadMarkdownForTextViewFromRaw(@RawRes int rawMdFile, String prepend) { public String loadMarkdownForTextViewFromRaw(@RawRes int rawMdFile, String prepend) {
@ -348,7 +354,6 @@ public class ContextUtils {
+ (0.114 * Color.blue(colorOnBottomInt))))); + (0.114 * Color.blue(colorOnBottomInt)))));
} }
@SuppressWarnings("deprecation")
public Spanned htmlToSpanned(String html) { public Spanned htmlToSpanned(String html) {
Spanned result; Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
@ -359,41 +364,53 @@ public class ContextUtils {
return result; return result;
} }
public void setClipboard(String text) { public boolean setClipboard(String text) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
((android.text.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(text); android.text.ClipboardManager cm = ((android.text.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE));
if (cm != null) {
cm.setText(text);
return true;
}
} else { } else {
ClipData clip = ClipData.newPlainText(_context.getPackageName(), text); android.content.ClipboardManager cm = ((android.content.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE));
((android.content.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip); if (cm != null) {
} ClipData clip = ClipData.newPlainText(_context.getPackageName(), text);
} cm.setPrimaryClip(clip);
return true;
public String[] getClipboard() {
String[] ret;
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
ret = new String[]{((android.text.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).getText().toString()};
} else {
ClipData data = ((android.content.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).getPrimaryClip();
ret = new String[data.getItemCount()];
for (int i = 0; i < data.getItemCount() && i < ret.length; i++) {
ret[i] = data.getItemAt(i).getText().toString();
} }
} }
return ret; return false;
} }
public float px2dp(final float px) { public List<String> getClipboard() {
List<String> clipper = new ArrayList<>();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager cm = ((android.text.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE));
if (cm != null) {
clipper.add(cm.getText().toString());
}
} else {
android.content.ClipboardManager cm = ((android.content.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE));
if (cm != null && cm.hasPrimaryClip()) {
ClipData data = cm.getPrimaryClip();
for (int i = 0; i < data.getItemCount() && i < data.getItemCount(); i++) {
clipper.add(data.getItemAt(i).getText().toString());
}
}
}
return clipper;
}
public float convertPxToDp(final float px) {
return px / _context.getResources().getDisplayMetrics().density; return px / _context.getResources().getDisplayMetrics().density;
} }
public float dp2px(final float dp) { public float convertDpToPx(final float dp) {
return dp * _context.getResources().getDisplayMetrics().density; return dp * _context.getResources().getDisplayMetrics().density;
} }
public void setViewVisible(View view, boolean visible) {
view.setVisibility(visible ? View.VISIBLE : View.GONE);
}
public static void setDrawableWithColorToImageView(ImageView imageView, @DrawableRes int drawableResId, @ColorRes int colorResId) { public static void setDrawableWithColorToImageView(ImageView imageView, @DrawableRes int drawableResId, @ColorRes int colorResId) {
imageView.setImageResource(drawableResId); imageView.setImageResource(drawableResId);
imageView.setColorFilter(ContextCompat.getColor(imageView.getContext(), colorResId)); imageView.setColorFilter(ContextCompat.getColor(imageView.getContext(), colorResId));
@ -453,31 +470,40 @@ public class ContextUtils {
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} }
public File writeImageToFileJpeg(File imageFile, Bitmap image) { public boolean writeImageToFileJpeg(File imageFile, Bitmap image) {
return writeImageToFile(imageFile, image, Bitmap.CompressFormat.JPEG, 95); return writeImageToFile(imageFile, image, Bitmap.CompressFormat.JPEG, 95);
} }
/**
public File writeImageToFileDetectFormat(File imageFile, Bitmap image, int quality) { * Write bitmap to the filesystem
CompressFormat format = CompressFormat.JPEG; *
String lc = imageFile.getAbsolutePath().toLowerCase(Locale.ROOT); * @param targetFile The file to be written in
if (lc.endsWith(".png")) { * @param image The image as android {@link Bitmap}
format = CompressFormat.PNG; * @param format One format of {@link CompressFormat}, null will determine based on filename
* @param quality Quality level, defaults to 95
* @return True if writing was successful
*/
public boolean writeImageToFile(File targetFile, Bitmap image, CompressFormat format, Integer quality) {
File folder = new File(targetFile.getParent());
if (quality == null || quality < 0 || quality > 100) {
quality = 95;
} }
if (lc.endsWith(".webp")) { if (format == null) {
format = CompressFormat.WEBP; format = CompressFormat.JPEG;
String lc = targetFile.getAbsolutePath().toLowerCase(Locale.ROOT);
if (lc.endsWith(".png")) {
format = CompressFormat.PNG;
}
if (lc.endsWith(".webp")) {
format = CompressFormat.WEBP;
}
} }
return writeImageToFile(imageFile, image, format, quality);
}
public File writeImageToFile(File imageFile, Bitmap image, CompressFormat format, int quality) {
File folder = new File(imageFile.getParent());
if (folder.exists() || folder.mkdirs()) { if (folder.exists() || folder.mkdirs()) {
FileOutputStream stream = null; FileOutputStream stream = null;
try { try {
stream = new FileOutputStream(imageFile); // overwrites this image every time stream = new FileOutputStream(targetFile); // overwrites this image every time
image.compress(format, quality, stream); image.compress(format, quality, stream);
return imageFile; return true;
} catch (FileNotFoundException ignored) { } catch (FileNotFoundException ignored) {
} finally { } finally {
try { try {
@ -488,13 +514,13 @@ public class ContextUtils {
} }
} }
} }
return null; return false;
} }
public Bitmap drawTextToDrawable(@DrawableRes int resId, String text, int textSize) { public Bitmap drawTextOnDrawable(@DrawableRes int resId, String text, int textSize) {
Resources resources = _context.getResources(); Resources resources = _context.getResources();
float scale = resources.getDisplayMetrics().density; float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = getBitmapFromDrawable(resId); Bitmap bitmap = bitmapToDrawable(resId);
bitmap = bitmap.copy(bitmap.getConfig(), true); bitmap = bitmap.copy(bitmap.getConfig(), true);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
@ -512,7 +538,7 @@ public class ContextUtils {
return bitmap; return bitmap;
} }
public Bitmap getBitmapFromDrawable(int drawableId) { public Bitmap bitmapToDrawable(@DrawableRes int drawableId) {
Bitmap bitmap = null; Bitmap bitmap = null;
Drawable drawable = ContextCompat.getDrawable(_context, drawableId); Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
@ -520,8 +546,7 @@ public class ContextUtils {
drawable = (DrawableCompat.wrap(drawable)).mutate(); drawable = (DrawableCompat.wrap(drawable)).mutate();
} }
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas); drawable.draw(canvas);
@ -531,7 +556,8 @@ public class ContextUtils {
return bitmap; return bitmap;
} }
public ContextUtils tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) { @SuppressWarnings("ConstantConditions")
public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
for (int i = 0; i < menu.size(); i++) { for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i); MenuItem item = menu.getItem(i);
tintDrawable(item.getIcon(), iconColor); tintDrawable(item.getIcon(), iconColor);
@ -539,7 +565,6 @@ public class ContextUtils {
tintMenuItems(item.getSubMenu(), recurse, iconColor); tintMenuItems(item.getSubMenu(), recurse, iconColor);
} }
} }
return this;
} }
public Drawable tintDrawable(@DrawableRes int drawableRes, @ColorInt int color) { public Drawable tintDrawable(@DrawableRes int drawableRes, @ColorInt int color) {
@ -554,16 +579,15 @@ public class ContextUtils {
return drawable; return drawable;
} }
@SuppressLint("PrivateApi") public void setSubMenuIconsVisiblity(Menu menu, boolean visible) {
public ContextUtils setSubMenuIconsVisiblity(Menu menu, boolean visible) {
if (menu.getClass().getSimpleName().equals("MenuBuilder")) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
try { try {
Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE); @SuppressLint("PrivateApi") Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true); m.setAccessible(true);
m.invoke(menu, visible); m.invoke(menu, visible);
} catch (Exception ignored) { } catch (Exception ignored) {
Log.d(getClass().getName(), "Error: 'setSubMenuIconsVisiblity' not supported on this device");
} }
} }
return this;
} }
} }

View file

@ -1,14 +1,13 @@
/* /*#######################################################
* ------------------------------------------------------------------------------
* Gregor Santner <gsantner.net> wrote this. You can do whatever you want
* with it. If we meet some day, and you think it is worth it, you can buy me a
* coke in return. Provided as is without any kind of warranty. Do not blame or
* sue me if something goes wrong. No attribution required. - Gregor Santner
* *
* License: Creative Commons Zero (CC0 1.0) * Maintained by Gregor Santner, 2018-
* http://creativecommons.org/publicdomain/zero/1.0/ * https://gsantner.net/
* ---------------------------------------------------------------------------- *
*/ * License: Apache 2.0
* https://github.com/gsantner/opoc/#licensing
* https://www.apache.org/licenses/LICENSE-2.0
*
#########################################################*/
package net.gsantner.opoc.util; package net.gsantner.opoc.util;
import java.util.List; import java.util.List;