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

Update to latest opoc version

* Move various clases
* Especially improve language preference, backported from compat lib
This commit is contained in:
Gregor Santner 2018-03-02 15:56:14 +01:00
parent 1bb061b563
commit dd0432f718
10 changed files with 281 additions and 115 deletions

View file

@ -87,7 +87,7 @@ import com.github.dfa.diaspora_android.web.ProxyHandler;
import com.github.dfa.diaspora_android.web.WebHelper; import com.github.dfa.diaspora_android.web.WebHelper;
import com.github.dfa.diaspora_android.web.custom_tab.CustomTabActivityHelper; import com.github.dfa.diaspora_android.web.custom_tab.CustomTabActivityHelper;
import net.gsantner.opoc.util.SimpleMarkdownParser; import net.gsantner.opoc.format.markdown.SimpleMarkdownParser;
import java.io.IOException; import java.io.IOException;

View file

@ -145,7 +145,11 @@ public class AppSettings extends AppSettingsBase {
} }
public void setPodAspects(DiasporaAspect[] aspects) { public void setPodAspects(DiasporaAspect[] aspects) {
setStringArray(R.string.pref_key__podprofile_aspects, aspects, _prefPod); String[] strs = new String[aspects.length];
for (int i = 0; i < strs.length; i++) {
strs[i] = aspects[i].toShareAbleText();
}
setStringArray(R.string.pref_key__podprofile_aspects, strs, _prefPod);
} }
public DiasporaAspect[] getAspects() { public DiasporaAspect[] getAspects() {

View file

@ -27,7 +27,7 @@
* FILTER_WEB is intended to be used at engines understanding most common HTML tags. * FILTER_WEB is intended to be used at engines understanding most common HTML tags.
*/ */
package net.gsantner.opoc.util; package net.gsantner.opoc.format.markdown;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileInputStream; import java.io.FileInputStream;

View file

@ -11,16 +11,16 @@
*/ */
/* /*
* A ListPreference that displays a list of available languages
* Requires: * Requires:
* The BuildConfig field "APPLICATION_LANGUAGES" which is a array of all available languages The BuildConfig field "APPLICATION_LANGUAGES" which is a array of all available languages
* opoc/ContextUtils opoc/ContextUtils
* BuildConfig field can be defined by using the method below * BuildConfig field can be defined by using the method below
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}') buildConfigField "String[]", "APPLICATION_LANGUAGES", "${getUsedAndroidLanguages()}"
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"]) @SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection", "GroovyUnusedDeclaration"])
static String[] getUsedAndroidLanguages() { // Returns used android languages as a buildConfig array: {'de', 'it', ..}"
static String getUsedAndroidLanguages() {
Set<String> langs = new HashSet<>() Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) { new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name final foldername = it.name
@ -32,25 +32,25 @@ static String[] getUsedAndroidLanguages() {
} }
} }
} }
return langs.toArray(new String[langs.size()]) return '{' + langs.collect { "\"${it}\"" }.join(",") + '}'
} }
* Summary: Change language of this app. Restart app for changes to take effect * Summary: Change language of this app. Restart app for changes to take effect
* Define element in Preferences-XML: * Define element in Preferences-XML:
<net.gsantner.opoc.ui.LanguagePreference <net.gsantner.opoc.preference.LanguagePreference
android:icon="@drawable/ic_language_black_24dp" android:icon="@drawable/ic_language_black_24dp"
android:key="@string/pref_key__language" android:key="@string/pref_key__language"
android:summary="@string/pref_desc__language" android:summary="@string/pref_desc__language"
android:title="@string/pref_title__language"/> android:title="@string/pref_title__language"/>
*/ */
package net.gsantner.opoc.ui; package net.gsantner.opoc.preference.nonsupport;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.preference.ListPreference;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.preference.ListPreference;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -69,7 +69,7 @@ public class LanguagePreference extends ListPreference {
private static final String SYSTEM_LANGUAGE_CODE = ""; private static final String SYSTEM_LANGUAGE_CODE = "";
// The language of res/values/ -> (usually English) // The language of res/values/ -> (usually English)
public String _systemLanguageName = "System"; public String _systemLanguageName = "System";
public String _defaultLanguageCode = "en"; public String _defaultLanguageCode = "en";
public LanguagePreference(Context context) { public LanguagePreference(Context context) {
@ -95,7 +95,7 @@ public class LanguagePreference extends ListPreference {
} }
@Override @Override
protected boolean callChangeListener(Object newValue) { public boolean callChangeListener(Object newValue) {
if (newValue instanceof String) { if (newValue instanceof String) {
// Does not apply to existing UI, use recreate() // Does not apply to existing UI, use recreate()
new ContextUtils(getContext()).setAppLanguage((String) newValue); new ContextUtils(getContext()).setAppLanguage((String) newValue);
@ -118,7 +118,7 @@ public class LanguagePreference extends ListPreference {
if (bcof instanceof String[]) { if (bcof instanceof String[]) {
for (String langId : (String[]) bcof) { for (String langId : (String[]) bcof) {
Locale locale = contextUtils.getLocaleByAndroidCode(langId); Locale locale = contextUtils.getLocaleByAndroidCode(langId);
languages.add(summarizeLocale(locale) + ";" + langId); languages.add(summarizeLocale(locale, langId) + ";" + langId);
} }
} }
@ -133,9 +133,9 @@ public class LanguagePreference extends ListPreference {
entryval[i + 2] = languages.get(i).split(";")[1]; entryval[i + 2] = languages.get(i).split(";")[1];
} }
entryval[0] = SYSTEM_LANGUAGE_CODE; entryval[0] = SYSTEM_LANGUAGE_CODE;
entries[0] = _systemLanguageName + "\n[" + summarizeLocale(context.getResources().getConfiguration().locale) + "]"; entries[0] = _systemLanguageName + " » " + summarizeLocale(context.getResources().getConfiguration().locale, "");
entryval[1] = _defaultLanguageCode; entryval[1] = _defaultLanguageCode;
entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode)); entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode), _defaultLanguageCode);
setEntries(entries); setEntries(entries);
setEntryValues(entryval); setEntryValues(entryval);
@ -143,13 +143,21 @@ public class LanguagePreference extends ListPreference {
// Concat english and localized language name // Concat english and localized language name
// Append country if country specific (e.g. Portuguese Brazil) // Append country if country specific (e.g. Portuguese Brazil)
private String summarizeLocale(Locale locale) { private String summarizeLocale(final Locale locale, final String localeAndroidCode) {
String country = locale.getDisplayCountry(locale); String country = locale.getDisplayCountry(locale);
String language = locale.getDisplayLanguage(locale); String language = locale.getDisplayLanguage(locale);
return locale.getDisplayLanguage(Locale.ENGLISH) String ret = locale.getDisplayLanguage(Locale.ENGLISH)
+ " (" + language.substring(0, 1).toUpperCase(Locale.getDefault()) + language.substring(1) + " (" + language.substring(0, 1).toUpperCase(Locale.getDefault()) + language.substring(1)
+ ((!country.isEmpty() && !country.toLowerCase(Locale.getDefault()).equals(language.toLowerCase(Locale.getDefault()))) ? (", " + country) : "") + ((!country.isEmpty() && !country.toLowerCase(Locale.getDefault()).equals(language.toLowerCase(Locale.getDefault()))) ? (", " + country) : "")
+ ")"; + ")";
if (localeAndroidCode.equals("zh-rCN")) {
ret = ret.substring(0, ret.indexOf(" ") + 1) + "Simplified" + ret.substring(ret.indexOf(" "));
} else if (localeAndroidCode.equals("zh-rTW")) {
ret = ret.substring(0, ret.indexOf(" ") + 1) + "Traditional" + ret.substring(ret.indexOf(" "));
}
return ret;
} }
// Add current language to summary // Add current language to summary
@ -158,7 +166,7 @@ public class LanguagePreference extends ListPreference {
Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue()); Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
String prefix = TextUtils.isEmpty(super.getSummary()) String prefix = TextUtils.isEmpty(super.getSummary())
? "" : super.getSummary() + "\n\n"; ? "" : super.getSummary() + "\n\n";
return prefix + summarizeLocale(locale); return prefix + summarizeLocale(locale, getValue());
} }
public String getSystemLanguageName() { public String getSystemLanguageName() {

View file

@ -28,6 +28,7 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection"}) @SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection"})
@ -93,16 +94,16 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
} }
public void hideSoftKeyboard() { public void hideSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (_activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) { if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
inputMethodManager.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0); imm.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0);
} }
} }
public void showSoftKeyboard() { public void showSoftKeyboard() {
InputMethodManager inputMethodManager = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (_activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) { if (imm != null && _activity.getCurrentFocus() != null && _activity.getCurrentFocus().getWindowToken() != null) {
inputMethodManager.showSoftInput(_activity.getCurrentFocus(), InputMethodManager.SHOW_FORCED); imm.showSoftInput(_activity.getCurrentFocus(), InputMethodManager.SHOW_FORCED);
} }
} }
@ -126,6 +127,16 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
dialog.show(); dialog.show();
} }
public void showDialogWithRawFileInWebView(String fileInRaw, @StringRes int resTitleId) {
WebView wv = new WebView(_context);
wv.loadUrl("file:///android_res/raw/" + fileInRaw);
AlertDialog.Builder dialog = new AlertDialog.Builder(_context)
.setPositiveButton(android.R.string.ok, null)
.setTitle(resTitleId)
.setView(wv);
dialog.show();
}
// Toggle with no param, else set visibility according to first bool // Toggle with no param, else set visibility according to first bool
public void toggleStatusbarVisibility(boolean... optionalForceVisible) { public void toggleStatusbarVisibility(boolean... optionalForceVisible) {
WindowManager.LayoutParams attrs = _activity.getWindow().getAttributes(); WindowManager.LayoutParams attrs = _activity.getWindow().getAttributes();
@ -140,7 +151,7 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
_activity.getWindow().setAttributes(attrs); _activity.getWindow().setAttributes(attrs);
} }
public void showRateOnGplayDialog() { public void showGooglePlayEntryForThisApp() {
String pkgId = "details?id=" + _activity.getPackageName(); String pkgId = "details?id=" + _activity.getPackageName();
Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId)); Intent goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + pkgId));
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |

