mirror of
https://github.com/gsantner/dandelion
synced 2025-09-09 18:29:47 +02:00
Update Readme
This commit is contained in:
parent
ea7ceacc12
commit
e9fa2082d9
6 changed files with 128 additions and 76 deletions
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* ---------------------------------------------------------------------------- *
|
||||
* Gregor Santner <gsantner.github.io> 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
|
||||
* ------------------------------------------------------------------------------
|
||||
* Gregor Santner <gsantner.github.io> 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)
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* ---------------------------------------------------------------------------- *
|
||||
* Gregor Santner <gsantner.github.io> 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
|
||||
* ------------------------------------------------------------------------------
|
||||
* Gregor Santner <gsantner.github.io> 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 of this file: Creative Commons Zero (CC0 1.0)
|
||||
* License: Creative Commons Zero (CC0 1.0)
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import android.content.pm.PackageInfo;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
|
@ -45,10 +46,9 @@ import android.widget.TextView;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection"})
|
||||
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation"})
|
||||
public class Helpers {
|
||||
//########################
|
||||
//## Members, Constructors
|
||||
|
@ -126,26 +126,19 @@ public class Helpers {
|
|||
}
|
||||
|
||||
/**
|
||||
* https://stackoverflow.com/a/25267049
|
||||
* Gets a field from the project's BuildConfig. This is useful when, for example, flavors
|
||||
* are used at the project level to set custom fields.
|
||||
*
|
||||
* @param fieldName The name of the field-to-access
|
||||
* @return The value of the field, or {@code null} if the field is not found.
|
||||
* Get field from PackageId.BuildConfig
|
||||
* May be helpful in libraries, where a access to
|
||||
* BuildConfig would only get values of the library
|
||||
* rather than the app ones
|
||||
*/
|
||||
public Object getBuildConfigValue(String fieldName) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(_context.getPackageName() + ".BuildConfig");
|
||||
Field field = clazz.getField(fieldName);
|
||||
return field.get(null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
Class<?> c = Class.forName(_context.getPackageName() + ".BuildConfig");
|
||||
return c.getField(fieldName).get(null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getBuildConfigBoolean(String fieldName, boolean defaultValue) {
|
||||
|
@ -220,6 +213,7 @@ public class Helpers {
|
|||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@SuppressWarnings("RestrictedApi")
|
||||
public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) {
|
||||
button.setSupportBackgroundTintList(ColorStateList.valueOf(
|
||||
color(resColor)
|
||||
|
@ -288,14 +282,15 @@ public class Helpers {
|
|||
? new Locale(code.substring(0, 2), code.substring(4, 6)) // de-rAt
|
||||
: new Locale(code); // de
|
||||
}
|
||||
return Locale.getDefault();
|
||||
return Resources.getSystem().getConfiguration().locale;
|
||||
}
|
||||
|
||||
// "en"/"de"/"de-rAt"; Empty string = default locale
|
||||
// en/de/de-rAt ; Empty string -> default locale
|
||||
public void setAppLanguage(String androidLocaleString) {
|
||||
Locale locale = getLocaleByAndroidCode(androidLocaleString);
|
||||
Configuration config = _context.getResources().getConfiguration();
|
||||
config.locale = locale != null ? locale : Locale.getDefault();
|
||||
config.locale = (locale != null && !androidLocaleString.isEmpty())
|
||||
? locale : Resources.getSystem().getConfiguration().locale;
|
||||
_context.getResources().updateConfiguration(config, null);
|
||||
}
|
||||
|
||||
|
@ -306,6 +301,7 @@ public class Helpers {
|
|||
+ (0.114 * Color.blue(colorOnBottomInt)))));
|
||||
}
|
||||
|
||||
|
||||
public float px2dp(final float px) {
|
||||
return px / _context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* ---------------------------------------------------------------------------- *
|
||||
* Gregor Santner <gsantner.github.io> 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
|
||||
* ------------------------------------------------------------------------------
|
||||
* Gregor Santner <gsantner.github.io> 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 of this file: Creative Commons Zero (CC0 1.0)
|
||||
* License: Creative Commons Zero (CC0 1.0)
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -44,9 +44,9 @@ public class HelpersA extends Helpers {
|
|||
/**
|
||||
* Animate to specified Activity
|
||||
*
|
||||
* @param to The class of the _activity
|
||||
* @param finishFromActivity true: Finish the current _activity
|
||||
* @param requestCode Request code for stating the _activity, not waiting for result if null
|
||||
* @param to The class of the activity
|
||||
* @param finishFromActivity true: Finish the current activity
|
||||
* @param requestCode Request code for stating the activity, not waiting for result if null
|
||||
*/
|
||||
public void animateToActivity(Class to, Boolean finishFromActivity, Integer requestCode) {
|
||||
animateToActivity(new Intent(_activity, to), finishFromActivity, requestCode);
|
||||
|
@ -56,9 +56,9 @@ public class HelpersA extends Helpers {
|
|||
* Animate to Activity specified in intent
|
||||
* Requires animation resources
|
||||
*
|
||||
* @param intent Intent to open start an _activity
|
||||
* @param finishFromActivity true: Finish the current _activity
|
||||
* @param requestCode Request code for stating the _activity, not waiting for result if null
|
||||
* @param intent Intent to open start an activity
|
||||
* @param finishFromActivity true: Finish the current activity
|
||||
* @param requestCode Request code for stating the activity, not waiting for result if null
|
||||
*/
|
||||
public void animateToActivity(Intent intent, Boolean finishFromActivity, Integer requestCode) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* ---------------------------------------------------------------------------- *
|
||||
* Gregor Santner <gsantner.github.io> 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
|
||||
* ------------------------------------------------------------------------------
|
||||
* Gregor Santner <gsantner.github.io> 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 of this file: Creative Commons Zero (CC0 1.0)
|
||||
* License: Creative Commons Zero (CC0 1.0)
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -50,7 +50,7 @@ public class SimpleMarkdownParser {
|
|||
public final static SmpFilter FILTER_ANDROID_TEXTVIEW = new SmpFilter() {
|
||||
@Override
|
||||
public String filter(String text) {
|
||||
// TextView supports a limited set of _html tags, most notably
|
||||
// TextView supports a limited set of html tags, most notably
|
||||
// a href, b, big, font size&color, i, li, small, u
|
||||
|
||||
// Don't start new line if 2 empty lines and heading
|
||||
|
@ -111,6 +111,22 @@ public class SimpleMarkdownParser {
|
|||
}
|
||||
};
|
||||
|
||||
public final static SmpFilter FILTER_CHANGELOG = new SmpFilter() {
|
||||
@Override
|
||||
public String filter(String text) {
|
||||
text = text
|
||||
.replace("New:", "<font color='#276230'>New:</font>")
|
||||
.replace("Added:", "<font color='#276230'>Added:</font>")
|
||||
.replace("Fixed:", "<font color='#005688'>Fixed:</font>")
|
||||
.replace("Removed:", "<font color='#C13524'>Removed:</font>")
|
||||
.replace("Updated:", "<font color='#555555'>Updated:</font>")
|
||||
.replace("Improved:", "<font color='#555555'>Improved:</font>")
|
||||
.replace("Modified:", "<font color='#555555'>Modified:</font>")
|
||||
;
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
//########################
|
||||
//## Singleton
|
||||
//########################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue