...
This commit is contained in:
@@ -4,8 +4,8 @@ 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 kr.lunaticbum.Base;
|
||||
import kr.lunaticbum.utils.preferences.PreferencesUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
@@ -1 +1 @@
|
||||
<manifest package="com.thefinestartist.helpers"/>
|
||||
<manifest package="kr.lunaticbum.helpers"/>
|
||||
@@ -0,0 +1,171 @@
|
||||
package android.print;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||
public class PDFPrint {
|
||||
|
||||
public static void generatePDFFromHTML(final Context context, final File file, final String htmlString, final OnPDFPrintListener onPDFPrintListener) {
|
||||
final WebView mWebView = new WebView(context);
|
||||
mWebView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
.setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
.build();
|
||||
|
||||
final PrintDocumentAdapter documentAdapter = mWebView.createPrintDocumentAdapter(file.getName());
|
||||
documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
@Override
|
||||
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
|
||||
@Override
|
||||
public void onWriteCancelled() {
|
||||
super.onWriteCancelled();
|
||||
onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFailed(CharSequence error) {
|
||||
super.onWriteFailed(error);
|
||||
onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFinished(PageRange[] pages) {
|
||||
super.onWriteFinished(pages);
|
||||
onPDFPrintListener.onSuccess(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
});
|
||||
mWebView.loadData(htmlString.replaceAll("#", "%23"), "text/HTML", "UTF-8");
|
||||
}
|
||||
|
||||
public static void generatePDFFromWebView(final File file, final WebView webView, final OnPDFPrintListener onPDFPrintListener) {
|
||||
PrintAttributes printAttributes = new PrintAttributes.Builder()
|
||||
.setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
.setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
|
||||
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
.build();
|
||||
|
||||
final PrintDocumentAdapter documentAdapter = webView.createPrintDocumentAdapter(file.getName());
|
||||
documentAdapter.onLayout(null, printAttributes, null, new PrintDocumentAdapter.LayoutResultCallback() {
|
||||
@Override
|
||||
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
||||
documentAdapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, getOutputFile(file), null, new PrintDocumentAdapter.WriteResultCallback() {
|
||||
|
||||
@Override
|
||||
public void onWriteCancelled() {
|
||||
super.onWriteCancelled();
|
||||
onPDFPrintListener.onError(new Exception("PDF Write cancelled."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFailed(CharSequence error) {
|
||||
super.onWriteFailed(error);
|
||||
try {
|
||||
if (error != null && error.toString().length() > 0) {
|
||||
onPDFPrintListener.onError(new Exception(error.toString()));
|
||||
} else {
|
||||
onPDFPrintListener.onError(new Exception("Empty Page"));
|
||||
}
|
||||
}catch (Exception e) {e.printStackTrace();}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteFinished(PageRange[] pages) {
|
||||
super.onWriteFinished(pages);
|
||||
onPDFPrintListener.onSuccess(file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
private static ParcelFileDescriptor getOutputFile(File file) {
|
||||
try {
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PrintJob printPDF(final Activity activity, final File pdfFileToPrint, final PrintAttributes printAttributes) {
|
||||
PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
|
||||
String jobName = Long.valueOf(System.currentTimeMillis()).toString();
|
||||
return printManager.print(jobName, new PrintDocumentAdapter() {
|
||||
@Override
|
||||
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try {
|
||||
|
||||
input = new FileInputStream(pdfFileToPrint);
|
||||
output = new FileOutputStream(destination.getFileDescriptor());
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = input.read(buf)) > 0) {
|
||||
output.write(buf, 0, bytesRead);
|
||||
}
|
||||
|
||||
callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES});
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
input.close();
|
||||
output.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
|
||||
if (cancellationSignal.isCanceled()) {
|
||||
callback.onLayoutCancelled();
|
||||
return;
|
||||
}
|
||||
|
||||
PrintDocumentInfo pdi = new PrintDocumentInfo.Builder(pdfFileToPrint.getName()).setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build();
|
||||
callback.onLayoutFinished(pdi, true);
|
||||
}
|
||||
}, printAttributes);
|
||||
}
|
||||
|
||||
public interface OnPDFPrintListener {
|
||||
void onSuccess(File file);
|
||||
|
||||
void onError(Exception exception);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
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
|
||||
@@ -1,82 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,502 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
|
||||
/**
|
||||
* Res is abbreviation class of {@link ResourcesUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class Res extends ResourcesUtil {
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
|
||||
/**
|
||||
* L is abbreviation class of {@link LogUtil}.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
public class L extends LogUtil {
|
||||
}
|
||||
@@ -1,702 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,406 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
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
|
||||
@@ -1,39 +0,0 @@
|
||||
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,57 @@
|
||||
//package kr.lunaticbum;
|
||||
//
|
||||
//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,49 @@
|
||||
package kr.lunaticbum
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.AssetManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.content.res.Resources.Theme
|
||||
import android.util.DisplayMetrics
|
||||
|
||||
/**
|
||||
* Base helps to get [Context], [Resources], [AssetManager], [Configuration] and [DisplayMetrics] in any class.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object Base {
|
||||
private var context: Context? = null
|
||||
|
||||
fun initialize(context: Context) {
|
||||
Base.context = context
|
||||
}
|
||||
|
||||
fun getContext(): Context {
|
||||
synchronized(Base::class.java) {
|
||||
if (context == null) throw NullPointerException("Call Base.initialize(context) within your Application onCreate() method.")
|
||||
return context!!.applicationContext
|
||||
}
|
||||
}
|
||||
|
||||
val resources: Resources
|
||||
get() = getContext().resources
|
||||
|
||||
val theme: Theme
|
||||
get() = getContext().theme
|
||||
|
||||
val assets: AssetManager
|
||||
get() = getContext().assets
|
||||
|
||||
val configuration: Configuration
|
||||
get() = resources.configuration
|
||||
|
||||
val displayMetrics: DisplayMetrics
|
||||
get() = resources.displayMetrics
|
||||
} // 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
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.annotations;
|
||||
package kr.lunaticbum.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.CLASS;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.binders;
|
||||
package kr.lunaticbum.binders;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@@ -0,0 +1,82 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.Base;
|
||||
//import kr.lunaticbum.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,72 @@
|
||||
package kr.lunaticbum.builders
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import kr.lunaticbum.Base.getContext
|
||||
import kr.lunaticbum.utils.content.ContextUtil
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
* ActivityBuilder helps to build [Activity] [Intent] and start [Activity].
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
class ActivityBuilder(clazz: Class<Activity?>) {
|
||||
val intent: Intent =
|
||||
Intent(getContext(), clazz)
|
||||
|
||||
fun <T : Serializable?> set(key: String, value: T): ActivityBuilder {
|
||||
intent.putExtra(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
fun set(key: String, value: Parcelable?): ActivityBuilder {
|
||||
intent.putExtra(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
fun set(key: String, value: Array<Parcelable?>?): ActivityBuilder {
|
||||
intent.putExtra(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
fun <T : Parcelable?> set(key: String, value: ArrayList<T>?): ActivityBuilder {
|
||||
intent.putExtra(key, value)
|
||||
return this
|
||||
}
|
||||
|
||||
fun remove(key: String): ActivityBuilder {
|
||||
intent.removeExtra(key)
|
||||
return this
|
||||
}
|
||||
|
||||
fun setFlags(flags: Int): ActivityBuilder {
|
||||
intent.setFlags(flags)
|
||||
return this
|
||||
}
|
||||
|
||||
fun addFlags(flags: Int): ActivityBuilder {
|
||||
intent.addFlags(flags)
|
||||
return this
|
||||
}
|
||||
|
||||
fun buildIntent(): Intent {
|
||||
return intent
|
||||
}
|
||||
|
||||
fun start() {
|
||||
ContextUtil.startActivity(intent)
|
||||
}
|
||||
|
||||
fun startForResult(activity: Activity, requestCode: Int) {
|
||||
activity.startActivityForResult(intent, requestCode)
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
fun startForResult(activity: Activity, requestCode: Int, options: Bundle?) {
|
||||
activity.startActivityForResult(intent, requestCode, options)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.builders;
|
||||
package kr.lunaticbum.builders;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.converters;
|
||||
package kr.lunaticbum.converters;
|
||||
|
||||
/**
|
||||
* Unit is abbreviation class of {@link UnitConverter}.
|
||||
@@ -0,0 +1,43 @@
|
||||
//package kr.lunaticbum.converters;
|
||||
//
|
||||
//import kr.lunaticbum.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,44 @@
|
||||
package kr.lunaticbum.converters
|
||||
|
||||
import kr.lunaticbum.Base.displayMetrics
|
||||
|
||||
/**
|
||||
* UnitConverter helps to convert dp or sp size into pixel.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
open class UnitConverter {
|
||||
companion object {
|
||||
fun dpToPx(dp: Float): Float {
|
||||
return dp * displayMetrics.density
|
||||
}
|
||||
|
||||
fun dpToPx(dp: Int): Int {
|
||||
return (dp * displayMetrics.density + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun pxToDp(px: Float): Float {
|
||||
return px / displayMetrics.density
|
||||
}
|
||||
|
||||
fun pxToDp(px: Int): Int {
|
||||
return (px / displayMetrics.density + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun spToPx(sp: Float): Float {
|
||||
return sp * displayMetrics.scaledDensity
|
||||
}
|
||||
|
||||
fun spToPx(sp: Int): Int {
|
||||
return (sp * displayMetrics.scaledDensity + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun pxToSp(px: Float): Float {
|
||||
return px / displayMetrics.scaledDensity
|
||||
}
|
||||
|
||||
fun pxToSp(px: Int): Int {
|
||||
return (px / displayMetrics.scaledDensity + 0.5f).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.thefinestartist.enums;
|
||||
package kr.lunaticbum.enums;
|
||||
|
||||
import com.thefinestartist.utils.log.LogUtil;
|
||||
import kr.lunaticbum.utils.log.LogUtil;
|
||||
|
||||
/**
|
||||
* Enum class associated with {@link LogUtil}.
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.thefinestartist.enums;
|
||||
package kr.lunaticbum.enums;
|
||||
|
||||
import com.thefinestartist.utils.ui.DisplayUtil;
|
||||
import kr.lunaticbum.utils.ui.DisplayUtil;
|
||||
|
||||
/**
|
||||
* Enum class associated with {@link DisplayUtil}.
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.thefinestartist.listeners;
|
||||
package kr.lunaticbum.listeners;
|
||||
|
||||
import com.thefinestartist.utils.ui.KeyboardUtil;
|
||||
import kr.lunaticbum.utils.ui.KeyboardUtil;
|
||||
|
||||
/**
|
||||
* Listener class associated with {@link KeyboardUtil}.
|
||||
@@ -0,0 +1,502 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.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,594 @@
|
||||
package kr.lunaticbum.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.IntentSender.SendIntentException
|
||||
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.Resources.Theme
|
||||
import android.content.res.TypedArray
|
||||
import android.database.DatabaseErrorHandler
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory
|
||||
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.StringRes
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.annotation.StyleableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import kr.lunaticbum.Base.getContext
|
||||
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 [Context] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
open class ContextUtil {
|
||||
companion object {
|
||||
fun bindService(service: Intent?, conn: ServiceConnection?, flags: Int): Boolean {
|
||||
return getContext().bindService(service!!, conn!!, flags)
|
||||
}
|
||||
|
||||
fun checkCallingOrSelfPermission(permission: String?): Int {
|
||||
return getContext().checkCallingOrSelfPermission(permission!!)
|
||||
}
|
||||
|
||||
fun checkCallingOrSelfUriPermission(uri: Uri?, modeFlags: Int): Int {
|
||||
return getContext().checkCallingOrSelfUriPermission(uri, modeFlags)
|
||||
}
|
||||
|
||||
fun checkCallingPermission(permission: String?): Int {
|
||||
return getContext().checkCallingPermission(permission!!)
|
||||
}
|
||||
|
||||
fun checkCallingUriPermission(uri: Uri?, modeFlags: Int): Int {
|
||||
return getContext().checkCallingUriPermission(uri, modeFlags)
|
||||
}
|
||||
|
||||
fun checkPermission(permission: String?, pid: Int, uid: Int): Int {
|
||||
return getContext().checkPermission(permission!!, pid, uid)
|
||||
}
|
||||
|
||||
fun checkSelfPermission(permission: String): Int {
|
||||
return ContextCompat.checkSelfPermission(getContext(), permission)
|
||||
}
|
||||
|
||||
fun checkUriPermission(uri: Uri?, pid: Int, uid: Int, modeFlags: Int): Int {
|
||||
return getContext().checkUriPermission(uri, pid, uid, modeFlags)
|
||||
}
|
||||
|
||||
fun checkUriPermission(
|
||||
uri: Uri?,
|
||||
readPermission: String?,
|
||||
writePermission: String?,
|
||||
pid: Int,
|
||||
uid: Int,
|
||||
modeFlags: Int
|
||||
): Int {
|
||||
return getContext().checkUriPermission(
|
||||
uri,
|
||||
readPermission,
|
||||
writePermission,
|
||||
pid,
|
||||
uid,
|
||||
modeFlags
|
||||
)
|
||||
}
|
||||
|
||||
@Throws(PackageManager.NameNotFoundException::class)
|
||||
fun createPackageContext(packageName: String?, flags: Int): Context {
|
||||
return getContext().createPackageContext(packageName, flags)
|
||||
}
|
||||
|
||||
fun databaseList(): Array<String> {
|
||||
return getContext().databaseList()
|
||||
}
|
||||
|
||||
fun deleteDatabase(name: String?): Boolean {
|
||||
return getContext().deleteDatabase(name)
|
||||
}
|
||||
|
||||
fun deleteFile(name: String?): Boolean {
|
||||
return getContext().deleteFile(name)
|
||||
}
|
||||
|
||||
fun enforceCallingOrSelfPermission(permission: String?, message: String?) {
|
||||
getContext().enforceCallingOrSelfPermission(permission!!, message)
|
||||
}
|
||||
|
||||
fun enforceCallingOrSelfUriPermission(uri: Uri?, modeFlags: Int, message: String?) {
|
||||
getContext().enforceCallingOrSelfUriPermission(uri, modeFlags, message)
|
||||
}
|
||||
|
||||
fun enforceCallingPermission(permission: String?, message: String?) {
|
||||
getContext().enforceCallingPermission(permission!!, message)
|
||||
}
|
||||
|
||||
fun enforceCallingUriPermission(uri: Uri?, modeFlags: Int, message: String?) {
|
||||
getContext().enforceCallingUriPermission(uri, modeFlags, message)
|
||||
}
|
||||
|
||||
fun enforcePermission(permission: String?, pid: Int, uid: Int, message: String?) {
|
||||
getContext().enforcePermission(permission!!, pid, uid, message)
|
||||
}
|
||||
|
||||
fun enforceUriPermission(uri: Uri?, pid: Int, uid: Int, modeFlags: Int, message: String?) {
|
||||
getContext().enforceUriPermission(uri, pid, uid, modeFlags, message)
|
||||
}
|
||||
|
||||
fun enforceUriPermission(
|
||||
uri: Uri?,
|
||||
readPermission: String?,
|
||||
writePermission: String?,
|
||||
pid: Int,
|
||||
uid: Int,
|
||||
modeFlags: Int,
|
||||
message: String?
|
||||
) {
|
||||
getContext().enforceUriPermission(
|
||||
uri,
|
||||
readPermission,
|
||||
writePermission,
|
||||
pid,
|
||||
uid,
|
||||
modeFlags,
|
||||
message
|
||||
)
|
||||
}
|
||||
|
||||
fun fileList(): Array<String> {
|
||||
return getContext().fileList()
|
||||
}
|
||||
|
||||
val applicationContext: Context
|
||||
get() = getContext().applicationContext
|
||||
|
||||
val applicationInfo: ApplicationInfo
|
||||
get() = getContext().applicationInfo
|
||||
|
||||
val assets: AssetManager
|
||||
get() = getContext().assets
|
||||
|
||||
val cacheDir: File
|
||||
get() = getContext().cacheDir
|
||||
|
||||
val classLoader: ClassLoader
|
||||
get() = getContext().classLoader
|
||||
|
||||
val codeCacheDir: File
|
||||
get() = ContextCompat.getCodeCacheDir(getContext())
|
||||
|
||||
@ColorInt
|
||||
fun getColor(@ColorRes colorRes: Int): Int {
|
||||
return ContextCompat.getColor(getContext(), colorRes)
|
||||
}
|
||||
|
||||
fun getColorStateList(@ColorRes colorRes: Int): ColorStateList? {
|
||||
return ContextCompat.getColorStateList(getContext(), colorRes)
|
||||
}
|
||||
|
||||
val contentResolver: ContentResolver
|
||||
get() = getContext().contentResolver
|
||||
|
||||
fun getDatabasePath(name: String?): File {
|
||||
return getContext().getDatabasePath(name)
|
||||
}
|
||||
|
||||
fun getDir(name: String?, mode: Int): File {
|
||||
return getContext().getDir(name, mode)
|
||||
}
|
||||
|
||||
fun getDrawable(@DrawableRes drawableRes: Int): Drawable? {
|
||||
return ContextCompat.getDrawable(getContext(), drawableRes)
|
||||
}
|
||||
|
||||
@get:TargetApi(8)
|
||||
val externalCacheDir: File?
|
||||
get() = getContext().externalCacheDir
|
||||
|
||||
val externalCacheDirs: Array<File>
|
||||
get() = ContextCompat.getExternalCacheDirs(getContext())
|
||||
|
||||
@TargetApi(8)
|
||||
fun getExternalFilesDir(type: String?): File? {
|
||||
return getContext().getExternalFilesDir(type)
|
||||
}
|
||||
|
||||
fun getExternalFilesDirs(type: String?): Array<File> {
|
||||
return ContextCompat.getExternalFilesDirs(getContext(), type)
|
||||
}
|
||||
|
||||
@get:TargetApi(21)
|
||||
val externalMediaDirs: Array<File>
|
||||
get() = getContext().externalMediaDirs
|
||||
|
||||
fun getFileStreamPath(name: String?): File {
|
||||
return getContext().getFileStreamPath(name)
|
||||
}
|
||||
|
||||
val filesDir: File
|
||||
get() = getContext().filesDir
|
||||
|
||||
val mainLooper: Looper
|
||||
get() = getContext().mainLooper
|
||||
|
||||
val noBackupFilesDir: File?
|
||||
get() = ContextCompat.getNoBackupFilesDir(getContext())
|
||||
|
||||
@get:TargetApi(11)
|
||||
val obbDir: File
|
||||
get() = getContext().obbDir
|
||||
|
||||
val obbDirs: Array<File>
|
||||
get() = ContextCompat.getObbDirs(getContext())
|
||||
|
||||
@get:TargetApi(8)
|
||||
val packageCodePath: String
|
||||
get() = getContext().packageCodePath
|
||||
|
||||
val packageManager: PackageManager
|
||||
get() = getContext().packageManager
|
||||
|
||||
val packageName: String
|
||||
get() = getContext().packageName
|
||||
|
||||
@get:TargetApi(8)
|
||||
val packageResourcePath: String
|
||||
get() = getContext().packageResourcePath
|
||||
|
||||
val resources: Resources
|
||||
get() = getContext().resources
|
||||
|
||||
fun getSharedPreferences(name: String?, mode: Int): SharedPreferences {
|
||||
return getContext().getSharedPreferences(name, mode)
|
||||
}
|
||||
|
||||
fun getString(@StringRes stringRes: Int): String {
|
||||
return getContext().getString(stringRes)
|
||||
}
|
||||
|
||||
fun getString(@StringRes stringRes: Int, vararg formatArgs: Any?): String {
|
||||
return getContext().getString(stringRes, *formatArgs)
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
fun <T> getSystemService(serviceClass: Class<T>): T {
|
||||
return getContext().getSystemService(serviceClass)
|
||||
}
|
||||
|
||||
fun getSystemService(name: String?): Any {
|
||||
return getContext().getSystemService(name!!)
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
fun getSystemServiceName(serviceClass: Class<*>?): String? {
|
||||
return getContext().getSystemServiceName(serviceClass!!)
|
||||
}
|
||||
|
||||
fun getText(@StringRes stringRes: Int): CharSequence {
|
||||
return getContext().getText(stringRes)
|
||||
}
|
||||
|
||||
val theme: Theme
|
||||
get() = getContext().theme
|
||||
|
||||
|
||||
val wallpaper: Drawable?
|
||||
@SuppressLint("MissingPermission")
|
||||
get() = WallpaperManager.getInstance(getContext()).drawable
|
||||
|
||||
val wallpaperDesiredMinimumHeight: Int
|
||||
get() = WallpaperManager.getInstance(getContext()).desiredMinimumHeight
|
||||
|
||||
val wallpaperDesiredMinimumWidth: Int
|
||||
get() = WallpaperManager.getInstance(getContext()).desiredMinimumWidth
|
||||
|
||||
fun grantUriPermission(toPackage: String?, uri: Uri?, modeFlags: Int) {
|
||||
getContext().grantUriPermission(toPackage, uri, modeFlags)
|
||||
}
|
||||
|
||||
val isRestricted: Boolean
|
||||
get() = getContext().isRestricted
|
||||
|
||||
fun obtainStyledAttributes(@StyleableRes attrs: IntArray?): TypedArray {
|
||||
return getContext().obtainStyledAttributes(attrs!!)
|
||||
}
|
||||
|
||||
fun obtainStyledAttributes(
|
||||
set: AttributeSet?,
|
||||
@StyleableRes attrs: IntArray?,
|
||||
@AttrRes defStyleAttr: Int,
|
||||
@StyleRes defStyleRes: Int
|
||||
): TypedArray {
|
||||
return getContext().obtainStyledAttributes(
|
||||
set,
|
||||
attrs!!, defStyleAttr, defStyleRes
|
||||
)
|
||||
}
|
||||
|
||||
fun obtainStyledAttributes(set: AttributeSet?, @StyleableRes attrs: IntArray?): TypedArray {
|
||||
return getContext().obtainStyledAttributes(set, attrs!!)
|
||||
}
|
||||
|
||||
fun obtainStyledAttributes(
|
||||
@StyleRes resid: Int,
|
||||
@StyleableRes attrs: IntArray?
|
||||
): TypedArray {
|
||||
return getContext().obtainStyledAttributes(resid, attrs!!)
|
||||
}
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
fun openFileInput(name: String?): FileInputStream {
|
||||
return getContext().openFileInput(name)
|
||||
}
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
fun openFileOutput(name: String?, mode: Int): FileOutputStream {
|
||||
return getContext().openFileOutput(name, mode)
|
||||
}
|
||||
|
||||
fun openOrCreateDatabase(
|
||||
name: String?,
|
||||
mode: Int,
|
||||
factory: CursorFactory?
|
||||
): SQLiteDatabase {
|
||||
return getContext().openOrCreateDatabase(name, mode, factory)
|
||||
}
|
||||
|
||||
@TargetApi(11)
|
||||
fun openOrCreateDatabase(
|
||||
name: String?,
|
||||
mode: Int,
|
||||
factory: CursorFactory?,
|
||||
errorHandler: DatabaseErrorHandler?
|
||||
): SQLiteDatabase {
|
||||
return getContext().openOrCreateDatabase(name, mode, factory, errorHandler)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun peekWallpaper(): Drawable? {
|
||||
return WallpaperManager.getInstance(getContext()).peekDrawable()
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
fun registerComponentCallbacks(callback: ComponentCallbacks?) {
|
||||
getContext().registerComponentCallbacks(callback)
|
||||
}
|
||||
|
||||
fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter?): Intent? {
|
||||
return getContext().registerReceiver(receiver, filter)
|
||||
}
|
||||
|
||||
fun registerReceiver(
|
||||
receiver: BroadcastReceiver?,
|
||||
filter: IntentFilter?,
|
||||
broadcastPermission: String?,
|
||||
scheduler: Handler?
|
||||
): Intent? {
|
||||
return 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);
|
||||
// }
|
||||
fun revokeUriPermission(uri: Uri?, modeFlags: Int) {
|
||||
getContext().revokeUriPermission(uri, modeFlags)
|
||||
}
|
||||
|
||||
fun sendBroadcast(intent: Intent?, receiverPermission: String?) {
|
||||
getContext().sendBroadcast(intent, receiverPermission)
|
||||
}
|
||||
|
||||
fun sendBroadcast(intent: Intent?) {
|
||||
getContext().sendBroadcast(intent)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@TargetApi(17)
|
||||
fun sendBroadcastAsUser(intent: Intent?, user: UserHandle?) {
|
||||
getContext().sendBroadcastAsUser(intent, user)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@TargetApi(17)
|
||||
fun sendBroadcastAsUser(intent: Intent?, user: UserHandle?, receiverPermission: String?) {
|
||||
getContext().sendBroadcastAsUser(intent, user, receiverPermission)
|
||||
}
|
||||
|
||||
fun sendOrderedBroadcast(
|
||||
intent: Intent?,
|
||||
receiverPermission: String?,
|
||||
resultReceiver: BroadcastReceiver?,
|
||||
scheduler: Handler?,
|
||||
initialCode: Int,
|
||||
initialData: String?,
|
||||
initialExtras: Bundle?
|
||||
) {
|
||||
getContext().sendOrderedBroadcast(
|
||||
intent!!,
|
||||
receiverPermission,
|
||||
resultReceiver,
|
||||
scheduler,
|
||||
initialCode,
|
||||
initialData,
|
||||
initialExtras
|
||||
)
|
||||
}
|
||||
|
||||
fun sendOrderedBroadcast(intent: Intent?, receiverPermission: String?) {
|
||||
getContext().sendOrderedBroadcast(intent, receiverPermission)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@TargetApi(17)
|
||||
fun sendOrderedBroadcastAsUser(
|
||||
intent: Intent?,
|
||||
user: UserHandle?,
|
||||
receiverPermission: String?,
|
||||
resultReceiver: BroadcastReceiver?,
|
||||
scheduler: Handler?,
|
||||
initialCode: Int,
|
||||
initialData: String?,
|
||||
initialExtras: Bundle?
|
||||
) {
|
||||
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);
|
||||
// }
|
||||
fun setTheme(@StyleRes styleRes: Int) {
|
||||
getContext().setTheme(styleRes)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Throws(IOException::class)
|
||||
fun setWallpaper(data: InputStream?) {
|
||||
WallpaperManager.getInstance(getContext()).setStream(data)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Throws(IOException::class)
|
||||
fun setWallpaper(bitmap: Bitmap?) {
|
||||
WallpaperManager.getInstance(getContext()).setBitmap(bitmap)
|
||||
}
|
||||
|
||||
fun startActivities(intents: Array<Intent?>, options: Bundle?): Boolean {
|
||||
for (intent in intents) intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return ContextCompat.startActivities(getContext(), intents, options)
|
||||
}
|
||||
|
||||
fun startActivities(intents: Array<Intent?>): Boolean {
|
||||
for (intent in intents) intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return ContextCompat.startActivities(getContext(), intents)
|
||||
}
|
||||
|
||||
fun startActivity(intent: Intent) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
getContext().startActivity(intent)
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
fun startActivity(intent: Intent?, options: Bundle?) {
|
||||
getContext().startActivity(intent, options)
|
||||
}
|
||||
|
||||
fun startInstrumentation(
|
||||
className: ComponentName?,
|
||||
profileFile: String?,
|
||||
arguments: Bundle?
|
||||
): Boolean {
|
||||
return getContext().startInstrumentation(className!!, profileFile, arguments)
|
||||
}
|
||||
|
||||
@TargetApi(16)
|
||||
@Throws(SendIntentException::class)
|
||||
fun startIntentSender(
|
||||
intent: IntentSender?,
|
||||
fillInIntent: Intent?,
|
||||
flagsMask: Int,
|
||||
flagsValues: Int,
|
||||
extraFlags: Int,
|
||||
options: Bundle?
|
||||
) {
|
||||
getContext().startIntentSender(
|
||||
intent,
|
||||
fillInIntent,
|
||||
flagsMask,
|
||||
flagsValues,
|
||||
extraFlags,
|
||||
options
|
||||
)
|
||||
}
|
||||
|
||||
@Throws(SendIntentException::class)
|
||||
fun startIntentSender(
|
||||
intent: IntentSender?,
|
||||
fillInIntent: Intent?,
|
||||
flagsMask: Int,
|
||||
flagsValues: Int,
|
||||
extraFlags: Int
|
||||
) {
|
||||
getContext().startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags)
|
||||
}
|
||||
|
||||
fun startService(service: Intent?): ComponentName? {
|
||||
return getContext().startService(service)
|
||||
}
|
||||
|
||||
fun stopService(service: Intent?): Boolean {
|
||||
return getContext().stopService(service)
|
||||
}
|
||||
|
||||
fun unbindService(conn: ServiceConnection?) {
|
||||
getContext().unbindService(conn!!)
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
fun unregisterComponentCallbacks(callback: ComponentCallbacks?) {
|
||||
getContext().unregisterComponentCallbacks(callback)
|
||||
}
|
||||
|
||||
fun unregisterReceiver(receiver: BroadcastReceiver?) {
|
||||
getContext().unregisterReceiver(receiver)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.content;
|
||||
package kr.lunaticbum.utils.content;
|
||||
|
||||
/**
|
||||
* Ctx is abbreviation class of {@link ContextUtil}.
|
||||
@@ -0,0 +1,9 @@
|
||||
//package kr.lunaticbum.utils.content;
|
||||
//
|
||||
///**
|
||||
// * Res is abbreviation class of {@link ResourcesUtil}.
|
||||
// *
|
||||
// * @author Leonardo Taehwan Kim
|
||||
// */
|
||||
//public class Res extends ResourcesUtil {
|
||||
//}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kr.lunaticbum.utils.content
|
||||
|
||||
/**
|
||||
* Res is abbreviation class of [ResourcesUtil].
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
//class Res : ResourcesUtil()
|
||||
@@ -0,0 +1,278 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.Base;
|
||||
//import kr.lunaticbum.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,276 @@
|
||||
package kr.lunaticbum.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.Resources.Theme
|
||||
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 kr.lunaticbum.Base
|
||||
import kr.lunaticbum.Base.getContext
|
||||
import kr.lunaticbum.Base.resources
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
import org.xmlpull.v1.XmlPullParserException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* ResourcesUtil helps to manage [Resources] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object ResourcesUtil {
|
||||
private fun finishPreloading() {
|
||||
resources.finishPreloading()
|
||||
}
|
||||
|
||||
private fun flushLayoutCache() {
|
||||
resources.flushLayoutCache()
|
||||
}
|
||||
|
||||
fun getAnimation(@AnimRes animRes: Int): XmlResourceParser {
|
||||
return resources.getAnimation(animRes)
|
||||
}
|
||||
|
||||
val assets: AssetManager
|
||||
get() = resources.assets
|
||||
|
||||
fun getBoolean(@BoolRes boolRes: Int): Boolean {
|
||||
return resources.getBoolean(boolRes)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getColor(@ColorRes colorRes: Int): Int {
|
||||
return ContextUtil.getColor(colorRes)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getColor(@ColorRes colorRes: Int, theme: Theme?): Int {
|
||||
return if (APILevel.require(23)) resources.getColor(colorRes, theme)
|
||||
else getColor(colorRes)
|
||||
}
|
||||
|
||||
fun getColorStateList(@ColorRes colorRes: Int): ColorStateList? {
|
||||
return ContextUtil.getColorStateList(colorRes)
|
||||
}
|
||||
|
||||
fun getColorStateList(@ColorRes colorRes: Int, theme: Theme?): ColorStateList? {
|
||||
return if (APILevel.require(23)) resources.getColorStateList(colorRes, theme)
|
||||
else getColorStateList(colorRes)
|
||||
}
|
||||
|
||||
val configuration: Configuration
|
||||
get() = Base.configuration
|
||||
|
||||
fun getDimension(@DimenRes dimenRes: Int): Float {
|
||||
return resources.getDimension(dimenRes)
|
||||
}
|
||||
|
||||
fun getDimensionPixelOffset(@DimenRes dimenRes: Int): Int {
|
||||
return resources.getDimensionPixelOffset(dimenRes)
|
||||
}
|
||||
|
||||
fun getDimensionPixelSize(@DimenRes dimenRes: Int): Int {
|
||||
return resources.getDimensionPixelSize(dimenRes)
|
||||
}
|
||||
|
||||
val displayMetrics: DisplayMetrics
|
||||
get() = Base.displayMetrics
|
||||
|
||||
fun getDrawable(@DrawableRes drawableRes: Int): Drawable? {
|
||||
return ContextUtil.getDrawable(drawableRes)
|
||||
}
|
||||
|
||||
fun getDrawable(@DrawableRes drawableRes: Int, theme: Theme?): Drawable {
|
||||
return if (APILevel.require(21)) resources.getDrawable(drawableRes, theme)
|
||||
else resources.getDrawable(drawableRes)
|
||||
}
|
||||
|
||||
fun getDrawableForDensity(@DrawableRes drawableRes: Int, density: Int): Drawable? {
|
||||
return if (APILevel.require(21)) resources.getDrawableForDensity(
|
||||
drawableRes,
|
||||
density,
|
||||
getContext().theme
|
||||
)
|
||||
else if (APILevel.require(15)) resources.getDrawableForDensity(drawableRes, density)
|
||||
else resources.getDrawable(drawableRes)
|
||||
}
|
||||
|
||||
fun getFraction(id: Int, base: Int, pbase: Int): Float {
|
||||
return resources.getFraction(id, base, pbase)
|
||||
}
|
||||
|
||||
fun getIdentifier(name: String?, defType: String?, defPackage: String?): Int {
|
||||
return resources.getIdentifier(name, defType, defPackage)
|
||||
}
|
||||
|
||||
fun getIntArray(@ArrayRes arrayRes: Int): IntArray {
|
||||
return resources.getIntArray(arrayRes)
|
||||
}
|
||||
|
||||
fun getInteger(@IntegerRes integerRes: Int): Int {
|
||||
return resources.getInteger(integerRes)
|
||||
}
|
||||
|
||||
fun getLayout(@LayoutRes layoutRes: Int): XmlResourceParser {
|
||||
return resources.getLayout(layoutRes)
|
||||
}
|
||||
|
||||
fun getMovie(@RawRes rawRes: Int): Movie {
|
||||
return resources.getMovie(rawRes)
|
||||
}
|
||||
|
||||
fun getQuantityString(id: Int, quantity: Int, vararg formatArgs: Any?): String {
|
||||
return resources.getQuantityString(id, quantity, *formatArgs)
|
||||
}
|
||||
|
||||
@Throws(Resources.NotFoundException::class)
|
||||
fun getQuantityString(@PluralsRes pluralsRes: Int, quantity: Int): String {
|
||||
return resources.getQuantityString(pluralsRes, quantity)
|
||||
}
|
||||
|
||||
fun getQuantityText(id: Int, quantity: Int): CharSequence {
|
||||
return resources.getQuantityText(id, quantity)
|
||||
}
|
||||
|
||||
fun getResourceEntryName(@AnyRes anyRes: Int): String {
|
||||
return resources.getResourceEntryName(anyRes)
|
||||
}
|
||||
|
||||
fun getResourceName(@AnyRes anyRes: Int): String {
|
||||
return resources.getResourceName(anyRes)
|
||||
}
|
||||
|
||||
fun getResourcePackageName(@AnyRes anyRes: Int): String {
|
||||
return resources.getResourcePackageName(anyRes)
|
||||
}
|
||||
|
||||
fun getResourceTypeName(@AnyRes anyRes: Int): String {
|
||||
return resources.getResourceTypeName(anyRes)
|
||||
}
|
||||
|
||||
fun getString(@StringRes stringRes: Int): String {
|
||||
return resources.getString(stringRes)
|
||||
}
|
||||
|
||||
fun getString(@StringRes stringRes: Int, vararg formatArgs: Any?): String {
|
||||
return resources.getString(stringRes, *formatArgs)
|
||||
}
|
||||
|
||||
fun getStringArray(@ArrayRes arrayRes: Int): Array<String> {
|
||||
return resources.getStringArray(arrayRes)
|
||||
}
|
||||
|
||||
val system: Resources
|
||||
get() = Resources.getSystem()
|
||||
|
||||
fun getText(@StringRes stringRes: Int, def: CharSequence?): CharSequence {
|
||||
return resources.getText(stringRes, def)
|
||||
}
|
||||
|
||||
fun getText(@StringRes stringRes: Int): CharSequence {
|
||||
return resources.getText(stringRes)
|
||||
}
|
||||
|
||||
fun getTextArray(@ArrayRes arrayRes: Int): Array<CharSequence> {
|
||||
return resources.getTextArray(arrayRes)
|
||||
}
|
||||
|
||||
fun getValue(name: String?, outValue: TypedValue?, resolveRefs: Boolean) {
|
||||
resources.getValue(name, outValue, resolveRefs)
|
||||
}
|
||||
|
||||
fun getValue(@AnyRes anyRes: Int, outValue: TypedValue?, resolveRefs: Boolean) {
|
||||
resources.getValue(anyRes, outValue, resolveRefs)
|
||||
}
|
||||
|
||||
fun getValueForDensity(
|
||||
@AnyRes anyRes: Int,
|
||||
density: Int,
|
||||
outValue: TypedValue?,
|
||||
resolveRefs: Boolean
|
||||
) {
|
||||
if (APILevel.require(15)) resources.getValueForDensity(
|
||||
anyRes,
|
||||
density,
|
||||
outValue,
|
||||
resolveRefs
|
||||
)
|
||||
else resources.getValue(anyRes, outValue, resolveRefs)
|
||||
}
|
||||
|
||||
fun getXml(@XmlRes xmlRes: Int): XmlResourceParser {
|
||||
return resources.getXml(xmlRes)
|
||||
}
|
||||
|
||||
fun newTheme(): Theme {
|
||||
return resources.newTheme()
|
||||
}
|
||||
|
||||
fun obtainAttributes(set: AttributeSet?, attrs: IntArray?): TypedArray {
|
||||
return resources.obtainAttributes(set, attrs)
|
||||
}
|
||||
|
||||
fun obtainTypedArray(@ArrayRes anyRes: Int): TypedArray {
|
||||
return resources.obtainTypedArray(anyRes)
|
||||
}
|
||||
|
||||
fun openRawResource(@RawRes rawRes: Int): InputStream {
|
||||
return resources.openRawResource(rawRes)
|
||||
}
|
||||
|
||||
fun openRawResource(@RawRes rawRes: Int, value: TypedValue?): InputStream {
|
||||
return resources.openRawResource(rawRes, value)
|
||||
}
|
||||
|
||||
fun openRawResourceFd(@RawRes rawRes: Int): AssetFileDescriptor {
|
||||
return resources.openRawResourceFd(rawRes)
|
||||
}
|
||||
|
||||
@Throws(XmlPullParserException::class)
|
||||
fun parseBundleExtra(tagName: String?, attrs: AttributeSet?, outBundle: Bundle?) {
|
||||
resources.parseBundleExtra(tagName, attrs, outBundle)
|
||||
}
|
||||
|
||||
@Throws(XmlPullParserException::class, IOException::class)
|
||||
fun parseBundleExtras(parser: XmlResourceParser?, outBundle: Bundle?) {
|
||||
resources.parseBundleExtras(parser, outBundle)
|
||||
}
|
||||
|
||||
fun updateConfiguration(config: Configuration?, metrics: DisplayMetrics?) {
|
||||
resources.updateConfiguration(config, metrics)
|
||||
}
|
||||
|
||||
// Added methods
|
||||
fun getColorArray(@ArrayRes array: Int): IntArray? {
|
||||
if (array == 0) return null
|
||||
|
||||
val typedArray = resources.obtainTypedArray(array)
|
||||
val colors = IntArray(typedArray.length())
|
||||
for (i in 0 until typedArray.length()) colors[i] = typedArray.getColor(i, 0)
|
||||
typedArray.recycle()
|
||||
return colors
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.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,69 @@
|
||||
package kr.lunaticbum.utils.content
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.res.Resources
|
||||
import android.content.res.Resources.Theme
|
||||
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 kr.lunaticbum.Base
|
||||
import kr.lunaticbum.Base.theme
|
||||
|
||||
/**
|
||||
* ThemeUtil helps to manage [Resources.Theme] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object ThemeUtil {
|
||||
fun applyStyle(resId: Int, force: Boolean) {
|
||||
theme.applyStyle(resId, force)
|
||||
}
|
||||
|
||||
fun dump(priority: Int, tag: String?, prefix: String?) {
|
||||
theme.dump(priority, tag, prefix)
|
||||
}
|
||||
|
||||
@get:TargetApi(23)
|
||||
val changingConfigurations: Int
|
||||
get() = theme.changingConfigurations
|
||||
|
||||
fun getDrawable(@DrawableRes drawableRes: Int): Drawable? {
|
||||
return ResourcesUtil.getDrawable(drawableRes)
|
||||
}
|
||||
|
||||
val resources: Resources
|
||||
get() = Base.resources
|
||||
|
||||
fun obtainStyledAttributes(@StyleableRes attrs: IntArray?): TypedArray {
|
||||
return theme.obtainStyledAttributes(attrs!!)
|
||||
}
|
||||
|
||||
fun obtainStyledAttributes(@StyleRes resid: Int, @StyleableRes attrs: IntArray?): TypedArray {
|
||||
return theme.obtainStyledAttributes(resid, attrs!!)
|
||||
}
|
||||
|
||||
fun obtainStyledAttributes(
|
||||
set: AttributeSet?,
|
||||
@StyleableRes attrs: IntArray?,
|
||||
@AttrRes defStyleAttr: Int,
|
||||
@StyleRes defStyleRes: Int
|
||||
): TypedArray {
|
||||
return theme.obtainStyledAttributes(
|
||||
set,
|
||||
attrs!!, defStyleAttr, defStyleRes
|
||||
)
|
||||
}
|
||||
|
||||
fun resolveAttribute(resid: Int, outValue: TypedValue?, resolveRefs: Boolean): Boolean {
|
||||
return theme.resolveAttribute(resid, outValue, resolveRefs)
|
||||
}
|
||||
|
||||
fun setTo(other: Theme?) {
|
||||
theme.setTo(other)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//package kr.lunaticbum.utils.content;
|
||||
//
|
||||
//import android.util.TypedValue;
|
||||
//
|
||||
//import kr.lunaticbum.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,27 @@
|
||||
package kr.lunaticbum.utils.content
|
||||
|
||||
import android.util.TypedValue
|
||||
import kr.lunaticbum.Base.displayMetrics
|
||||
|
||||
/**
|
||||
* TypedValueUtil helps to manage [TypedValue] class conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object TypedValueUtil {
|
||||
fun applyDimension(unit: Int, value: Float): Float {
|
||||
return TypedValue.applyDimension(unit, value, displayMetrics)
|
||||
}
|
||||
|
||||
fun complexToDimension(data: Int): Float {
|
||||
return TypedValue.complexToDimension(data, displayMetrics)
|
||||
}
|
||||
|
||||
fun complexToDimensionPixelOffset(data: Int): Int {
|
||||
return TypedValue.complexToDimensionPixelOffset(data, displayMetrics)
|
||||
}
|
||||
|
||||
fun complexToDimensionPixelSize(data: Int): Int {
|
||||
return TypedValue.complexToDimensionPixelSize(data, displayMetrics)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
package kr.lunaticbum.utils.etc;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
package kr.lunaticbum.utils.etc;
|
||||
|
||||
/**
|
||||
* IntArrayUtil helps to manage IntArray conveniently.
|
||||
@@ -0,0 +1,58 @@
|
||||
//package kr.lunaticbum.utils.etc;
|
||||
//
|
||||
//import android.content.ActivityNotFoundException;
|
||||
//import android.content.Intent;
|
||||
//import android.content.pm.PackageManager;
|
||||
//import android.net.Uri;
|
||||
//
|
||||
//import kr.lunaticbum.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,63 @@
|
||||
package kr.lunaticbum.utils.etc
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import kr.lunaticbum.Base.getContext
|
||||
|
||||
/**
|
||||
* PackageUtil helps to handle methods related to package.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object PackageUtil {
|
||||
const val FACEBOOK: String = "com.facebook.katana"
|
||||
const val TWITTER: String = "com.twitter.android"
|
||||
const val GOOGLE_PLUS: String = "com.google.android.apps.plus"
|
||||
const val GMAIL: String = "com.google.android.gm"
|
||||
const val PINTEREST: String = "com.pinterest"
|
||||
const val TUMBLR: String = "com.tumblr"
|
||||
const val FANCY: String = "com.thefancy.app"
|
||||
const val FLIPBOARD: String = "flipboard.app"
|
||||
const val KAKAOTALK: String = "com.kakao.talk"
|
||||
const val KAKAOSTORY: String = "com.kakao.story"
|
||||
|
||||
fun isInstalled(packageName: String?): Boolean {
|
||||
val packageManager = getContext().packageManager
|
||||
try {
|
||||
packageManager.getPackageInfo(packageName!!, PackageManager.GET_ACTIVITIES)
|
||||
return true
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
val packageName: String
|
||||
get() = getContext().packageName
|
||||
|
||||
fun openPlayStore() {
|
||||
val packageName = getContext().packageName
|
||||
openPlayStore(packageName)
|
||||
}
|
||||
|
||||
fun openPlayStore(packageName: String) {
|
||||
try {
|
||||
val intent = Intent(
|
||||
Intent.ACTION_VIEW, Uri.parse(
|
||||
"market://details?id=$packageName"
|
||||
)
|
||||
)
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
getContext().startActivity(intent)
|
||||
} catch (exception: ActivityNotFoundException) {
|
||||
val intent = Intent(
|
||||
Intent.ACTION_VIEW, Uri.parse(
|
||||
"http://play.google.com/store/apps/details?id=$packageName"
|
||||
)
|
||||
)
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
getContext().startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
package kr.lunaticbum.utils.etc;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.etc;
|
||||
package kr.lunaticbum.utils.etc;
|
||||
|
||||
import android.os.Looper;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//package kr.lunaticbum.utils.etc;
|
||||
//
|
||||
//import android.graphics.Typeface;
|
||||
//import android.widget.TextView;
|
||||
//
|
||||
//import androidx.annotation.NonNull;
|
||||
//import androidx.collection.SimpleArrayMap;
|
||||
//
|
||||
//import kr.lunaticbum.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,47 @@
|
||||
package kr.lunaticbum.utils.etc
|
||||
|
||||
import android.graphics.Typeface
|
||||
import android.widget.TextView
|
||||
import androidx.collection.SimpleArrayMap
|
||||
import kr.lunaticbum.Base.getContext
|
||||
|
||||
/**
|
||||
* TypefaceUtil helps to retrieve typeface from assets folder.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object TypefaceUtil {
|
||||
private val cache = SimpleArrayMap<String, Typeface>()
|
||||
|
||||
fun get(path: String): Typeface? {
|
||||
synchronized(cache) {
|
||||
if (cache.containsKey(path)) return cache[path]
|
||||
try {
|
||||
val typeface =
|
||||
Typeface.createFromAsset(getContext().assets, path)
|
||||
cache.put(path, typeface)
|
||||
return typeface
|
||||
} catch (e: RuntimeException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setTypeface(path: String, vararg textViews: TextView?) {
|
||||
if (textViews == null) return
|
||||
|
||||
for (textView in textViews) if (textView != null) textView.typeface =
|
||||
get(path)
|
||||
}
|
||||
|
||||
fun setTypeface(path: String, includeFontPadding: Boolean, vararg textViews: TextView?) {
|
||||
if (textViews == null) return
|
||||
|
||||
for (textView in textViews) {
|
||||
if (textView != null) {
|
||||
textView.typeface = get(path)
|
||||
textView.includeFontPadding = includeFontPadding
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
package kr.lunaticbum.utils.log;
|
||||
|
||||
/**
|
||||
* AndroidLogPrinter log message via Android system.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
package kr.lunaticbum.utils.log;
|
||||
|
||||
/**
|
||||
* FileLogPrinter log message via file system.
|
||||
@@ -0,0 +1,9 @@
|
||||
//package kr.lunaticbum.utils.log;
|
||||
//
|
||||
///**
|
||||
// * L is abbreviation class of {@link LogUtil}.
|
||||
// *
|
||||
// * @author Leonardo Taehwan Kim
|
||||
// */
|
||||
//public class L extends LogUtil {
|
||||
//}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kr.lunaticbum.utils.log
|
||||
|
||||
/**
|
||||
* L is abbreviation class of [LogUtil].
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
//class L : LogUtil()
|
||||
@@ -0,0 +1,702 @@
|
||||
//package kr.lunaticbum.utils.log;
|
||||
//
|
||||
//import android.text.TextUtils;
|
||||
//import android.util.Log;
|
||||
//
|
||||
//import androidx.annotation.StringRes;
|
||||
//
|
||||
//import kr.lunaticbum.enums.LogLevel;
|
||||
//import kr.lunaticbum.utils.content.ResourcesUtil;
|
||||
//import kr.lunaticbum.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,683 @@
|
||||
package kr.lunaticbum.utils.log
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Build
|
||||
import android.text.TextUtils
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
import kr.lunaticbum.enums.LogLevel
|
||||
import kr.lunaticbum.utils.content.ResourcesUtil.getString
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.io.StringReader
|
||||
import java.io.StringWriter
|
||||
import javax.xml.transform.OutputKeys
|
||||
import javax.xml.transform.Source
|
||||
import javax.xml.transform.TransformerException
|
||||
import javax.xml.transform.TransformerFactory
|
||||
import javax.xml.transform.stream.StreamResult
|
||||
import javax.xml.transform.stream.StreamSource
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* LogHelper helps to deal with [Log] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
class LogHelper {
|
||||
protected var settings: Settings = Settings(LogHelper::class.java.simpleName)
|
||||
|
||||
// Constructors
|
||||
constructor()
|
||||
|
||||
constructor(tag: String?) {
|
||||
settings.setTag(tag!!)
|
||||
}
|
||||
|
||||
constructor(@StringRes tagRes: Int) {
|
||||
settings.setTag(getString(tagRes))
|
||||
}
|
||||
|
||||
constructor(clazz: Class<*>) {
|
||||
settings.setTag(clazz.simpleName)
|
||||
}
|
||||
|
||||
// Setters
|
||||
fun tag(tag: String?): LogHelper {
|
||||
settings.setTag(tag!!)
|
||||
return this
|
||||
}
|
||||
|
||||
fun tag(@StringRes tagRes: Int): LogHelper {
|
||||
settings.setTag(tagRes)
|
||||
return this
|
||||
}
|
||||
|
||||
fun tag(clazz: Class<*>?): LogHelper {
|
||||
settings.setTag(clazz!!)
|
||||
return this
|
||||
}
|
||||
|
||||
fun showThreadInfo(showThreadInfo: Boolean): LogHelper {
|
||||
settings.setShowThreadInfo(showThreadInfo)
|
||||
return this
|
||||
}
|
||||
|
||||
fun stackTraceCount(stackTraceCount: Int): LogHelper {
|
||||
settings.setStackTraceCount(stackTraceCount)
|
||||
return this
|
||||
}
|
||||
|
||||
fun logLevel(logLevel: LogLevel?): LogHelper {
|
||||
settings.setLogLevel(logLevel!!)
|
||||
return this
|
||||
}
|
||||
|
||||
fun showDivider(showDivider: Boolean): LogHelper {
|
||||
settings.setShowDivider(showDivider)
|
||||
return this
|
||||
}
|
||||
|
||||
fun logPrinter(logPrinter: LogPrinter?): LogHelper {
|
||||
settings.setLogPrinter(logPrinter!!)
|
||||
return this
|
||||
}
|
||||
|
||||
// Logging Verbose
|
||||
fun v(message: Byte) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Char) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Short) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Int) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Long) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Float) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Double) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Boolean) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: String) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: JSONObject) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: JSONArray) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Exception) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
fun v(message: Any) {
|
||||
log(LogLevel.VERBOSE, message)
|
||||
}
|
||||
|
||||
// Logging Debug
|
||||
fun d(message: Byte) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Char) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Short) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Int) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Long) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Float) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Double) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Boolean) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: String) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: JSONObject) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: JSONArray) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Exception) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
fun d(message: Any) {
|
||||
log(LogLevel.DEBUG, message)
|
||||
}
|
||||
|
||||
// Logging Information
|
||||
fun i(message: Byte) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Char) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Short) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Int) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Long) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Float) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Double) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Boolean) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: String) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: JSONObject) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: JSONArray) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Exception) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
fun i(message: Any) {
|
||||
log(LogLevel.INFO, message)
|
||||
}
|
||||
|
||||
// Logging Warning
|
||||
fun w(message: Byte) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Char) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Short) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Int) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Long) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Float) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Double) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Boolean) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: String) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: JSONObject) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: JSONArray) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Exception) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
fun w(message: Any) {
|
||||
log(LogLevel.WARN, message)
|
||||
}
|
||||
|
||||
// Logging Error
|
||||
fun e(message: Byte) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Char) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Short) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Int) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Long) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Float) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Double) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Boolean) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: String) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: JSONObject) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: JSONArray) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Exception) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
fun e(message: Any) {
|
||||
log(LogLevel.ERROR, message)
|
||||
}
|
||||
|
||||
// Logging Assert
|
||||
fun wtf(message: Byte) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Char) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Short) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Int) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Long) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Float) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Double) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Boolean) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: String) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: JSONObject) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: JSONArray) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Exception) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
fun wtf(message: Any) {
|
||||
log(LogLevel.ASSERT, message)
|
||||
}
|
||||
|
||||
// Logging JsonString
|
||||
fun json(jsonString: String) {
|
||||
json(LogLevel.DEBUG, jsonString)
|
||||
}
|
||||
|
||||
fun json(logLevel: LogLevel, jsonString: String) {
|
||||
var jsonString = jsonString
|
||||
if (TextUtils.isEmpty(jsonString)) {
|
||||
log(logLevel, "Json string is empty.")
|
||||
} else {
|
||||
jsonString = jsonString.trim { it <= ' ' }
|
||||
|
||||
try {
|
||||
if (jsonString.startsWith("{")) {
|
||||
val jsonObject = JSONObject(jsonString)
|
||||
val message = jsonObject.toString(INDENT_SPACES)
|
||||
log(logLevel, message)
|
||||
return
|
||||
}
|
||||
if (jsonString.startsWith("[")) {
|
||||
val jsonArray = JSONArray(jsonString)
|
||||
val message = jsonArray.toString(INDENT_SPACES)
|
||||
log(logLevel, message)
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
log(logLevel, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logging XmlString
|
||||
@RequiresApi(Build.VERSION_CODES.FROYO)
|
||||
fun xml(xmlString: String) {
|
||||
xml(LogLevel.DEBUG, xmlString)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.FROYO)
|
||||
fun xml(logLevel: LogLevel, xmlString: String) {
|
||||
if (TextUtils.isEmpty(xmlString)) {
|
||||
log(logLevel, "Xml string is empty.")
|
||||
} else {
|
||||
if (APILevel.require(8)) {
|
||||
try {
|
||||
val xmlInput: Source = StreamSource(StringReader(xmlString))
|
||||
val xmlOutput = StreamResult(StringWriter())
|
||||
val 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.writer.toString().replaceFirst(">".toRegex(), ">\n"))
|
||||
} catch (@SuppressLint("NewApi") e: TransformerException) {
|
||||
log(logLevel, e)
|
||||
}
|
||||
} else {
|
||||
log(logLevel, xmlString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Printing
|
||||
private fun log(logLevel: LogLevel, message: Byte) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Char) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Short) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Int) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Long) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Float) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Double) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Boolean) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message.toString())
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: String) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
printString(logLevel, message)
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: JSONObject) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
try {
|
||||
printString(logLevel, message.toString(INDENT_SPACES))
|
||||
} catch (e: JSONException) {
|
||||
log(logLevel, e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: JSONArray) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
try {
|
||||
printString(logLevel, message.toString(INDENT_SPACES))
|
||||
} catch (e: JSONException) {
|
||||
log(logLevel, e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Exception) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
|
||||
val builder = StringBuilder()
|
||||
builder.append(message.toString())
|
||||
builder.append("\n")
|
||||
|
||||
val traces = message.stackTrace
|
||||
for (trace in traces) {
|
||||
builder.append(" at ")
|
||||
.append(trace.className)
|
||||
.append(".")
|
||||
.append(trace.methodName)
|
||||
.append("(")
|
||||
.append(trace.fileName)
|
||||
.append(":")
|
||||
.append(trace.lineNumber)
|
||||
.append(")")
|
||||
.append("\n")
|
||||
}
|
||||
|
||||
printString(logLevel, builder.toString(), true)
|
||||
}
|
||||
|
||||
private fun log(logLevel: LogLevel, message: Any) {
|
||||
if (logLevel.ordinal < settings.logLevel.ordinal) return
|
||||
val log = if (message is ByteArray) message.contentToString()
|
||||
else if (message is CharArray) message.contentToString()
|
||||
else if (message is ShortArray) message.contentToString()
|
||||
else if (message is IntArray) message.contentToString()
|
||||
else if (message is LongArray) message.contentToString()
|
||||
else if (message is FloatArray) message.contentToString()
|
||||
else if (message is DoubleArray) message.contentToString()
|
||||
else if (message is BooleanArray) message.contentToString()
|
||||
else if (message is Array<*> && message.isArrayOf<Any>()) (message as Array<Any?>).contentToString()
|
||||
else message.toString()
|
||||
|
||||
printString(logLevel, log)
|
||||
}
|
||||
|
||||
private fun printString(logLevel: LogLevel, message: String) {
|
||||
printString(logLevel, message, false)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun printString(logLevel: LogLevel, message: String, fromException: Boolean) {
|
||||
// Create TAG
|
||||
var TAG = settings.tag
|
||||
if (settings.showThreadInfo) TAG += "(" + Thread.currentThread().name + ")"
|
||||
|
||||
// Top Divider
|
||||
if (settings.showDivider) printLine(logLevel, TAG, TOP_DIVIDER)
|
||||
|
||||
// Log Content
|
||||
val lines = message.split(System.getProperty("line.separator").toRegex())
|
||||
.dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
for (line in lines) printLine(logLevel, TAG, if (settings.showDivider) "┃ $line" else line)
|
||||
|
||||
if (settings.stackTraceCount > 0 && fromException) printLine(
|
||||
logLevel,
|
||||
TAG,
|
||||
"Exception occurred"
|
||||
)
|
||||
|
||||
// Middle Divider
|
||||
if (settings.showDivider) printLine(logLevel, TAG, MIDDLE_DIVIDER)
|
||||
|
||||
// Log Stack Trace
|
||||
val traces = Thread.currentThread().stackTrace
|
||||
var startIndex = 2
|
||||
while (LogUtil::class.java.canonicalName == traces[startIndex].className || LogHelper::class.java.canonicalName == traces[startIndex].className) startIndex++
|
||||
|
||||
for (i in startIndex until min(
|
||||
traces.size.toDouble(),
|
||||
(startIndex + settings.stackTraceCount).toDouble()
|
||||
)
|
||||
.toInt()) {
|
||||
val builder = StringBuilder()
|
||||
builder.append(" at ")
|
||||
.append(traces[i].className)
|
||||
.append(".")
|
||||
.append(traces[i].methodName)
|
||||
.append("(")
|
||||
.append(traces[i].fileName)
|
||||
.append(":")
|
||||
.append(traces[i].lineNumber)
|
||||
.append(")")
|
||||
|
||||
printLine(logLevel, TAG, if (settings.showDivider) "┃ $builder" else builder.toString())
|
||||
}
|
||||
|
||||
// Log ellipsized stack trance
|
||||
val leftTraceCount = traces.size - startIndex - settings.stackTraceCount
|
||||
if (settings.stackTraceCount > 0 && leftTraceCount > 1) printLine(
|
||||
logLevel,
|
||||
TAG,
|
||||
if (settings.showDivider) "┃ at $leftTraceCount more stack traces..." else " at $leftTraceCount more stack traces..."
|
||||
)
|
||||
if (settings.stackTraceCount > 0 && leftTraceCount == 1) printLine(
|
||||
logLevel,
|
||||
TAG,
|
||||
if (settings.showDivider) "┃ at 1 more stack trace..." else " at 1 more stack trace..."
|
||||
)
|
||||
|
||||
// Middle Divider
|
||||
if (settings.showDivider) printLine(logLevel, TAG, BOTTOM_DIVIDER)
|
||||
|
||||
// LogUtil setToDefault
|
||||
if (this === LogUtil.instance) setToDefault()
|
||||
}
|
||||
|
||||
private fun printLine(logLevel: LogLevel, tag: String, message: String) {
|
||||
when (logLevel) {
|
||||
LogLevel.FULL, LogLevel.VERBOSE -> settings.logPrinter.v(tag, message)
|
||||
LogLevel.DEBUG -> settings.logPrinter.d(tag, message)
|
||||
LogLevel.INFO -> settings.logPrinter.i(tag, message)
|
||||
LogLevel.WARN -> settings.logPrinter.w(tag, message)
|
||||
LogLevel.ERROR -> settings.logPrinter.e(tag, message)
|
||||
LogLevel.ASSERT -> settings.logPrinter.wtf(tag, message)
|
||||
LogLevel.NONE -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
fun setToDefault() {
|
||||
settings.setTag(LogUtil.defaultSettings.tag)
|
||||
settings.setShowThreadInfo(LogUtil.defaultSettings.showThreadInfo)
|
||||
settings.setStackTraceCount(LogUtil.defaultSettings.stackTraceCount)
|
||||
settings.setLogLevel(LogUtil.defaultSettings.logLevel)
|
||||
settings.setShowDivider(LogUtil.defaultSettings.showDivider)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val INDENT_SPACES = 4
|
||||
|
||||
// http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5B%E2%94%80-%E2%95%BF%EF%BF%A8%5D
|
||||
private const val TOP_DIVIDER =
|
||||
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
private const val MIDDLE_DIVIDER =
|
||||
"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
private const val BOTTOM_DIVIDER =
|
||||
"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package com.thefinestartist.utils.log;
|
||||
package kr.lunaticbum.utils.log;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.thefinestartist.utils.etc.APILevel;
|
||||
import kr.lunaticbum.utils.etc.APILevel;
|
||||
|
||||
/**
|
||||
* LogPrinter helps to print message for {@link LogHelper}.
|
||||
@@ -0,0 +1,406 @@
|
||||
//package kr.lunaticbum.utils.log;
|
||||
//
|
||||
//import android.util.Log;
|
||||
//
|
||||
//import androidx.annotation.StringRes;
|
||||
//
|
||||
//import kr.lunaticbum.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,403 @@
|
||||
package kr.lunaticbum.utils.log
|
||||
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
import kr.lunaticbum.enums.LogLevel
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import kotlin.concurrent.Volatile
|
||||
|
||||
/**
|
||||
* LogUtil helps to manage application-wide [Log] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object LogUtil {
|
||||
fun logPrinter(logPrinter: LogPrinter?): LogHelper {
|
||||
return instance.logPrinter(logPrinter)
|
||||
}
|
||||
|
||||
// companion object {
|
||||
// Defaults
|
||||
val defaultSettings: Settings = Settings(
|
||||
LogUtil::class.java.simpleName
|
||||
)
|
||||
|
||||
// Singleton
|
||||
val instance: LogHelper = LogHelper()
|
||||
.tag(defaultSettings.tag)
|
||||
.showThreadInfo(defaultSettings.showThreadInfo)
|
||||
.stackTraceCount(defaultSettings.stackTraceCount)
|
||||
.logLevel(defaultSettings.logLevel)
|
||||
.showDivider(defaultSettings.showDivider)
|
||||
|
||||
// Builder
|
||||
fun tag(tag: String?): LogHelper {
|
||||
return instance.tag(tag)
|
||||
}
|
||||
|
||||
fun tag(@StringRes tagRes: Int): LogHelper {
|
||||
return instance.tag(tagRes)
|
||||
}
|
||||
|
||||
fun tag(clazz: Class<*>?): LogHelper {
|
||||
return instance.tag(clazz)
|
||||
}
|
||||
|
||||
fun showThreadInfo(showThreadInfo: Boolean): LogHelper {
|
||||
return instance.showThreadInfo(showThreadInfo)
|
||||
}
|
||||
|
||||
fun stackTraceCount(stackTraceCount: Int): LogHelper {
|
||||
return instance.stackTraceCount(stackTraceCount)
|
||||
}
|
||||
|
||||
fun logLevel(logLevel: LogLevel?): LogHelper {
|
||||
return instance.logLevel(logLevel)
|
||||
}
|
||||
|
||||
fun showDivider(showDivider: Boolean): LogHelper {
|
||||
return instance.showDivider(showDivider)
|
||||
}
|
||||
|
||||
// Logging Verbose
|
||||
fun v(message: Byte) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Char) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Short) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Int) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Long) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Float) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Double) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: Boolean) {
|
||||
instance.v(message)
|
||||
}
|
||||
|
||||
fun v(message: String?) {
|
||||
instance.v(message!!)
|
||||
}
|
||||
|
||||
fun v(message: JSONObject?) {
|
||||
instance.v(message!!)
|
||||
}
|
||||
|
||||
fun v(message: JSONArray?) {
|
||||
instance.v(message!!)
|
||||
}
|
||||
|
||||
fun v(message: Exception?) {
|
||||
instance.v(message!!)
|
||||
}
|
||||
|
||||
fun v(message: Any?) {
|
||||
instance.v(message!!)
|
||||
}
|
||||
|
||||
// Logging Debug
|
||||
fun d(message: Byte) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Char) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Short) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Int) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Long) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Float) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Double) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: Boolean) {
|
||||
instance.d(message)
|
||||
}
|
||||
|
||||
fun d(message: String?) {
|
||||
instance.d(message!!)
|
||||
}
|
||||
|
||||
fun d(message: JSONObject?) {
|
||||
instance.d(message!!)
|
||||
}
|
||||
|
||||
fun d(message: JSONArray?) {
|
||||
instance.d(message!!)
|
||||
}
|
||||
|
||||
fun d(message: Exception?) {
|
||||
instance.d(message!!)
|
||||
}
|
||||
|
||||
fun d(message: Any?) {
|
||||
instance.d(message!!)
|
||||
}
|
||||
|
||||
// Logging Information
|
||||
fun i(message: Byte) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Char) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Short) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Int) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Long) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Float) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Double) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: Boolean) {
|
||||
instance.i(message)
|
||||
}
|
||||
|
||||
fun i(message: String?) {
|
||||
instance.i(message!!)
|
||||
}
|
||||
|
||||
fun i(message: JSONObject?) {
|
||||
instance.i(message!!)
|
||||
}
|
||||
|
||||
fun i(message: JSONArray?) {
|
||||
instance.i(message!!)
|
||||
}
|
||||
|
||||
fun i(message: Exception?) {
|
||||
instance.i(message!!)
|
||||
}
|
||||
|
||||
fun i(message: Any?) {
|
||||
instance.i(message!!)
|
||||
}
|
||||
|
||||
// Logging Warning
|
||||
fun w(message: Byte) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Char) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Short) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Int) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Long) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Float) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Double) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: Boolean) {
|
||||
instance.w(message)
|
||||
}
|
||||
|
||||
fun w(message: String?) {
|
||||
instance.w(message!!)
|
||||
}
|
||||
|
||||
fun w(message: JSONObject?) {
|
||||
instance.w(message!!)
|
||||
}
|
||||
|
||||
fun w(message: JSONArray?) {
|
||||
instance.w(message!!)
|
||||
}
|
||||
|
||||
fun w(message: Exception?) {
|
||||
instance.w(message!!)
|
||||
}
|
||||
|
||||
fun w(message: Any?) {
|
||||
instance.w(message!!)
|
||||
}
|
||||
|
||||
// Logging Error
|
||||
fun e(message: Byte) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Char) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Short) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Int) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Long) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Float) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Double) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: Boolean) {
|
||||
instance.e(message)
|
||||
}
|
||||
|
||||
fun e(message: String?) {
|
||||
instance.e(message!!)
|
||||
}
|
||||
|
||||
fun e(message: JSONObject?) {
|
||||
instance.e(message!!)
|
||||
}
|
||||
|
||||
fun e(message: JSONArray?) {
|
||||
instance.e(message!!)
|
||||
}
|
||||
|
||||
fun e(message: Exception?) {
|
||||
instance.e(message!!)
|
||||
}
|
||||
|
||||
fun e(message: Any?) {
|
||||
instance.e(message!!)
|
||||
}
|
||||
|
||||
// Logging Assert
|
||||
fun wtf(message: Byte) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Char) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Short) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Int) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Long) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Float) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Double) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: Boolean) {
|
||||
instance.wtf(message)
|
||||
}
|
||||
|
||||
fun wtf(message: String?) {
|
||||
instance.wtf(message!!)
|
||||
}
|
||||
|
||||
fun wtf(message: JSONObject?) {
|
||||
instance.wtf(message!!)
|
||||
}
|
||||
|
||||
fun wtf(message: JSONArray?) {
|
||||
instance.wtf(message!!)
|
||||
}
|
||||
|
||||
fun wtf(message: Exception?) {
|
||||
instance.wtf(message!!)
|
||||
}
|
||||
|
||||
fun wtf(message: Any?) {
|
||||
instance.wtf(message!!)
|
||||
}
|
||||
|
||||
// Logging JsonString
|
||||
fun json(jsonString: String?) {
|
||||
json(LogLevel.DEBUG, jsonString)
|
||||
}
|
||||
|
||||
fun json(logLevel: LogLevel?, jsonString: String?) {
|
||||
instance.json(logLevel!!, jsonString!!)
|
||||
}
|
||||
|
||||
// Logging XmlString
|
||||
@RequiresApi(Build.VERSION_CODES.FROYO)
|
||||
fun xml(xmlString: String?) {
|
||||
xml(LogLevel.DEBUG, xmlString)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.FROYO)
|
||||
fun xml(logLevel: LogLevel?, jsonString: String?) {
|
||||
instance.xml(logLevel!!, jsonString!!)
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
//package kr.lunaticbum.utils.log;
|
||||
//
|
||||
//
|
||||
//import androidx.annotation.StringRes;
|
||||
//
|
||||
//import kr.lunaticbum.enums.LogLevel;
|
||||
//import kr.lunaticbum.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,88 @@
|
||||
package kr.lunaticbum.utils.log
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import kr.lunaticbum.enums.LogLevel
|
||||
import kr.lunaticbum.utils.content.ResourcesUtil.getString
|
||||
|
||||
|
||||
/**
|
||||
* Settings for [LogHelper].
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
class Settings {
|
||||
var tag: String = Settings::class.java.simpleName
|
||||
private set
|
||||
var showThreadInfo: Boolean = false
|
||||
private set
|
||||
var stackTraceCount: Int = 0
|
||||
private set
|
||||
var logLevel: LogLevel = LogLevel.FULL
|
||||
private set
|
||||
var showDivider: Boolean = false
|
||||
private set
|
||||
var logPrinter: LogPrinter = AndroidLogPrinter()
|
||||
private set
|
||||
|
||||
constructor()
|
||||
|
||||
constructor(tag: String) {
|
||||
this.tag = tag
|
||||
}
|
||||
|
||||
constructor(@StringRes tagRes: Int) {
|
||||
this.tag = getString(tagRes)
|
||||
}
|
||||
|
||||
constructor(clazz: Class<*>) {
|
||||
this.tag = clazz.simpleName
|
||||
}
|
||||
|
||||
fun setTag(tag: String): Settings {
|
||||
this.tag = tag
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setTag(@StringRes tagRes: Int): Settings {
|
||||
this.tag = getString(tagRes)
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setTag(clazz: Class<*>): Settings {
|
||||
this.tag = clazz.simpleName
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setShowThreadInfo(showThreadInfo: Boolean): Settings {
|
||||
this.showThreadInfo = showThreadInfo
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setStackTraceCount(stackTraceCount: Int): Settings {
|
||||
this.stackTraceCount = stackTraceCount
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setLogLevel(logLevel: LogLevel): Settings {
|
||||
this.logLevel = logLevel
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setShowDivider(showDivider: Boolean): Settings {
|
||||
this.showDivider = showDivider
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
|
||||
fun setLogPrinter(logPrinter: LogPrinter): Settings {
|
||||
this.logPrinter = logPrinter
|
||||
if (this === LogUtil.defaultSettings) LogUtil.instance.setToDefault()
|
||||
return this
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.preferences;
|
||||
package kr.lunaticbum.utils.preferences;
|
||||
|
||||
/**
|
||||
* Pref is abbreviation class of {@link PreferencesUtil}.
|
||||
@@ -0,0 +1,271 @@
|
||||
//package kr.lunaticbum.utils.preferences;
|
||||
//
|
||||
//import android.annotation.TargetApi;
|
||||
//import android.content.Context;
|
||||
//import android.content.SharedPreferences;
|
||||
//import android.os.Build;
|
||||
//import android.util.Base64;
|
||||
//
|
||||
//import kr.lunaticbum.Base;
|
||||
//import kr.lunaticbum.utils.etc.APILevel;
|
||||
//import kr.lunaticbum.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 kr.lunaticbum.utils.log.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,237 @@
|
||||
package kr.lunaticbum.utils.preferences
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.util.Base64
|
||||
import kr.lunaticbum.Base.getContext
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
import kr.lunaticbum.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
|
||||
|
||||
/**
|
||||
* PreferencesUtil helps to manage application-wide [SharedPreferences] conveniently.
|
||||
*
|
||||
* @author Robin Gustafsson
|
||||
*/
|
||||
open class PreferencesUtil {
|
||||
companion object {
|
||||
private val LogHelper = LogHelper(PreferencesUtil::class.java)
|
||||
var defaultName: String = PreferencesUtil::class.java.canonicalName
|
||||
|
||||
private fun getPreferences(name: String): SharedPreferences {
|
||||
return getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
|
||||
fun get(key: String?, defValue: Boolean): Boolean {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
fun get(key: String?, defValue: Int): Int {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
fun get(key: String?, defValue: Float): Float {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
fun get(key: String?, defValue: Long): Long {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
fun get(key: String?, defValue: String?): String? {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun get(key: String?, defValue: Set<String?>?): Set<String>? {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
fun <C : Serializable?> get(key: String?, defValue: C): C {
|
||||
return get(defaultName, key, defValue)
|
||||
}
|
||||
|
||||
fun get(name: String, key: String?, defValue: Boolean): Boolean {
|
||||
return getPreferences(name).getBoolean(key, defValue)
|
||||
}
|
||||
|
||||
fun get(name: String, key: String?, defValue: Int): Int {
|
||||
return getPreferences(name).getInt(key, defValue)
|
||||
}
|
||||
|
||||
fun get(name: String, key: String?, defValue: Float): Float {
|
||||
return getPreferences(name).getFloat(key, defValue)
|
||||
}
|
||||
|
||||
fun get(name: String, key: String?, defValue: Long): Long {
|
||||
return getPreferences(name).getLong(key, defValue)
|
||||
}
|
||||
|
||||
fun get(name: String, key: String?, defValue: String?): String? {
|
||||
return getPreferences(name).getString(key, defValue)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun get(name: String, key: String?, defValue: Set<String?>?): Set<String>? {
|
||||
return getPreferences(name).getStringSet(key, defValue)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
fun <C : Serializable?> get(name: String, key: String?, defValue: C): C {
|
||||
var bais: ByteArrayInputStream? = null
|
||||
var ois: ObjectInputStream? = null
|
||||
var result = defValue
|
||||
|
||||
val value = getPreferences(name).getString(key, null)
|
||||
if (value != null) {
|
||||
try {
|
||||
val decoded = Base64.decode(value.toByteArray(), Base64.DEFAULT)
|
||||
bais = ByteArrayInputStream(decoded)
|
||||
ois = ObjectInputStream(bais)
|
||||
result = ois.readObject() as C
|
||||
} catch (e: Exception) {
|
||||
LogHelper.e(e)
|
||||
} finally {
|
||||
if (ois != null) {
|
||||
try {
|
||||
ois.close()
|
||||
} catch (e: IOException) {
|
||||
LogHelper.e(e)
|
||||
}
|
||||
}
|
||||
if (bais != null) {
|
||||
try {
|
||||
bais.close()
|
||||
} catch (e: IOException) {
|
||||
LogHelper.e(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun put(key: String?, value: Boolean) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
fun put(key: String?, value: Int) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
fun put(key: String?, value: Float) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
fun put(key: String?, value: Long) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
fun put(key: String?, value: String?) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun put(key: String?, value: Set<String?>?) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
fun <C : Serializable?> put(key: String?, value: C) {
|
||||
put(defaultName, key, value)
|
||||
}
|
||||
|
||||
fun put(name: String, key: String?, value: Boolean) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putBoolean(key, value).apply()
|
||||
else getPreferences(name).edit().putBoolean(key, value).commit()
|
||||
}
|
||||
|
||||
fun put(name: String, key: String?, value: Int) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putInt(key, value).apply()
|
||||
else getPreferences(name).edit().putInt(key, value).commit()
|
||||
}
|
||||
|
||||
fun put(name: String, key: String?, value: Float) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putFloat(key, value).apply()
|
||||
else getPreferences(name).edit().putFloat(key, value).commit()
|
||||
}
|
||||
|
||||
fun put(name: String, key: String?, value: Long) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putLong(key, value).apply()
|
||||
else getPreferences(name).edit().putLong(key, value).commit()
|
||||
}
|
||||
|
||||
fun put(name: String, key: String?, value: String?) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putString(key, value).apply()
|
||||
else getPreferences(name).edit().putString(key, value).commit()
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun put(name: String, key: String?, value: Set<String?>?) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putStringSet(key, value).apply()
|
||||
else getPreferences(name).edit().putStringSet(key, value).commit()
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.FROYO)
|
||||
fun <C : Serializable?> put(name: String, key: String?, value: C) {
|
||||
var baos: ByteArrayOutputStream? = null
|
||||
var oos: ObjectOutputStream? = null
|
||||
|
||||
try {
|
||||
baos = ByteArrayOutputStream()
|
||||
oos = ObjectOutputStream(baos)
|
||||
oos.writeObject(value)
|
||||
val encoded = Base64.encode(baos.toByteArray(), Base64.DEFAULT)
|
||||
if (APILevel.require(9)) getPreferences(name).edit().putString(key, String(encoded))
|
||||
.apply()
|
||||
else getPreferences(name).edit().putString(key, String(encoded)).commit()
|
||||
} catch (e: IOException) {
|
||||
LogHelper.e(e)
|
||||
throw RuntimeException(e)
|
||||
} finally {
|
||||
if (oos != null) {
|
||||
try {
|
||||
oos.close()
|
||||
} catch (e: IOException) {
|
||||
LogHelper.e(e)
|
||||
}
|
||||
}
|
||||
if (baos != null) {
|
||||
try {
|
||||
baos.close()
|
||||
} catch (e: IOException) {
|
||||
LogHelper.e(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun remove(key: String?) {
|
||||
remove(defaultName, key)
|
||||
}
|
||||
|
||||
fun remove(name: String, key: String?) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().remove(key).apply()
|
||||
else getPreferences(name).edit().remove(key).commit()
|
||||
}
|
||||
|
||||
|
||||
@JvmOverloads
|
||||
fun clear(name: String = defaultName) {
|
||||
if (APILevel.require(9)) getPreferences(name).edit().clear().apply()
|
||||
else getPreferences(name).edit().clear().commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//package kr.lunaticbum.utils.service;
|
||||
//
|
||||
//import android.content.ClipData;
|
||||
//import android.content.ClipDescription;
|
||||
//import android.content.ClipboardManager;
|
||||
//
|
||||
//import kr.lunaticbum.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,55 @@
|
||||
package kr.lunaticbum.utils.service
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipDescription
|
||||
import android.content.ClipboardManager
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
import kr.lunaticbum.utils.service.ServiceUtil.clipboardManager
|
||||
|
||||
/**
|
||||
* ClipboardManagerUtil helps to manage [ClipboardManager] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object ClipboardManagerUtil {
|
||||
fun hasText(): Boolean {
|
||||
val clipboardManager = clipboardManager
|
||||
if (APILevel.require(11)) {
|
||||
val cm = clipboardManager as ClipboardManager
|
||||
val description = cm.primaryClipDescription
|
||||
val clipData = cm.primaryClip
|
||||
return clipData != null && description != null && (description.hasMimeType(
|
||||
ClipDescription.MIMETYPE_TEXT_PLAIN
|
||||
))
|
||||
} else {
|
||||
return clipboardManager.hasText()
|
||||
}
|
||||
}
|
||||
|
||||
var text: CharSequence?
|
||||
get() {
|
||||
val clipboardManager = clipboardManager
|
||||
if (APILevel.require(11)) {
|
||||
val cm = clipboardManager as ClipboardManager
|
||||
val description = cm.primaryClipDescription
|
||||
val clipData = cm.primaryClip
|
||||
return if (clipData != null && description != null && description.hasMimeType(
|
||||
ClipDescription.MIMETYPE_TEXT_PLAIN
|
||||
)
|
||||
) clipData.getItemAt(0).text
|
||||
else null
|
||||
} else {
|
||||
return clipboardManager.text
|
||||
}
|
||||
}
|
||||
set(text) {
|
||||
val clipboardManager = clipboardManager
|
||||
if (APILevel.require(11)) {
|
||||
val cm = clipboardManager as ClipboardManager
|
||||
val clip = ClipData.newPlainText("ClipboardManagerUtil", text)
|
||||
cm.setPrimaryClip(clip)
|
||||
} else {
|
||||
clipboardManager.text = text
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.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,273 @@
|
||||
package kr.lunaticbum.utils.service
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.annotation.SuppressLint
|
||||
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 kr.lunaticbum.Base.getContext
|
||||
|
||||
/**
|
||||
* ServiceUtil helps to manage Android system service conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object ServiceUtil {
|
||||
fun getSystemService(serviceName: String): Any {
|
||||
return getContext().getSystemService(serviceName)
|
||||
}
|
||||
|
||||
val accessibilityManager: AccessibilityManager
|
||||
get() = getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
|
||||
|
||||
@get:TargetApi(19)
|
||||
val captioningManager: CaptioningManager
|
||||
get() = getSystemService(Context.CAPTIONING_SERVICE) as CaptioningManager
|
||||
|
||||
val accountManager: AccountManager
|
||||
get() = getSystemService(Context.ACCOUNT_SERVICE) as AccountManager
|
||||
|
||||
val activityManager: ActivityManager
|
||||
get() = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
|
||||
val alarmManager: AlarmManager
|
||||
get() = getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
val audioManager: AudioManager
|
||||
get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
||||
@get:TargetApi(16)
|
||||
val mediaRouter: MediaRouter
|
||||
get() = getSystemService(Context.MEDIA_ROUTER_SERVICE) as MediaRouter
|
||||
|
||||
@get:TargetApi(18)
|
||||
val bluetoothManager: BluetoothManager
|
||||
get() = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||
|
||||
val clipboardManager: ClipboardManager
|
||||
get() = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
|
||||
val connectivityManager: ConnectivityManager
|
||||
get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
|
||||
@get:TargetApi(8)
|
||||
val devicePolicyManager: DevicePolicyManager
|
||||
get() = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
|
||||
@get:TargetApi(9)
|
||||
val downloadManager: DownloadManager
|
||||
get() = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val batteryManager: BatteryManager
|
||||
get() = getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||
|
||||
@get:TargetApi(10)
|
||||
val nfcManager: NfcManager
|
||||
get() = getSystemService(Context.NFC_SERVICE) as NfcManager
|
||||
|
||||
@get:TargetApi(8)
|
||||
val dropBoxManager: DropBoxManager
|
||||
get() = getSystemService(Context.DROPBOX_SERVICE) as DropBoxManager
|
||||
|
||||
@get:TargetApi(16)
|
||||
val inputManager: InputManager
|
||||
get() = getSystemService(Context.INPUT_SERVICE) as InputManager
|
||||
|
||||
@get:TargetApi(17)
|
||||
val displayManager: DisplayManager
|
||||
get() = getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
||||
|
||||
val inputMethodManager: InputMethodManager
|
||||
get() = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
@get:TargetApi(14)
|
||||
val textServicesManager: TextServicesManager
|
||||
get() = getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE) as TextServicesManager
|
||||
|
||||
val keyguardManager: KeyguardManager
|
||||
get() = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
|
||||
val layoutInflater: LayoutInflater
|
||||
get() = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
|
||||
val locationManager: LocationManager
|
||||
get() = getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
|
||||
val notificationManager: NotificationManager
|
||||
get() = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
||||
@get:TargetApi(16)
|
||||
val nsdManager: NsdManager
|
||||
get() = getSystemService(Context.NSD_SERVICE) as NsdManager
|
||||
|
||||
val powerManager: PowerManager
|
||||
get() = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
|
||||
val searchManager: SearchManager
|
||||
get() = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||
|
||||
val sensorManager: SensorManager
|
||||
get() = getSystemService(Context.SENSOR_SERVICE) as SensorManager
|
||||
|
||||
@get:TargetApi(9)
|
||||
val storageManager: StorageManager
|
||||
get() = getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
||||
|
||||
val telephonyManager: TelephonyManager
|
||||
get() = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
|
||||
|
||||
@get:TargetApi(22)
|
||||
val subscriptionManager: SubscriptionManager
|
||||
get() = getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
|
||||
|
||||
@get:TargetApi(23)
|
||||
val carrierConfigManager: CarrierConfigManager
|
||||
get() = getSystemService(Context.CARRIER_CONFIG_SERVICE) as CarrierConfigManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val telecomManager: TelecomManager
|
||||
get() = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
||||
|
||||
@get:TargetApi(8)
|
||||
val uiModeManager: UiModeManager
|
||||
get() = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
|
||||
@get:TargetApi(12)
|
||||
val usbManager: UsbManager
|
||||
get() = getSystemService(Context.USB_SERVICE) as UsbManager
|
||||
|
||||
val vibrator: Vibrator
|
||||
get() = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
||||
|
||||
val wallpaperManager: WallpaperManager
|
||||
get() = WallpaperManager.getInstance(getContext())
|
||||
|
||||
val wifiManager: WifiManager
|
||||
@SuppressLint("WifiManagerLeak")
|
||||
get() = getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
|
||||
@get:TargetApi(14)
|
||||
val wifiP2pManager: WifiP2pManager
|
||||
get() = getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager
|
||||
|
||||
val windowManager: WindowManager
|
||||
get() = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
|
||||
@get:TargetApi(17)
|
||||
val userManager: UserManager
|
||||
get() = getSystemService(Context.USER_SERVICE) as UserManager
|
||||
|
||||
@get:TargetApi(19)
|
||||
val appOpsManager: AppOpsManager
|
||||
get() = getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val cameraManager: CameraManager
|
||||
get() = getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val launcherApps: LauncherApps
|
||||
get() = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
|
||||
@get:TargetApi(21)
|
||||
val restrictionsManager: RestrictionsManager
|
||||
get() = getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
|
||||
|
||||
@get:TargetApi(19)
|
||||
val printManager: PrintManager
|
||||
get() = getSystemService(Context.PRINT_SERVICE) as PrintManager
|
||||
|
||||
@get:TargetApi(19)
|
||||
val consumerIrManager: ConsumerIrManager
|
||||
get() = getSystemService(Context.CONSUMER_IR_SERVICE) as ConsumerIrManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val mediaSessionManager: MediaSessionManager
|
||||
get() = getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager
|
||||
|
||||
@get:TargetApi(23)
|
||||
val fingerprintManager: FingerprintManager
|
||||
get() = getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val tvInputManager: TvInputManager
|
||||
get() = getSystemService(Context.TV_INPUT_SERVICE) as TvInputManager
|
||||
|
||||
@get:TargetApi(22)
|
||||
val usageStatsManager: UsageStatsManager
|
||||
get() = getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager
|
||||
|
||||
@get:TargetApi(23)
|
||||
val networkStatsManager: NetworkStatsManager
|
||||
get() = getSystemService(Context.NETWORK_STATS_SERVICE) as NetworkStatsManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val jobScheduler: JobScheduler
|
||||
get() = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
|
||||
@get:TargetApi(21)
|
||||
val mediaProjectionManager: MediaProjectionManager
|
||||
get() = getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
|
||||
|
||||
@get:TargetApi(21)
|
||||
val appWidgetManager: AppWidgetManager
|
||||
get() = getSystemService(Context.APPWIDGET_SERVICE) as AppWidgetManager
|
||||
|
||||
@get:TargetApi(23)
|
||||
val midiManager: MidiManager
|
||||
get() = getSystemService(Context.MIDI_SERVICE) as MidiManager
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//package kr.lunaticbum.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,45 @@
|
||||
package kr.lunaticbum.utils.service
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.media.AudioAttributes
|
||||
import kr.lunaticbum.utils.service.ServiceUtil.vibrator
|
||||
|
||||
/**
|
||||
* VibratorUtil helps to manage [Vibrator] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object VibratorUtil {
|
||||
@TargetApi(11)
|
||||
fun hasVibrator(): Boolean {
|
||||
return vibrator.hasVibrator()
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun vibrate(milliseconds: Long = 200) {
|
||||
vibrate(longArrayOf(milliseconds))
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@JvmOverloads
|
||||
fun vibrate(pattern: LongArray?, repeat: Int = -1) {
|
||||
vibrator.vibrate(pattern, repeat)
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
fun vibrate(milliseconds: Long, attributes: AudioAttributes?) {
|
||||
vibrate(longArrayOf(milliseconds), -1, attributes)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@TargetApi(21)
|
||||
fun vibrate(pattern: LongArray?, repeat: Int, attributes: AudioAttributes?) {
|
||||
vibrator.vibrate(pattern, repeat, attributes)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun cancel() {
|
||||
vibrator.cancel()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//package kr.lunaticbum.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,19 @@
|
||||
package kr.lunaticbum.utils.service
|
||||
|
||||
import android.view.Display
|
||||
import android.view.View
|
||||
import kr.lunaticbum.utils.service.ServiceUtil.windowManager
|
||||
|
||||
/**
|
||||
* WindowManagerUtil helps to manage [WindowManager] conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object WindowManagerUtil {
|
||||
val defaultDisplay: Display
|
||||
get() = windowManager.defaultDisplay
|
||||
|
||||
fun removeViewImmediate(view: View?) {
|
||||
windowManager.removeViewImmediate(view)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
//package kr.lunaticbum.utils.ui;
|
||||
//
|
||||
//import android.graphics.Point;
|
||||
//import android.util.TypedValue;
|
||||
//import android.view.Display;
|
||||
//
|
||||
//import kr.lunaticbum.utils.etc.APILevel;
|
||||
//import kr.lunaticbum.enums.Rotation;
|
||||
//import kr.lunaticbum.utils.content.ResourcesUtil;
|
||||
//import kr.lunaticbum.utils.content.ThemeUtil;
|
||||
//import kr.lunaticbum.utils.content.TypedValueUtil;
|
||||
//import kr.lunaticbum.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,79 @@
|
||||
package kr.lunaticbum.utils.ui
|
||||
|
||||
import android.R
|
||||
import android.graphics.Point
|
||||
import android.util.TypedValue
|
||||
import kr.lunaticbum.enums.Rotation
|
||||
import kr.lunaticbum.utils.content.ResourcesUtil.getDimensionPixelSize
|
||||
import kr.lunaticbum.utils.content.ResourcesUtil.getIdentifier
|
||||
import kr.lunaticbum.utils.content.ThemeUtil
|
||||
import kr.lunaticbum.utils.content.TypedValueUtil
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
import kr.lunaticbum.utils.service.WindowManagerUtil
|
||||
|
||||
/**
|
||||
* DisplayUtil helps to calculate screen size conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object DisplayUtil {
|
||||
val width: Int
|
||||
get() {
|
||||
val display = WindowManagerUtil.defaultDisplay
|
||||
if (APILevel.require(13)) {
|
||||
val size = Point()
|
||||
display.getSize(size)
|
||||
return size.x
|
||||
} else {
|
||||
return display.width
|
||||
}
|
||||
}
|
||||
|
||||
val height: Int
|
||||
get() {
|
||||
val display = WindowManagerUtil.defaultDisplay
|
||||
if (APILevel.require(13)) {
|
||||
val size = Point()
|
||||
display.getSize(size)
|
||||
return size.y
|
||||
} else {
|
||||
return display.height
|
||||
}
|
||||
}
|
||||
|
||||
val rotation: Rotation
|
||||
get() = if (APILevel.require(8)) Rotation.fromValue(WindowManagerUtil.defaultDisplay.rotation)
|
||||
else Rotation.fromValue(WindowManagerUtil.defaultDisplay.orientation)
|
||||
|
||||
val isPortrait: Boolean
|
||||
get() = height >= width
|
||||
|
||||
val isLandscape: Boolean
|
||||
get() = height < width
|
||||
|
||||
val statusBarHeight: Int
|
||||
get() {
|
||||
val resourceId = getIdentifier("status_bar_height", "dimen", "android")
|
||||
return if (resourceId > 0) getDimensionPixelSize(resourceId) else 0
|
||||
}
|
||||
|
||||
val toolbarHeight: Int
|
||||
get() = actionBarHeight
|
||||
|
||||
val actionBarHeight: Int
|
||||
get() {
|
||||
val tv = TypedValue()
|
||||
return if (ThemeUtil.resolveAttribute(
|
||||
R.attr.actionBarSize,
|
||||
tv,
|
||||
true
|
||||
)
|
||||
) TypedValueUtil.complexToDimensionPixelSize(tv.data) else 0
|
||||
}
|
||||
|
||||
val navigationBarHeight: Int
|
||||
get() {
|
||||
val resourceId = getIdentifier("navigation_bar_height", "dimen", "android")
|
||||
return if (resourceId > 0) getDimensionPixelSize(resourceId) else 0
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.utils.ui;
|
||||
package kr.lunaticbum.utils.ui;
|
||||
|
||||
/**
|
||||
* Keyboard is abbreviation class of {@link KeyboardUtil}.
|
||||
@@ -0,0 +1,184 @@
|
||||
//package kr.lunaticbum.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 kr.lunaticbum.Base;
|
||||
//import kr.lunaticbum.utils.etc.ThreadUtil;
|
||||
//import kr.lunaticbum.converters.UnitConverter;
|
||||
//import kr.lunaticbum.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,155 @@
|
||||
package kr.lunaticbum.utils.ui
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.fragment.app.Fragment
|
||||
import kr.lunaticbum.Base.getContext
|
||||
import kr.lunaticbum.converters.UnitConverter
|
||||
import kr.lunaticbum.utils.etc.ThreadUtil
|
||||
import kr.lunaticbum.utils.service.ServiceUtil
|
||||
|
||||
/**
|
||||
* KeyboardUtil helps to show and hide keyboard conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
open class KeyboardUtil {
|
||||
companion object {
|
||||
var currentHeight: Int = 0
|
||||
const val KEYBOARD_UTIL_PREF: String = "KEYBOARD_UTIL_PREF"
|
||||
const val KEYBOARD_HEIGHT: String = "KEYBOARD_HEIGHT"
|
||||
const val DEFAULT_KEYBOARD_HEIGHT: Int = 200
|
||||
|
||||
/**
|
||||
* Helps to show keyboard in [Activity.onCreate], [Activity.onStart],
|
||||
* [Activity.onResume],
|
||||
* [MenuItem.OnActionExpandListener.onMenuItemActionExpand],
|
||||
* [Fragment.onCreateView] and etc
|
||||
* This method guarantee to show keyboard every time.
|
||||
*/
|
||||
fun show(view: View?) {
|
||||
if (view == null) return
|
||||
|
||||
view.postDelayed(Runnable { showInMainThread(view) }, 200)
|
||||
}
|
||||
|
||||
/**
|
||||
* Please note that this method does not guarantee to show keyboard every time. To guarantee
|
||||
* to show keyboard, please use [.show] 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
|
||||
*/
|
||||
fun showImmediately(view: View?) {
|
||||
if (view == null) return
|
||||
|
||||
if (ThreadUtil.isMain()) {
|
||||
showInMainThread(view)
|
||||
} else {
|
||||
view.post(Runnable { showInMainThread(view) })
|
||||
}
|
||||
}
|
||||
|
||||
private fun showInMainThread(view: View?) {
|
||||
if (view == null) return
|
||||
|
||||
view.requestFocus()
|
||||
ServiceUtil.inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
fun hide(fragment: Fragment?) {
|
||||
if (fragment == null || fragment.activity == null) return
|
||||
|
||||
hide(fragment.activity)
|
||||
}
|
||||
|
||||
fun hide(fragment: Fragment?, clearFocus: Boolean) {
|
||||
if (fragment == null || fragment.activity == null) return
|
||||
|
||||
hide(fragment.activity)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun hide(activity: Activity?, clearFocus: Boolean = true) {
|
||||
if (activity == null) return
|
||||
|
||||
hide(activity.currentFocus, clearFocus)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun hide(fragment: android.app.Fragment?) {
|
||||
hide(fragment, true)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
fun hide(fragment: android.app.Fragment?, clearFocus: Boolean) {
|
||||
if (fragment == null || fragment.activity == null) return
|
||||
|
||||
hide(fragment.activity, clearFocus)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun hide(dialog: Dialog?, clearFocus: Boolean = true) {
|
||||
if (dialog == null) return
|
||||
|
||||
hide(dialog.currentFocus, clearFocus)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun hide(view: View?, clearFocus: Boolean = true) {
|
||||
if (view == null) return
|
||||
|
||||
if (clearFocus) {
|
||||
view.clearFocus()
|
||||
}
|
||||
|
||||
ServiceUtil.inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
|
||||
fun getHeight(): Int {
|
||||
if (currentHeight <= 0) currentHeight =
|
||||
getContext().getSharedPreferences(KEYBOARD_UTIL_PREF, Context.MODE_PRIVATE).getInt(
|
||||
KEYBOARD_HEIGHT, UnitConverter.dpToPx(DEFAULT_KEYBOARD_HEIGHT)
|
||||
)
|
||||
|
||||
return currentHeight
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.GINGERBREAD)
|
||||
fun setHeight(height: Int) {
|
||||
Companion.currentHeight = height
|
||||
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 kr.lunaticbum.utils.ui;
|
||||
//
|
||||
//import android.graphics.drawable.Drawable;
|
||||
//import android.view.View;
|
||||
//
|
||||
//import androidx.annotation.DrawableRes;
|
||||
//
|
||||
//import kr.lunaticbum.Base;
|
||||
//import kr.lunaticbum.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,34 @@
|
||||
package kr.lunaticbum.utils.ui
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.view.View
|
||||
import androidx.annotation.DrawableRes
|
||||
import kr.lunaticbum.Base.resources
|
||||
import kr.lunaticbum.utils.etc.APILevel
|
||||
|
||||
/**
|
||||
* ViewUtil helps to set background drawable conveniently.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
object ViewUtil {
|
||||
fun setBackground(view: View?, drawable: Drawable?) {
|
||||
if (view == null) return
|
||||
|
||||
if (APILevel.require(16)) {
|
||||
view.background = drawable
|
||||
} else {
|
||||
view.setBackgroundDrawable(drawable)
|
||||
}
|
||||
}
|
||||
|
||||
fun setBackground(view: View?, @DrawableRes drawableRes: Int) {
|
||||
if (view == null) return
|
||||
|
||||
if (APILevel.require(16)) {
|
||||
view.background = resources.getDrawable(drawableRes)
|
||||
} else {
|
||||
view.setBackgroundDrawable(resources.getDrawable(drawableRes))
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/18/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/10/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/9/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 1/26/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/10/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2014. 9. 2..
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/21/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/21/16.
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.thefinestartist.wip;
|
||||
package kr.lunaticbum.wip;
|
||||
|
||||
/**
|
||||
* Created by TheFinestArtist on 2/18/16.
|
||||
Reference in New Issue
Block a user