View file

@ -16,29 +16,19 @@
* getters/setters for the app's settings. * getters/setters for the app's settings.
* Example: * Example:
public boolean isAppFirstStart(boolean doSet) { public boolean isAppFirstStart(boolean doSet) {
boolean value = getBool(prefApp, R.string.pref_key__app_first_start, true); int value = getInt(R.string.pref_key__app_first_start, -1);
if (doSet) { if (doSet) {
setBool(prefApp, R.string.pref_key__app_first_start, false); setBool(true);
} }
return value; return value;
} }
public boolean isAppCurrentVersionFirstStart(boolean doSet) { public boolean isAppCurrentVersionFirstStart(boolean doSet) {
int value = getInt(prefApp, R.string.pref_key__app_first_start_current_version, -1); int value = getInt(R.string.pref_key__app_first_start_current_version, -1);
if (doSet) { if (doSet) {
setInt(prefApp, R.string.pref_key__app_first_start_current_version, BuildConfig.VERSION_CODE); setInt(R.string.pref_key__app_first_start_current_version, BuildConfig.VERSION_CODE);
} }
return value != BuildConfig.VERSION_CODE && !BuildConfig.IS_TEST_BUILD; return value != BuildConfig.VERSION_CODE;
}
* Maybe add a singleton for this:
* Whereas App.get() is returning ApplicationContext
private AppSettings(Context _context) {
super(_context);
}
public static AppSettings get() {
return new AppSettings(App.get());
} }
*/ */
@ -63,7 +53,7 @@ import java.util.List;
* Default SharedPreference (_prefApp) will be taken if no SP is specified, else the first one * Default SharedPreference (_prefApp) will be taken if no SP is specified, else the first one
*/ */
@SuppressWarnings({"WeakerAccess", "unused", "SpellCheckingInspection", "SameParameterValue"}) @SuppressWarnings({"WeakerAccess", "unused", "SpellCheckingInspection", "SameParameterValue"})
public class AppSettingsBase { public class AppSettingsBase implements PropertyBackend<String, AppSettingsBase> {
protected static final String ARRAY_SEPARATOR = "%%%"; protected static final String ARRAY_SEPARATOR = "%%%";
protected static final String ARRAY_SEPARATOR_SUBSTITUTE = "§§§"; protected static final String ARRAY_SEPARATOR_SUBSTITUTE = "§§§";
public static final String SHARED_PREF_APP = "app"; public static final String SHARED_PREF_APP = "app";
@ -190,36 +180,33 @@ public class AppSettingsBase {
return gp(pref).getString(rstr(keyResourceId), rstr(keyResourceIdDefaultValue)); return gp(pref).getString(rstr(keyResourceId), rstr(keyResourceIdDefaultValue));
} }
public void setStringArray(@StringRes int keyResourceId, Object[] values, final SharedPreferences... pref) { private void setStringListOne(String key, List<String> values, final SharedPreferences pref) {
setStringArray(rstr(keyResourceId), values, gp(pref));
}
public void setStringArray(String key, Object[] values, final SharedPreferences... pref) {
setStringArray(key, values, gp(pref));
}
private void setStringArray(String key, Object[] values, final SharedPreferences pref) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Object value : values) { for (String value : values) {
sb.append(ARRAY_SEPARATOR); sb.append(ARRAY_SEPARATOR);
sb.append(value.toString().replace(ARRAY_SEPARATOR, ARRAY_SEPARATOR_SUBSTITUTE)); sb.append(value.replace(ARRAY_SEPARATOR, ARRAY_SEPARATOR_SUBSTITUTE));
} }
setString(key, sb.toString().replaceFirst(ARRAY_SEPARATOR, ""), pref); setString(key, sb.toString().replaceFirst(ARRAY_SEPARATOR, ""), pref);
} }
@NonNull private ArrayList<String> getStringListOne(String key, final SharedPreferences pref) {
public String[] getStringArray(@StringRes int keyResourceId, final SharedPreferences... pref) { ArrayList<String> ret = new ArrayList<>();
return getStringArray(rstr(keyResourceId), gp(pref)); String value = pref
}
private String[] getStringArray(String key, final SharedPreferences... pref) {
String value = gp(pref)
.getString(key, ARRAY_SEPARATOR) .getString(key, ARRAY_SEPARATOR)
.replace(ARRAY_SEPARATOR_SUBSTITUTE, ARRAY_SEPARATOR); .replace(ARRAY_SEPARATOR_SUBSTITUTE, ARRAY_SEPARATOR);
if (value.equals(ARRAY_SEPARATOR)) { if (value.equals(ARRAY_SEPARATOR)) {
return new String[0]; return ret;
} }
return value.split(ARRAY_SEPARATOR); ret.addAll(Arrays.asList(value.split(ARRAY_SEPARATOR)));
return ret;
}
public void setStringArray(@StringRes int keyResourceId, String[] values, final SharedPreferences... pref) {
setStringArray(rstr(keyResourceId), values, pref);
}
public void setStringArray(String key, String[] values, final SharedPreferences... pref) {
setStringListOne(key, Arrays.asList(values), gp(pref));
} }
public void setStringList(@StringRes int keyResourceId, List<String> values, final SharedPreferences... pref) { public void setStringList(@StringRes int keyResourceId, List<String> values, final SharedPreferences... pref) {
@ -230,12 +217,23 @@ public class AppSettingsBase {
setStringArray(key, values.toArray(new String[values.size()]), pref); setStringArray(key, values.toArray(new String[values.size()]), pref);
} }
@NonNull
public String[] getStringArray(@StringRes int keyResourceId, final SharedPreferences... pref) {
return getStringArray(rstr(keyResourceId), pref);
}
@NonNull
public String[] getStringArray(String key, final SharedPreferences... pref) {
List<String> list = getStringListOne(key, gp(pref));
return list.toArray(new String[list.size()]);
}
public ArrayList<String> getStringList(@StringRes int keyResourceId, final SharedPreferences... pref) { public ArrayList<String> getStringList(@StringRes int keyResourceId, final SharedPreferences... pref) {
return new ArrayList<>(Arrays.asList(getStringArray(rstr(keyResourceId), gp(pref)))); return getStringListOne(rstr(keyResourceId), gp(pref));
} }
public ArrayList<String> getStringList(String key, final SharedPreferences... pref) { public ArrayList<String> getStringList(String key, final SharedPreferences... pref) {
return new ArrayList<>(Arrays.asList(getStringArray(key, gp(pref)))); return getStringListOne(key, gp(pref));
} }
//################################# //#################################
@ -266,56 +264,59 @@ public class AppSettingsBase {
return Integer.valueOf(strNum); return Integer.valueOf(strNum);
} }
private void setIntListOne(String key, List<Integer> values, final SharedPreferences pref) {
public void setIntArray(@StringRes int keyResourceId, Object[] values, final SharedPreferences... pref) {
setIntArray(rstr(keyResourceId), values, gp(pref));
}
public void setIntArray(String key, Object[] values, final SharedPreferences... pref) {
setIntArray(key, values, gp(pref));
}
private void setIntArray(String key, Object[] values, final SharedPreferences pref) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Object value : values) { for (Integer value : values) {
sb.append(ARRAY_SEPARATOR); sb.append(ARRAY_SEPARATOR);
sb.append(value.toString()); sb.append(value.toString());
} }
setString(key, sb.toString().replaceFirst(ARRAY_SEPARATOR, ""), pref); setString(key, sb.toString().replaceFirst(ARRAY_SEPARATOR, ""), pref);
} }
@NonNull private ArrayList<Integer> getIntListOne(String key, final SharedPreferences pref) {
public Integer[] getIntArray(@StringRes int keyResourceId, final SharedPreferences... pref) { ArrayList<Integer> ret = new ArrayList<>();
return getIntArray(rstr(keyResourceId), gp(pref)); String value = pref.getString(key, ARRAY_SEPARATOR);
}
private Integer[] getIntArray(String key, final SharedPreferences... pref) {
String value = gp(pref).getString(key, ARRAY_SEPARATOR);
if (value.equals(ARRAY_SEPARATOR)) { if (value.equals(ARRAY_SEPARATOR)) {
return new Integer[0]; return ret;
} }
String[] split = value.split(ARRAY_SEPARATOR); for (String s : value.split(ARRAY_SEPARATOR)) {
Integer[] ret = new Integer[split.length]; ret.add(Integer.parseInt(s));
for (int i = 0; i < ret.length; i++) {
ret[i] = Integer.parseInt(split[i]);
} }
return ret; return ret;
} }
public void setIntArray(@StringRes int keyResourceId, Integer[] values, final SharedPreferences... pref) {
setIntArray(rstr(keyResourceId), values, gp(pref));
}
public void setIntArray(String key, Integer[] values, final SharedPreferences... pref) {
setIntListOne(key, Arrays.asList(values), gp(pref));
}
public Integer[] getIntArray(@StringRes int keyResourceId, final SharedPreferences... pref) {
return getIntArray(rstr(keyResourceId), gp(pref));
}
public Integer[] getIntArray(String key, final SharedPreferences... pref) {
List<Integer> data = getIntListOne(key, gp(pref));
return data.toArray(new Integer[data.size()]);
}
public void setIntList(@StringRes int keyResourceId, List<Integer> values, final SharedPreferences... pref) { public void setIntList(@StringRes int keyResourceId, List<Integer> values, final SharedPreferences... pref) {
setIntArray(rstr(keyResourceId), values.toArray(new Integer[values.size()]), pref); setIntListOne(rstr(keyResourceId), values, gp(pref));
} }
public void setIntList(String key, List<Integer> values, final SharedPreferences... pref) { public void setIntList(String key, List<Integer> values, final SharedPreferences... pref) {
setIntArray(key, values.toArray(new Integer[values.size()]), pref); setIntListOne(key, values, gp(pref));
} }
public ArrayList<Integer> getIntList(@StringRes int keyResourceId, final SharedPreferences... pref) { public ArrayList<Integer> getIntList(@StringRes int keyResourceId, final SharedPreferences... pref) {
return new ArrayList<>(Arrays.asList(getIntArray(rstr(keyResourceId), gp(pref)))); return getIntListOne(rstr(keyResourceId), gp(pref));
} }
public ArrayList<Integer> getIntList(String key, final SharedPreferences... pref) { public ArrayList<Integer> getIntList(String key, final SharedPreferences... pref) {
return new ArrayList<>(Arrays.asList(getIntArray(key, gp(pref)))); return getIntListOne(key, gp(pref));
} }
@ -405,4 +406,95 @@ public class AppSettingsBase {
public int getColor(@StringRes int keyResourceId, @ColorRes int defaultColor, final SharedPreferences... pref) { public int getColor(@StringRes int keyResourceId, @ColorRes int defaultColor, final SharedPreferences... pref) {
return gp(pref).getInt(rstr(keyResourceId), rcolor(defaultColor)); return gp(pref).getInt(rstr(keyResourceId), rcolor(defaultColor));
} }
//
// PropertyBackend<String> implementations
//
@Override
public String getString(String key, String defaultValue) {
return getString(key, defaultValue, _prefApp);
}
@Override
public int getInt(String key, int defaultValue) {
return getInt(key, defaultValue, _prefApp);
}
@Override
public long getLong(String key, long defaultValue) {
return getLong(key, defaultValue, _prefApp);
}
@Override
public boolean getBool(String key, boolean defaultValue) {
return getBool(key, defaultValue, _prefApp);
}
@Override
public float getFloat(String key, float defaultValue) {
return getFloat(key, defaultValue, _prefApp);
}
@Override
public double getDouble(String key, double defaultValue) {
return getDouble(key, defaultValue, _prefApp);
}
@Override
public ArrayList<Integer> getIntList(String key) {
return getIntList(key, _prefApp);
}
@Override
public ArrayList<String> getStringList(String key) {
return getStringList(key, _prefApp);
}
@Override
public AppSettingsBase setString(String key, String value) {
setString(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setInt(String key, int value) {
setInt(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setLong(String key, long value) {
setLong(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setBool(String key, boolean value) {
setBool(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setFloat(String key, float value) {
setFloat(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setDouble(String key, double value) {
setDouble(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setIntList(String key, List<Integer> value) {
setIntListOne(key, value, _prefApp);
return this;
}
@Override
public AppSettingsBase setStringList(String key, List<String> value) {
setStringListOne(key, value, _prefApp);
return this;
}
} }

View file

@ -29,7 +29,6 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -47,7 +46,6 @@ 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.app.AlertDialog;
import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.AppCompatButton;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
@ -58,11 +56,12 @@ import android.util.DisplayMetrics;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.gsantner.opoc.format.markdown.SimpleMarkdownParser;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -152,7 +151,11 @@ public class ContextUtils {
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(Intent.FLAG_ACTIVITY_NEW_TASK);
_context.startActivity(intent); try {
_context.startActivity(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
} }
/** /**
@ -232,16 +235,6 @@ public class ContextUtils {
return sb.toString(); return sb.toString();
} }
public void showDialogWithRawFileInWebView(String fileInRaw, @StringRes int resTitleId) {
WebView wv = new WebView(_context);
wv.loadUrl("file:///android_res/raw/" + fileInRaw);
AlertDialog.Builder dialog = new AlertDialog.Builder(_context)
.setPositiveButton(android.R.string.ok, null)
.setTitle(resTitleId)
.setView(wv);
dialog.show();
}
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
@SuppressWarnings("RestrictedApi") @SuppressWarnings("RestrictedApi")
public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) { public void setTintColorOfButton(AppCompatButton button, @ColorRes int resColor) {
@ -519,11 +512,7 @@ public class ContextUtils {
public ContextUtils tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) { public ContextUtils 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);
Drawable drawable = item.getIcon(); tintDrawable(item.getIcon(), iconColor);
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(iconColor, PorterDuff.Mode.SRC_IN);
}
if (item.hasSubMenu() && recurse) { if (item.hasSubMenu() && recurse) {
tintMenuItems(item.getSubMenu(), recurse, iconColor); tintMenuItems(item.getSubMenu(), recurse, iconColor);
} }
@ -531,6 +520,18 @@ public class ContextUtils {
return this; return this;
} }
public Drawable tintDrawable(@DrawableRes int drawableRes, @ColorInt int color) {
return tintDrawable(_context.getResources().getDrawable(drawableRes), color);
}
public Drawable tintDrawable(@Nullable Drawable drawable, @ColorInt int color) {
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), color);
}
return drawable;
}
@SuppressLint("PrivateApi") @SuppressLint("PrivateApi")
public ContextUtils setSubMenuIconsVisiblity(Menu menu, boolean visible) { public ContextUtils setSubMenuIconsVisiblity(Menu menu, boolean visible) {
if (menu.getClass().getSimpleName().equals("MenuBuilder")) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) {

View file

@ -0,0 +1,50 @@
/*
* ------------------------------------------------------------------------------
* 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)
* http://creativecommons.org/publicdomain/zero/1.0/
* ----------------------------------------------------------------------------
*/
package net.gsantner.opoc.util;
import java.util.List;
@SuppressWarnings({"UnusedReturnValue", "SpellCheckingInspection"})
public interface PropertyBackend<TKEY, TTHIS> {
String getString(TKEY key, String defaultValue);
int getInt(TKEY key, int defaultValue);
long getLong(TKEY key, long defaultValue);
boolean getBool(TKEY key, boolean defaultValue);
float getFloat(TKEY key, float defaultValue);
double getDouble(TKEY key, double defaultValue);
List<Integer> getIntList(TKEY key);
List<String> getStringList(TKEY key);
TTHIS setString(TKEY key, String value);
TTHIS setInt(TKEY key, int value);
TTHIS setLong(TKEY key, long value);
TTHIS setBool(TKEY key, boolean value);
TTHIS setFloat(TKEY key, float value);
TTHIS setDouble(TKEY key, double value);
TTHIS setIntList(TKEY key, List<Integer> value);
TTHIS setStringList(TKEY key, List<String> value);
}

View file

@ -17,7 +17,7 @@
android:summary="@string/pref_desc__sub_nav_slider" android:summary="@string/pref_desc__sub_nav_slider"
android:title="@string/pref_title__sub_nav_slider"/> android:title="@string/pref_title__sub_nav_slider"/>
<net.gsantner.opoc.ui.LanguagePreference <net.gsantner.opoc.preference.nonsupport.LanguagePreference
android:icon="@drawable/ic_language_black_48px" android:icon="@drawable/ic_language_black_48px"
android:key="@string/pref_key__language" android:key="@string/pref_key__language"
android:summary="@string/pref_desc__language" android:summary="@string/pref_desc__language"

View file

@ -9,7 +9,7 @@ buildscript {
// https://developer.android.com/studio/releases/gradle-plugin.html // https://developer.android.com/studio/releases/gradle-plugin.html
ext.version_gradle_tools = "3.0.1" ext.version_gradle_tools = "3.0.1"
// https://developer.android.com/topic/libraries/support-library/revisions.html // https://developer.android.com/topic/libraries/support-library/revisions.html
ext.version_library_appcompat = "27.0.2" ext.version_library_appcompat = "27.1.0"
// https://github.com/JakeWharton/butterknife/releases // https://github.com/JakeWharton/butterknife/releases
ext.version_library_butterknife = "8.8.1" ext.version_library_butterknife = "8.8.1"
// https://github.com/atlassian/commonmark-java/releases // https://github.com/atlassian/commonmark-java/releases
@ -17,7 +17,7 @@ buildscript {
// https://github.com/guardianproject/NetCipher/releases // https://github.com/guardianproject/NetCipher/releases
ext.version_library_netcipher = "2.0.0-alpha1" ext.version_library_netcipher = "2.0.0-alpha1"
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin#LookAtCentral // https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin#LookAtCentral
ext.version_plugin_kotlin = "1.2.10" ext.version_plugin_kotlin = "1.2.21"
ext.enable_plugin_kotlin = false ext.enable_plugin_kotlin = false
repositories { repositories {