...
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.thefinestartist.utils;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.utils.preferences.PreferencesUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Tests of the {@link PreferencesUtil} class.
|
||||
*
|
||||
* @author Robin Gustafsson
|
||||
*/
|
||||
public class PreferencesUtilTest extends AndroidTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Base.initialize(getContext());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testSetGetDefaultName() {
|
||||
final String expected = "TEST_DEFAULT_NAME";
|
||||
|
||||
PreferencesUtil.setDefaultName(expected);
|
||||
String actual = PreferencesUtil.getDefaultName();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testDifferentNames() {
|
||||
final String name1 = "TEST_DIFFERENTNAMES_NAME1";
|
||||
final String name2 = "TEST_DIFFERENTNAMES_NAME2";
|
||||
final String key = "TEST_DIFFERENTNAMES_KEY";
|
||||
final boolean value = true;
|
||||
final boolean expected = false;
|
||||
|
||||
PreferencesUtil.put(name1, key, value);
|
||||
boolean actual = PreferencesUtil.get(name2, key, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreBoolean() {
|
||||
final String key = "TEST_BOOLEAN";
|
||||
final boolean expected = true;
|
||||
final boolean defValue = false;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
boolean actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreBooleanNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_BOOLEAN";
|
||||
final boolean expected = true;
|
||||
final boolean defValue = false;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
boolean actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreInt() {
|
||||
final String key = "TEST_INT";
|
||||
final int expected = 321;
|
||||
final int defValue = 0;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
int actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreIntNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_INT";
|
||||
final int expected = 321;
|
||||
final int defValue = 0;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
int actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreFloat() {
|
||||
final String key = "TEST_FLOAT";
|
||||
final float expected = 12.3f;
|
||||
final float defValue = 0.0f;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
float actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreFloatNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_FLOAT";
|
||||
final float expected = 12.3f;
|
||||
final float defValue = 0.0f;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
float actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreLong() {
|
||||
final String key = "TEST_LONG";
|
||||
final long expected = 321L;
|
||||
final long defValue = 0L;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
long actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreLongNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_LONG";
|
||||
final long expected = 321L;
|
||||
final long defValue = 0L;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
long actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreString() {
|
||||
final String key = "TEST_STRING";
|
||||
final String expected = "Lorem ipsum";
|
||||
final String defValue = null;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
String actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreStringNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_STRING";
|
||||
final String expected = "Lorem ipsum";
|
||||
final String defValue = null;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
String actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreStringSet() {
|
||||
final String key = "TEST_STRINGSET";
|
||||
final Set<String> expected = new HashSet<>();
|
||||
expected.add("Lorem ipsum");
|
||||
expected.add("dolor sit amet");
|
||||
expected.add("consectetur adipiscing elit");
|
||||
final Set<String> defValue = null;
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
Set<String> actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testStoreStringSetNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_STRINGSET";
|
||||
final Set<String> expected = new HashSet<>();
|
||||
expected.add("Lorem ipsum");
|
||||
expected.add("dolor sit amet");
|
||||
expected.add("consectetur adipiscing elit");
|
||||
final Set<String> defValue = null;
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
Set<String> actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testStoreSerializable() {
|
||||
final String key = "TEST_SERIALIZABLE";
|
||||
final ArrayList<String> expected = new ArrayList<>();
|
||||
expected.add("Lorem ipsum");
|
||||
expected.add("dolor sit amet");
|
||||
expected.add("consectetur adipiscing elit");
|
||||
final ArrayList<String> defValue = new ArrayList<>();
|
||||
defValue.add("Proin mollis dictum");
|
||||
|
||||
PreferencesUtil.put(key, expected);
|
||||
ArrayList<String> actual = PreferencesUtil.get(key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testStoreSerializableNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_SERIALIZABLE";
|
||||
final ArrayList<String> expected = new ArrayList<>();
|
||||
expected.add("Lorem ipsum");
|
||||
expected.add("dolor sit amet");
|
||||
expected.add("consectetur adipiscing elit");
|
||||
final ArrayList<String> defValue = new ArrayList<>();
|
||||
defValue.add("Proin mollis dictum");
|
||||
|
||||
PreferencesUtil.put(name, key, expected);
|
||||
ArrayList<String> actual = PreferencesUtil.get(name, key, defValue);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testRemove() {
|
||||
final String key = "TEST_REMOVE";
|
||||
final String expected = null;
|
||||
|
||||
PreferencesUtil.put(key, "Lorem ipsum");
|
||||
PreferencesUtil.remove(key);
|
||||
String actual = PreferencesUtil.get(key, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testRemoveNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String key = "TEST_REMOVE";
|
||||
final String expected = null;
|
||||
|
||||
PreferencesUtil.put(name, key, "Lorem ipsum");
|
||||
PreferencesUtil.remove(name, key);
|
||||
String actual = PreferencesUtil.get(name, key, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testClear() {
|
||||
final String[] keys = {"TEST_REMOVE_1", "TEST_REMOVE_2", "TEST_REMOVE_2"};
|
||||
final String expected = null;
|
||||
|
||||
for (String key : keys) {
|
||||
PreferencesUtil.put(key, "Lorem ipsum");
|
||||
}
|
||||
PreferencesUtil.clear();
|
||||
for (String key : keys) {
|
||||
String actual = PreferencesUtil.get(key, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testClearNamed() {
|
||||
final String name = "TEST_NAMED";
|
||||
final String[] keys = {"TEST_REMOVE_1", "TEST_REMOVE_2", "TEST_REMOVE_2"};
|
||||
final String expected = null;
|
||||
|
||||
for (String key : keys) {
|
||||
PreferencesUtil.put(name, key, "Lorem ipsum");
|
||||
}
|
||||
PreferencesUtil.clear(name);
|
||||
for (String key : keys) {
|
||||
String actual = PreferencesUtil.get(name, key, expected);
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<manifest package="com.thefinestartist.helpers"/>
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.thefinestartist;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Base helps to get {@link Context}, {@link Resources}, {@link AssetManager}, {@link Configuration} and {@link DisplayMetrics} in any class.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Base {
|
||||
|
||||
private static Context context;
|
||||
|
||||
public static void initialize(@NonNull Context context) {
|
||||
Base.context = context;
|
||||
}
|
||||
|
||||
public static Context getContext() {
|
||||
synchronized (Base.class) {
|
||||
if (Base.context == null)
|
||||
throw new NullPointerException("Call Base.initialize(context) within your Application onCreate() method.");
|
||||
|
||||
return Base.context.getApplicationContext();
|
||||
}
|
||||
}
|
||||
|
||||
public static Resources getResources() {
|
||||
return Base.getContext().getResources();
|
||||
}
|
||||
|
||||
public static Resources.Theme getTheme() {
|
||||
return Base.getContext().getTheme();
|
||||
}
|
||||
|
||||
public static AssetManager getAssets() {
|
||||
return Base.getContext().getAssets();
|
||||
}
|
||||
|
||||
public static Configuration getConfiguration() {
|
||||
return Base.getResources().getConfiguration();
|
||||
}
|
||||
|
||||
public static DisplayMetrics getDisplayMetrics() {
|
||||
return Base.getResources().getDisplayMetrics();
|
||||
}
|
||||
}
|
||||
// TODO: Thread safety
|
||||
// TODO: ripple, bitmap, time, contact list, picture list, video list, connectivity, wake lock, screen lock/off/on, get attributes, cookie, audio
|
||||
// TODO: keystore
|
||||
// TODO: http://jo.centis1504.net/?p=1189
|
||||
// TODO: Test codes
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.thefinestartist.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.CLASS;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Bind a field to the bundle data for the specific key.
|
||||
* <pre><code>
|
||||
* {@literal @}Extra(EXTRA_TITLE) String title;
|
||||
* </code></pre>
|
||||
*/
|
||||
@Retention(CLASS)
|
||||
@Target(FIELD)
|
||||
public @interface Extra {
|
||||
String value() default "";
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.thefinestartist.binders;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* ExtrasBinder binds data from {@link Intent} or {@link Bundle} to matching variable.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ExtrasBinder {
|
||||
|
||||
static final String SUFFIX = "$$ExtraBinder";
|
||||
|
||||
public static void bind(Activity activity) {
|
||||
if (activity == null)
|
||||
return;
|
||||
|
||||
bindObject(activity);
|
||||
}
|
||||
|
||||
public static void bind(Fragment fragment) {
|
||||
if (fragment == null)
|
||||
return;
|
||||
|
||||
bindObject(fragment);
|
||||
}
|
||||
|
||||
public static void bind(android.app.Fragment fragment) {
|
||||
if (fragment == null)
|
||||
return;
|
||||
|
||||
bindObject(fragment);
|
||||
}
|
||||
|
||||
private static void bindObject(@NonNull Object object) {
|
||||
try {
|
||||
Class<?> binder = Class.forName(object.getClass().getName() + SUFFIX);
|
||||
Method bind = binder.getMethod("bind", object.getClass());
|
||||
bind.invoke(null, object);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to bind extras for " + object, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.thefinestartist.builders;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.utils.content.ContextUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* ActivityBuilder helps to build {@link Activity} {@link Intent} and start {@link Activity}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ActivityBuilder {
|
||||
|
||||
final Intent intent;
|
||||
|
||||
public <C extends Activity> ActivityBuilder(@NonNull Class<C> clazz) {
|
||||
intent = new Intent(Base.getContext(), clazz);
|
||||
}
|
||||
|
||||
public <T extends Serializable> ActivityBuilder set(@NonNull String key, T value) {
|
||||
intent.putExtra(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityBuilder set(@NonNull String key, Parcelable value) {
|
||||
intent.putExtra(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityBuilder set(@NonNull String key, Parcelable[] value) {
|
||||
intent.putExtra(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends Parcelable> ActivityBuilder set(@NonNull String key, ArrayList<T> value) {
|
||||
intent.putExtra(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityBuilder remove(@NonNull String key) {
|
||||
intent.removeExtra(key);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityBuilder setFlags(int flags) {
|
||||
intent.setFlags(flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActivityBuilder addFlags(int flags) {
|
||||
intent.addFlags(flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Intent buildIntent() {
|
||||
return intent;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
ContextUtil.startActivity(intent);
|
||||
}
|
||||
|
||||
public void startForResult(@NonNull Activity activity, int requestCode) {
|
||||
activity.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public void startForResult(@NonNull Activity activity, int requestCode, @Nullable Bundle options) {
|
||||
activity.startActivityForResult(intent, requestCode, options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.thefinestartist.builders;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* BundleBuilder helps to build {@link Bundle} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class BundleBuilder {
|
||||
|
||||
final Bundle bundle = new Bundle();
|
||||
|
||||
public <T extends Serializable> BundleBuilder set(String key, T value) {
|
||||
bundle.putSerializable(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BundleBuilder set(String key, Parcelable value) {
|
||||
bundle.putParcelable(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> T get(String key) {
|
||||
return (T) bundle.getSerializable(key);
|
||||
}
|
||||
|
||||
public Bundle build() {
|
||||
return bundle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.converters;
|
||||
|
||||
/**
|
||||
* Unit is abbreviation class of {@link UnitConverter}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Unit extends UnitConverter {
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.thefinestartist.converters;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* UnitConverter helps to convert dp or sp size into pixel.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class UnitConverter {
|
||||
|
||||
public static float dpToPx(float dp) {
|
||||
return dp * Base.getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public static int dpToPx(int dp) {
|
||||
return (int) (dp * Base.getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
public static float pxToDp(float px) {
|
||||
return px / Base.getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public static int pxToDp(int px) {
|
||||
return (int) (px / Base.getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
public static float spToPx(float sp) {
|
||||
return sp * Base.getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
|
||||
public static int spToPx(int sp) {
|
||||
return (int) (sp * Base.getDisplayMetrics().scaledDensity + 0.5f);
|
||||
}
|
||||
|
||||
public static float pxToSp(float px) {
|
||||
return px / Base.getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
|
||||
public static int pxToSp(int px) {
|
||||
return (int) (px / Base.getDisplayMetrics().scaledDensity + 0.5f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.thefinestartist.enums;
|
||||
|
||||
import com.thefinestartist.utils.log.LogUtil;
|
||||
|
||||
/**
|
||||
* Enum class associated with {@link LogUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public enum LogLevel {
|
||||
FULL,
|
||||
VERBOSE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
ASSERT,
|
||||
NONE
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.thefinestartist.enums;
|
||||
|
||||
import com.thefinestartist.utils.ui.DisplayUtil;
|
||||
|
||||
/**
|
||||
* Enum class associated with {@link DisplayUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public enum Rotation {
|
||||
DEGREES_0(0),
|
||||
DEGREES_90(1),
|
||||
DEGREES_180(2),
|
||||
DEGREES_270(3);
|
||||
|
||||
int value;
|
||||
|
||||
Rotation(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static Rotation fromValue(int value) {
|
||||
for (Rotation rotation : values())
|
||||
if (rotation.value == value)
|
||||
return rotation;
|
||||
|
||||
return DEGREES_0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.thefinestartist.listeners;
|
||||
|
||||
import com.thefinestartist.utils.ui.KeyboardUtil;
|
||||
|
||||
/**
|
||||
* Listener class associated with {@link KeyboardUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public abstract class KeyboardStateListener {
|
||||
|
||||
public void onStateChanged(int keyboardHeight, boolean opened) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,502 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.WallpaperManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentCallbacks;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentSender;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.DatabaseErrorHandler;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.annotation.StyleableRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* ContextUtil helps to manage {@link Context} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ContextUtil {
|
||||
|
||||
public static boolean bindService(Intent service, ServiceConnection conn, int flags) {
|
||||
return Base.getContext().bindService(service, conn, flags);
|
||||
}
|
||||
|
||||
public static int checkCallingOrSelfPermission(String permission) {
|
||||
return Base.getContext().checkCallingOrSelfPermission(permission);
|
||||
}
|
||||
|
||||
public static int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
|
||||
return Base.getContext().checkCallingOrSelfUriPermission(uri, modeFlags);
|
||||
}
|
||||
|
||||
public static int checkCallingPermission(String permission) {
|
||||
return Base.getContext().checkCallingPermission(permission);
|
||||
}
|
||||
|
||||
public static int checkCallingUriPermission(Uri uri, int modeFlags) {
|
||||
return Base.getContext().checkCallingUriPermission(uri, modeFlags);
|
||||
}
|
||||
|
||||
public static int checkPermission(String permission, int pid, int uid) {
|
||||
return Base.getContext().checkPermission(permission, pid, uid);
|
||||
}
|
||||
|
||||
public static int checkSelfPermission(@NonNull String permission) {
|
||||
return ContextCompat.checkSelfPermission(Base.getContext(), permission);
|
||||
}
|
||||
|
||||
public static int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
|
||||
return Base.getContext().checkUriPermission(uri, pid, uid, modeFlags);
|
||||
}
|
||||
|
||||
public static int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags) {
|
||||
return Base.getContext().checkUriPermission(uri, readPermission, writePermission, pid, uid, modeFlags);
|
||||
}
|
||||
|
||||
public static Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException {
|
||||
return Base.getContext().createPackageContext(packageName, flags);
|
||||
}
|
||||
|
||||
public static String[] databaseList() {
|
||||
return Base.getContext().databaseList();
|
||||
}
|
||||
|
||||
public static boolean deleteDatabase(String name) {
|
||||
return Base.getContext().deleteDatabase(name);
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String name) {
|
||||
return Base.getContext().deleteFile(name);
|
||||
}
|
||||
|
||||
public static void enforceCallingOrSelfPermission(String permission, String message) {
|
||||
Base.getContext().enforceCallingOrSelfPermission(permission, message);
|
||||
}
|
||||
|
||||
public static void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message) {
|
||||
Base.getContext().enforceCallingOrSelfUriPermission(uri, modeFlags, message);
|
||||
}
|
||||
|
||||
public static void enforceCallingPermission(String permission, String message) {
|
||||
Base.getContext().enforceCallingPermission(permission, message);
|
||||
}
|
||||
|
||||
public static void enforceCallingUriPermission(Uri uri, int modeFlags, String message) {
|
||||
Base.getContext().enforceCallingUriPermission(uri, modeFlags, message);
|
||||
}
|
||||
|
||||
public static void enforcePermission(String permission, int pid, int uid, String message) {
|
||||
Base.getContext().enforcePermission(permission, pid, uid, message);
|
||||
}
|
||||
|
||||
public static void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message) {
|
||||
Base.getContext().enforceUriPermission(uri, pid, uid, modeFlags, message);
|
||||
}
|
||||
|
||||
public static void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message) {
|
||||
Base.getContext().enforceUriPermission(uri, readPermission, writePermission, pid, uid, modeFlags, message);
|
||||
}
|
||||
|
||||
public static String[] fileList() {
|
||||
return Base.getContext().fileList();
|
||||
}
|
||||
|
||||
public static Context getApplicationContext() {
|
||||
return Base.getContext().getApplicationContext();
|
||||
}
|
||||
|
||||
public static ApplicationInfo getApplicationInfo() {
|
||||
return Base.getContext().getApplicationInfo();
|
||||
}
|
||||
|
||||
public static AssetManager getAssets() {
|
||||
return Base.getContext().getAssets();
|
||||
}
|
||||
|
||||
public static File getCacheDir() {
|
||||
return Base.getContext().getCacheDir();
|
||||
}
|
||||
|
||||
public static ClassLoader getClassLoader() {
|
||||
return Base.getContext().getClassLoader();
|
||||
}
|
||||
|
||||
public static File getCodeCacheDir() {
|
||||
return ContextCompat.getCodeCacheDir(Base.getContext());
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColor(@ColorRes int colorRes) {
|
||||
return ContextCompat.getColor(Base.getContext(), colorRes);
|
||||
}
|
||||
|
||||
public static ColorStateList getColorStateList(@ColorRes int colorRes) {
|
||||
return ContextCompat.getColorStateList(Base.getContext(), colorRes);
|
||||
}
|
||||
|
||||
public static ContentResolver getContentResolver() {
|
||||
return Base.getContext().getContentResolver();
|
||||
}
|
||||
|
||||
public static File getDatabasePath(String name) {
|
||||
return Base.getContext().getDatabasePath(name);
|
||||
}
|
||||
|
||||
public static File getDir(String name, int mode) {
|
||||
return Base.getContext().getDir(name, mode);
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(@DrawableRes int drawableRes) {
|
||||
return ContextCompat.getDrawable(Base.getContext(), drawableRes);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@TargetApi(8)
|
||||
public static File getExternalCacheDir() {
|
||||
return Base.getContext().getExternalCacheDir();
|
||||
}
|
||||
|
||||
public static File[] getExternalCacheDirs() {
|
||||
return ContextCompat.getExternalCacheDirs(Base.getContext());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@TargetApi(8)
|
||||
public static File getExternalFilesDir(String type) {
|
||||
return Base.getContext().getExternalFilesDir(type);
|
||||
}
|
||||
|
||||
public static File[] getExternalFilesDirs(String type) {
|
||||
return ContextCompat.getExternalFilesDirs(Base.getContext(), type);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static File[] getExternalMediaDirs() {
|
||||
return Base.getContext().getExternalMediaDirs();
|
||||
}
|
||||
|
||||
public static File getFileStreamPath(String name) {
|
||||
return Base.getContext().getFileStreamPath(name);
|
||||
}
|
||||
|
||||
public static File getFilesDir() {
|
||||
return Base.getContext().getFilesDir();
|
||||
}
|
||||
|
||||
public static Looper getMainLooper() {
|
||||
return Base.getContext().getMainLooper();
|
||||
}
|
||||
|
||||
public static File getNoBackupFilesDir() {
|
||||
return ContextCompat.getNoBackupFilesDir(Base.getContext());
|
||||
}
|
||||
|
||||
@TargetApi(11)
|
||||
public static File getObbDir() {
|
||||
return Base.getContext().getObbDir();
|
||||
}
|
||||
|
||||
public static File[] getObbDirs() {
|
||||
return ContextCompat.getObbDirs(Base.getContext());
|
||||
}
|
||||
|
||||
@TargetApi(8)
|
||||
public static String getPackageCodePath() {
|
||||
return Base.getContext().getPackageCodePath();
|
||||
}
|
||||
|
||||
public static PackageManager getPackageManager() {
|
||||
return Base.getContext().getPackageManager();
|
||||
}
|
||||
|
||||
public static String getPackageName() {
|
||||
return Base.getContext().getPackageName();
|
||||
}
|
||||
|
||||
@TargetApi(8)
|
||||
public static String getPackageResourcePath() {
|
||||
return Base.getContext().getPackageResourcePath();
|
||||
}
|
||||
|
||||
public static Resources getResources() {
|
||||
return Base.getContext().getResources();
|
||||
}
|
||||
|
||||
public static SharedPreferences getSharedPreferences(String name, int mode) {
|
||||
return Base.getContext().getSharedPreferences(name, mode);
|
||||
}
|
||||
|
||||
public static String getString(@StringRes int stringRes) {
|
||||
return Base.getContext().getString(stringRes);
|
||||
}
|
||||
|
||||
public static String getString(@StringRes int stringRes, Object... formatArgs) {
|
||||
return Base.getContext().getString(stringRes, formatArgs);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static <T> T getSystemService(Class<T> serviceClass) {
|
||||
return Base.getContext().getSystemService(serviceClass);
|
||||
}
|
||||
|
||||
public static Object getSystemService(String name) {
|
||||
return Base.getContext().getSystemService(name);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static String getSystemServiceName(Class<?> serviceClass) {
|
||||
return Base.getContext().getSystemServiceName(serviceClass);
|
||||
}
|
||||
|
||||
public static CharSequence getText(@StringRes int stringRes) {
|
||||
return Base.getContext().getText(stringRes);
|
||||
}
|
||||
|
||||
public static Resources.Theme getTheme() {
|
||||
return Base.getContext().getTheme();
|
||||
}
|
||||
|
||||
public static Drawable getWallpaper() {
|
||||
return WallpaperManager.getInstance(Base.getContext()).getDrawable();
|
||||
}
|
||||
|
||||
public static int getWallpaperDesiredMinimumHeight() {
|
||||
return WallpaperManager.getInstance(Base.getContext()).getDesiredMinimumHeight();
|
||||
}
|
||||
|
||||
public static int getWallpaperDesiredMinimumWidth() {
|
||||
return WallpaperManager.getInstance(Base.getContext()).getDesiredMinimumWidth();
|
||||
}
|
||||
|
||||
public static void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
|
||||
Base.getContext().grantUriPermission(toPackage, uri, modeFlags);
|
||||
}
|
||||
|
||||
public static boolean isRestricted() {
|
||||
return Base.getContext().isRestricted();
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
|
||||
return Base.getContext().obtainStyledAttributes(attrs);
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
|
||||
return Base.getContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs) {
|
||||
return Base.getContext().obtainStyledAttributes(set, attrs);
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
|
||||
return Base.getContext().obtainStyledAttributes(resid, attrs);
|
||||
}
|
||||
|
||||
public static FileInputStream openFileInput(String name) throws FileNotFoundException {
|
||||
return Base.getContext().openFileInput(name);
|
||||
}
|
||||
|
||||
public static FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
|
||||
return Base.getContext().openFileOutput(name, mode);
|
||||
}
|
||||
|
||||
public static SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
|
||||
return Base.getContext().openOrCreateDatabase(name, mode, factory);
|
||||
}
|
||||
|
||||
@TargetApi(11)
|
||||
public static SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
|
||||
return Base.getContext().openOrCreateDatabase(name, mode, factory, errorHandler);
|
||||
}
|
||||
|
||||
public static Drawable peekWallpaper() {
|
||||
return WallpaperManager.getInstance(Base.getContext()).peekDrawable();
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public static void registerComponentCallbacks(ComponentCallbacks callback) {
|
||||
Base.getContext().registerComponentCallbacks(callback);
|
||||
}
|
||||
|
||||
public static Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
|
||||
return Base.getContext().registerReceiver(receiver, filter);
|
||||
}
|
||||
|
||||
public static Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) {
|
||||
return Base.getContext().registerReceiver(receiver, filter, broadcastPermission, scheduler);
|
||||
}
|
||||
|
||||
// public static void removeStickyBroadcast(Intent intent) {
|
||||
// Base.getContext().removeStickyBroadcast(intent);
|
||||
// }
|
||||
//
|
||||
// @TargetApi(17)
|
||||
// public static void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
// Base.getContext().removeStickyBroadcastAsUser(intent, user);
|
||||
// }
|
||||
|
||||
public static void revokeUriPermission(Uri uri, int modeFlags) {
|
||||
Base.getContext().revokeUriPermission(uri, modeFlags);
|
||||
}
|
||||
|
||||
public static void sendBroadcast(Intent intent, String receiverPermission) {
|
||||
Base.getContext().sendBroadcast(intent, receiverPermission);
|
||||
}
|
||||
|
||||
public static void sendBroadcast(Intent intent) {
|
||||
Base.getContext().sendBroadcast(intent);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static void sendBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
Base.getContext().sendBroadcastAsUser(intent, user);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission) {
|
||||
Base.getContext().sendBroadcastAsUser(intent, user, receiverPermission);
|
||||
}
|
||||
|
||||
public static void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
|
||||
Base.getContext().sendOrderedBroadcast(intent, receiverPermission, resultReceiver, scheduler, initialCode, initialData, initialExtras);
|
||||
}
|
||||
|
||||
public static void sendOrderedBroadcast(Intent intent, String receiverPermission) {
|
||||
Base.getContext().sendOrderedBroadcast(intent, receiverPermission);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
|
||||
Base.getContext().sendOrderedBroadcastAsUser(intent, user, receiverPermission, resultReceiver, scheduler, initialCode, initialData, initialExtras);
|
||||
}
|
||||
|
||||
// public static void sendStickyBroadcast(Intent intent) {
|
||||
// Base.getContext().sendStickyBroadcast(intent);
|
||||
// }
|
||||
//
|
||||
// @TargetApi(17)
|
||||
// public static void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
|
||||
// Base.getContext().sendStickyBroadcastAsUser(intent, user);
|
||||
// }
|
||||
//
|
||||
// public static void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
|
||||
// Base.getContext().sendStickyOrderedBroadcast(intent, resultReceiver, scheduler, initialCode, initialData, initialExtras);
|
||||
// }
|
||||
//
|
||||
// @TargetApi(17)
|
||||
// public static void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
|
||||
// Base.getContext().sendStickyOrderedBroadcastAsUser(intent, user, resultReceiver, scheduler, initialCode, initialData, initialExtras);
|
||||
// }
|
||||
|
||||
public static void setTheme(@StyleRes int styleRes) {
|
||||
Base.getContext().setTheme(styleRes);
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public static void setWallpaper(InputStream data) throws IOException {
|
||||
WallpaperManager.getInstance(Base.getContext()).setStream(data);
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
public static void setWallpaper(Bitmap bitmap) throws IOException {
|
||||
WallpaperManager.getInstance(Base.getContext()).setBitmap(bitmap);
|
||||
}
|
||||
|
||||
public static boolean startActivities(Intent[] intents, Bundle options) {
|
||||
for (Intent intent : intents)
|
||||
if (intent != null)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return ContextCompat.startActivities(Base.getContext(), intents, options);
|
||||
}
|
||||
|
||||
public static boolean startActivities(Intent[] intents) {
|
||||
for (Intent intent : intents)
|
||||
if (intent != null)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return ContextCompat.startActivities(Base.getContext(), intents);
|
||||
}
|
||||
|
||||
public static void startActivity(@NonNull Intent intent) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Base.getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public static void startActivity(Intent intent, Bundle options) {
|
||||
Base.getContext().startActivity(intent, options);
|
||||
}
|
||||
|
||||
public static boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments) {
|
||||
return Base.getContext().startInstrumentation(className, profileFile, arguments);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public static void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException {
|
||||
Base.getContext().startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, options);
|
||||
}
|
||||
|
||||
public static void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException {
|
||||
Base.getContext().startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
|
||||
}
|
||||
|
||||
public static ComponentName startService(Intent service) {
|
||||
return Base.getContext().startService(service);
|
||||
}
|
||||
|
||||
public static boolean stopService(Intent service) {
|
||||
return Base.getContext().stopService(service);
|
||||
}
|
||||
|
||||
public static void unbindService(ServiceConnection conn) {
|
||||
Base.getContext().unbindService(conn);
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public static void unregisterComponentCallbacks(ComponentCallbacks callback) {
|
||||
Base.getContext().unregisterComponentCallbacks(callback);
|
||||
}
|
||||
|
||||
public static void unregisterReceiver(BroadcastReceiver receiver) {
|
||||
Base.getContext().unregisterReceiver(receiver);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
/**
|
||||
* Ctx is abbreviation class of {@link ContextUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Ctx extends ContextUtil {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
/**
|
||||
* Res is abbreviation class of {@link ResourcesUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Res extends ResourcesUtil {
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.graphics.Movie;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.AnimRes;
|
||||
import androidx.annotation.AnyRes;
|
||||
import androidx.annotation.ArrayRes;
|
||||
import androidx.annotation.BoolRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.IntegerRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.PluralsRes;
|
||||
import androidx.annotation.RawRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.XmlRes;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* ResourcesUtil helps to manage {@link Resources} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ResourcesUtil {
|
||||
|
||||
private static void finishPreloading() {
|
||||
Base.getResources().finishPreloading();
|
||||
}
|
||||
|
||||
private static void flushLayoutCache() {
|
||||
Base.getResources().flushLayoutCache();
|
||||
}
|
||||
|
||||
public static XmlResourceParser getAnimation(@AnimRes int animRes) {
|
||||
return Base.getResources().getAnimation(animRes);
|
||||
}
|
||||
|
||||
public static AssetManager getAssets() {
|
||||
return Base.getResources().getAssets();
|
||||
}
|
||||
|
||||
public static boolean getBoolean(@BoolRes int boolRes) {
|
||||
return Base.getResources().getBoolean(boolRes);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColor(@ColorRes int colorRes) {
|
||||
return ContextUtil.getColor(colorRes);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColor(@ColorRes int colorRes, Resources.Theme theme) {
|
||||
if (APILevel.require(23))
|
||||
return Base.getResources().getColor(colorRes, theme);
|
||||
else
|
||||
return getColor(colorRes);
|
||||
}
|
||||
|
||||
public static ColorStateList getColorStateList(@ColorRes int colorRes) {
|
||||
return ContextUtil.getColorStateList(colorRes);
|
||||
}
|
||||
|
||||
public static ColorStateList getColorStateList(@ColorRes int colorRes, Resources.Theme theme) {
|
||||
if (APILevel.require(23))
|
||||
return Base.getResources().getColorStateList(colorRes, theme);
|
||||
else
|
||||
return getColorStateList(colorRes);
|
||||
}
|
||||
|
||||
public static Configuration getConfiguration() {
|
||||
return Base.getConfiguration();
|
||||
}
|
||||
|
||||
public static float getDimension(@DimenRes int dimenRes) {
|
||||
return Base.getResources().getDimension(dimenRes);
|
||||
}
|
||||
|
||||
public static int getDimensionPixelOffset(@DimenRes int dimenRes) {
|
||||
return Base.getResources().getDimensionPixelOffset(dimenRes);
|
||||
}
|
||||
|
||||
public static int getDimensionPixelSize(@DimenRes int dimenRes) {
|
||||
return Base.getResources().getDimensionPixelSize(dimenRes);
|
||||
}
|
||||
|
||||
public static DisplayMetrics getDisplayMetrics() {
|
||||
return Base.getDisplayMetrics();
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(@DrawableRes int drawableRes) {
|
||||
return ContextUtil.getDrawable(drawableRes);
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(@DrawableRes int drawableRes, Resources.Theme theme) {
|
||||
if (APILevel.require(21))
|
||||
return Base.getResources().getDrawable(drawableRes, theme);
|
||||
else
|
||||
return Base.getResources().getDrawable(drawableRes);
|
||||
}
|
||||
|
||||
public static Drawable getDrawableForDensity(@DrawableRes int drawableRes, int density) {
|
||||
if (APILevel.require(21))
|
||||
return Base.getResources().getDrawableForDensity(drawableRes, density, Base.getContext().getTheme());
|
||||
else if (APILevel.require(15))
|
||||
return Base.getResources().getDrawableForDensity(drawableRes, density);
|
||||
else
|
||||
return Base.getResources().getDrawable(drawableRes);
|
||||
}
|
||||
|
||||
public static float getFraction(int id, int base, int pbase) {
|
||||
return Base.getResources().getFraction(id, base, pbase);
|
||||
}
|
||||
|
||||
public static int getIdentifier(String name, String defType, String defPackage) {
|
||||
return Base.getResources().getIdentifier(name, defType, defPackage);
|
||||
}
|
||||
|
||||
public static int[] getIntArray(@ArrayRes int arrayRes) {
|
||||
return Base.getResources().getIntArray(arrayRes);
|
||||
}
|
||||
|
||||
public static int getInteger(@IntegerRes int integerRes) {
|
||||
return Base.getResources().getInteger(integerRes);
|
||||
}
|
||||
|
||||
public static XmlResourceParser getLayout(@LayoutRes int layoutRes) {
|
||||
return Base.getResources().getLayout(layoutRes);
|
||||
}
|
||||
|
||||
public static Movie getMovie(@RawRes int rawRes) {
|
||||
return Base.getResources().getMovie(rawRes);
|
||||
}
|
||||
|
||||
public static String getQuantityString(int id, int quantity, Object... formatArgs) {
|
||||
return Base.getResources().getQuantityString(id, quantity, formatArgs);
|
||||
}
|
||||
|
||||
public static String getQuantityString(@PluralsRes int pluralsRes, int quantity) throws Resources.NotFoundException {
|
||||
return Base.getResources().getQuantityString(pluralsRes, quantity);
|
||||
}
|
||||
|
||||
public static CharSequence getQuantityText(int id, int quantity) {
|
||||
return Base.getResources().getQuantityText(id, quantity);
|
||||
}
|
||||
|
||||
public static String getResourceEntryName(@AnyRes int anyRes) {
|
||||
return Base.getResources().getResourceEntryName(anyRes);
|
||||
}
|
||||
|
||||
public static String getResourceName(@AnyRes int anyRes) {
|
||||
return Base.getResources().getResourceName(anyRes);
|
||||
}
|
||||
|
||||
public static String getResourcePackageName(@AnyRes int anyRes) {
|
||||
return Base.getResources().getResourcePackageName(anyRes);
|
||||
}
|
||||
|
||||
public static String getResourceTypeName(@AnyRes int anyRes) {
|
||||
return Base.getResources().getResourceTypeName(anyRes);
|
||||
}
|
||||
|
||||
public static String getString(@StringRes int stringRes) {
|
||||
return Base.getResources().getString(stringRes);
|
||||
}
|
||||
|
||||
public static String getString(@StringRes int stringRes, Object... formatArgs) {
|
||||
return Base.getResources().getString(stringRes, formatArgs);
|
||||
}
|
||||
|
||||
public static String[] getStringArray(@ArrayRes int arrayRes) {
|
||||
return Base.getResources().getStringArray(arrayRes);
|
||||
}
|
||||
|
||||
public static Resources getSystem() {
|
||||
return Base.getResources().getSystem();
|
||||
}
|
||||
|
||||
public static CharSequence getText(@StringRes int stringRes, CharSequence def) {
|
||||
return Base.getResources().getText(stringRes, def);
|
||||
}
|
||||
|
||||
public static CharSequence getText(@StringRes int stringRes) {
|
||||
return Base.getResources().getText(stringRes);
|
||||
}
|
||||
|
||||
public static CharSequence[] getTextArray(@ArrayRes int arrayRes) {
|
||||
return Base.getResources().getTextArray(arrayRes);
|
||||
}
|
||||
|
||||
public static void getValue(String name, TypedValue outValue, boolean resolveRefs) {
|
||||
Base.getResources().getValue(name, outValue, resolveRefs);
|
||||
}
|
||||
|
||||
public static void getValue(@AnyRes int anyRes, TypedValue outValue, boolean resolveRefs) {
|
||||
Base.getResources().getValue(anyRes, outValue, resolveRefs);
|
||||
}
|
||||
|
||||
public static void getValueForDensity(@AnyRes int anyRes, int density, TypedValue outValue, boolean resolveRefs) {
|
||||
if (APILevel.require(15))
|
||||
Base.getResources().getValueForDensity(anyRes, density, outValue, resolveRefs);
|
||||
else
|
||||
Base.getResources().getValue(anyRes, outValue, resolveRefs);
|
||||
}
|
||||
|
||||
public static XmlResourceParser getXml(@XmlRes int xmlRes) {
|
||||
return Base.getResources().getXml(xmlRes);
|
||||
}
|
||||
|
||||
public static Resources.Theme newTheme() {
|
||||
return Base.getResources().newTheme();
|
||||
}
|
||||
|
||||
public static TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
||||
return Base.getResources().obtainAttributes(set, attrs);
|
||||
}
|
||||
|
||||
public static TypedArray obtainTypedArray(@ArrayRes int anyRes) {
|
||||
return Base.getResources().obtainTypedArray(anyRes);
|
||||
}
|
||||
|
||||
public static InputStream openRawResource(@RawRes int rawRes) {
|
||||
return Base.getResources().openRawResource(rawRes);
|
||||
}
|
||||
|
||||
public static InputStream openRawResource(@RawRes int rawRes, TypedValue value) {
|
||||
return Base.getResources().openRawResource(rawRes, value);
|
||||
}
|
||||
|
||||
public static AssetFileDescriptor openRawResourceFd(@RawRes int rawRes) {
|
||||
return Base.getResources().openRawResourceFd(rawRes);
|
||||
}
|
||||
|
||||
public static void parseBundleExtra(String tagName, AttributeSet attrs, Bundle outBundle) throws XmlPullParserException {
|
||||
Base.getResources().parseBundleExtra(tagName, attrs, outBundle);
|
||||
}
|
||||
|
||||
public static void parseBundleExtras(XmlResourceParser parser, Bundle outBundle) throws XmlPullParserException, IOException {
|
||||
Base.getResources().parseBundleExtras(parser, outBundle);
|
||||
}
|
||||
|
||||
public static void updateConfiguration(Configuration config, DisplayMetrics metrics) {
|
||||
Base.getResources().updateConfiguration(config, metrics);
|
||||
}
|
||||
|
||||
// Added methods
|
||||
public static int[] getColorArray(@ArrayRes int array) {
|
||||
if (array == 0)
|
||||
return null;
|
||||
|
||||
TypedArray typedArray = Base.getResources().obtainTypedArray(array);
|
||||
int[] colors = new int[typedArray.length()];
|
||||
for (int i = 0; i < typedArray.length(); i++)
|
||||
colors[i] = typedArray.getColor(i, 0);
|
||||
typedArray.recycle();
|
||||
return colors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.annotation.StyleableRes;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* ThemeUtil helps to manage {@link Resources.Theme} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ThemeUtil {
|
||||
|
||||
public static void applyStyle(int resId, boolean force) {
|
||||
Base.getTheme().applyStyle(resId, force);
|
||||
}
|
||||
|
||||
public static void dump(int priority, String tag, String prefix) {
|
||||
Base.getTheme().dump(priority, tag, prefix);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static int getChangingConfigurations() {
|
||||
return Base.getTheme().getChangingConfigurations();
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(@DrawableRes int drawableRes) {
|
||||
return ResourcesUtil.getDrawable(drawableRes);
|
||||
}
|
||||
|
||||
public static Resources getResources() {
|
||||
return Base.getResources();
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
|
||||
return Base.getTheme().obtainStyledAttributes(attrs);
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) {
|
||||
return Base.getTheme().obtainStyledAttributes(resid, attrs);
|
||||
}
|
||||
|
||||
public static TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
|
||||
return Base.getTheme().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public static boolean resolveAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
|
||||
return Base.getTheme().resolveAttribute(resid, outValue, resolveRefs);
|
||||
}
|
||||
|
||||
public static void setTo(Resources.Theme other) {
|
||||
Base.getTheme().setTo(other);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
import android.util.TypedValue;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* TypedValueUtil helps to manage {@link TypedValue} class conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class TypedValueUtil {
|
||||
|
||||
public static float applyDimension(int unit, float value) {
|
||||
return TypedValue.applyDimension(unit, value, Base.getDisplayMetrics());
|
||||
}
|
||||
|
||||
public static float complexToDimension(int data) {
|
||||
return TypedValue.complexToDimension(data, Base.getDisplayMetrics());
|
||||
}
|
||||
|
||||
public static int complexToDimensionPixelOffset(int data) {
|
||||
return TypedValue.complexToDimensionPixelOffset(data, Base.getDisplayMetrics());
|
||||
}
|
||||
|
||||
public static int complexToDimensionPixelSize(int data) {
|
||||
return TypedValue.complexToDimensionPixelSize(data, Base.getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
/**
|
||||
* APILevel helps to check device API {@link android.os.Build.VERSION} conveniently.
|
||||
*
|
||||
* @author Marcos Trujillo, Leonardo Taehwan Kim
|
||||
*/
|
||||
public class APILevel {
|
||||
|
||||
/**
|
||||
* @param level minimum API level version that has to support the device
|
||||
* @return true when the caller API version is at least level
|
||||
*/
|
||||
public static boolean require(int level) {
|
||||
return Build.VERSION.SDK_INT >= level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Cupcake 3
|
||||
*/
|
||||
public static boolean requireCupcake() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Donut 4
|
||||
*/
|
||||
public static boolean requireDonut() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Eclair 5
|
||||
*/
|
||||
public static boolean requireEclair() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Froyo 8
|
||||
*/
|
||||
public static boolean requireFroyo() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least GingerBread 9
|
||||
*/
|
||||
public static boolean requireGingerbread() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Honeycomb 11
|
||||
*/
|
||||
public static boolean requireHoneycomb() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Honeycomb 3.2, 13
|
||||
*/
|
||||
public static boolean requireHoneycombMR2() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least ICS 14
|
||||
*/
|
||||
public static boolean requireIceCreamSandwich() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least JellyBean 16
|
||||
*/
|
||||
public static boolean requireJellyBean() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least JellyBean MR1 17
|
||||
*/
|
||||
public static boolean requireJellyBeanMR1() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least JellyBean MR2 18
|
||||
*/
|
||||
public static boolean requireJellyBeanMR2() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Kitkat 19
|
||||
*/
|
||||
public static boolean requireKitkat() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Lollipop 21
|
||||
*/
|
||||
public static boolean requireLollipop() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Lollipop MR1 22
|
||||
*/
|
||||
public static boolean requireLollipopMR1() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is at least Marshmallow 23
|
||||
*/
|
||||
public static boolean requireMarshmallow() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param level API level version that specific method or variable has been deprecated
|
||||
* @return true when the caller API version is less than level
|
||||
*/
|
||||
public static boolean deprecatedAt(int level) {
|
||||
return Build.VERSION.SDK_INT < level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Cupcake 3
|
||||
*/
|
||||
public static boolean deprecatedAtCupcake() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.CUPCAKE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Donut 4
|
||||
*/
|
||||
public static boolean deprecatedAtDonut() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Eclair 5
|
||||
*/
|
||||
public static boolean deprecatedAtEclair() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Froyo 8
|
||||
*/
|
||||
public static boolean deprecatedAtFroyo() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than GingerBread 9
|
||||
*/
|
||||
public static boolean deprecatedAtGingerbread() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Honeycomb 11
|
||||
*/
|
||||
public static boolean deprecatedAtHoneycomb() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Honeycomb 3.2, 13
|
||||
*/
|
||||
public static boolean deprecatedAtHoneycombMR2() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than ICS 14
|
||||
*/
|
||||
public static boolean deprecatedAtIceCreamSandwich() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than JellyBean 16
|
||||
*/
|
||||
public static boolean deprecatedAtJellyBean() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than JellyBean MR1 17
|
||||
*/
|
||||
public static boolean deprecatedAtJellyBeanMR1() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than JellyBean MR2 18
|
||||
*/
|
||||
public static boolean deprecatedAtJellyBeanMR2() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Kitkat 19
|
||||
*/
|
||||
public static boolean deprecatedAtKitkat() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Lollipop 21
|
||||
*/
|
||||
public static boolean deprecatedAtLollipop() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Lollipop MR1 22
|
||||
*/
|
||||
public static boolean deprecatedAtLollipopMR1() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true when the caller API version is less than Marshmallow 23
|
||||
*/
|
||||
public static boolean deprecatedAtMarshmallow() {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
/**
|
||||
* IntArrayUtil helps to manage IntArray conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class IntArrayUtil {
|
||||
|
||||
public static boolean contains(int[] array, int value) {
|
||||
if (array == null)
|
||||
return false;
|
||||
|
||||
for (int i : array)
|
||||
if (i == value)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int[] add(int[] array, int value) {
|
||||
if (array == null)
|
||||
return new int[]{value};
|
||||
|
||||
int[] newArray = new int[array.length + 1];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
newArray[array.length] = value;
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* PackageUtil helps to handle methods related to package.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class PackageUtil {
|
||||
|
||||
public static final String FACEBOOK = "com.facebook.katana";
|
||||
public static final String TWITTER = "com.twitter.android";
|
||||
public static final String GOOGLE_PLUS = "com.google.android.apps.plus";
|
||||
public static final String GMAIL = "com.google.android.gm";
|
||||
public static final String PINTEREST = "com.pinterest";
|
||||
public static final String TUMBLR = "com.tumblr";
|
||||
public static final String FANCY = "com.thefancy.app";
|
||||
public static final String FLIPBOARD = "flipboard.app";
|
||||
public static final String KAKAOTALK = "com.kakao.talk";
|
||||
public static final String KAKAOSTORY = "com.kakao.story";
|
||||
|
||||
public static boolean isInstalled(String packageName) {
|
||||
PackageManager packageManager = Base.getContext().getPackageManager();
|
||||
try {
|
||||
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPackageName() {
|
||||
return Base.getContext().getPackageName();
|
||||
}
|
||||
|
||||
public static void openPlayStore() {
|
||||
String packageName = Base.getContext().getPackageName();
|
||||
openPlayStore(packageName);
|
||||
}
|
||||
|
||||
public static void openPlayStore(String packageName) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Base.getContext().startActivity(intent);
|
||||
} catch (ActivityNotFoundException exception) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + packageName));
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Base.getContext().startActivity(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SparseArrayUtil helps to manage SparseArray conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class SparseArrayUtil {
|
||||
|
||||
public static <C> List<C> asArrayList(SparseArray<C> sparseArray) {
|
||||
if (sparseArray == null)
|
||||
return new ArrayList<C>();
|
||||
|
||||
ArrayList<C> arrayList = new ArrayList<C>(sparseArray.size());
|
||||
for (int i = 0; i < sparseArray.size(); i++)
|
||||
arrayList.add(sparseArray.valueAt(i));
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.os.Looper;
|
||||
|
||||
/**
|
||||
* ThreadUtil helps to manage thread conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ThreadUtil {
|
||||
|
||||
public static boolean isMain() {
|
||||
return Looper.myLooper() == Looper.getMainLooper();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.collection.SimpleArrayMap;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* TypefaceUtil helps to retrieve typeface from assets folder.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class TypefaceUtil {
|
||||
|
||||
private static final SimpleArrayMap<String, Typeface> cache = new SimpleArrayMap<>();
|
||||
|
||||
public static Typeface get(@NonNull String path) {
|
||||
synchronized (cache) {
|
||||
if (cache.containsKey(path))
|
||||
return cache.get(path);
|
||||
|
||||
try {
|
||||
Typeface typeface = Typeface.createFromAsset(Base.getContext().getAssets(), path);
|
||||
cache.put(path, typeface);
|
||||
return typeface;
|
||||
} catch (RuntimeException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setTypeface(@NonNull String path, TextView... textViews) {
|
||||
if (textViews == null)
|
||||
return;
|
||||
|
||||
for (TextView textView : textViews)
|
||||
if (textView != null)
|
||||
textView.setTypeface(get(path));
|
||||
}
|
||||
|
||||
public static void setTypeface(@NonNull String path, boolean includeFontPadding, TextView... textViews) {
|
||||
if (textViews == null)
|
||||
return;
|
||||
|
||||
for (TextView textView : textViews) {
|
||||
if (textView != null) {
|
||||
textView.setTypeface(get(path));
|
||||
textView.setIncludeFontPadding(includeFontPadding);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
/**
|
||||
* AndroidLogPrinter log message via Android system.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class AndroidLogPrinter extends LogPrinter {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
/**
|
||||
* FileLogPrinter log message via file system.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class FileLogPrinter extends LogPrinter {
|
||||
|
||||
@Override
|
||||
public void v(String tag, String message) {
|
||||
super.v(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void d(String tag, String message) {
|
||||
super.d(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void i(String tag, String message) {
|
||||
super.i(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void w(String tag, String message) {
|
||||
super.w(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(String tag, String message) {
|
||||
super.e(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wtf(String tag, String message) {
|
||||
super.wtf(tag, message);
|
||||
}
|
||||
}
|
||||
// TODO: Finish this file after FileUtil
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
/**
|
||||
* L is abbreviation class of {@link LogUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class L extends LogUtil {
|
||||
}
|
||||
@@ -0,0 +1,702 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.thefinestartist.enums.LogLevel;
|
||||
import com.thefinestartist.utils.content.ResourcesUtil;
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
/**
|
||||
* LogHelper helps to deal with {@link Log} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class LogHelper {
|
||||
|
||||
private static final int INDENT_SPACES = 4;
|
||||
// http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5B%E2%94%80-%E2%95%BF%EF%BF%A8%5D
|
||||
private static final String TOP_DIVIDER = "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
||||
private static final String MIDDLE_DIVIDER = "┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
||||
private static final String BOTTOM_DIVIDER = "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━";
|
||||
|
||||
protected Settings settings = new Settings(LogHelper.class.getSimpleName());
|
||||
|
||||
// Constructors
|
||||
public LogHelper() {
|
||||
}
|
||||
|
||||
public LogHelper(String tag) {
|
||||
settings.setTag(tag);
|
||||
}
|
||||
|
||||
public LogHelper(@StringRes int tagRes) {
|
||||
settings.setTag(ResourcesUtil.getString(tagRes));
|
||||
}
|
||||
|
||||
public LogHelper(Class clazz) {
|
||||
settings.setTag(clazz.getSimpleName());
|
||||
}
|
||||
|
||||
// Setters
|
||||
public LogHelper tag(String tag) {
|
||||
settings.setTag(tag);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper tag(@StringRes int tagRes) {
|
||||
settings.setTag(tagRes);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper tag(Class clazz) {
|
||||
settings.setTag(clazz);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper showThreadInfo(boolean showThreadInfo) {
|
||||
settings.setShowThreadInfo(showThreadInfo);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper stackTraceCount(int stackTraceCount) {
|
||||
settings.setStackTraceCount(stackTraceCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper logLevel(LogLevel logLevel) {
|
||||
settings.setLogLevel(logLevel);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper showDivider(boolean showDivider) {
|
||||
settings.setShowDivider(showDivider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogHelper logPrinter(LogPrinter logPrinter) {
|
||||
settings.setLogPrinter(logPrinter);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Logging Verbose
|
||||
public void v(byte message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(char message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(short message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(int message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(long message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(float message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(double message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(boolean message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(String message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(JSONObject message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(JSONArray message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(Exception message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
public void v(Object message) {
|
||||
log(LogLevel.VERBOSE, message);
|
||||
}
|
||||
|
||||
// Logging Debug
|
||||
public void d(byte message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(char message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(short message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(int message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(long message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(float message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(double message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(boolean message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(String message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(JSONObject message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(JSONArray message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(Exception message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
public void d(Object message) {
|
||||
log(LogLevel.DEBUG, message);
|
||||
}
|
||||
|
||||
// Logging Information
|
||||
public void i(byte message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(char message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(short message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(int message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(long message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(float message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(double message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(boolean message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(String message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(JSONObject message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(JSONArray message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(Exception message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
public void i(Object message) {
|
||||
log(LogLevel.INFO, message);
|
||||
}
|
||||
|
||||
// Logging Warning
|
||||
public void w(byte message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(char message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(short message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(int message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(long message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(float message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(double message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(boolean message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(String message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(JSONObject message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(JSONArray message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(Exception message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
public void w(Object message) {
|
||||
log(LogLevel.WARN, message);
|
||||
}
|
||||
|
||||
// Logging Error
|
||||
public void e(byte message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(char message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(short message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(int message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(long message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(float message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(double message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(boolean message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(String message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(JSONObject message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(JSONArray message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(Exception message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
public void e(Object message) {
|
||||
log(LogLevel.ERROR, message);
|
||||
}
|
||||
|
||||
// Logging Assert
|
||||
public void wtf(byte message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(char message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(short message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(int message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(long message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(float message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(double message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(boolean message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(String message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(JSONObject message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(JSONArray message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(Exception message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
public void wtf(Object message) {
|
||||
log(LogLevel.ASSERT, message);
|
||||
}
|
||||
|
||||
// Logging JsonString
|
||||
public void json(String jsonString) {
|
||||
json(LogLevel.DEBUG, jsonString);
|
||||
}
|
||||
|
||||
public void json(LogLevel logLevel, String jsonString) {
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
log(logLevel, "Json string is empty.");
|
||||
} else {
|
||||
jsonString = jsonString.trim();
|
||||
|
||||
try {
|
||||
if (jsonString.startsWith("{")) {
|
||||
JSONObject jsonObject = new JSONObject(jsonString);
|
||||
String message = jsonObject.toString(INDENT_SPACES);
|
||||
log(logLevel, message);
|
||||
return;
|
||||
}
|
||||
if (jsonString.startsWith("[")) {
|
||||
JSONArray jsonArray = new JSONArray(jsonString);
|
||||
String message = jsonArray.toString(INDENT_SPACES);
|
||||
log(logLevel, message);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log(logLevel, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logging XmlString
|
||||
public void xml(String xmlString) {
|
||||
xml(LogLevel.DEBUG, xmlString);
|
||||
}
|
||||
|
||||
public void xml(LogLevel logLevel, String xmlString) {
|
||||
if (TextUtils.isEmpty(xmlString)) {
|
||||
log(logLevel, "Xml string is empty.");
|
||||
} else {
|
||||
if (APILevel.require(8)) {
|
||||
try {
|
||||
Source xmlInput = new StreamSource(new StringReader(xmlString));
|
||||
StreamResult xmlOutput = new StreamResult(new StringWriter());
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||
transformer.transform(xmlInput, xmlOutput);
|
||||
log(logLevel, xmlOutput.getWriter().toString().replaceFirst(">", ">\n"));
|
||||
} catch (TransformerException e) {
|
||||
log(logLevel, e);
|
||||
}
|
||||
} else {
|
||||
log(logLevel, xmlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Printing
|
||||
private void log(LogLevel logLevel, byte message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, char message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, short message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, int message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, long message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, float message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, double message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, boolean message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, String.valueOf(message));
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, String message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
printString(logLevel, message);
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, JSONObject message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
try {
|
||||
printString(logLevel, message.toString(INDENT_SPACES));
|
||||
} catch (JSONException e) {
|
||||
log(logLevel, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, JSONArray message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
try {
|
||||
printString(logLevel, message.toString(INDENT_SPACES));
|
||||
} catch (JSONException e) {
|
||||
log(logLevel, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, Exception message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(String.valueOf(message));
|
||||
builder.append("\n");
|
||||
|
||||
StackTraceElement[] traces = message.getStackTrace();
|
||||
for (StackTraceElement trace : traces) {
|
||||
builder.append(" at ")
|
||||
.append(trace.getClassName())
|
||||
.append(".")
|
||||
.append(trace.getMethodName())
|
||||
.append("(")
|
||||
.append(trace.getFileName())
|
||||
.append(":")
|
||||
.append(trace.getLineNumber())
|
||||
.append(")")
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
printString(logLevel, builder.toString(), true);
|
||||
}
|
||||
|
||||
private void log(LogLevel logLevel, Object message) {
|
||||
if (logLevel.ordinal() < settings.getLogLevel().ordinal())
|
||||
return;
|
||||
|
||||
String log;
|
||||
if (message instanceof byte[]) log = Arrays.toString((byte[]) message);
|
||||
else if (message instanceof char[]) log = Arrays.toString((char[]) message);
|
||||
else if (message instanceof short[]) log = Arrays.toString((short[]) message);
|
||||
else if (message instanceof int[]) log = Arrays.toString((int[]) message);
|
||||
else if (message instanceof long[]) log = Arrays.toString((long[]) message);
|
||||
else if (message instanceof float[]) log = Arrays.toString((float[]) message);
|
||||
else if (message instanceof double[]) log = Arrays.toString((double[]) message);
|
||||
else if (message instanceof boolean[]) log = Arrays.toString((boolean[]) message);
|
||||
else if (message instanceof Object[]) log = Arrays.toString((Object[]) message);
|
||||
else log = String.valueOf(message);
|
||||
|
||||
printString(logLevel, log);
|
||||
}
|
||||
|
||||
private void printString(LogLevel logLevel, String message) {
|
||||
printString(logLevel, message, false);
|
||||
}
|
||||
|
||||
private synchronized void printString(LogLevel logLevel, String message, boolean fromException) {
|
||||
// Create TAG
|
||||
String TAG = settings.getTag();
|
||||
if (settings.getShowThreadInfo()) TAG += "(" + Thread.currentThread().getName() + ")";
|
||||
|
||||
// Top Divider
|
||||
if (settings.getShowDivider()) printLine(logLevel, TAG, TOP_DIVIDER);
|
||||
|
||||
// Log Content
|
||||
String[] lines = message.split(System.getProperty("line.separator"));
|
||||
for (String line : lines)
|
||||
printLine(logLevel, TAG, settings.getShowDivider() ?
|
||||
"┃ " + line :
|
||||
line);
|
||||
|
||||
if (settings.getStackTraceCount() > 0 && fromException)
|
||||
printLine(logLevel, TAG, "Exception occurred");
|
||||
|
||||
// Middle Divider
|
||||
if (settings.getShowDivider()) printLine(logLevel, TAG, MIDDLE_DIVIDER);
|
||||
|
||||
// Log Stack Trace
|
||||
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
|
||||
int startIndex = 2;
|
||||
while (LogUtil.class.getCanonicalName().equals(traces[startIndex].getClassName())
|
||||
|| LogHelper.class.getCanonicalName().equals(traces[startIndex].getClassName()))
|
||||
startIndex++;
|
||||
|
||||
for (int i = startIndex; i < Math.min(traces.length, startIndex + settings.getStackTraceCount()); i++) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(" at ")
|
||||
.append(traces[i].getClassName())
|
||||
.append(".")
|
||||
.append(traces[i].getMethodName())
|
||||
.append("(")
|
||||
.append(traces[i].getFileName())
|
||||
.append(":")
|
||||
.append(traces[i].getLineNumber())
|
||||
.append(")");
|
||||
|
||||
printLine(logLevel, TAG, settings.getShowDivider() ?
|
||||
"┃ " + builder.toString() :
|
||||
builder.toString());
|
||||
}
|
||||
|
||||
// Log ellipsized stack trance
|
||||
int leftTraceCount = traces.length - startIndex - settings.getStackTraceCount();
|
||||
if (settings.getStackTraceCount() > 0 && leftTraceCount > 1)
|
||||
printLine(logLevel, TAG, settings.getShowDivider() ?
|
||||
"┃ at " + leftTraceCount + " more stack traces..." :
|
||||
" at " + leftTraceCount + " more stack traces...");
|
||||
if (settings.getStackTraceCount() > 0 && leftTraceCount == 1)
|
||||
printLine(logLevel, TAG, settings.getShowDivider() ?
|
||||
"┃ at 1 more stack trace..." :
|
||||
" at 1 more stack trace...");
|
||||
|
||||
// Middle Divider
|
||||
if (settings.getShowDivider()) printLine(logLevel, TAG, BOTTOM_DIVIDER);
|
||||
|
||||
// LogUtil setToDefault
|
||||
if (this == LogUtil.getInstance()) setToDefault();
|
||||
}
|
||||
|
||||
private void printLine(LogLevel logLevel, String tag, String message) {
|
||||
switch (logLevel) {
|
||||
case FULL:
|
||||
case VERBOSE:
|
||||
settings.getLogPrinter().v(tag, message);
|
||||
break;
|
||||
case DEBUG:
|
||||
settings.getLogPrinter().d(tag, message);
|
||||
break;
|
||||
case INFO:
|
||||
settings.getLogPrinter().i(tag, message);
|
||||
break;
|
||||
case WARN:
|
||||
settings.getLogPrinter().w(tag, message);
|
||||
break;
|
||||
case ERROR:
|
||||
settings.getLogPrinter().e(tag, message);
|
||||
break;
|
||||
case ASSERT:
|
||||
settings.getLogPrinter().wtf(tag, message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected void setToDefault() {
|
||||
settings.setTag(LogUtil.getDefaultSettings().getTag());
|
||||
settings.setShowThreadInfo(LogUtil.getDefaultSettings().getShowThreadInfo());
|
||||
settings.setStackTraceCount(LogUtil.getDefaultSettings().getStackTraceCount());
|
||||
settings.setLogLevel(LogUtil.getDefaultSettings().getLogLevel());
|
||||
settings.setShowDivider(LogUtil.getDefaultSettings().getShowDivider());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
|
||||
/**
|
||||
* LogPrinter helps to print message for {@link LogHelper}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public abstract class LogPrinter {
|
||||
|
||||
public void v(String tag, String message) {
|
||||
Log.v(tag, message);
|
||||
}
|
||||
|
||||
public void d(String tag, String message) {
|
||||
Log.d(tag, message);
|
||||
}
|
||||
|
||||
public void i(String tag, String message) {
|
||||
Log.i(tag, message);
|
||||
}
|
||||
|
||||
public void w(String tag, String message) {
|
||||
Log.w(tag, message);
|
||||
}
|
||||
|
||||
public void e(String tag, String message) {
|
||||
Log.e(tag, message);
|
||||
}
|
||||
|
||||
public void wtf(String tag, String message) {
|
||||
if (APILevel.require(8))
|
||||
Log.wtf(tag, message);
|
||||
else
|
||||
Log.e(tag, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.thefinestartist.enums.LogLevel;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* LogUtil helps to manage application-wide {@link Log} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class LogUtil {
|
||||
|
||||
// Defaults
|
||||
private static Settings defaultSettings = new Settings(LogUtil.class.getSimpleName());
|
||||
|
||||
// Singleton
|
||||
private static volatile LogHelper logHelper = new LogHelper()
|
||||
.tag(defaultSettings.getTag())
|
||||
.showThreadInfo(defaultSettings.getShowThreadInfo())
|
||||
.stackTraceCount(defaultSettings.getStackTraceCount())
|
||||
.logLevel(defaultSettings.getLogLevel())
|
||||
.showDivider(defaultSettings.getShowDivider());
|
||||
|
||||
public static Settings getDefaultSettings() {
|
||||
return defaultSettings;
|
||||
}
|
||||
|
||||
public static LogHelper getInstance() {
|
||||
return logHelper;
|
||||
}
|
||||
|
||||
// Builder
|
||||
public static LogHelper tag(String tag) {
|
||||
return logHelper.tag(tag);
|
||||
}
|
||||
|
||||
public static LogHelper tag(@StringRes int tagRes) {
|
||||
return logHelper.tag(tagRes);
|
||||
}
|
||||
|
||||
public static LogHelper tag(Class clazz) {
|
||||
return logHelper.tag(clazz);
|
||||
}
|
||||
|
||||
public static LogHelper showThreadInfo(boolean showThreadInfo) {
|
||||
return logHelper.showThreadInfo(showThreadInfo);
|
||||
}
|
||||
|
||||
public static LogHelper stackTraceCount(int stackTraceCount) {
|
||||
return logHelper.stackTraceCount(stackTraceCount);
|
||||
}
|
||||
|
||||
public static LogHelper logLevel(LogLevel logLevel) {
|
||||
return logHelper.logLevel(logLevel);
|
||||
}
|
||||
|
||||
public static LogHelper showDivider(boolean showDivider) {
|
||||
return logHelper.showDivider(showDivider);
|
||||
}
|
||||
|
||||
public LogHelper logPrinter(LogPrinter logPrinter) {
|
||||
return logHelper.logPrinter(logPrinter);
|
||||
}
|
||||
|
||||
// Logging Verbose
|
||||
public static void v(byte message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(char message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(short message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(int message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(long message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(float message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(double message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(boolean message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(String message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(JSONObject message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(JSONArray message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(Exception message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
public static void v(Object message) {
|
||||
logHelper.v(message);
|
||||
}
|
||||
|
||||
// Logging Debug
|
||||
public static void d(byte message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(char message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(short message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(int message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(long message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(float message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(double message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(boolean message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(String message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(JSONObject message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(JSONArray message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(Exception message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
public static void d(Object message) {
|
||||
logHelper.d(message);
|
||||
}
|
||||
|
||||
// Logging Information
|
||||
public static void i(byte message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(char message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(short message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(int message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(long message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(float message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(double message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(boolean message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(String message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(JSONObject message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(JSONArray message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(Exception message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
public static void i(Object message) {
|
||||
logHelper.i(message);
|
||||
}
|
||||
|
||||
// Logging Warning
|
||||
public static void w(byte message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(char message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(short message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(int message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(long message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(float message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(double message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(boolean message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(String message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(JSONObject message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(JSONArray message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(Exception message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
public static void w(Object message) {
|
||||
logHelper.w(message);
|
||||
}
|
||||
|
||||
// Logging Error
|
||||
public static void e(byte message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(char message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(short message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(int message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(long message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(float message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(double message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(boolean message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(String message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(JSONObject message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(JSONArray message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(Exception message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
public static void e(Object message) {
|
||||
logHelper.e(message);
|
||||
}
|
||||
|
||||
// Logging Assert
|
||||
public static void wtf(byte message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(char message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(short message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(int message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(long message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(float message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(double message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(boolean message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(String message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(JSONObject message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(JSONArray message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(Exception message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
public static void wtf(Object message) {
|
||||
logHelper.wtf(message);
|
||||
}
|
||||
|
||||
// Logging JsonString
|
||||
public static void json(String jsonString) {
|
||||
json(LogLevel.DEBUG, jsonString);
|
||||
}
|
||||
|
||||
public static void json(LogLevel logLevel, String jsonString) {
|
||||
logHelper.json(logLevel, jsonString);
|
||||
}
|
||||
|
||||
// Logging XmlString
|
||||
public static void xml(String xmlString) {
|
||||
xml(LogLevel.DEBUG, xmlString);
|
||||
}
|
||||
|
||||
public static void xml(LogLevel logLevel, String jsonString) {
|
||||
logHelper.xml(logLevel, jsonString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.thefinestartist.enums.LogLevel;
|
||||
import com.thefinestartist.utils.content.ResourcesUtil;
|
||||
|
||||
/**
|
||||
* Settings for {@link LogHelper}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Settings {
|
||||
|
||||
private String tag = Settings.class.getSimpleName();
|
||||
private boolean showThreadInfo = false;
|
||||
private int stackTraceCount = 0;
|
||||
private LogLevel logLevel = LogLevel.FULL;
|
||||
private boolean showDivider = false;
|
||||
private LogPrinter logPrinter = new AndroidLogPrinter();
|
||||
|
||||
public Settings() {
|
||||
}
|
||||
|
||||
public Settings(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public Settings(@StringRes int tagRes) {
|
||||
this.tag = ResourcesUtil.getString(tagRes);
|
||||
}
|
||||
|
||||
public Settings(Class clazz) {
|
||||
this.tag = clazz.getSimpleName();
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public Settings setTag(String tag) {
|
||||
this.tag = tag;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings setTag(@StringRes int tagRes) {
|
||||
this.tag = ResourcesUtil.getString(tagRes);
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings setTag(Class clazz) {
|
||||
this.tag = clazz.getSimpleName();
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getShowThreadInfo() {
|
||||
return showThreadInfo;
|
||||
}
|
||||
|
||||
public Settings setShowThreadInfo(boolean showThreadInfo) {
|
||||
this.showThreadInfo = showThreadInfo;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getStackTraceCount() {
|
||||
return stackTraceCount;
|
||||
}
|
||||
|
||||
public Settings setStackTraceCount(int stackTraceCount) {
|
||||
this.stackTraceCount = stackTraceCount;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogLevel getLogLevel() {
|
||||
return logLevel;
|
||||
}
|
||||
|
||||
public Settings setLogLevel(LogLevel logLevel) {
|
||||
this.logLevel = logLevel;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getShowDivider() {
|
||||
return showDivider;
|
||||
}
|
||||
|
||||
public Settings setShowDivider(boolean showDivider) {
|
||||
this.showDivider = showDivider;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LogPrinter getLogPrinter() {
|
||||
return logPrinter;
|
||||
}
|
||||
|
||||
public Settings setLogPrinter(LogPrinter logPrinter) {
|
||||
this.logPrinter = logPrinter;
|
||||
if (this == LogUtil.getDefaultSettings()) LogUtil.getInstance().setToDefault();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.preferences;
|
||||
|
||||
/**
|
||||
* Pref is abbreviation class of {@link PreferencesUtil}.
|
||||
*
|
||||
* @author Robin Gustafsson
|
||||
*/
|
||||
public class Pref extends PreferencesUtil {
|
||||
}
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
package com.thefinestartist.utils.preferences;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.util.Base64;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
import com.thefinestartist.utils.log.LogHelper;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* PreferencesUtil helps to manage application-wide {@link SharedPreferences} conveniently.
|
||||
*
|
||||
* @author Robin Gustafsson
|
||||
*/
|
||||
public class PreferencesUtil {
|
||||
|
||||
private static final LogHelper LogHelper = new LogHelper(PreferencesUtil.class);
|
||||
private static String defaultName = PreferencesUtil.class.getCanonicalName();
|
||||
|
||||
private static SharedPreferences getPreferences(String name) {
|
||||
return Base.getContext().getSharedPreferences(name, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
|
||||
public static String getDefaultName() {
|
||||
return defaultName;
|
||||
}
|
||||
|
||||
public static void setDefaultName(String name) {
|
||||
defaultName = name;
|
||||
}
|
||||
|
||||
|
||||
public static boolean get(String key, boolean defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
public static int get(String key, int defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
public static float get(String key, float defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
public static long get(String key, long defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
public static String get(String key, String defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static Set<String> get(String key, Set<String> defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public static <C extends Serializable> C get(String key, C defValue) {
|
||||
return get(defaultName, key, defValue);
|
||||
}
|
||||
|
||||
public static boolean get(String name, String key, boolean defValue) {
|
||||
return getPreferences(name).getBoolean(key, defValue);
|
||||
}
|
||||
|
||||
public static int get(String name, String key, int defValue) {
|
||||
return getPreferences(name).getInt(key, defValue);
|
||||
}
|
||||
|
||||
public static float get(String name, String key, float defValue) {
|
||||
return getPreferences(name).getFloat(key, defValue);
|
||||
}
|
||||
|
||||
public static long get(String name, String key, long defValue) {
|
||||
return getPreferences(name).getLong(key, defValue);
|
||||
}
|
||||
|
||||
public static String get(String name, String key, String defValue) {
|
||||
return getPreferences(name).getString(key, defValue);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static Set<String> get(String name, String key, Set<String> defValue) {
|
||||
return getPreferences(name).getStringSet(key, defValue);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public static <C extends Serializable> C get(String name, String key, C defValue) {
|
||||
ByteArrayInputStream bais = null;
|
||||
ObjectInputStream ois = null;
|
||||
C result = defValue;
|
||||
|
||||
String value = getPreferences(name).getString(key, null);
|
||||
if (value != null) {
|
||||
try {
|
||||
byte[] decoded = Base64.decode(value.getBytes(), Base64.DEFAULT);
|
||||
bais = new ByteArrayInputStream(decoded);
|
||||
ois = new ObjectInputStream(bais);
|
||||
result = (C) ois.readObject();
|
||||
|
||||
} catch (Exception e) {
|
||||
LogHelper.e(e);
|
||||
} finally {
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close();
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(e);
|
||||
}
|
||||
}
|
||||
if (bais != null) {
|
||||
try {
|
||||
bais.close();
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void put(String key, boolean value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, int value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, float value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, long value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
public static void put(String key, String value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static void put(String key, Set<String> value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public static <C extends Serializable> void put(String key, C value) {
|
||||
put(defaultName, key, value);
|
||||
}
|
||||
|
||||
public static void put(String name, String key, boolean value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putBoolean(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putBoolean(key, value).commit();
|
||||
}
|
||||
|
||||
public static void put(String name, String key, int value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putInt(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putInt(key, value).commit();
|
||||
}
|
||||
|
||||
public static void put(String name, String key, float value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putFloat(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putFloat(key, value).commit();
|
||||
}
|
||||
|
||||
public static void put(String name, String key, long value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putLong(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putLong(key, value).commit();
|
||||
}
|
||||
|
||||
public static void put(String name, String key, String value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putString(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putString(key, value).commit();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static void put(String name, String key, Set<String> value) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putStringSet(key, value).apply();
|
||||
else
|
||||
getPreferences(name).edit().putStringSet(key, value).commit();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
public static <C extends Serializable> void put(String name, String key, C value) {
|
||||
ByteArrayOutputStream baos = null;
|
||||
ObjectOutputStream oos = null;
|
||||
|
||||
try {
|
||||
baos = new ByteArrayOutputStream();
|
||||
oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(value);
|
||||
byte[] encoded = Base64.encode(baos.toByteArray(), Base64.DEFAULT);
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().putString(key, new String(encoded)).apply();
|
||||
else
|
||||
getPreferences(name).edit().putString(key, new String(encoded)).commit();
|
||||
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(e);
|
||||
throw new RuntimeException(e);
|
||||
|
||||
} finally {
|
||||
if (oos != null) {
|
||||
try {
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(e);
|
||||
}
|
||||
}
|
||||
if (baos != null) {
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException e) {
|
||||
LogHelper.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void remove(String key) {
|
||||
remove(defaultName, key);
|
||||
}
|
||||
|
||||
public static void remove(String name, String key) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().remove(key).apply();
|
||||
else
|
||||
getPreferences(name).edit().remove(key).commit();
|
||||
}
|
||||
|
||||
|
||||
public static void clear() {
|
||||
clear(defaultName);
|
||||
}
|
||||
|
||||
public static void clear(String name) {
|
||||
if (APILevel.require(9))
|
||||
getPreferences(name).edit().clear().apply();
|
||||
else
|
||||
getPreferences(name).edit().clear().commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.thefinestartist.utils.service;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipDescription;
|
||||
import android.content.ClipboardManager;
|
||||
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
|
||||
/**
|
||||
* ClipboardManagerUtil helps to manage {@link ClipboardManager} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ClipboardManagerUtil {
|
||||
|
||||
public static void setText(CharSequence text) {
|
||||
android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
|
||||
if (APILevel.require(11)) {
|
||||
ClipboardManager cm = (ClipboardManager) clipboardManager;
|
||||
ClipData clip = ClipData.newPlainText("ClipboardManagerUtil", text);
|
||||
cm.setPrimaryClip(clip);
|
||||
} else {
|
||||
clipboardManager.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasText() {
|
||||
android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
|
||||
if (APILevel.require(11)) {
|
||||
ClipboardManager cm = (ClipboardManager) clipboardManager;
|
||||
ClipDescription description = cm.getPrimaryClipDescription();
|
||||
ClipData clipData = cm.getPrimaryClip();
|
||||
return clipData != null
|
||||
&& description != null
|
||||
&& (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN));
|
||||
} else {
|
||||
return clipboardManager.hasText();
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSequence getText() {
|
||||
android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager();
|
||||
if (APILevel.require(11)) {
|
||||
ClipboardManager cm = (ClipboardManager) clipboardManager;
|
||||
ClipDescription description = cm.getPrimaryClipDescription();
|
||||
ClipData clipData = cm.getPrimaryClip();
|
||||
if (clipData != null
|
||||
&& description != null
|
||||
&& description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
|
||||
return clipData.getItemAt(0).getText();
|
||||
else
|
||||
return null;
|
||||
} else {
|
||||
return clipboardManager.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
package com.thefinestartist.utils.service;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.DownloadManager;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.SearchManager;
|
||||
import android.app.UiModeManager;
|
||||
import android.app.WallpaperManager;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.app.usage.NetworkStatsManager;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
import android.content.Context;
|
||||
import android.content.RestrictionsManager;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.hardware.ConsumerIrManager;
|
||||
import android.hardware.SensorManager;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.location.LocationManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaRouter;
|
||||
import android.media.midi.MidiManager;
|
||||
import android.media.projection.MediaProjectionManager;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.media.tv.TvInputManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.nsd.NsdManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.nfc.NfcManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.DropBoxManager;
|
||||
import android.os.PowerManager;
|
||||
import android.os.UserManager;
|
||||
import android.os.Vibrator;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.print.PrintManager;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.ClipboardManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.view.accessibility.CaptioningManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.textservice.TextServicesManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
|
||||
/**
|
||||
* ServiceUtil helps to manage Android system service conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ServiceUtil {
|
||||
|
||||
public static Object getSystemService(@NonNull String serviceName) {
|
||||
return Base.getContext().getSystemService(serviceName);
|
||||
}
|
||||
|
||||
public static AccessibilityManager getAccessibilityManager() {
|
||||
return (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public static CaptioningManager getCaptioningManager() {
|
||||
return (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE);
|
||||
}
|
||||
|
||||
public static AccountManager getAccountManager() {
|
||||
return (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
|
||||
}
|
||||
|
||||
public static ActivityManager getActivityManager() {
|
||||
return (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
}
|
||||
|
||||
public static AlarmManager getAlarmManager() {
|
||||
return (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
}
|
||||
|
||||
public static AudioManager getAudioManager() {
|
||||
return (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public static MediaRouter getMediaRouter() {
|
||||
return (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(18)
|
||||
public static BluetoothManager getBluetoothManager() {
|
||||
return (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
}
|
||||
|
||||
public static ClipboardManager getClipboardManager() {
|
||||
return (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
}
|
||||
|
||||
public static ConnectivityManager getConnectivityManager() {
|
||||
return (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(8)
|
||||
public static DevicePolicyManager getDevicePolicyManager() {
|
||||
return (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(9)
|
||||
public static DownloadManager getDownloadManager() {
|
||||
return (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static BatteryManager getBatteryManager() {
|
||||
return (BatteryManager) getSystemService(Context.BATTERY_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(10)
|
||||
public static NfcManager getNfcManager() {
|
||||
return (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(8)
|
||||
public static DropBoxManager getDropBoxManager() {
|
||||
return (DropBoxManager) getSystemService(Context.DROPBOX_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public static InputManager getInputManager() {
|
||||
return (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static DisplayManager getDisplayManager() {
|
||||
return (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
|
||||
}
|
||||
|
||||
public static InputMethodManager getInputMethodManager() {
|
||||
return (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public static TextServicesManager getTextServicesManager() {
|
||||
return (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||
}
|
||||
|
||||
public static KeyguardManager getKeyguardManager() {
|
||||
return (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
|
||||
}
|
||||
|
||||
public static LayoutInflater getLayoutInflater() {
|
||||
return (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
public static LocationManager getLocationManager() {
|
||||
return (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
}
|
||||
|
||||
public static NotificationManager getNotificationManager() {
|
||||
return (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
public static NsdManager getNsdManager() {
|
||||
return (NsdManager) getSystemService(Context.NSD_SERVICE);
|
||||
}
|
||||
|
||||
public static PowerManager getPowerManager() {
|
||||
return (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
}
|
||||
|
||||
public static SearchManager getSearchManager() {
|
||||
return (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
}
|
||||
|
||||
public static SensorManager getSensorManager() {
|
||||
return (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(9)
|
||||
public static StorageManager getStorageManager() {
|
||||
return (StorageManager) getSystemService(Context.STORAGE_SERVICE);
|
||||
}
|
||||
|
||||
public static TelephonyManager getTelephonyManager() {
|
||||
return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(22)
|
||||
public static SubscriptionManager getSubscriptionManager() {
|
||||
return (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static CarrierConfigManager getCarrierConfigManager() {
|
||||
return (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static TelecomManager getTelecomManager() {
|
||||
return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(8)
|
||||
public static UiModeManager getUiModeManager() {
|
||||
return (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(12)
|
||||
public static UsbManager getUsbManager() {
|
||||
return (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
}
|
||||
|
||||
public static Vibrator getVibrator() {
|
||||
return (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||
}
|
||||
|
||||
public static WallpaperManager getWallpaperManager() {
|
||||
return WallpaperManager.getInstance(Base.getContext());
|
||||
}
|
||||
|
||||
public static WifiManager getWifiManager() {
|
||||
return (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public static WifiP2pManager getWifiP2pManager() {
|
||||
return (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
|
||||
}
|
||||
|
||||
public static WindowManager getWindowManager() {
|
||||
return (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(17)
|
||||
public static UserManager getUserManager() {
|
||||
return (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public static AppOpsManager getAppOpsManager() {
|
||||
return (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static CameraManager getCameraManager() {
|
||||
return (CameraManager) getSystemService(Context.CAMERA_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static LauncherApps getLauncherApps() {
|
||||
return (LauncherApps) getSystemService(Context.LAUNCHER_APPS_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static RestrictionsManager getRestrictionsManager() {
|
||||
return (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public static PrintManager getPrintManager() {
|
||||
return (PrintManager) getSystemService(Context.PRINT_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public static ConsumerIrManager getConsumerIrManager() {
|
||||
return (ConsumerIrManager) getSystemService(Context.CONSUMER_IR_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static MediaSessionManager getMediaSessionManager() {
|
||||
return (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static FingerprintManager getFingerprintManager() {
|
||||
return (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static TvInputManager getTvInputManager() {
|
||||
return (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(22)
|
||||
public static UsageStatsManager getUsageStatsManager() {
|
||||
return (UsageStatsManager) getSystemService(Context.USAGE_STATS_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static NetworkStatsManager getNetworkStatsManager() {
|
||||
return (NetworkStatsManager) getSystemService(Context.NETWORK_STATS_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static JobScheduler getJobScheduler() {
|
||||
return (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static MediaProjectionManager getMediaProjectionManager() {
|
||||
return (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static AppWidgetManager getAppWidgetManager() {
|
||||
return (AppWidgetManager) getSystemService(Context.APPWIDGET_SERVICE);
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
public static MidiManager getMidiManager() {
|
||||
return (MidiManager) getSystemService(Context.MIDI_SERVICE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.thefinestartist.utils.service;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.media.AudioAttributes;
|
||||
import android.os.Vibrator;
|
||||
|
||||
/**
|
||||
* VibratorUtil helps to manage {@link Vibrator} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class VibratorUtil {
|
||||
|
||||
@TargetApi(11)
|
||||
public static boolean hasVibrator() {
|
||||
return ServiceUtil.getVibrator().hasVibrator();
|
||||
}
|
||||
|
||||
public static void vibrate() {
|
||||
vibrate(200);
|
||||
}
|
||||
|
||||
public static void vibrate(long milliseconds) {
|
||||
vibrate(new long[]{milliseconds});
|
||||
}
|
||||
|
||||
public static void vibrate(long[] pattern) {
|
||||
vibrate(pattern, -1);
|
||||
}
|
||||
|
||||
public static void vibrate(long[] pattern, int repeat) {
|
||||
ServiceUtil.getVibrator().vibrate(pattern, repeat);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static void vibrate(long milliseconds, AudioAttributes attributes) {
|
||||
vibrate(new long[]{milliseconds}, -1, attributes);
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
public static void vibrate(long[] pattern, int repeat, AudioAttributes attributes) {
|
||||
ServiceUtil.getVibrator().vibrate(pattern, repeat, attributes);
|
||||
}
|
||||
|
||||
public static void cancel() {
|
||||
ServiceUtil.getVibrator().cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.thefinestartist.utils.service;
|
||||
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
* WindowManagerUtil helps to manage {@link WindowManager} conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class WindowManagerUtil {
|
||||
|
||||
public static Display getDefaultDisplay() {
|
||||
return ServiceUtil.getWindowManager().getDefaultDisplay();
|
||||
}
|
||||
|
||||
public static void removeViewImmediate(View view) {
|
||||
ServiceUtil.getWindowManager().removeViewImmediate(view);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.thefinestartist.utils.ui;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
|
||||
import com.thefinestartist.enums.Rotation;
|
||||
import com.thefinestartist.utils.content.ResourcesUtil;
|
||||
import com.thefinestartist.utils.content.ThemeUtil;
|
||||
import com.thefinestartist.utils.content.TypedValueUtil;
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
import com.thefinestartist.utils.service.WindowManagerUtil;
|
||||
|
||||
/**
|
||||
* DisplayUtil helps to calculate screen size conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class DisplayUtil {
|
||||
|
||||
public static int getWidth() {
|
||||
Display display = WindowManagerUtil.getDefaultDisplay();
|
||||
if (APILevel.require(13)) {
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
return size.x;
|
||||
} else {
|
||||
return display.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
Display display = WindowManagerUtil.getDefaultDisplay();
|
||||
if (APILevel.require(13)) {
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
return size.y;
|
||||
} else {
|
||||
return display.getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
public static Rotation getRotation() {
|
||||
if (APILevel.require(8))
|
||||
return Rotation.fromValue(WindowManagerUtil.getDefaultDisplay().getRotation());
|
||||
else
|
||||
return Rotation.fromValue(WindowManagerUtil.getDefaultDisplay().getOrientation());
|
||||
}
|
||||
|
||||
public static boolean isPortrait() {
|
||||
return getHeight() >= getWidth();
|
||||
}
|
||||
|
||||
public static boolean isLandscape() {
|
||||
return getHeight() < getWidth();
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight() {
|
||||
int resourceId = ResourcesUtil.getIdentifier("status_bar_height", "dimen", "android");
|
||||
return resourceId > 0 ?
|
||||
ResourcesUtil.getDimensionPixelSize(resourceId) :
|
||||
0;
|
||||
}
|
||||
|
||||
public static int getToolbarHeight() {
|
||||
return getActionBarHeight();
|
||||
}
|
||||
|
||||
public static int getActionBarHeight() {
|
||||
TypedValue tv = new TypedValue();
|
||||
return ThemeUtil.resolveAttribute(android.R.attr.actionBarSize, tv, true) ?
|
||||
TypedValueUtil.complexToDimensionPixelSize(tv.data) :
|
||||
0;
|
||||
}
|
||||
|
||||
public static int getNavigationBarHeight() {
|
||||
int resourceId = ResourcesUtil.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
return resourceId > 0 ?
|
||||
ResourcesUtil.getDimensionPixelSize(resourceId) :
|
||||
0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.thefinestartist.utils.ui;
|
||||
|
||||
/**
|
||||
* Keyboard is abbreviation class of {@link KeyboardUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Keyboard extends KeyboardUtil {
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package com.thefinestartist.utils.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.converters.UnitConverter;
|
||||
import com.thefinestartist.utils.etc.ThreadUtil;
|
||||
import com.thefinestartist.utils.service.ServiceUtil;
|
||||
|
||||
/**
|
||||
* KeyboardUtil helps to show and hide keyboard conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class KeyboardUtil {
|
||||
|
||||
public static int height = 0;
|
||||
public static final String KEYBOARD_UTIL_PREF = "KEYBOARD_UTIL_PREF";
|
||||
public static final String KEYBOARD_HEIGHT = "KEYBOARD_HEIGHT";
|
||||
public static final int DEFAULT_KEYBOARD_HEIGHT = 200;
|
||||
|
||||
/**
|
||||
* Helps to show keyboard in {@link Activity#onCreate(Bundle)}, {@link Activity#onStart()},
|
||||
* {@link Activity#onResume()},
|
||||
* {@link MenuItem.OnActionExpandListener#onMenuItemActionExpand(MenuItem)},
|
||||
* {@link Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)} and etc
|
||||
* This method guarantee to show keyboard every time.
|
||||
*/
|
||||
public static void show(final View view) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
view.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showInMainThread(view);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Please note that this method does not guarantee to show keyboard every time. To guarantee
|
||||
* to show keyboard, please use {@link #show(View)} instead. It doesn't have any delay, use
|
||||
* this method when it is able to show keyboard immediately. EX) when user click a button to
|
||||
* show keyboard
|
||||
*/
|
||||
public static void showImmediately(final View view) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
if (ThreadUtil.isMain()) {
|
||||
showInMainThread(view);
|
||||
} else {
|
||||
view.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showInMainThread(view);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void showInMainThread(final View view) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
view.requestFocus();
|
||||
ServiceUtil.getInputMethodManager().showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
|
||||
public static void hide(Fragment fragment) {
|
||||
if (fragment == null || fragment.getActivity() == null)
|
||||
return;
|
||||
|
||||
hide(fragment.getActivity());
|
||||
}
|
||||
|
||||
public static void hide(Fragment fragment, boolean clearFocus) {
|
||||
if (fragment == null || fragment.getActivity() == null)
|
||||
return;
|
||||
|
||||
hide(fragment.getActivity());
|
||||
}
|
||||
|
||||
public static void hide(Activity activity) {
|
||||
hide(activity, true);
|
||||
}
|
||||
|
||||
public static void hide(Activity activity, boolean clearFocus) {
|
||||
if (activity == null)
|
||||
return;
|
||||
|
||||
hide(activity.getCurrentFocus(), clearFocus);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static void hide(android.app.Fragment fragment) {
|
||||
hide(fragment, true);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static void hide(android.app.Fragment fragment, boolean clearFocus) {
|
||||
if (fragment == null || fragment.getActivity() == null)
|
||||
return;
|
||||
|
||||
hide(fragment.getActivity(), clearFocus);
|
||||
}
|
||||
|
||||
public static void hide(Dialog dialog) {
|
||||
hide(dialog, true);
|
||||
}
|
||||
|
||||
public static void hide(Dialog dialog, boolean clearFocus) {
|
||||
if (dialog == null)
|
||||
return;
|
||||
|
||||
hide(dialog.getCurrentFocus(), clearFocus);
|
||||
}
|
||||
|
||||
public static void hide(View view) {
|
||||
hide(view, true);
|
||||
}
|
||||
|
||||
public static void hide(View view, boolean clearFocus) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
if (clearFocus) {
|
||||
view.clearFocus();
|
||||
}
|
||||
|
||||
ServiceUtil.getInputMethodManager().hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
if (height <= 0)
|
||||
height = Base.getContext().getSharedPreferences(KEYBOARD_UTIL_PREF, Context.MODE_PRIVATE).getInt(KEYBOARD_HEIGHT, UnitConverter.dpToPx(DEFAULT_KEYBOARD_HEIGHT));
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
public static void setHeight(int height) {
|
||||
KeyboardUtil.height = height;
|
||||
Base.getContext().getSharedPreferences(KEYBOARD_UTIL_PREF, Context.MODE_PRIVATE).edit().putInt(KEYBOARD_HEIGHT, height).apply();
|
||||
}
|
||||
|
||||
// coordinatorLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
// @Override
|
||||
// public void onGlobalLayout() {
|
||||
// Rect r = new Rect();
|
||||
// coordinatorLayout.getWindowVisibleDisplayFrame(r);
|
||||
// if (ResourcesUtil.navigationBarHeight == -1) {
|
||||
// ResourcesUtil.navigationBarHeight = coordinatorLayout.getRootView().getHeight() - r.height() - ResourcesUtil.statusBarHeight;
|
||||
// }
|
||||
// int usableHeight = coordinatorLayout.getRootView().getHeight() - ResourcesUtil.statusBarHeight - ResourcesUtil.navigationBarHeight;
|
||||
// int keyboardHeight = usableHeight - r.height();
|
||||
// if (isKeyboardOpened) {
|
||||
// if (keyboardHeight < 100) {
|
||||
// onKeyboardChanged(usableHeight, keyboardHeight, false);
|
||||
// isKeyboardOpened = false;
|
||||
// }
|
||||
// } else {
|
||||
// if (keyboardHeight > 100) {
|
||||
// onKeyboardChanged(usableHeight, keyboardHeight, true);
|
||||
// isKeyboardOpened = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
//TODO: Support keyboard show and hide listener
|
||||
//TODO: Keyboard height
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.thefinestartist.utils.ui;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
||||
import com.thefinestartist.Base;
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
|
||||
/**
|
||||
* ViewUtil helps to set background drawable conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class ViewUtil {
|
||||
|
||||
public static void setBackground(View view, Drawable drawable) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
if (APILevel.require(16)) {
|
||||
view.setBackground(drawable);
|
||||
} else {
|
||||
view.setBackgroundDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBackground(View view, @DrawableRes int drawableRes) {
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
if (APILevel.require(16)) {
|
||||
view.setBackground(Base.getResources().getDrawable(drawableRes));
|
||||
} else {
|
||||
view.setBackgroundDrawable(Base.getResources().getDrawable(drawableRes));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
*/
|
||||
public class AgeUtil {
|
||||
|
||||
// public static String getFromBirthDay(Date date) {
|
||||
// if (date == null)
|
||||
// return "?";
|
||||
//
|
||||
// int year = Integer.parseInt((String) DateFormat.format("yyyy", date));
|
||||
// int month = Integer.parseInt((String) DateFormat.format("MM", date));
|
||||
// int day = Integer.parseInt((String) DateFormat.format("dd", date));
|
||||
//
|
||||
// Calendar birthday = Calendar.getInstance();
|
||||
// birthday.set(year, month - 1, day);
|
||||
// Calendar today = Calendar.getInstance();
|
||||
//
|
||||
//
|
||||
// int age = today.get(Calendar.YEAR) - birthday.get(Calendar.YEAR);
|
||||
//
|
||||
// if (today.get(Calendar.DAY_OF_YEAR) < birthday.get(Calendar.DAY_OF_YEAR)) {
|
||||
// age--;
|
||||
// }
|
||||
//
|
||||
// return String.format("%d", age);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/18/16.
|
||||
*/
|
||||
public class AudioManagerUtil {
|
||||
|
||||
// public static void getMode() {
|
||||
// AudioManager am = ServiceUtil.getAudioManager();
|
||||
// switch (am.getRingerMode()) {
|
||||
// case AudioManager.RINGER_MODE_NORMAL:
|
||||
// case AudioManager.RINGER_MODE_VIBRATE:
|
||||
// case AudioManager.RINGER_MODE_SILENT:
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void getVolume() {
|
||||
// AudioManager am = ServiceUtil.getAudioManager();
|
||||
// int voiceCall = am.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
|
||||
// int system = am.getStreamVolume(AudioManager.STREAM_SYSTEM);
|
||||
// int ring = am.getStreamVolume(AudioManager.STREAM_RING);
|
||||
// int music = am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
// int alarm = am.getStreamVolume(AudioManager.STREAM_ALARM);
|
||||
// int notification = am.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
|
||||
// }
|
||||
//
|
||||
// public static void setVolume() {
|
||||
// AudioManager am = ServiceUtil.getAudioManager();
|
||||
// int currentVolumn = am.getStreamVolume(AudioManager.STREAM_SYSTEM);
|
||||
// switch (am.getRingerMode()) {
|
||||
// case AudioManager.RINGER_MODE_SILENT:
|
||||
// am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
|
||||
// break;
|
||||
// case AudioManager.RINGER_MODE_VIBRATE:
|
||||
// am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
|
||||
// break;
|
||||
// case AudioManager.RINGER_MODE_NORMAL:
|
||||
// am.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolumn, 0);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/10/16.
|
||||
*/
|
||||
public class AwakeUtil {
|
||||
|
||||
// private static Map<String, PowerManager.WakeLock> wakeLocks = new HashMap<>();
|
||||
// private static final String TAG = "AwakeUtil";
|
||||
//
|
||||
// public static void awakeCPU() {
|
||||
// awakeCPU(TAG);
|
||||
// }
|
||||
//
|
||||
// public static void awakeCPU(@NonNull String tag) {
|
||||
// PowerManager.WakeLock wakeLock = ServiceUtil.getPowerManager().newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag);
|
||||
// wakeLock.acquire();
|
||||
//
|
||||
// if (wakeLocks.get(tag) != null)
|
||||
// releaseCPU(tag);
|
||||
// wakeLocks.put(tag, wakeLock);
|
||||
// }
|
||||
//
|
||||
// public static void releaseCPU() {
|
||||
// releaseCPU(TAG);
|
||||
// }
|
||||
//
|
||||
// public static void releaseCPU(@NonNull String tag) {
|
||||
// if (wakeLocks.get(tag) == null)
|
||||
// return;
|
||||
//
|
||||
// wakeLocks.get(tag).release();
|
||||
// wakeLocks.remove(tag);
|
||||
// }
|
||||
//
|
||||
// public static void awakeScreen(@NonNull Activity activity) {
|
||||
// activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
// }
|
||||
//
|
||||
// public static void releaseScreen(@NonNull Activity activity) {
|
||||
// activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||
// }
|
||||
//
|
||||
// public void turnOnScreen() {
|
||||
// ServiceUtil.getPowerManager().newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag").acquire();
|
||||
// }
|
||||
//
|
||||
// public void turnOffScreen() {
|
||||
// if (APILevel.require(21))
|
||||
// ServiceUtil.getPowerManager().newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag").acquire();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/9/16.
|
||||
*/
|
||||
public class BitmapUtil {
|
||||
|
||||
// private final static String TAG = ImageUtils.class.getSimpleName();
|
||||
//
|
||||
// private static final String ERROR_URI_NULL = "Uri cannot be null";
|
||||
//
|
||||
// /***
|
||||
// * Scales the image depending upon the display density of the device. Maintains image aspect
|
||||
// * ratio.
|
||||
// *
|
||||
// * When dealing with the bitmaps of bigger size, this method must be called from a non-UI
|
||||
// * thread.
|
||||
// * ***/
|
||||
// public static Bitmap scaleDownBitmap(Context ctx, Bitmap source, int newHeight) {
|
||||
// final float densityMultiplier = Utils.getDensityMultiplier(ctx);
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Original w: " + source.getWidth() + " h: " +
|
||||
// // source.getHeight() );
|
||||
//
|
||||
// int h = (int) (newHeight * densityMultiplier);
|
||||
// int w = (int) (h * source.getWidth() / ((double) source.getHeight()));
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Computed w: " + w + " h: " + h );
|
||||
//
|
||||
// Bitmap photo = Bitmap.createScaledBitmap(source, w, h, true);
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Final w: " + w + " h: " + h );
|
||||
//
|
||||
// return photo;
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * Scales the image independently of the screen density of the device. Maintains image aspect
|
||||
// * ratio.
|
||||
// *
|
||||
// * When dealing with the bitmaps of bigger size, this method must be called from a non-UI
|
||||
// * thread.
|
||||
// * ***/
|
||||
// public static Bitmap scaleBitmap(Context ctx, Bitmap source, int newHeight) {
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Original w: " + source.getWidth() + " h: " +
|
||||
// // source.getHeight() );
|
||||
//
|
||||
// int w = (int) (newHeight * source.getWidth() / ((double) source.getHeight()));
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Computed w: " + w + " h: " + newHeight );
|
||||
//
|
||||
// Bitmap photo = Bitmap.createScaledBitmap(source, w, newHeight, true);
|
||||
//
|
||||
// // Log.v( TAG, "#scaleDownBitmap Final w: " + w + " h: " + newHeight );
|
||||
//
|
||||
// return photo;
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * Scales the image independently of the screen density of the device. Maintains image aspect
|
||||
// * ratio.
|
||||
// *
|
||||
// * @param uri
|
||||
// * Uri of the source bitmap
|
||||
// ****/
|
||||
// public static Bitmap scaleDownBitmap(Context ctx, Uri uri, int newHeight) throws FileNotFoundException, IOException {
|
||||
// Bitmap original = Media.getBitmap(ctx.getContentResolver(), uri);
|
||||
// return scaleBitmap(ctx, original, newHeight);
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * Scales the image independently of the screen density of the device. Maintains image aspect
|
||||
// * ratio.
|
||||
// *
|
||||
// * @param uri
|
||||
// * Uri of the source bitmap
|
||||
// ****/
|
||||
// public static Uri scaleDownBitmapForUri(Context ctx, Uri uri, int newHeight) throws FileNotFoundException, IOException {
|
||||
//
|
||||
// if (uri == null)
|
||||
// throw new NullPointerException(ERROR_URI_NULL);
|
||||
//
|
||||
// if (!isMediaContentUri(uri))
|
||||
// return null;
|
||||
//
|
||||
// Bitmap original = Media.getBitmap(ctx.getContentResolver(), uri);
|
||||
// Bitmap bmp = scaleBitmap(ctx, original, newHeight);
|
||||
//
|
||||
// Uri destUri = null;
|
||||
// String uriStr = Utils.writeImageToMedia(ctx, bmp, "", "");
|
||||
//
|
||||
// if (uriStr != null) {
|
||||
// destUri = Uri.parse(uriStr);
|
||||
// }
|
||||
//
|
||||
// return destUri;
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * Gets the orientation of the image pointed to by the parameter uri
|
||||
// *
|
||||
// * @return Image orientation value corresponding to <code>ExifInterface.ORIENTATION_*</code> <br/>
|
||||
// * Returns -1 if the row for the {@link android.net.Uri} is not found.
|
||||
// ****/
|
||||
// public static int getOrientation(Context context, Uri uri) {
|
||||
//
|
||||
// int invalidOrientation = -1;
|
||||
// if (uri == null) {
|
||||
// throw new NullPointerException(ERROR_URI_NULL);
|
||||
// }
|
||||
//
|
||||
// if (!isMediaContentUri(uri)) {
|
||||
// return invalidOrientation;
|
||||
// }
|
||||
//
|
||||
// String filePath = Utils.getImagePathForUri(context, uri);
|
||||
// ExifInterface exif = null;
|
||||
//
|
||||
// try {
|
||||
// exif = new ExifInterface(filePath);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// int orientation = invalidOrientation;
|
||||
// if (exif != null) {
|
||||
// orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, invalidOrientation);
|
||||
// }
|
||||
//
|
||||
// return orientation;
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * @deprecated Use {@link MediaUtils#isMediaContentUri(android.net.Uri)} instead. <br/>
|
||||
// * Checks if the parameter {@link android.net.Uri} is a
|
||||
// * {@link android.provider.MediaStore.Audio.Media} content uri.
|
||||
// ****/
|
||||
// public static boolean isMediaContentUri(Uri uri) {
|
||||
// if (!uri.toString().contains("content://media/")) {
|
||||
// Log.w(TAG, "#isContentUri The uri is not a media content uri");
|
||||
// return false;
|
||||
// } else {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * Rotate the image at the specified uri. For the rotation of the image the
|
||||
// * {@link android.media.ExifInterface} data in the image will be used.
|
||||
// *
|
||||
// * @param uri
|
||||
// * Uri of the image to be rotated.
|
||||
// ****/
|
||||
// public static Uri rotateImage(Context context, Uri uri) throws FileNotFoundException, IOException {
|
||||
// // rotate the image
|
||||
// if (uri == null) {
|
||||
// throw new NullPointerException(ERROR_URI_NULL);
|
||||
// }
|
||||
//
|
||||
// if (!isMediaContentUri(uri)) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// int invalidOrientation = -1;
|
||||
// byte[] data = Utils.getMediaData(context, uri);
|
||||
//
|
||||
// int orientation = getOrientation(context, uri);
|
||||
//
|
||||
// Uri newUri = null;
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// Log.d(TAG, "#rotateImage Exif orientation: " + orientation);
|
||||
//
|
||||
// if (orientation != invalidOrientation) {
|
||||
// Matrix matrix = new Matrix();
|
||||
//
|
||||
// switch (orientation) {
|
||||
// case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
// matrix.postRotate(90);
|
||||
// break;
|
||||
// case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
// matrix.postRotate(180);
|
||||
// break;
|
||||
// case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
// matrix.postRotate(270);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// // set some options so the memory is manager properly
|
||||
// BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// // options.inPreferredConfig = Bitmap.Config.RGB_565; // try to enable this if
|
||||
// // OutOfMem issue still persists
|
||||
// options.inPurgeable = true;
|
||||
// options.inInputShareable = true;
|
||||
//
|
||||
// Bitmap original = BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
||||
// Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true); // rotating
|
||||
// // bitmap
|
||||
// String newUrl = Media.insertImage(((Activity) context).getContentResolver(), rotatedBitmap, "", "");
|
||||
//
|
||||
// if (newUrl != null) {
|
||||
// newUri = Uri.parse(newUrl);
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return newUri;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 1/26/16.
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
// public static String SERVER_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.'000Z'";
|
||||
// public static String POST_FORMAT = "yy/MM/dd HH:mm";
|
||||
// public static String CLICKER_FORMAT = "yyyy/MM/dd kk:mm";
|
||||
// public static String DATE_FORMAT = "yyyy/MM/dd";
|
||||
// public static String TIME_FORMAT = "HH:mm";
|
||||
// private static SimpleDateFormat server_format = new SimpleDateFormat(SERVER_FORMAT);
|
||||
// private static SimpleDateFormat post_format = new SimpleDateFormat(POST_FORMAT);
|
||||
// private static SimpleDateFormat date_format = new SimpleDateFormat(DATE_FORMAT);
|
||||
// private static SimpleDateFormat time_format = new SimpleDateFormat(TIME_FORMAT);
|
||||
//
|
||||
// public static synchronized long getCurrentGMTTimeMillis() {
|
||||
// final Date currentTime = new Date();
|
||||
// final SimpleDateFormat sdf = new SimpleDateFormat(SERVER_FORMAT);
|
||||
// sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// String time = sdf.format(currentTime);
|
||||
// return getTime(time);
|
||||
// }
|
||||
//
|
||||
// public static String getCurrentTimeString() {
|
||||
// return (String) DateFormat.format(CLICKER_FORMAT, System.currentTimeMillis());
|
||||
// }
|
||||
//
|
||||
// public static long getTime(String timeStr) {
|
||||
// Date date;
|
||||
// try {
|
||||
// server_format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// date = server_format.parse(timeStr);
|
||||
// return date.getTime();
|
||||
// } catch (ParseException e) {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static Date getDate(String timeStr) {
|
||||
// Date date;
|
||||
// try {
|
||||
// server_format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// date = server_format.parse(timeStr);
|
||||
// return date;
|
||||
// } catch (ParseException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String getPostFormatString(String timeStr) {
|
||||
// Date date;
|
||||
// try {
|
||||
// server_format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// post_format.setTimeZone(TimeZone.getDefault());
|
||||
// date = server_format.parse(timeStr);
|
||||
// return post_format.format(date);
|
||||
// } catch (ParseException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String getDateFormatString(String timeStr) {
|
||||
// Date date;
|
||||
// try {
|
||||
// server_format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// date_format.setTimeZone(TimeZone.getDefault());
|
||||
// date = server_format.parse(timeStr);
|
||||
// return date_format.format(date);
|
||||
// } catch (ParseException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String getTimeFormatString(String timeStr) {
|
||||
// Date date;
|
||||
// try {
|
||||
// server_format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
// time_format.setTimeZone(TimeZone.getDefault());
|
||||
// date = server_format.parse(timeStr);
|
||||
// return time_format.format(date);
|
||||
// } catch (ParseException e) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
*/
|
||||
public class EmailUtil {
|
||||
|
||||
// public static void sendSupportMail(String url) {
|
||||
// Intent i = new Intent(Intent.ACTION_SEND);
|
||||
// i.setType("message/rfc822");
|
||||
// i.putExtra(Intent.EXTRA_EMAIL, new String[]{url});
|
||||
// i.putExtra(Intent.EXTRA_SUBJECT, "[FEEDBACK] Android App (" + Build.VERSION.CODENAME + ")");
|
||||
// i.putExtra(Intent.EXTRA_TEXT, "");
|
||||
// try {
|
||||
// Base.getContext().startActivity(Intent.createChooser(i, "Send Feedback"));
|
||||
// } catch (android.content.ActivityNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/10/16.
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
// public static String readJsonFile(String filePath) {
|
||||
// try {
|
||||
// String json = null;
|
||||
// InputStream is = Base.getContext().getAssets().open(filePath);
|
||||
// int size = is.available();
|
||||
// byte[] buffer = new byte[size];
|
||||
// is.read(buffer);
|
||||
// is.close();
|
||||
// return new String(buffer, "UTF-8");
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2014. 9. 2..
|
||||
*/
|
||||
public class LanguageDetector {
|
||||
|
||||
// public static boolean isEnglish(CharSequence charSequence) {
|
||||
// boolean isEnglish = true;
|
||||
// for (char c : charSequence.toString().toCharArray()) {
|
||||
// if (Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN) {
|
||||
// isEnglish = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return isEnglish;
|
||||
// }
|
||||
//
|
||||
// public static boolean hasKorean(CharSequence charSequence) {
|
||||
// boolean hasKorean = false;
|
||||
// for (char c : charSequence.toString().toCharArray()) {
|
||||
// if (Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HANGUL_JAMO
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HANGUL_SYLLABLES) {
|
||||
// hasKorean = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return hasKorean;
|
||||
// }
|
||||
//
|
||||
// public static boolean hasJapanese(CharSequence charSequence) {
|
||||
// boolean hasJapanese = false;
|
||||
// for (char c : charSequence.toString().toCharArray()) {
|
||||
// if (Character.UnicodeBlock.of(c) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HIRAGANA
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.KATAKANA
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
|
||||
// || Character.UnicodeBlock.of(c) == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION) {
|
||||
// hasJapanese = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return hasJapanese;
|
||||
// }
|
||||
//
|
||||
// public enum Language {Korean, Japanese, English}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/21/16.
|
||||
*/
|
||||
public class NetworkUtil {
|
||||
|
||||
// public static NetworkInfo getNetworkInfo() {
|
||||
// return ServiceUtil.getConnectivityManager().getActiveNetworkInfo();
|
||||
// }
|
||||
//
|
||||
// public static boolean isConnected() {
|
||||
// NetworkInfo info = getNetworkInfo();
|
||||
// return (info != null && info.isConnected());
|
||||
// }
|
||||
//
|
||||
// public static boolean isConnectedWifi() {
|
||||
// NetworkInfo info = getNetworkInfo();
|
||||
// return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);
|
||||
// }
|
||||
//
|
||||
// public static boolean isConnectedMobile() {
|
||||
// NetworkInfo info = getNetworkInfo();
|
||||
// return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_MOBILE);
|
||||
// }
|
||||
//
|
||||
// public static boolean isConnectedFast() {
|
||||
// NetworkInfo info = getNetworkInfo();
|
||||
// return (info != null && info.isConnected() && isConnectionFast(info.getType(), info.getSubtype()));
|
||||
// }
|
||||
//
|
||||
// public static boolean isConnectionFast(int type, int subType) {
|
||||
// if (type == ConnectivityManager.TYPE_WIFI) {
|
||||
// return true;
|
||||
// } else if (type == ConnectivityManager.TYPE_MOBILE) {
|
||||
// switch (subType) {
|
||||
// case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
// return false; // ~ 50-100 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||
// return false; // ~ 14-64 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||
// return false; // ~ 50-100 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
// return true; // ~ 400-1000 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
||||
// return true; // ~ 600-1400 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||
// return false; // ~ 100 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
// return true; // ~ 2-14 Mbps
|
||||
// case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
// return true; // ~ 700-1700 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
// return true; // ~ 1-23 Mbps
|
||||
// case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
// return true; // ~ 400-7000 kbps
|
||||
// /*
|
||||
// * Above API level 7, make sure to set android:targetSdkVersion
|
||||
// * to appropriate level to use these
|
||||
// */
|
||||
// case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
|
||||
// return true; // ~ 1-2 Mbps
|
||||
// case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
|
||||
// return true; // ~ 5 Mbps
|
||||
// case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
|
||||
// return true; // ~ 10-20 Mbps
|
||||
// case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
|
||||
// return false; // ~25 kbps
|
||||
// case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
|
||||
// return true; // ~ 10+ Mbps
|
||||
// // Unknown
|
||||
// case TelephonyManager.NETWORK_TYPE_UNKNOWN:
|
||||
// default:
|
||||
// return false;
|
||||
// }
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
*/
|
||||
public class PhotoUtil {
|
||||
|
||||
// public static final int IMAGE_MAX_WIDTH = 800;
|
||||
//
|
||||
// public static SoftReference<byte[]> convertToByte(String path) {
|
||||
// if (path == null)
|
||||
// return new SoftReference<>(new byte[0]);
|
||||
//
|
||||
// BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
// int inSampleSize = getInSampleSize(path, IMAGE_MAX_WIDTH * 2);
|
||||
// options.inSampleSize = inSampleSize;
|
||||
// Bitmap bitmap = BitmapFactory.decodeFile(path, options);
|
||||
//
|
||||
// if (bitmap == null) {
|
||||
// inSampleSize = getInSampleSize(path, IMAGE_MAX_WIDTH * 2);
|
||||
// options.inSampleSize = inSampleSize;
|
||||
// bitmap = BitmapFactory.decodeFile(path, options);
|
||||
// }
|
||||
//
|
||||
// if (bitmap == null)
|
||||
// return new SoftReference<>(new byte[0]);
|
||||
//
|
||||
// // Scale the bitmap
|
||||
// if (inSampleSize > 1) {
|
||||
// float height;
|
||||
// switch (getRotation(path)) {
|
||||
// case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
// case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
// height = ((float) bitmap.getWidth()) * ((float) IMAGE_MAX_WIDTH) / ((float) bitmap.getHeight());
|
||||
// bitmap = Bitmap.createScaledBitmap(bitmap, (int) height, IMAGE_MAX_WIDTH, true);
|
||||
// break;
|
||||
// case ExifInterface.ORIENTATION_NORMAL:
|
||||
// case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
// default:
|
||||
// height = ((float) bitmap.getHeight()) * ((float) IMAGE_MAX_WIDTH) / ((float) bitmap.getWidth());
|
||||
// bitmap = Bitmap.createScaledBitmap(bitmap, IMAGE_MAX_WIDTH, (int) height, true);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Rotate the bitmap
|
||||
// switch (getRotation(path)) {
|
||||
// case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
// bitmap = rotateBitmap(bitmap, 90);
|
||||
// break;
|
||||
// case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
// bitmap = rotateBitmap(bitmap, 270);
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// byte[] bytes = null;
|
||||
// try {
|
||||
// ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
// bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);
|
||||
// bytes = stream.toByteArray();
|
||||
// stream.close();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return new SoftReference<>(bytes);
|
||||
// }
|
||||
//
|
||||
// public static Bitmap rotateBitmap(Bitmap bitmap, float angle) {
|
||||
// Matrix matrix = new Matrix();
|
||||
// matrix.postRotate(angle);
|
||||
// return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static int getInSampleSize(String path, int maxWidth) {
|
||||
// SoftReference<Bitmap> bitmap = getBitmap(path);
|
||||
// int inSampleSize = 1;
|
||||
// float currentWidth = 0;
|
||||
// switch (getRotation(path)) {
|
||||
// case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
// case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
// if (bitmap != null && bitmap.get() != null)
|
||||
// currentWidth = bitmap.get().getHeight();
|
||||
// break;
|
||||
// case ExifInterface.ORIENTATION_NORMAL:
|
||||
// case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
// default:
|
||||
// if (bitmap != null && bitmap.get() != null)
|
||||
// currentWidth = bitmap.get().getWidth();
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// currentWidth /= (float) maxWidth;
|
||||
// while (currentWidth > 1) {
|
||||
// inSampleSize *= 2;
|
||||
// currentWidth /= 2;
|
||||
// }
|
||||
//
|
||||
// return inSampleSize;
|
||||
// }
|
||||
//
|
||||
// public static SoftReference<Bitmap> getBitmap(String path) {
|
||||
// SoftReference<Bitmap> bitmap = null;
|
||||
//
|
||||
// try {
|
||||
// bitmap = new SoftReference<>(BitmapFactory.decodeStream(new FileInputStream(new File(path))));
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return bitmap;
|
||||
// }
|
||||
//
|
||||
// public static int getRotation(String path) {
|
||||
// int rotate = ExifInterface.ORIENTATION_NORMAL;
|
||||
// try {
|
||||
// File imageFile = new File(path);
|
||||
// ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
|
||||
// rotate = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return rotate;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/21/16.
|
||||
*/
|
||||
public class RippleUtil {
|
||||
|
||||
// public static void forceEvent(View view, float x, float y) {
|
||||
// Drawable background = view.getBackground();
|
||||
// if (APILevel.require(21)) {
|
||||
// if (background instanceof RippleDrawable) {
|
||||
// RippleDrawable ripple = (RippleDrawable) background;
|
||||
// ripple.setHotspot(x, y);
|
||||
// ripple.setVisible(true, true);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.thefinestartist.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/18/16.
|
||||
*/
|
||||
public class Validator {
|
||||
|
||||
// public static final String SPECIAL_CHARS = "\\p{Cntrl}\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]";
|
||||
// public static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
|
||||
// public static final String QUOTED_USER = "(\"[^\"]*\")";
|
||||
// public static final String WORD = "((" + VALID_CHARS + "|')+|" + QUOTED_USER + ")";
|
||||
//
|
||||
// public static final String EMAIL_REGEX = "^\\s*?(.+)@(.+?)\\s*$";
|
||||
// public static final String IP_DOMAIN_REGEX = "^\\[(.*)\\]$";
|
||||
// public static final String USER_REGEX = "^\\s*" + WORD + "(\\." + WORD + ")*$";
|
||||
//
|
||||
// public static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
|
||||
// public static final Pattern IP_DOMAIN_PATTERN = Pattern.compile(IP_DOMAIN_REGEX);
|
||||
// public static final Pattern USER_PATTERN = Pattern.compile(USER_REGEX);
|
||||
//
|
||||
//
|
||||
// // Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
|
||||
//
|
||||
// // RFC2396: domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
||||
// // Max 63 characters
|
||||
// public static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
|
||||
//
|
||||
// // RFC2396 toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
||||
// // Max 63 characters
|
||||
// public static final String TOP_LABEL_REGEX = "\\p{Alpha}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
|
||||
//
|
||||
// // RFC2396 hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
// // Note that the regex currently requires both a domain label and a top level label, whereas
|
||||
// // the RFC does not. This is because the regex is used to detect if a TLD is present.
|
||||
// // If the match fails, input is checked against DOMAIN_LABEL_REGEX (hostnameRegex)
|
||||
// // RFC1123 sec 2.1 allows hostnames to start with a digit
|
||||
// public static final String DOMAIN_NAME_REGEX = "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX + ")\\.?$";
|
||||
//
|
||||
//
|
||||
// public static boolean isEmail(String email) {
|
||||
// String emailPattern = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
|
||||
// Pattern pattern = Pattern.compile(emailPattern);
|
||||
// Matcher matcher = pattern.matcher(email);
|
||||
// return matcher.matches();
|
||||
// }
|
||||
}
|
||||
// https://github.com/throrin19/Android-Validator/tree/master/library/src/com/throrinstudio/android/common/libs/validator/validator
|
||||
// https://github.com/ragunathjawahar/android-saripaar/tree/master/saripaar/src/main/java/commons/validator/routines
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="1.5" />
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="2.0" />
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<accelerateInterpolator
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="2.5" />
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@android:color/black"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="250"
|
||||
android:fromAlpha="0.2"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:toAlpha="1.0" />
|
||||
<scale
|
||||
android:duration="250"
|
||||
android:fromXScale="0.9"
|
||||
android:fromYScale="0.9"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:pivotX="50.0%p"
|
||||
android:pivotY="50.0%p"
|
||||
android:toXScale="1.0"
|
||||
android:toYScale="1.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:zAdjustment="top">
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fromXDelta="0.0%p"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:toXDelta="100.0%p" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:zAdjustment="top">
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fromXDelta="100.0%p"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:toXDelta="0.0%p" />
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@android:color/black"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="normal">
|
||||
<alpha
|
||||
android:duration="250"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:toAlpha="0.2" />
|
||||
<scale
|
||||
android:duration="250"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="1.0"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:pivotX="50.0%p"
|
||||
android:pivotY="50.0%p"
|
||||
android:toXScale="0.9"
|
||||
android:toYScale="0.9" />
|
||||
</set>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="1.5" />
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<decelerateInterpolator
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="2.0" />
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<decelerateInterpolator
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:factor="2.5" />
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="350"
|
||||
android:fromAlpha="0.0"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:toAlpha="1.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="100"
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="350"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:toAlpha="0.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="100"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<alpha
|
||||
android:duration="1700"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="150"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@anim/accelerate_quart"
|
||||
android:startOffset="100"
|
||||
android:toAlpha="0.0" />
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:fromYDelta="0.0%"
|
||||
android:interpolator="@anim/accelerate_quint"
|
||||
android:toYDelta="4.999995%" />
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="150"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@anim/accelerate_quart"
|
||||
android:startOffset="100"
|
||||
android:toAlpha="0.0" />
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:fromYDelta="0.0%"
|
||||
android:interpolator="@anim/accelerate_quint"
|
||||
android:toYDelta="-4.999995%" />
|
||||
</set>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="200"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:fromAlpha="0.0"
|
||||
android:interpolator="@anim/decelerate_quart"
|
||||
android:toAlpha="1.0" />
|
||||
<translate
|
||||
android:duration="350"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:fromYDelta="8.000004%"
|
||||
android:interpolator="@anim/decelerate_quint"
|
||||
android:toYDelta="0.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="200"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:fromAlpha="0.0"
|
||||
android:interpolator="@anim/decelerate_quart"
|
||||
android:toAlpha="1.0" />
|
||||
<translate
|
||||
android:duration="350"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:fromYDelta="-8.000004%"
|
||||
android:interpolator="@anim/decelerate_quint"
|
||||
android:toYDelta="0.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@android:color/black"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="true"
|
||||
android:fillEnabled="true"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="top">
|
||||
<alpha
|
||||
android:duration="250"
|
||||
android:fromAlpha="0.2"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:toAlpha="1.0" />
|
||||
<scale
|
||||
android:duration="250"
|
||||
android:fromXScale="0.9"
|
||||
android:fromYScale="0.9"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:pivotX="50.0%p"
|
||||
android:pivotY="50.0%p"
|
||||
android:toXScale="1.0"
|
||||
android:toYScale="1.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:zAdjustment="top">
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fromYDelta="0.0%p"
|
||||
android:interpolator="@anim/accelerate_cubic"
|
||||
android:toYDelta="100.0%p" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:zAdjustment="top">
|
||||
<translate
|
||||
android:duration="250"
|
||||
android:fromYDelta="100.0%p"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:toYDelta="0.0%p" />
|
||||
</set>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:background="@android:color/black"
|
||||
android:fillAfter="true"
|
||||
android:fillBefore="false"
|
||||
android:fillEnabled="true"
|
||||
android:shareInterpolator="false"
|
||||
android:zAdjustment="normal">
|
||||
<alpha
|
||||
android:duration="250"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:toAlpha="0.2" />
|
||||
<scale
|
||||
android:duration="250"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="1.0"
|
||||
android:interpolator="@anim/decelerate_cubic"
|
||||
android:pivotX="50.0%p"
|
||||
android:pivotY="50.0%p"
|
||||
android:toXScale="0.9"
|
||||
android:toYScale="0.9" />
|
||||
</set>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="1.0" />
|
||||
</set>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<alpha
|
||||
android:duration="500"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.3" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:duration="600"
|
||||
android:repeatMode="reverse"
|
||||
android:repeatCount="infinite" />
|
||||
</set>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true"
|
||||
android:interpolator="@android:anim/bounce_interpolator">
|
||||
|
||||
<scale
|
||||
android:duration="500"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="0.0"
|
||||
android:toXScale="1.0"
|
||||
android:toYScale="1.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true">
|
||||
|
||||
<alpha
|
||||
android:duration="1000"
|
||||
android:fromAlpha="0.0"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:toAlpha="1.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true">
|
||||
|
||||
<alpha
|
||||
android:duration="1000"
|
||||
android:fromAlpha="1.0"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:toAlpha="0.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:interpolator="@android:anim/linear_interpolator"
|
||||
android:fillAfter="true">
|
||||
|
||||
<translate
|
||||
android:fromXDelta="0%p"
|
||||
android:toXDelta="75%p"
|
||||
android:duration="800" />
|
||||
</set>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<rotate
|
||||
android:fromDegrees="0"
|
||||
android:toDegrees="360"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:duration="600"
|
||||
android:repeatMode="restart"
|
||||
android:repeatCount="infinite"
|
||||
android:interpolator="@android:anim/cycle_interpolator" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true">
|
||||
|
||||
<scale
|
||||
android:duration="500"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="0.0"
|
||||
android:interpolator="@android:anim/linear_interpolator"
|
||||
android:toXScale="1.0"
|
||||
android:toYScale="1.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true" >
|
||||
|
||||
<scale
|
||||
android:duration="500"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="1.0"
|
||||
android:interpolator="@android:anim/linear_interpolator"
|
||||
android:toXScale="1.0"
|
||||
android:toYScale="0.0" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true">
|
||||
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="1000"
|
||||
android:fromXScale="1"
|
||||
android:fromYScale="1"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toXScale="3"
|
||||
android:toYScale="3" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:fillAfter="true">
|
||||
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="1000"
|
||||
android:fromXScale="1.0"
|
||||
android:fromYScale="1.0"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:toXScale="0.5"
|
||||
android:toYScale="0.5" />
|
||||
|
||||
</set>
|
||||
@@ -0,0 +1,60 @@
|
||||
<!--
|
||||
Copyright 2012 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This object animator is used as a custom fragment transition. See
|
||||
FragmentTransaction.setCustomAnimation for more details.
|
||||
|
||||
The overall effect of this animator is to rotate the back of the card
|
||||
into view. The order of operations is described below:
|
||||
|
||||
1. The back is immediately set to transparent.
|
||||
2. The invisible back rotates 90 degrees, from being fully flipped
|
||||
to being zero-width, fully perpendicular to the viewer, facing right.
|
||||
It is still invisible.
|
||||
3. The back is then made visible (this is half-way through the
|
||||
animation).
|
||||
4. The back rotates another 90 degrees, from zero-width, to
|
||||
100% of its normal width, facing the user.
|
||||
|
||||
This is accomplished using the 3 child animators below, executed in
|
||||
parallel. Note that the last animator starts half-way into the animation.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Before rotating, immediately set the alpha to 0. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="1.0"
|
||||
android:valueTo="0.0"
|
||||
android:propertyName="alpha"
|
||||
android:duration="0" />
|
||||
|
||||
<!-- Rotate. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="-180"
|
||||
android:valueTo="0"
|
||||
android:propertyName="rotationY"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="300" />
|
||||
|
||||
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="0.0"
|
||||
android:valueTo="1.0"
|
||||
android:propertyName="alpha"
|
||||
android:startOffset="150"
|
||||
android:duration="1" />
|
||||
</set>
|
||||
@@ -0,0 +1,52 @@
|
||||
<!--
|
||||
Copyright 2012 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This object animator is used as a custom fragment transition. See
|
||||
FragmentTransaction.setCustomAnimation for more details.
|
||||
|
||||
The overall effect of this animator is to rotate the front of the card
|
||||
out of view. The order of operations is described below:
|
||||
|
||||
1. The front rotates 90 degrees, from facing the user to being
|
||||
zero-width, fully perpendicular to the viewer, facing left.
|
||||
2. The front is then made invisible (this is half-way through the
|
||||
animation).
|
||||
3. The front rotates another 90 degrees, from zero-width, to
|
||||
100% of its normal width, but facing away from the user and
|
||||
still invisible.
|
||||
|
||||
This is accomplished using the 2 child animators below, executed in
|
||||
parallel. Note that the last animator starts half-way into the animation.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Rotate. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="0"
|
||||
android:valueTo="180"
|
||||
android:propertyName="rotationY"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="300" />
|
||||
|
||||
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="1.0"
|
||||
android:valueTo="0.0"
|
||||
android:propertyName="alpha"
|
||||
android:startOffset="150"
|
||||
android:duration="1" />
|
||||
</set>
|
||||
@@ -0,0 +1,60 @@
|
||||
<!--
|
||||
Copyright 2012 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This object animator is used as a custom fragment transition. See
|
||||
FragmentTransaction.setCustomAnimation for more details.
|
||||
|
||||
The overall effect of this animator is to rotate the front of the card
|
||||
into view. The order of operations is described below:
|
||||
|
||||
1. The front is immediately set to transparent.
|
||||
2. The invisible front rotates 90 degrees, from being fully flipped
|
||||
to being zero-width, fully perpendicular to the viewer, facing left.
|
||||
It is still invisible.
|
||||
3. The front is then made visible (this is half-way through the
|
||||
animation).
|
||||
4. The front rotates another 90 degrees, from zero-width, to
|
||||
100% of its normal width, facing the user.
|
||||
|
||||
This is accomplished using the 3 child animators below, executed in
|
||||
parallel. Note that the last animator starts half-way into the animation.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Before rotating, immediately set the alpha to 0. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="1.0"
|
||||
android:valueTo="0.0"
|
||||
android:propertyName="alpha"
|
||||
android:duration="0" />
|
||||
|
||||
<!-- Rotate. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="180"
|
||||
android:valueTo="0"
|
||||
android:propertyName="rotationY"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="300" />
|
||||
|
||||
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="0.0"
|
||||
android:valueTo="1.0"
|
||||
android:propertyName="alpha"
|
||||
android:startOffset="150"
|
||||
android:duration="1" />
|
||||
</set>
|
||||
@@ -0,0 +1,52 @@
|
||||
<!--
|
||||
Copyright 2012 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This object animator is used as a custom fragment transition. See
|
||||
FragmentTransaction.setCustomAnimation for more details.
|
||||
|
||||
The overall effect of this animator is to rotate the back of the card
|
||||
out of view. The order of operations is described below:
|
||||
|
||||
1. The back rotates 90 degrees, from facing the user to being
|
||||
zero-width, fully perpendicular to the viewer, facing right.
|
||||
2. The back is then made invisible (this is half-way through the
|
||||
animation).
|
||||
3. The back rotates another 90 degrees, from zero-width, to
|
||||
100% of its normal width, but facing away from the user and
|
||||
still invisible.
|
||||
|
||||
This is accomplished using the 2 child animators below, executed in
|
||||
parallel. Note that the last animator starts half-way into the animation.
|
||||
-->
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Rotate. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="0"
|
||||
android:valueTo="-180"
|
||||
android:propertyName="rotationY"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="300" />
|
||||
|
||||
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
|
||||
<objectAnimator
|
||||
android:valueFrom="1.0"
|
||||
android:valueTo="0.0"
|
||||
android:propertyName="alpha"
|
||||
android:startOffset="150"
|
||||
android:duration="1" />
|
||||
</set>
|
||||
Executable
+145
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<color name="Color_White">#FFFFFF</color>
|
||||
<color name="Color_Ivory">#FFFFF0</color>
|
||||
<color name="Color_LightYellow">#FFFFE0</color>
|
||||
<color name="Color_Yellow">#FFFF00</color>
|
||||
<color name="Color_Snow">#FFFAFA</color>
|
||||
<color name="Color_FloralWhite">#FFFAF0</color>
|
||||
<color name="Color_LemonChiffon">#FFFACD</color>
|
||||
<color name="Color_Cornsilk">#FFF8DC</color>
|
||||
<color name="Color_Seashell">#FFF5EE</color>
|
||||
<color name="Color_LavenderBlush">#FFF0F5</color>
|
||||
<color name="Color_PapayaWhip">#FFEFD5</color>
|
||||
<color name="Color_BlanchedAlmond">#FFEBCD</color>
|
||||
<color name="Color_MistyRose">#FFE4E1</color>
|
||||
<color name="Color_Bisque">#FFE4C4</color>
|
||||
<color name="Color_Moccasin">#FFE4B5</color>
|
||||
<color name="Color_NavajoWhite">#FFDEAD</color>
|
||||
<color name="Color_PeachPuff">#FFDAB9</color>
|
||||
<color name="Color_Gold">#FFD700</color>
|
||||
<color name="Color_Pink">#FFC0CB</color>
|
||||
<color name="Color_LightPink">#FFB6C1</color>
|
||||
<color name="Color_Orange">#FFA500</color>
|
||||
<color name="Color_LightSalmon">#FFA07A</color>
|
||||
<color name="Color_DarkOrange">#FF8C00</color>
|
||||
<color name="Color_Coral">#FF7F50</color>
|
||||
<color name="Color_HotPink">#FF69B4</color>
|
||||
<color name="Color_Tomato">#FF6347</color>
|
||||
<color name="Color_OrangeRed">#FF4500</color>
|
||||
<color name="Color_DeepPink">#FF1493</color>
|
||||
<color name="Color_Fuchsia">#FF00FF</color>
|
||||
<color name="Color_Magenta">#FF00FF</color>
|
||||
<color name="Color_Red">#FF0000</color>
|
||||
<color name="Color_OldLace">#FDF5E6</color>
|
||||
<color name="Color_LightGoldenrodYellow">#FAFAD2</color>
|
||||
<color name="Color_Linen">#FAF0E6</color>
|
||||
<color name="Color_AntiqueWhite">#FAEBD7</color>
|
||||
<color name="Color_Salmon">#FA8072</color>
|
||||
<color name="Color_GhostWhite">#F8F8FF</color>
|
||||
<color name="Color_MintCream">#F5FFFA</color>
|
||||
<color name="Color_WhiteSmoke">#F5F5F5</color>
|
||||
<color name="Color_Beige">#F5F5DC</color>
|
||||
<color name="Color_Wheat">#F5DEB3</color>
|
||||
<color name="Color_SandyBrown">#F4A460</color>
|
||||
<color name="Color_Azure">#F0FFFF</color>
|
||||
<color name="Color_Honeydew">#F0FFF0</color>
|
||||
<color name="Color_AliceBlue">#F0F8FF</color>
|
||||
<color name="Color_Khaki">#F0E68C</color>
|
||||
<color name="Color_LightCoral">#F08080</color>
|
||||
<color name="Color_PaleGoldenrod">#EEE8AA</color>
|
||||
<color name="Color_Violet">#EE82EE</color>
|
||||
<color name="Color_DarkSalmon">#E9967A</color>
|
||||
<color name="Color_Lavender">#E6E6FA</color>
|
||||
<color name="Color_LightCyan">#E0FFFF</color>
|
||||
<color name="Color_BurlyWood">#DEB887</color>
|
||||
<color name="Color_Plum">#DDA0DD</color>
|
||||
<color name="Color_Gainsboro">#DCDCDC</color>
|
||||
<color name="Color_Crimson">#DC143C</color>
|
||||
<color name="Color_PaleVioletRed">#DB7093</color>
|
||||
<color name="Color_Goldenrod">#DAA520</color>
|
||||
<color name="Color_Orchid">#DA70D6</color>
|
||||
<color name="Color_Thistle">#D8BFD8</color>
|
||||
<color name="Color_LightGrey">#D3D3D3</color>
|
||||
<color name="Color_Tan">#D2B48C</color>
|
||||
<color name="Color_Chocolate">#D2691E</color>
|
||||
<color name="Color_Peru">#CD853F</color>
|
||||
<color name="Color_IndianRed">#CD5C5C</color>
|
||||
<color name="Color_MediumVioletRed">#C71585</color>
|
||||
<color name="Color_Silver">#C0C0C0</color>
|
||||
<color name="Color_DarkKhaki">#BDB76B</color>
|
||||
<color name="Color_RosyBrown">#BC8F8F</color>
|
||||
<color name="Color_MediumOrchid">#BA55D3</color>
|
||||
<color name="Color_DarkGoldenrod">#B8860B</color>
|
||||
<color name="Color_FireBrick">#B22222</color>
|
||||
<color name="Color_PowderBlue">#B0E0E6</color>
|
||||
<color name="Color_LightSteelBlue">#B0C4DE</color>
|
||||
<color name="Color_PaleTurquoise">#AFEEEE</color>
|
||||
<color name="Color_GreenYellow">#ADFF2F</color>
|
||||
<color name="Color_LightBlue">#ADD8E6</color>
|
||||
<color name="Color_DarkGray">#A9A9A9</color>
|
||||
<color name="Color_Brown">#A52A2A</color>
|
||||
<color name="Color_Sienna">#A0522D</color>
|
||||
<color name="Color_YellowGreen">#9ACD32</color>
|
||||
<color name="Color_DarkOrchid">#9932CC</color>
|
||||
<color name="Color_PaleGreen">#98FB98</color>
|
||||
<color name="Color_DarkViolet">#9400D3</color>
|
||||
<color name="Color_MediumPurple">#9370DB</color>
|
||||
<color name="Color_LightGreen">#90EE90</color>
|
||||
<color name="Color_DarkSeaGreen">#8FBC8F</color>
|
||||
<color name="Color_SaddleBrown">#8B4513</color>
|
||||
<color name="Color_DarkMagenta">#8B008B</color>
|
||||
<color name="Color_DarkRed">#8B0000</color>
|
||||
<color name="Color_BlueViolet">#8A2BE2</color>
|
||||
<color name="Color_LightSkyBlue">#87CEFA</color>
|
||||
<color name="Color_SkyBlue">#87CEEB</color>
|
||||
<color name="Color_Gray">#808080</color>
|
||||
<color name="Color_Olive">#808000</color>
|
||||
<color name="Color_Purple">#800080</color>
|
||||
<color name="Color_Maroon">#800000</color>
|
||||
<color name="Color_Aquamarine">#7FFFD4</color>
|
||||
<color name="Color_Chartreuse">#7FFF00</color>
|
||||
<color name="Color_LawnGreen">#7CFC00</color>
|
||||
<color name="Color_MediumSlateBlue">#7B68EE</color>
|
||||
<color name="Color_LightSlateGray">#778899</color>
|
||||
<color name="Color_SlateGray">#708090</color>
|
||||
<color name="Color_OliveDrab">#6B8E23</color>
|
||||
<color name="Color_SlateBlue">#6A5ACD</color>
|
||||
<color name="Color_DimGray">#696969</color>
|
||||
<color name="Color_MediumAquamarine">#66CDAA</color>
|
||||
<color name="Color_CornflowerBlue">#6495ED</color>
|
||||
<color name="Color_CadetBlue">#5F9EA0</color>
|
||||
<color name="Color_DarkOliveGreen">#556B2F</color>
|
||||
<color name="Color_Indigo">#4B0082</color>
|
||||
<color name="Color_MediumTurquoise">#48D1CC</color>
|
||||
<color name="Color_DarkSlateBlue">#483D8B</color>
|
||||
<color name="Color_SteelBlue">#4682B4</color>
|
||||
<color name="Color_RoyalBlue">#4169E1</color>
|
||||
<color name="Color_Turquoise">#40E0D0</color>
|
||||
<color name="Color_MediumSeaGreen">#3CB371</color>
|
||||
<color name="Color_LimeGreen">#32CD32</color>
|
||||
<color name="Color_DarkSlateGray">#2F4F4F</color>
|
||||
<color name="Color_SeaGreen">#2E8B57</color>
|
||||
<color name="Color_ForestGreen">#228B22</color>
|
||||
<color name="Color_LightSeaGreen">#20B2AA</color>
|
||||
<color name="Color_DodgerBlue">#1E90FF</color>
|
||||
<color name="Color_MidnightBlue">#191970</color>
|
||||
<color name="Color_Aqua">#00FFFF</color>
|
||||
<color name="Color_Cyan">#00FFFF</color>
|
||||
<color name="Color_SpringGreen">#00FF7F</color>
|
||||
<color name="Color_Lime">#00FF00</color>
|
||||
<color name="Color_MediumSpringGreen">#00FA9A</color>
|
||||
<color name="Color_DarkTurquoise">#00CED1</color>
|
||||
<color name="Color_DeepSkyBlue">#00BFFF</color>
|
||||
<color name="Color_DarkCyan">#008B8B</color>
|
||||
<color name="Color_Teal">#008080</color>
|
||||
<color name="Color_Green">#008000</color>
|
||||
<color name="Color_DarkGreen">#006400</color>
|
||||
<color name="Color_Blue">#0000FF</color>
|
||||
<color name="Color_MediumBlue">#0000CD</color>
|
||||
<color name="Color_DarkBlue">#00008B</color>
|
||||
<color name="Color_Navy">#000080</color>
|
||||
<color name="Color_Black">#000000</color>
|
||||
|
||||
</resources>
|
||||
Executable
+315
@@ -0,0 +1,315 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright 2013 The Finest Artist
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<!-- Grey Percent -->
|
||||
<color name="grey_percent_05">#0D0D0D</color>
|
||||
<color name="grey_percent_10">#1A1A1A</color>
|
||||
<color name="grey_percent_15">#262626</color>
|
||||
<color name="grey_percent_20">#333333</color>
|
||||
<color name="grey_percent_25">#404040</color>
|
||||
<color name="grey_percent_30">#4D4D4D</color>
|
||||
<color name="grey_percent_35">#595959</color>
|
||||
<color name="grey_percent_40">#666666</color>
|
||||
<color name="grey_percent_45">#737373</color>
|
||||
<color name="grey_percent_50">#808080</color>
|
||||
<color name="grey_percent_55">#8C8C8C</color>
|
||||
<color name="grey_percent_60">#999999</color>
|
||||
<color name="grey_percent_65">#A6A6A5</color>
|
||||
<color name="grey_percent_70">#B3B3B3</color>
|
||||
<color name="grey_percent_75">#BFBFBF</color>
|
||||
<color name="grey_percent_80">#CCCCCC</color>
|
||||
<color name="grey_percent_85">#D9D9D9</color>
|
||||
<color name="grey_percent_90">#E6E6E6</color>
|
||||
<color name="grey_percent_95">#F2F2F2</color>
|
||||
|
||||
<!-- Grey 0 -->
|
||||
<color name="grey_hex_00">#000000</color>
|
||||
<color name="grey_hex_01">#010101</color>
|
||||
<color name="grey_hex_02">#020202</color>
|
||||
<color name="grey_hex_03">#030303</color>
|
||||
<color name="grey_hex_04">#040404</color>
|
||||
<color name="grey_hex_05">#050505</color>
|
||||
<color name="grey_hex_06">#060606</color>
|
||||
<color name="grey_hex_07">#070707</color>
|
||||
<color name="grey_hex_08">#080808</color>
|
||||
<color name="grey_hex_09">#090909</color>
|
||||
<color name="grey_hex_0a">#0a0a0a</color>
|
||||
<color name="grey_hex_0b">#0b0b0b</color>
|
||||
<color name="grey_hex_0c">#0c0c0c</color>
|
||||
<color name="grey_hex_0d">#0d0d0d</color>
|
||||
<color name="grey_hex_0e">#0e0e0e</color>
|
||||
<color name="grey_hex_0f">#0f0f0f</color>
|
||||
<!-- Grey 1 -->
|
||||
<color name="grey_hex_10">#101010</color>
|
||||
<color name="grey_hex_11">#111111</color>
|
||||
<color name="grey_hex_12">#121212</color>
|
||||
<color name="grey_hex_13">#131313</color>
|
||||
<color name="grey_hex_14">#141414</color>
|
||||
<color name="grey_hex_15">#151515</color>
|
||||
<color name="grey_hex_16">#161616</color>
|
||||
<color name="grey_hex_17">#171717</color>
|
||||
<color name="grey_hex_18">#181818</color>
|
||||
<color name="grey_hex_19">#191919</color>
|
||||
<color name="grey_hex_1a">#1a1a1a</color>
|
||||
<color name="grey_hex_1b">#1b1b1b</color>
|
||||
<color name="grey_hex_1c">#1c1c1c</color>
|
||||
<color name="grey_hex_1d">#1d1d1d</color>
|
||||
<color name="grey_hex_1e">#1e1e1e</color>
|
||||
<color name="grey_hex_1f">#1f1f1f</color>
|
||||
<!-- Grey 2 -->
|
||||
<color name="grey_hex_20">#202020</color>
|
||||
<color name="grey_hex_21">#212121</color>
|
||||
<color name="grey_hex_22">#222222</color>
|
||||
<color name="grey_hex_23">#232323</color>
|
||||
<color name="grey_hex_24">#242424</color>
|
||||
<color name="grey_hex_25">#252525</color>
|
||||
<color name="grey_hex_26">#262626</color>
|
||||
<color name="grey_hex_27">#272727</color>
|
||||
<color name="grey_hex_28">#282828</color>
|
||||
<color name="grey_hex_29">#292929</color>
|
||||
<color name="grey_hex_2a">#2a2a2a</color>
|
||||
<color name="grey_hex_2b">#2b2b2b</color>
|
||||
<color name="grey_hex_2c">#2c2c2c</color>
|
||||
<color name="grey_hex_2d">#2d2d2d</color>
|
||||
<color name="grey_hex_2e">#2e2e2e</color>
|
||||
<color name="grey_hex_2f">#2f2f2f</color>
|
||||
<!-- Grey 3 -->
|
||||
<color name="grey_hex_30">#303030</color>
|
||||
<color name="grey_hex_31">#313131</color>
|
||||
<color name="grey_hex_32">#323232</color>
|
||||
<color name="grey_hex_33">#333333</color>
|
||||
<color name="grey_hex_34">#343434</color>
|
||||
<color name="grey_hex_35">#353535</color>
|
||||
<color name="grey_hex_36">#363636</color>
|
||||
<color name="grey_hex_37">#373737</color>
|
||||
<color name="grey_hex_38">#383838</color>
|
||||
<color name="grey_hex_39">#393939</color>
|
||||
<color name="grey_hex_3a">#3a3a3a</color>
|
||||
<color name="grey_hex_3b">#3b3b3b</color>
|
||||
<color name="grey_hex_3c">#3c3c3c</color>
|
||||
<color name="grey_hex_3d">#3d3d3d</color>
|
||||
<color name="grey_hex_3e">#3e3e3e</color>
|
||||
<color name="grey_hex_3f">#3f3f3f</color>
|
||||
<!-- Grey 4 -->
|
||||
<color name="grey_hex_40">#404040</color>
|
||||
<color name="grey_hex_41">#414141</color>
|
||||
<color name="grey_hex_42">#424242</color>
|
||||
<color name="grey_hex_43">#434343</color>
|
||||
<color name="grey_hex_44">#444444</color>
|
||||
<color name="grey_hex_45">#454545</color>
|
||||
<color name="grey_hex_46">#464646</color>
|
||||
<color name="grey_hex_47">#474747</color>
|
||||
<color name="grey_hex_48">#484848</color>
|
||||
<color name="grey_hex_49">#494949</color>
|
||||
<color name="grey_hex_4a">#4a4a4a</color>
|
||||
<color name="grey_hex_4b">#4b4b4b</color>
|
||||
<color name="grey_hex_4c">#4c4c4c</color>
|
||||
<color name="grey_hex_4d">#4d4d4d</color>
|
||||
<color name="grey_hex_4e">#4e4e4e</color>
|
||||
<color name="grey_hex_4f">#4f4f4f</color>
|
||||
<!-- Grey 5 -->
|
||||
<color name="grey_hex_50">#505050</color>
|
||||
<color name="grey_hex_51">#515151</color>
|
||||
<color name="grey_hex_52">#525252</color>
|
||||
<color name="grey_hex_53">#535353</color>
|
||||
<color name="grey_hex_54">#545454</color>
|
||||
<color name="grey_hex_55">#555555</color>
|
||||
<color name="grey_hex_56">#565656</color>
|
||||
<color name="grey_hex_57">#575757</color>
|
||||
<color name="grey_hex_58">#585858</color>
|
||||
<color name="grey_hex_59">#595959</color>
|
||||
<color name="grey_hex_5a">#5a5a5a</color>
|
||||
<color name="grey_hex_5b">#5b5b5b</color>
|
||||
<color name="grey_hex_5c">#5c5c5c</color>
|
||||
<color name="grey_hex_5d">#5d5d5d</color>
|
||||
<color name="grey_hex_5e">#5e5e5e</color>
|
||||
<color name="grey_hex_5f">#5f5f5f</color>
|
||||
<!-- Grey 6 -->
|
||||
<color name="grey_hex_60">#606060</color>
|
||||
<color name="grey_hex_61">#616161</color>
|
||||
<color name="grey_hex_62">#626262</color>
|
||||
<color name="grey_hex_63">#636363</color>
|
||||
<color name="grey_hex_64">#646464</color>
|
||||
<color name="grey_hex_65">#656565</color>
|
||||
<color name="grey_hex_66">#666666</color>
|
||||
<color name="grey_hex_67">#676767</color>
|
||||
<color name="grey_hex_68">#686868</color>
|
||||
<color name="grey_hex_69">#696969</color>
|
||||
<color name="grey_hex_6a">#6a6a6a</color>
|
||||
<color name="grey_hex_6b">#6b6b6b</color>
|
||||
<color name="grey_hex_6c">#6c6c6c</color>
|
||||
<color name="grey_hex_6d">#6d6d6d</color>
|
||||
<color name="grey_hex_6e">#6e6e6e</color>
|
||||
<color name="grey_hex_6f">#6f6f6f</color>
|
||||
<!-- Grey 7 -->
|
||||
<color name="grey_hex_70">#707070</color>
|
||||
<color name="grey_hex_71">#717171</color>
|
||||
<color name="grey_hex_72">#727272</color>
|
||||
<color name="grey_hex_73">#737373</color>
|
||||
<color name="grey_hex_74">#747474</color>
|
||||
<color name="grey_hex_75">#757575</color>
|
||||
<color name="grey_hex_76">#767676</color>
|
||||
<color name="grey_hex_77">#777777</color>
|
||||
<color name="grey_hex_78">#787878</color>
|
||||
<color name="grey_hex_79">#797979</color>
|
||||
<color name="grey_hex_7a">#7a7a7a</color>
|
||||
<color name="grey_hex_7b">#7b7b7b</color>
|
||||
<color name="grey_hex_7c">#7c7c7c</color>
|
||||
<color name="grey_hex_7d">#7d7d7d</color>
|
||||
<color name="grey_hex_7e">#7e7e7e</color>
|
||||
<color name="grey_hex_7f">#7f7f7f</color>
|
||||
<!-- Grey 8 -->
|
||||
<color name="grey_hex_80">#808080</color>
|
||||
<color name="grey_hex_81">#818181</color>
|
||||
<color name="grey_hex_82">#828282</color>
|
||||
<color name="grey_hex_83">#838383</color>
|
||||
<color name="grey_hex_84">#848484</color>
|
||||
<color name="grey_hex_85">#858585</color>
|
||||
<color name="grey_hex_86">#868686</color>
|
||||
<color name="grey_hex_87">#878787</color>
|
||||
<color name="grey_hex_88">#888888</color>
|
||||
<color name="grey_hex_89">#898989</color>
|
||||
<color name="grey_hex_8a">#8a8a8a</color>
|
||||
<color name="grey_hex_8b">#8b8b8b</color>
|
||||
<color name="grey_hex_8c">#8c8c8c</color>
|
||||
<color name="grey_hex_8d">#8d8d8d</color>
|
||||
<color name="grey_hex_8e">#8e8e8e</color>
|
||||
<color name="grey_hex_8f">#8f8f8f</color>
|
||||
<!-- Grey 9 -->
|
||||
<color name="grey_hex_90">#909090</color>
|
||||
<color name="grey_hex_91">#919191</color>
|
||||
<color name="grey_hex_92">#929292</color>
|
||||
<color name="grey_hex_93">#939393</color>
|
||||
<color name="grey_hex_94">#949494</color>
|
||||
<color name="grey_hex_95">#959595</color>
|
||||
<color name="grey_hex_96">#969696</color>
|
||||
<color name="grey_hex_97">#979797</color>
|
||||
<color name="grey_hex_98">#989898</color>
|
||||
<color name="grey_hex_99">#999999</color>
|
||||
<color name="grey_hex_9a">#9a9a9a</color>
|
||||
<color name="grey_hex_9b">#9b9b9b</color>
|
||||
<color name="grey_hex_9c">#9c9c9c</color>
|
||||
<color name="grey_hex_9d">#9d9d9d</color>
|
||||
<color name="grey_hex_9e">#9e9e9e</color>
|
||||
<color name="grey_hex_9f">#9f9f9f</color>
|
||||
<!-- Grey a -->
|
||||
<color name="grey_hex_a0">#a0a0a0</color>
|
||||
<color name="grey_hex_a1">#a1a1a1</color>
|
||||
<color name="grey_hex_a2">#a2a2a2</color>
|
||||
<color name="grey_hex_a3">#a3a3a3</color>
|
||||
<color name="grey_hex_a4">#a4a4a4</color>
|
||||
<color name="grey_hex_a5">#a5a5a5</color>
|
||||
<color name="grey_hex_a6">#a6a6a6</color>
|
||||
<color name="grey_hex_a7">#a7a7a7</color>
|
||||
<color name="grey_hex_a8">#a8a8a8</color>
|
||||
<color name="grey_hex_a9">#a9a9a9</color>
|
||||
<color name="grey_hex_aa">#aaaaaa</color>
|
||||
<color name="grey_hex_ab">#ababab</color>
|
||||
<color name="grey_hex_ac">#acacac</color>
|
||||
<color name="grey_hex_ad">#adadad</color>
|
||||
<color name="grey_hex_ae">#aeaeae</color>
|
||||
<color name="grey_hex_af">#afafaf</color>
|
||||
<!-- Grey b -->
|
||||
<color name="grey_hex_b0">#b0b0b0</color>
|
||||
<color name="grey_hex_b1">#b1b1b1</color>
|
||||
<color name="grey_hex_b2">#b2b2b2</color>
|
||||
<color name="grey_hex_b3">#b3b3b3</color>
|
||||
<color name="grey_hex_b4">#b4b4b4</color>
|
||||
<color name="grey_hex_b5">#b5b5b5</color>
|
||||
<color name="grey_hex_b6">#b6b6b6</color>
|
||||
<color name="grey_hex_b7">#b7b7b7</color>
|
||||
<color name="grey_hex_b8">#b8b8b8</color>
|
||||
<color name="grey_hex_b9">#b9b9b9</color>
|
||||
<color name="grey_hex_ba">#bababa</color>
|
||||
<color name="grey_hex_bb">#bbbbbb</color>
|
||||
<color name="grey_hex_bc">#bcbcbc</color>
|
||||
<color name="grey_hex_bd">#bdbdbd</color>
|
||||
<color name="grey_hex_be">#bebebe</color>
|
||||
<color name="grey_hex_bf">#bfbfbf</color>
|
||||
<!-- Grey c -->
|
||||
<color name="grey_hex_c0">#c0c0c0</color>
|
||||
<color name="grey_hex_c1">#c1c1c1</color>
|
||||
<color name="grey_hex_c2">#c2c2c2</color>
|
||||
<color name="grey_hex_c3">#c3c3c3</color>
|
||||
<color name="grey_hex_c4">#c4c4c4</color>
|
||||
<color name="grey_hex_c5">#c5c5c5</color>
|
||||
<color name="grey_hex_c6">#c6c6c6</color>
|
||||
<color name="grey_hex_c7">#c7c7c7</color>
|
||||
<color name="grey_hex_c8">#c8c8c8</color>
|
||||
<color name="grey_hex_c9">#c9c9c9</color>
|
||||
<color name="grey_hex_ca">#cacaca</color>
|
||||
<color name="grey_hex_cb">#cbcbcb</color>
|
||||
<color name="grey_hex_cc">#cccccc</color>
|
||||
<color name="grey_hex_cd">#cdcdcd</color>
|
||||
<color name="grey_hex_ce">#cecece</color>
|
||||
<color name="grey_hex_cf">#cfcfcf</color>
|
||||
<!-- Grey d -->
|
||||
<color name="grey_hex_d0">#d0d0d0</color>
|
||||
<color name="grey_hex_d1">#d1d1d1</color>
|
||||
<color name="grey_hex_d2">#d2d2d2</color>
|
||||
<color name="grey_hex_d3">#d3d3d3</color>
|
||||
<color name="grey_hex_d4">#d4d4d4</color>
|
||||
<color name="grey_hex_d5">#d5d5d5</color>
|
||||
<color name="grey_hex_d6">#d6d6d6</color>
|
||||
<color name="grey_hex_d7">#d7d7d7</color>
|
||||
<color name="grey_hex_d8">#d8d8d8</color>
|
||||
<color name="grey_hex_d9">#d9d9d9</color>
|
||||
<color name="grey_hex_da">#dadada</color>
|
||||
<color name="grey_hex_db">#dbdbdb</color>
|
||||
<color name="grey_hex_dc">#dcdcdc</color>
|
||||
<color name="grey_hex_dd">#dddddd</color>
|
||||
<color name="grey_hex_de">#dedede</color>
|
||||
<color name="grey_hex_df">#dfdfdf</color>
|
||||
<!-- Grey e -->
|
||||
<color name="grey_hex_e0">#e0e0e0</color>
|
||||
<color name="grey_hex_e1">#e1e1e1</color>
|
||||
<color name="grey_hex_e2">#e2e2e2</color>
|
||||
<color name="grey_hex_e3">#e3e3e3</color>
|
||||
<color name="grey_hex_e4">#e4e4e4</color>
|
||||
<color name="grey_hex_e5">#e5e5e5</color>
|
||||
<color name="grey_hex_e6">#e6e6e6</color>
|
||||
<color name="grey_hex_e7">#e7e7e7</color>
|
||||
<color name="grey_hex_e8">#e8e8e8</color>
|
||||
<color name="grey_hex_e9">#e9e9e9</color>
|
||||
<color name="grey_hex_ea">#eaeaea</color>
|
||||
<color name="grey_hex_eb">#ebebeb</color>
|
||||
<color name="grey_hex_ec">#ececec</color>
|
||||
<color name="grey_hex_ed">#ededed</color>
|
||||
<color name="grey_hex_ee">#eeeeee</color>
|
||||
<color name="grey_hex_ef">#efefef</color>
|
||||
<!-- Grey f -->
|
||||
<color name="grey_hex_f0">#f0f0f0</color>
|
||||
<color name="grey_hex_f1">#f1f1f1</color>
|
||||
<color name="grey_hex_f2">#f2f2f2</color>
|
||||
<color name="grey_hex_f3">#f3f3f3</color>
|
||||
<color name="grey_hex_f4">#f4f4f4</color>
|
||||
<color name="grey_hex_f5">#f5f5f5</color>
|
||||
<color name="grey_hex_f6">#f6f6f6</color>
|
||||
<color name="grey_hex_f7">#f7f7f7</color>
|
||||
<color name="grey_hex_f8">#f8f8f8</color>
|
||||
<color name="grey_hex_f9">#f9f9f9</color>
|
||||
<color name="grey_hex_fa">#fafafa</color>
|
||||
<color name="grey_hex_fb">#fbfbfb</color>
|
||||
<color name="grey_hex_fc">#fcfcfc</color>
|
||||
<color name="grey_hex_fd">#fdfdfd</color>
|
||||
<color name="grey_hex_fe">#fefefe</color>
|
||||
<color name="grey_hex_ff">#ffffff</color>
|
||||
|
||||
</resources>
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/**
|
||||
* Copyright 2013 The Finest Artist
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
-->
|
||||
<resources>
|
||||
|
||||
<!-- Black Transparent -->
|
||||
<color name="transparent_black_hex_11">#11000000</color>
|
||||
<color name="transparent_black_hex_22">#22000000</color>
|
||||
<color name="transparent_black_hex_33">#33000000</color>
|
||||
<color name="transparent_black_hex_44">#44000000</color>
|
||||
<color name="transparent_black_hex_55">#55000000</color>
|
||||
<color name="transparent_black_hex_66">#66000000</color>
|
||||
<color name="transparent_black_hex_77">#77000000</color>
|
||||
<color name="transparent_black_hex_88">#88000000</color>
|
||||
<color name="transparent_black_hex_99">#99000000</color>
|
||||
<color name="transparent_black_hex_aa">#aa000000</color>
|
||||
<color name="transparent_black_hex_bb">#bb000000</color>
|
||||
<color name="transparent_black_hex_cc">#cc000000</color>
|
||||
<color name="transparent_black_hex_dd">#dd000000</color>
|
||||
<color name="transparent_black_hex_ee">#ee000000</color>
|
||||
<color name="transparent_black_percent_05">#0D000000</color>
|
||||
<color name="transparent_black_percent_10">#1A000000</color>
|
||||
<color name="transparent_black_percent_15">#26000000</color>
|
||||
<color name="transparent_black_percent_20">#33000000</color>
|
||||
<color name="transparent_black_percent_25">#40000000</color>
|
||||
<color name="transparent_black_percent_30">#4D000000</color>
|
||||
<color name="transparent_black_percent_35">#59000000</color>
|
||||
<color name="transparent_black_percent_40">#66000000</color>
|
||||
<color name="transparent_black_percent_45">#73000000</color>
|
||||
<color name="transparent_black_percent_50">#80000000</color>
|
||||
<color name="transparent_black_percent_55">#8C000000</color>
|
||||
<color name="transparent_black_percent_60">#99000000</color>
|
||||
<color name="transparent_black_percent_65">#A6000000</color>
|
||||
<color name="transparent_black_percent_70">#B3000000</color>
|
||||
<color name="transparent_black_percent_75">#BF000000</color>
|
||||
<color name="transparent_black_percent_80">#CC000000</color>
|
||||
<color name="transparent_black_percent_85">#D9000000</color>
|
||||
<color name="transparent_black_percent_90">#E6000000</color>
|
||||
<color name="transparent_black_percent_95">#F2000000</color>
|
||||
|
||||
<!-- White Transparent -->
|
||||
<color name="transparent_white_hex_11">#11ffffff</color>
|
||||
<color name="transparent_white_hex_22">#22ffffff</color>
|
||||
<color name="transparent_white_hex_33">#33ffffff</color>
|
||||
<color name="transparent_white_hex_44">#44ffffff</color>
|
||||
<color name="transparent_white_hex_55">#55ffffff</color>
|
||||
<color name="transparent_white_hex_66">#66ffffff</color>
|
||||
<color name="transparent_white_hex_77">#77ffffff</color>
|
||||
<color name="transparent_white_hex_88">#88ffffff</color>
|
||||
<color name="transparent_white_hex_99">#99ffffff</color>
|
||||
<color name="transparent_white_hex_aa">#aaffffff</color>
|
||||
<color name="transparent_white_hex_bb">#bbffffff</color>
|
||||
<color name="transparent_white_hex_cc">#ccffffff</color>
|
||||
<color name="transparent_white_hex_dd">#ddffffff</color>
|
||||
<color name="transparent_white_hex_ee">#eeffffff</color>
|
||||
<color name="transparent_white_percent_05">#0Dffffff</color>
|
||||
<color name="transparent_white_percent_10">#1Affffff</color>
|
||||
<color name="transparent_white_percent_15">#26ffffff</color>
|
||||
<color name="transparent_white_percent_20">#33ffffff</color>
|
||||
<color name="transparent_white_percent_25">#40ffffff</color>
|
||||
<color name="transparent_white_percent_30">#4Dffffff</color>
|
||||
<color name="transparent_white_percent_35">#59ffffff</color>
|
||||
<color name="transparent_white_percent_40">#66ffffff</color>
|
||||
<color name="transparent_white_percent_45">#73ffffff</color>
|
||||
<color name="transparent_white_percent_50">#80ffffff</color>
|
||||
<color name="transparent_white_percent_55">#8Cffffff</color>
|
||||
<color name="transparent_white_percent_60">#99ffffff</color>
|
||||
<color name="transparent_white_percent_65">#A6ffffff</color>
|
||||
<color name="transparent_white_percent_70">#B3ffffff</color>
|
||||
<color name="transparent_white_percent_75">#BFffffff</color>
|
||||
<color name="transparent_white_percent_80">#CCffffff</color>
|
||||
<color name="transparent_white_percent_85">#D9ffffff</color>
|
||||
<color name="transparent_white_percent_90">#E6ffffff</color>
|
||||
<color name="transparent_white_percent_95">#F2ffffff</color>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.thefinestartist.utils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user