mirror of
https://github.com/gsantner/dandelion
synced 2024-11-24 21:32:07 +01:00
Remove metadata...again
This commit is contained in:
parent
ac8b8469b0
commit
34882ba69f
4 changed files with 106 additions and 21 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "metadata"]
|
||||
path = metadata
|
||||
url = https://github.com/diaspora-for-android/dandelion-metadata-latest.git
|
|
@ -51,6 +51,7 @@ import android.annotation.TargetApi;
|
|||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.preference.ListPreference;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import net.gsantner.opoc.util.ContextUtils;
|
||||
|
@ -66,32 +67,31 @@ import java.util.Locale;
|
|||
@SuppressWarnings({"unused", "SpellCheckingInspection", "WeakerAccess"})
|
||||
public class LanguagePreference extends ListPreference {
|
||||
private static final String SYSTEM_LANGUAGE_CODE = "";
|
||||
public static String SYSTEM_LANGUAGE_NAME = "System";
|
||||
|
||||
// The language of res/values/ -> (usually English)
|
||||
public static String DEFAULT_LANGUAGE_NAME = "English";
|
||||
public static String DEFAULT_LANGUAGE_CODE = "en";
|
||||
public String _systemLanguageName = "★System★";
|
||||
public String _defaultLanguageCode = "en";
|
||||
|
||||
public LanguagePreference(Context context) {
|
||||
super(context);
|
||||
init(context, null);
|
||||
loadLangs(context, null);
|
||||
}
|
||||
|
||||
public LanguagePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
loadLangs(context, attrs);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public LanguagePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
loadLangs(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);
|
||||
loadLangs(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,7 +103,12 @@ public class LanguagePreference extends ListPreference {
|
|||
return super.callChangeListener(newValue);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
|
||||
private void loadLangs(Context context) {
|
||||
loadLangs(context, null);
|
||||
}
|
||||
|
||||
private void loadLangs(Context context, @Nullable AttributeSet attrs) {
|
||||
setDefaultValue(SYSTEM_LANGUAGE_CODE);
|
||||
|
||||
// Fetch readable details
|
||||
|
@ -127,10 +132,10 @@ public class LanguagePreference extends ListPreference {
|
|||
entries[i + 2] = languages.get(i).split(";")[0];
|
||||
entryval[i + 2] = languages.get(i).split(";")[1];
|
||||
}
|
||||
entries[0] = SYSTEM_LANGUAGE_NAME;
|
||||
entryval[0] = SYSTEM_LANGUAGE_CODE;
|
||||
entries[1] = DEFAULT_LANGUAGE_NAME;
|
||||
entryval[1] = DEFAULT_LANGUAGE_CODE;
|
||||
entries[0] = _systemLanguageName + "\n[" + summarizeLocale(context.getResources().getConfiguration().locale) + "]";
|
||||
entryval[1] = _defaultLanguageCode;
|
||||
entries[1] = summarizeLocale(contextUtils.getLocaleByAndroidCode(_defaultLanguageCode));
|
||||
|
||||
setEntries(entries);
|
||||
setEntryValues(entryval);
|
||||
|
@ -153,4 +158,22 @@ public class LanguagePreference extends ListPreference {
|
|||
Locale locale = new ContextUtils(getContext()).getLocaleByAndroidCode(getValue());
|
||||
return super.getSummary() + "\n\n" + summarizeLocale(locale);
|
||||
}
|
||||
|
||||
public String getSystemLanguageName() {
|
||||
return _systemLanguageName;
|
||||
}
|
||||
|
||||
public void setSystemLanguageName(String systemLanguageName) {
|
||||
_systemLanguageName = systemLanguageName;
|
||||
loadLangs(getContext());
|
||||
}
|
||||
|
||||
public String getDefaultLanguageCode() {
|
||||
return _defaultLanguageCode;
|
||||
}
|
||||
|
||||
public void setDefaultLanguageCode(String defaultLanguageCode) {
|
||||
_defaultLanguageCode = defaultLanguageCode;
|
||||
loadLangs(getContext());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
|
@ -27,6 +28,8 @@ import android.graphics.BitmapFactory;
|
|||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
|
@ -66,7 +69,7 @@ import java.util.Locale;
|
|||
|
||||
import static android.graphics.Bitmap.CompressFormat;
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation"})
|
||||
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation", "ObsoleteSdkInt"})
|
||||
public class ContextUtils {
|
||||
//########################
|
||||
//## Members, Constructors
|
||||
|
@ -242,10 +245,10 @@ public class ContextUtils {
|
|||
));
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission") // ACCESS_NETWORK_STATE required
|
||||
public boolean isConnectedToInternet() {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager)
|
||||
_context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
|
||||
ConnectivityManager con = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetInfo = con == null ? null : con.getActiveNetworkInfo();
|
||||
return activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
|
||||
}
|
||||
|
||||
|
@ -336,6 +339,29 @@ public class ContextUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void setClipboard(String text) {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
((android.text.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).setText(text);
|
||||
} else {
|
||||
ClipData clip = ClipData.newPlainText(_context.getPackageName(), text);
|
||||
((android.content.ClipboardManager) _context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(clip);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public float px2dp(final float px) {
|
||||
return px / _context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
@ -388,7 +414,7 @@ public class ContextUtils {
|
|||
* @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 conf
|
||||
// Raw height and width of image
|
||||
int height = options.outHeight;
|
||||
int width = options.outWidth;
|
||||
int inSampleSize = 1;
|
||||
|
@ -429,7 +455,7 @@ public class ContextUtils {
|
|||
if (folder.exists() || folder.mkdirs()) {
|
||||
FileOutputStream stream = null;
|
||||
try {
|
||||
stream = new FileOutputStream(imageFile); // overwrites this conf every time
|
||||
stream = new FileOutputStream(imageFile); // overwrites this image every time
|
||||
image.compress(format, quality, stream);
|
||||
return imageFile;
|
||||
} catch (FileNotFoundException ignored) {
|
||||
|
@ -444,4 +470,44 @@ public class ContextUtils {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bitmap drawTextToDrawable(@DrawableRes int resId, String text, int textSize) {
|
||||
Resources resources = _context.getResources();
|
||||
float scale = resources.getDisplayMetrics().density;
|
||||
Bitmap bitmap = getBitmapFromDrawable(resId);
|
||||
|
||||
bitmap = bitmap.copy(bitmap.getConfig(), true);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setColor(Color.rgb(61, 61, 61));
|
||||
paint.setTextSize((int) (textSize * scale));
|
||||
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
|
||||
|
||||
Rect bounds = new Rect();
|
||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
||||
int x = (bitmap.getWidth() - bounds.width()) / 2;
|
||||
int y = (bitmap.getHeight() + bounds.height()) / 2;
|
||||
canvas.drawText(text, x, y, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public Bitmap getBitmapFromDrawable(int drawableId) {
|
||||
Bitmap bitmap = null;
|
||||
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 = (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;
|
||||
}
|
||||
}
|
||||
|
|
1
metadata
1
metadata
|
@ -1 +0,0 @@
|
|||
Subproject commit 0f83b91174b5dc0eb72479fd0d63e5e7c0bd40cc
|
Loading…
Reference in a new issue