1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-21 20:02:07 +01:00

Change package ID of gsantner/opoc

This commit is contained in:
Gregor Santner 2017-09-09 17:09:04 +02:00
parent b3129e0e91
commit 15a34a1895
No known key found for this signature in database
GPG key ID: 7E83A7834AECB009
20 changed files with 360 additions and 77 deletions

View file

@ -34,7 +34,7 @@ import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import io.github.gsantner.opoc.util.AdBlock;
import net.gsantner.opoc.util.AdBlock;
public class App extends Application {
private volatile static App app;

View file

@ -52,7 +52,7 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedActivity;
import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
import java.util.Observable;
import java.util.Observer;
@ -212,13 +212,13 @@ public class AboutActivity extends ThemedActivity
public void buttonClicked(View view) {
switch (view.getId()) {
case R.id.fragment_about__contribute_button:
Helpers.get().openWebpageInExternalBrowser(getString(R.string.fragment_about__contribute_link));
ContextUtils.get().openWebpageInExternalBrowser(getString(R.string.fragment_about__contribute_link));
break;
case R.id.fragment_about__translate_button:
Helpers.get().openWebpageInExternalBrowser(getString(R.string.fragment_about__translate_link));
ContextUtils.get().openWebpageInExternalBrowser(getString(R.string.fragment_about__translate_link));
break;
case R.id.fragment_about__feedback_button:
Helpers.get().openWebpageInExternalBrowser(getString(R.string.fragment_About__feedback_link));
ContextUtils.get().openWebpageInExternalBrowser(getString(R.string.fragment_About__feedback_link));
break;
case R.id.fragment_about__spread_the_word_button:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
@ -263,14 +263,14 @@ public class AboutActivity extends ThemedActivity
View rootView = inflater.inflate(R.layout.about__fragment_license, container, false);
ButterKnife.bind(this, rootView);
final Context context = rootView.getContext();
accentColor = Helpers.get().colorToHexString(ThemeHelper.getAccentColor());
accentColor = ContextUtils.get().colorToHexString(ThemeHelper.getAccentColor());
maintainers.setTextFormatted(getString(R.string.fragment_license__maintainers_text,
Helpers.get().loadMarkdownForTextViewFromRaw(R.raw.maintainers, "")));
ContextUtils.get().loadMarkdownForTextViewFromRaw(R.raw.maintainers, "")));
contributors.setTextFormatted(getString(R.string.fragment_license__contributors_thank_you,
Helpers.get().loadMarkdownForTextViewFromRaw(R.raw.contributors, "")));
ContextUtils.get().loadMarkdownForTextViewFromRaw(R.raw.contributors, "")));
thirdPartyLibs.setTextFormatted(
Helpers.get().loadMarkdownForTextViewFromRaw(R.raw.license_third_party, ""));
ContextUtils.get().loadMarkdownForTextViewFromRaw(R.raw.license_third_party, ""));
return rootView;
}
@ -278,10 +278,10 @@ public class AboutActivity extends ThemedActivity
public void buttonClicked(View v) {
switch (v.getId()) {
case R.id.fragment_license__leafpic_button:
Helpers.get().openWebpageInExternalBrowser(getString(R.string.fragment_licesen__misc_leafpic_link));
ContextUtils.get().openWebpageInExternalBrowser(getString(R.string.fragment_licesen__misc_leafpic_link));
break;
case R.id.fragment_license__license_button:
Helpers.get().openWebpageInExternalBrowser(getString(R.string.fragment_license__license_gpl_link));
ContextUtils.get().openWebpageInExternalBrowser(getString(R.string.fragment_license__license_gpl_link));
break;
}
}

View file

@ -41,7 +41,7 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
import java.util.ArrayList;
import java.util.Arrays;
@ -174,7 +174,7 @@ public class AspectListFragment extends ThemedFragment implements OnSomethingCli
final DiasporaAspect aspect = aspectList[position];
holder.title.setText(aspect.name);
if (position % 2 == 1) {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Helpers.get().color(R.color.alternate_row_color));
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().color(R.color.alternate_row_color));
holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK);
} else {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE);

View file

@ -45,7 +45,7 @@ import com.github.dfa.diaspora_android.data.DiasporaUserProfile;
import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.web.BrowserFragment;
import com.github.dfa.diaspora_android.web.DiasporaStreamWebChromeClient;
import com.github.dfa.diaspora_android.web.FileUploadWebChromeClient;
@ -271,7 +271,7 @@ public class DiasporaStreamFragment extends BrowserFragment {
// Create the File where the photo should go
File photoFile;
try {
photoFile = Helpers.get().createImageFile();
photoFile = ContextUtils.get().createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
AppLog.e(this, "ERROR creating temp file: " + ex.toString());

View file

@ -78,7 +78,7 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedAlertDialogBuilder;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.HelpersA;
import com.github.dfa.diaspora_android.util.ActivityUtils;
import com.github.dfa.diaspora_android.web.BrowserFragment;
import com.github.dfa.diaspora_android.web.ContextMenuWebView;
import com.github.dfa.diaspora_android.web.ProxyHandler;
@ -90,7 +90,7 @@ import java.io.IOException;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.github.gsantner.opoc.util.SimpleMarkdownParser;
import net.gsantner.opoc.util.SimpleMarkdownParser;
public class MainActivity extends ThemedActivity
implements NavigationView.OnNavigationItemSelectedListener,
@ -230,12 +230,12 @@ public class MainActivity extends ThemedActivity
+ "<h1>" + getString(R.string.fragment_license__thirdparty_libs) + "</h1>"
+ mdParser.parse(getResources().openRawResource(R.raw.license_third_party), "");
html = mdParser.setHtml(html).removeMultiNewlines().getHtml();
HelpersA.get(this).showDialogWithHtmlTextView(R.string.about_activity__title_about_license, html);
ActivityUtils.get(this).showDialogWithHtmlTextView(R.string.about_activity__title_about_license, html);
appSettings.isAppCurrentVersionFirstStart();
} else if (appSettings.isAppCurrentVersionFirstStart()) {
SimpleMarkdownParser smp = new SimpleMarkdownParser().parse(
getResources().openRawResource(R.raw.changelog), "");
HelpersA.get(this).showDialogWithHtmlTextView(R.string.changelog, smp.getHtml());
ActivityUtils.get(this).showDialogWithHtmlTextView(R.string.changelog, smp.getHtml());
}
} catch (IOException e) {
e.printStackTrace();

View file

@ -55,8 +55,8 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.HelpersA;
import com.github.dfa.diaspora_android.util.ContextUtils;
import com.github.dfa.diaspora_android.util.ActivityUtils;
import org.json.JSONException;
import org.json.JSONObject;
@ -129,11 +129,11 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
}
});
LocalBroadcastManager.getInstance(getContext()).registerReceiver(podListReceiver, new IntentFilter(FetchPodsService.MESSAGE_PODS_RECEIVED));
HelpersA.get(getActivity()).showInfoIfUserNotConnectedToInternet(listViewPod);
ActivityUtils.get(getActivity()).showInfoIfUserNotConnectedToInternet(listViewPod);
}
public void mergePodlistWithRessources(DiasporaPodList podlist) {
String sPodlist = Helpers.get().readTextfileFromRawRes(R.raw.podlist, "", "");
String sPodlist = ContextUtils.get().readTextfileFromRawRes(R.raw.podlist, "", "");
try {
JSONObject jPodlist = new JSONObject(sPodlist);
podlist.mergeWithNewerEntries(new DiasporaPodList().fromJson(jPodlist));
@ -182,7 +182,7 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
buttonUseCustomPod.setTextColor(Color.WHITE);
} else {
buttonUseCustomPod.setSupportBackgroundTintList(ColorStateList.valueOf(appSettings.getAccentColor()));
buttonUseCustomPod.setTextColor(Helpers.get().shouldColorOnTopBeLight(appSettings.getAccentColor()) ? Color.WHITE : Color.BLACK);
buttonUseCustomPod.setTextColor(ContextUtils.get().shouldColorOnTopBeLight(appSettings.getAccentColor()) ? Color.WHITE : Color.BLACK);
}
}
@ -250,7 +250,7 @@ public class PodSelectionFragment extends ThemedFragment implements SearchView.O
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_reload: {
if (!HelpersA.get(getActivity()).showInfoIfUserNotConnectedToInternet(listViewPod)) {
if (!ActivityUtils.get(getActivity()).showInfoIfUserNotConnectedToInternet(listViewPod)) {
Intent i = new Intent(getContext(), FetchPodsService.class);
getContext().startService(i);
return true;

View file

@ -40,7 +40,7 @@ import com.github.dfa.diaspora_android.ui.theme.ThemedFragment;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
import java.util.ArrayList;
import java.util.Arrays;
@ -173,7 +173,7 @@ public class TagListFragment extends ThemedFragment implements OnSomethingClickL
final String tag = followedTagsList[position];
holder.title.setText(tag);
if (position % 2 == 1) {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Helpers.get().color(R.color.alternate_row_color));
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : ContextUtils.get().color(R.color.alternate_row_color));
holder.title.setTextColor(isAmoledColorMode ? Color.GRAY : Color.BLACK);
} else {
holder.root.setBackgroundColor(isAmoledColorMode ? Color.BLACK : Color.WHITE);

View file

@ -32,7 +32,7 @@ import android.support.annotation.NonNull;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
@SuppressWarnings("WeakerAccess")
public class BadgeDrawable extends Drawable {
@ -56,7 +56,7 @@ public class BadgeDrawable extends Drawable {
_badgeBackground.setStyle(Paint.Style.FILL);
_badgeText = new Paint();
_badgeText.setColor(Helpers.get().shouldColorOnTopBeLight(settings.getAccentColor()) ? Color.WHITE : Color.BLACK);
_badgeText.setColor(ContextUtils.get().shouldColorOnTopBeLight(settings.getAccentColor()) ? Color.WHITE : Color.BLACK);
_badgeText.setTypeface(Typeface.DEFAULT);
_badgeText.setTextSize(textSize);
_badgeText.setAntiAlias(true);
@ -71,7 +71,7 @@ public class BadgeDrawable extends Drawable {
Rect bounds = getBounds();
float width = bounds.right - bounds.left;
float height = bounds.bottom - bounds.top;
float oneDp = Helpers.get().dp2px(1);
float oneDp = ContextUtils.get().dp2px(1);
// Position the badge in the top-right quadrant of the icon.
float radius = ((Math.max(width, height) / 2)) / 2;

View file

@ -29,7 +29,7 @@ import android.support.v7.app.AppCompatActivity;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
import java.util.Locale;
@ -99,7 +99,7 @@ public abstract class ThemedActivity extends AppCompatActivity {
public void updateLanguage() {
AppSettings appSettings = getAppSettings();
Locale locale = Helpers.get().getLocaleByAndroidCode(appSettings.getLanguage());
Locale locale = ContextUtils.get().getLocaleByAndroidCode(appSettings.getLanguage());
Configuration config = appSettings.getContext().getResources().getConfiguration();
config.locale = locale != null ? locale : Locale.getDefault();
appSettings.getContext().getResources().updateConfiguration(config, null);

View file

@ -10,7 +10,7 @@ import android.widget.ImageView;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.AppSettings;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.ContextUtils;
/**
* Preference that shows selected Color in a circle
@ -50,7 +50,7 @@ public class ThemedColorPickerPreference extends Preference implements Themeable
AppSettings appSettings = AppSettings.get();
String key = getKey();
int color = Helpers.get().color(R.color.primary);
int color = ContextUtils.get().color(R.color.primary);
if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) {
color = appSettings.getPrimaryColor();
} else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) {

View file

@ -16,21 +16,21 @@ import java.util.Date;
import java.util.Locale;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue"})
public class HelpersA extends io.github.gsantner.opoc.util.HelpersA {
protected HelpersA(Activity activity) {
public class ActivityUtils extends net.gsantner.opoc.util.ActivityUtils {
protected ActivityUtils(Activity activity) {
super(activity);
}
public static HelpersA get(Activity activity) {
return new HelpersA(activity);
public static ActivityUtils get(Activity activity) {
return new ActivityUtils(activity);
}
public File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
AppLog.d(HelpersA.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
AppLog.d(ActivityUtils.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
return new File(

View file

@ -31,7 +31,7 @@ import org.json.JSONObject;
import java.util.List;
import io.github.gsantner.opoc.util.AppSettingsBase;
import net.gsantner.opoc.util.AppSettingsBase;
/**
* Settings

View file

@ -14,21 +14,21 @@ import java.util.Date;
import java.util.Locale;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue"})
public class Helpers extends io.github.gsantner.opoc.util.Helpers {
protected Helpers(Context context) {
public class ContextUtils extends net.gsantner.opoc.util.ContextUtils {
protected ContextUtils(Context context) {
super(context);
}
public static Helpers get() {
return new Helpers(App.get());
public static ContextUtils get() {
return new ContextUtils(App.get());
}
public File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
AppLog.d(Helpers.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
AppLog.d(ContextUtils.class, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
return new File(

View file

@ -32,7 +32,7 @@ import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.DiasporaPodList;
import com.github.dfa.diaspora_android.util.AppSettings;
import io.github.gsantner.opoc.util.AdBlock;
import net.gsantner.opoc.util.AdBlock;
public class CustomWebViewClient extends WebViewClient {
private final App app;

View file

@ -0,0 +1,149 @@
/*
* ------------------------------------------------------------------------------
* 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/
* ----------------------------------------------------------------------------
*/
/*
* A ListPreference that displays a list of available languages
* Requires:
* The BuildConfig field "APPLICATION_LANGUAGES" which is a array of all available languages
* opoc/ContextUtils
* BuildConfig field can be defined by using the method below
buildConfigField("String[]", "APPLICATION_LANGUAGES", '{' + getUsedAndroidLanguages().collect {"\"${it}\""}.join(",") + '}')
@SuppressWarnings(["UnnecessaryQualifiedReference", "SpellCheckingInspection"])
static String[] getUsedAndroidLanguages() {
Set<String> langs = new HashSet<>()
new File('.').eachFileRecurse(groovy.io.FileType.DIRECTORIES) {
final foldername = it.name
if (foldername.startsWith('values-') && !it.canonicalPath.contains("build" + File.separator + "intermediates")) {
new File(it.toString()).eachFileRecurse(groovy.io.FileType.FILES) {
if (it.name.toLowerCase().endsWith(".xml") && it.getCanonicalFile().getText('UTF-8').contains("<string")) {
langs.add(foldername.replace("values-", ""))
}
}
}
}
return langs.toArray(new String[langs.size()])
}
* Summary: Change language of this app. Restart app for changes to take effect
* Define element in Preferences-XML:
<!--suppress AndroidDomInspection -->
<net.gsantner.opoc.ui.LanguagePreference
android:icon="@drawable/ic_language_black_24dp"
android:defaultValue=""
android:key="@string/pref_key__language"
android:summary="@string/pref_desc__language"
android:title="@string/pref_title__language"/>
*/
package net.gsantner.opoc.ui;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.preference.ListPreference;
import android.util.AttributeSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import net.gsantner.opoc.util.ContextUtils;
/**
* A {@link android.preference.ListPreference} that displays a list of languages to select from
*/
@SuppressWarnings({"unused", "SpellCheckingInspection"})
public class LanguagePreference extends ListPreference {
public LanguagePreference(Context context) {
super(context);
init(context, null);
}
public LanguagePreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LanguagePreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public LanguagePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
@Override
protected boolean callChangeListener(Object newValue) {
if (newValue instanceof String) {
// Does not apply to existing UI, use recreate()
new ContextUtils(getContext()).setAppLanguage((String) newValue);
}
return super.callChangeListener(newValue);
}
private void init(Context context, AttributeSet attrs) {
// Fetch readable details
ContextUtils ContextUtils = new ContextUtils(context);
List<String> languages = new ArrayList<>();
Object bcof = ContextUtils.getBuildConfigValue("APPLICATION_LANGUAGES");
if (bcof instanceof String[]) {
for (String langId : (String[]) bcof) {
Locale locale = ContextUtils.getLocaleByAndroidCode(langId);
languages.add(summarizeLocale(locale) + ";" + langId);
}
}
// Sort languages naturally
Collections.sort(languages);
// Show in UI
String[] entries = new String[languages.size() + 2];
String[] entryval = new String[languages.size() + 2];
for (int i = 0; i < languages.size(); i++) {
entries[i + 2] = languages.get(i).split(";")[0];
entryval[i + 2] = languages.get(i).split(";")[1];
}
entries[0] = "System";
entryval[0] = "";
entries[1] = "English";
entryval[1] = "en";
setEntries(entries);
setEntryValues(entryval);
}
// Concat english and localized language name
// Append country if country specific (e.g. Portuguese Brazil)
private String summarizeLocale(Locale locale) {
String country = locale.getDisplayCountry(locale);
String language = locale.getDisplayLanguage(locale);
return locale.getDisplayLanguage(Locale.ENGLISH)
+ " (" + language.substring(0, 1).toUpperCase() + language.substring(1)
+ ((!country.isEmpty() && !country.toLowerCase().equals(language.toLowerCase())) ? (", " + country) : "")
+ ")";
}
// Add current language to summary
@Override
public CharSequence getSummary() {
Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
return super.getSummary() + "\n\n" + summarizeLocale(locale);
}
}

View file

@ -9,7 +9,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/
* ----------------------------------------------------------------------------
*/
package io.github.gsantner.opoc.util;
package net.gsantner.opoc.util;
import android.app.Activity;
import android.content.DialogInterface;
@ -22,17 +22,18 @@ import android.text.Html;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection"})
public class HelpersA extends Helpers {
public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
//########################
//## Members, Constructors
//########################
protected Activity _activity;
public HelpersA(final Activity activity) {
public ActivityUtils(final Activity activity) {
super(activity);
_activity = activity;
}
@ -106,4 +107,18 @@ public class HelpersA extends Helpers {
.setView(textView);
dialog.show();
}
// Toggle with no param, else set visibility according to first bool
public void toggleStatusbarVisibility(boolean... optionalForceVisible) {
WindowManager.LayoutParams attrs = _activity.getWindow().getAttributes();
int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
if (optionalForceVisible.length == 0) {
attrs.flags ^= flag;
} else if (optionalForceVisible.length == 1 && optionalForceVisible[0]) {
attrs.flags &= ~flag;
} else {
attrs.flags |= flag;
}
_activity.getWindow().setAttributes(attrs);
}
}

View file

@ -24,7 +24,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
: super.shouldInterceptRequest(view, url);
}
*/
package io.github.gsantner.opoc.util;
package net.gsantner.opoc.util;
import android.content.Context;
import android.util.Log;
@ -47,7 +47,7 @@ import java.util.Set;
/**
* Simple Host-Based AdBlocker
*/
@SuppressWarnings({"WeakerAccess", "SpellCheckingInspection"})
@SuppressWarnings({"WeakerAccess", "SpellCheckingInspection", "unused"})
public class AdBlock {
private static final AdBlock instance = new AdBlock();
@ -60,9 +60,9 @@ public class AdBlock {
//## Members
//##
//########################
private final Set<String> adblockHostsFromRaw = new HashSet<>();
private final Set<String> adblockHosts = new HashSet<>();
private boolean isLoaded;
private final Set<String> _adblockHostsFromRaw = new HashSet<>();
private final Set<String> _adblockHosts = new HashSet<>();
private boolean _isLoaded;
//########################
//##
@ -80,7 +80,7 @@ public class AdBlock {
if (host.startsWith("www.") && host.length() >= 4) {
host = host.substring(4);
}
return adblockHosts.contains(host) || adblockHosts.contains("www." + host);
return _adblockHosts.contains(host) || _adblockHosts.contains("www." + host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
@ -90,11 +90,15 @@ public class AdBlock {
}
public AdBlock reset() {
adblockHosts.clear();
adblockHosts.addAll(adblockHostsFromRaw);
_adblockHosts.clear();
_adblockHosts.addAll(_adblockHostsFromRaw);
return this;
}
public boolean isLoaded() {
return _isLoaded;
}
public static WebResourceResponse createEmptyResponse() {
return new WebResourceResponse("text/plain", "utf-8", new ByteArrayInputStream("".getBytes()));
}
@ -107,7 +111,7 @@ public class AdBlock {
host = host.substring(4);
}
if (!host.startsWith("#") && !host.startsWith("\"")) {
adblockHosts.add(host);
_adblockHosts.add(host);
}
}
}
@ -120,7 +124,7 @@ public class AdBlock {
public void run() {
try {
loadHostsFromRawAssets(context);
isLoaded = true;
_isLoaded = true;
} catch (IOException e) {
e.printStackTrace();
}
@ -132,7 +136,7 @@ public class AdBlock {
BufferedReader br = null;
String host;
adblockHosts.clear();
_adblockHosts.clear();
for (int rawId : getAdblockIdsInRaw()) {
try {
br = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(rawId)));
@ -150,8 +154,8 @@ public class AdBlock {
}
}
}
adblockHostsFromRaw.clear();
adblockHostsFromRaw.addAll(adblockHosts);
_adblockHostsFromRaw.clear();
_adblockHostsFromRaw.addAll(_adblockHosts);
}
private List<Integer> getAdblockIdsInRaw() {

View file

@ -11,8 +11,6 @@
*/
/*
* Get updates:
* https://github.com/gsantner/onePieceOfCode/blob/master/java/AppSettingsBase.java
* This is a wrapper for settings based on SharedPreferences
* with keys in resources. Extend from this class and add
* getters/setters for the app's settings.
@ -44,7 +42,7 @@
}
*/
package io.github.gsantner.opoc.util;
package net.gsantner.opoc.util;
import android.annotation.SuppressLint;
import android.content.Context;
@ -73,9 +71,9 @@ public class AppSettingsBase {
//########################
//## Members, Constructors
//########################
protected final Context _context;
protected final SharedPreferences _prefApp;
protected final String _prefAppName;
protected final Context _context;
public AppSettingsBase(final Context context) {
this(context, SHARED_PREF_APP);

View file

@ -9,7 +9,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/
* ----------------------------------------------------------------------------
*/
package io.github.gsantner.opoc.util;
package net.gsantner.opoc.util;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
@ -22,16 +22,26 @@ import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.RawRes;
import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatButton;
import android.text.Html;
@ -40,22 +50,31 @@ import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;
import static android.graphics.Bitmap.CompressFormat;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation"})
public class Helpers {
public class ContextUtils {
//########################
//## Members, Constructors
//########################
protected Context _context;
public Helpers(Context context) {
public ContextUtils(Context context) {
_context = context;
}
@ -231,6 +250,14 @@ public class Helpers {
return activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
}
public boolean isConnectedToInternet(@Nullable @StringRes Integer warnMessageStringRes) {
final boolean result = isConnectedToInternet();
if (!result && warnMessageStringRes != null)
Toast.makeText(_context, _context.getString(warnMessageStringRes), Toast.LENGTH_SHORT).show();
return result;
}
public void restartApp(Class classToStartupWith) {
Intent restartIntent = new Intent(_context, classToStartupWith);
PendingIntent restartIntentP = PendingIntent.getActivity(_context, 555,
@ -317,4 +344,94 @@ public class Helpers {
public float dp2px(final float dp) {
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) {
imageView.setImageResource(drawableResId);
imageView.setColorFilter(ContextCompat.getColor(imageView.getContext(), colorResId));
}
public Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = null;
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 = (DrawableCompat.wrap(drawable)).mutate();
}
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} else if (drawable instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
}
return bitmap;
}
public Bitmap loadImageFromFilesystem(String imagePath, int maxDimen) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, options);
options.inSampleSize = calculateInSampleSize(options, maxDimen);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(imagePath, options);
}
/**
* Calculates the scaling factor so the bitmap is maximal as big as the maxDimen
*
* @param options Bitmap-options that contain the current dimensions of the bitmap
* @param maxDimen Max size of the Bitmap (width or height)
* @return the scaling factor that needs to be applied to the bitmap
*/
public int calculateInSampleSize(BitmapFactory.Options options, int maxDimen) {
// Raw height and width of image
int height = options.outHeight;
int width = options.outWidth;
int inSampleSize = 1;
if (Math.max(height, width) > maxDimen) {
inSampleSize = Math.round(1f * Math.max(height, width) / maxDimen);
}
return inSampleSize;
}
public Bitmap scaleBitmap(Bitmap bitmap, int maxDimen) {
int picSize = Math.min(bitmap.getHeight(), bitmap.getWidth());
float scale = 1.f * maxDimen / picSize;
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
public File writeImageToFileJpeg(String path, String filename, Bitmap image) {
return writeImageToFile(path, filename, image, Bitmap.CompressFormat.JPEG, 95);
}
public File writeImageToFile(String path, String filename, Bitmap image, CompressFormat format, int quality) {
File imageFile = new File(path);
if (imageFile.exists() || imageFile.mkdirs()) {
imageFile = new File(path, filename);
FileOutputStream stream = null;
try {
stream = new FileOutputStream(imageFile); // overwrites this image every time
image.compress(format, quality, stream);
return imageFile;
} catch (FileNotFoundException ignored) {
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException ignored) {
}
}
}
return null;
}
}

View file

@ -14,7 +14,7 @@
* Get updates:
* https://github.com/gsantner/onePieceOfCode/blob/master/java/SimpleMarkdownParser.java
* Apply to TextView:
* See https://github.com/gsantner/onePieceOfCode/blob/master/android/Helpers.get().java
* See https://github.com/gsantner/onePieceOfCode/blob/master/android/ContextUtils.java
* 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.
*
@ -27,7 +27,7 @@
* FILTER_WEB is intended to be used at engines understanding most common HTML tags.
*/
package io.github.gsantner.opoc.util;
package net.gsantner.opoc.util;
import java.io.BufferedReader;
import java.io.FileInputStream;
@ -130,13 +130,13 @@ public class SimpleMarkdownParser {
//########################
//## Singleton
//########################
private static SimpleMarkdownParser instance;
private static SimpleMarkdownParser __instance;
public static SimpleMarkdownParser get() {
if (instance == null) {
instance = new SimpleMarkdownParser();
if (__instance == null) {
__instance = new SimpleMarkdownParser();
}
return instance;
return __instance;
}
//########################
@ -152,8 +152,8 @@ public class SimpleMarkdownParser {
//########################
//## Methods
//########################
public SimpleMarkdownParser setDefaultSmpFilter(SmpFilter _defaultSmpFilter) {
this._defaultSmpFilter = _defaultSmpFilter;
public SimpleMarkdownParser setDefaultSmpFilter(SmpFilter defaultSmpFilter) {
_defaultSmpFilter = defaultSmpFilter;
return this;
}