diff --git a/annotations/.gitignore b/annotations/.gitignore
deleted file mode 100644
index 796b96d..0000000
--- a/annotations/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/annotations/build.gradle b/annotations/build.gradle
deleted file mode 100644
index ea568f8..0000000
--- a/annotations/build.gradle
+++ /dev/null
@@ -1,15 +0,0 @@
-apply plugin: 'java'
-//apply plugin: 'com.novoda.bintray-release'
-
-//publish {
-// userOrg = 'thefinestartist'
-// groupId = 'com.thefinestartist'
-// artifactId = 'annotations'
-// publishVersion = rootProject.ext.versionName
-// desc = 'Context free and basic utils to build Android project conveniently.'
-// website = 'https://github.com/TheFinestArtist/AndroidBaseUtils'
-//}
-java {
- sourceCompatibility = JavaVersion.VERSION_1_8
- targetCompatibility = JavaVersion.VERSION_1_8
-}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 791ecfd..0b79218 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -154,10 +154,10 @@
+ android:theme="@style/FinestWebViewTheme.Fullscreen" />
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);
- }
-}
\ No newline at end of file
+//package android.print;
+//
+//import android.app.Activity;
+//import android.content.Context;
+//import android.os.Bundle;
+//import android.os.CancellationSignal;
+//import android.os.ParcelFileDescriptor;
+//import android.webkit.WebView;
+//import android.webkit.WebViewClient;
+//
+//import java.io.File;
+//import java.io.FileInputStream;
+//import java.io.FileOutputStream;
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.OutputStream;
+//
+//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);
+// }
+//}
\ No newline at end of file
diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt
index e707bf6..c767125 100644
--- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt
+++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt
@@ -341,9 +341,8 @@ internal class LauncherActivity : AppCompatActivity() {
BLog.LOGE("onConfigurationChanged Configuration >> ${newConfig}")
BLog.LOGE("onConfigurationChanged newConfig?.screenWidthDp >> ${newConfig?.screenWidthDp}")
- isOpendFold = (newConfig?.screenWidthDp?.toInt() ?: 0 > 700) == true
-// binding.viewPager.invalidate()
-// binding.viewPager.currentItem = 1
+ BLog.LOGE("onConfigurationChanged newConfig?.screenHeightDp >> ${newConfig?.screenHeightDp}")
+ isOpendFold = (newConfig.screenWidthDp * 1.1f) > newConfig.screenHeightDp
}
override fun onNewIntent(intent: Intent?) {
diff --git a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt
index 81d192b..7c2d932 100644
--- a/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt
+++ b/app/src/main/kotlin/bums/lunatic/launcher/home/adapters/RssItemAdapter.kt
@@ -42,7 +42,7 @@ import bums.lunatic.launcher.workers.WorkersDb
import com.google.android.material.imageview.ShapeableImageView
import com.google.gson.Gson
import com.squareup.picasso.Picasso
-import com.wuadam.awesomewebview.AwesomeWebView
+import kr.lunaticbum.awesomewebview.AwesomeWebView
import io.realm.kotlin.UpdatePolicy
import java.text.SimpleDateFormat
import java.util.Date
@@ -78,9 +78,11 @@ internal class RssItemAdapter (
// show(lActivity!!.supportFragmentManager,rss.originPage)
// }
} else {
- RssViewer().apply {
- show(lActivity!!.supportFragmentManager,rss.originPage)
- }
+// RssViewer().apply {
+// show(lActivity!!.supportFragmentManager,rss.originPage)
+// }
+ AwesomeWebView.Builder(lActivity!!).showIconClose(true).showIconBack(false).showProgressBar(true).webViewMixedContentMode(0)
+ .show(rss.originPage!!)
// openOpera(rss.originPage())
}
}
diff --git a/build.gradle.kts b/build.gradle.kts
index b11fde1..cb99dcd 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -17,32 +17,3 @@ plugins {
tasks.register("clean") {
delete(rootProject.buildDir)
}
-
-
-ext {
-// minSdkVersion = 7
-// targetSdkVersion = 23
-// compileSdkVersion = 23
-// buildToolsVersion = '23.0.2'
-//
-// sourceCompatibility = JavaVersion.VERSION_1_7
-// targetCompatibility = JavaVersion.VERSION_1_7
-//
-// versionCode = 1
-// versionName = '0.9.5'
-//
-// supportLibVersion = '23.3.0'
-// playLibVersion = '8.4.0'
-}
-
-//repositories {
-// mavenCentral()
-// maven {
-// url = uri("https://jitpack.io")
-// }
-// jcenter()
-// mavenLocal()
-// flatDir {
-// dirs("libs")
-// }
-//}
\ No newline at end of file
diff --git a/library/build.gradle b/library/build.gradle
deleted file mode 100644
index 032f212..0000000
--- a/library/build.gradle
+++ /dev/null
@@ -1,42 +0,0 @@
-apply plugin: 'com.android.library'
-apply from: 'maven_publish.gradle'
-
-android {
- compileSdk 34
-
- defaultConfig {
- minSdk 14
- //noinspection ExpiredTargetSdkVersion
- targetSdk 31
- vectorDrawables.useSupportLibrary = true
- consumerProguardFiles 'proguard-rules.pro'
- }
- namespace 'com.wuadam.awesomewebview'
- lint {
- abortOnError false
- }
-
- // https://developer.android.com/build/publish-library/configure-pub-variants?hl=zh-cn#single-pub-var
- // https://stackoverflow.com/a/71366104
- publishing {
- singleVariant('release') {
- withSourcesJar()
- withJavadocJar()
- }
- }
-}
-
-dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.annotation:annotation:1.7.0'
- implementation 'androidx.appcompat:appcompat:1.6.1'
- implementation 'com.google.android.material:material:1.10.0'
- implementation 'com.nineoldandroids:library:2.4.0'
- implementation project(':utils')
-// implementation("com.thefinestartist:utils:0.9.5")
-
-
-// api ('com.yanzhenjie:permission:2.0.3') {
-// exclude group: 'com.android.support'
-// }
-}
diff --git a/library/build.gradle.kts b/library/build.gradle.kts
new file mode 100644
index 0000000..7748f3e
--- /dev/null
+++ b/library/build.gradle.kts
@@ -0,0 +1,45 @@
+plugins {
+ id ("com.android.library")
+ id ("kotlin-android")
+}
+
+android {
+ namespace = "kr.lunaticbum.awesomewebview"
+ compileSdk = 34
+
+ defaultConfig {
+// applicationId = "kr.lunaticbum.awesomewebview"
+ minSdk = 26
+ targetSdk = 34
+// versionCode = 1
+// versionName = "0.0.1"
+ }
+
+
+
+
+
+ buildFeatures {
+ viewBinding = true
+ dataBinding = true
+ }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+dependencies {
+// implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation ("androidx.annotation:annotation:1.9.1")
+ implementation ("androidx.appcompat:appcompat:1.7.0")
+ implementation ("com.google.android.material:material:1.12.0")
+// implementation ("com.nineoldandroids:library:2.4.0")
+ implementation ("androidx.core:core-ktx:1.13.1")
+ implementation(project(":utils"))
+}
\ No newline at end of file
diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
index 202eff7..2313e8c 100644
--- a/library/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -2,7 +2,7 @@
diff --git a/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebView.java b/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebView.java
deleted file mode 100644
index 01cc529..0000000
--- a/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebView.java
+++ /dev/null
@@ -1,1016 +0,0 @@
-package com.wuadam.awesomewebview;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import androidx.annotation.AnimRes;
-import androidx.annotation.ColorInt;
-import androidx.annotation.ColorRes;
-import androidx.annotation.DimenRes;
-import androidx.annotation.DrawableRes;
-import androidx.annotation.NonNull;
-import androidx.annotation.StringRes;
-import androidx.annotation.StyleRes;
-import android.webkit.WebSettings;
-
-import com.thefinestartist.Base;
-import com.thefinestartist.utils.content.Ctx;
-import com.thefinestartist.utils.content.Res;
-import com.wuadam.awesomewebview.enums.Position;
-import com.wuadam.awesomewebview.listeners.BroadCastManager;
-import com.wuadam.awesomewebview.listeners.WebViewListener;
-import com.wuadam.awesomewebview.objects.CustomMenu;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by Leonardo on 11/21/15.
- */
-public class AwesomeWebView {
-
- public static class Builder implements Serializable {
-
- protected final transient Context context;
- protected transient List listeners = new ArrayList<>();
-
- protected Integer key;
-
- protected Boolean rtl;
- protected Integer theme;
-
- protected Integer statusBarColor;
- protected Boolean statusBarIconDark;
-
- protected Integer toolbarColor;
- protected Boolean toolbarVisible;
-
- protected Integer iconDefaultColor;
- protected Integer iconDisabledColor;
- protected Integer iconPressedColor;
- protected Integer iconSelector;
-
- protected Boolean showIconClose;
- protected Boolean disableIconClose;
- protected Boolean showIconBack;
- protected Boolean disableIconBack;
- protected Boolean showIconForward;
- protected Boolean disableIconForward;
- protected Boolean showIconMenu;
- protected Boolean disableIconMenu;
-
- protected Boolean showDivider;
- protected Boolean gradientDivider;
- protected Integer dividerColor;
- protected Float dividerHeight;
-
- protected Boolean showProgressBar;
- protected Integer progressBarColor;
- protected Float progressBarHeight;
- protected Position progressBarPosition;
-
- protected String titleDefault;
- protected Boolean updateTitleFromHtml;
- protected Float titleSize;
- protected String titleFont;
- protected Integer titleColor;
-
- protected Boolean showUrl;
- protected Float urlSize;
- protected String urlFont;
- protected Integer urlColor;
-
- protected Integer menuColor;
- protected Integer menuDropShadowColor;
- protected Float menuDropShadowSize;
- protected Integer menuSelector;
-
- protected Float menuTextSize;
- protected String menuTextFont;
- protected Integer menuTextColor;
-
- protected Integer menuTextGravity;
- protected Float menuTextPaddingLeft;
- protected Float menuTextPaddingRight;
-
- protected Boolean showMenuRefresh;
- protected Integer stringResRefresh;
- protected Boolean showMenuFind;
- protected Integer stringResFind;
- protected Boolean showMenuShareVia;
- protected Integer stringResShareVia;
- protected Boolean showMenuCopyLink;
- protected Integer stringResCopyLink;
- protected Boolean showMenuOpenWith;
- protected Integer stringResOpenWith;
- protected Boolean showMenuSavePhoto;
- protected Integer stringResSavePhoto;
- protected Boolean showToastPhotoSavedOrFailed;
- protected Integer stringResPhotoSavedTo;
- protected Integer stringResPhotoSaveFailed;
- protected Boolean fileChooserEnabled;
- protected Integer stringResFileChooserTitle;
-
- protected List customMenus = new ArrayList<>();
-
- protected Integer animationOpenEnter = R.anim.modal_activity_open_enter;
- protected Integer animationOpenExit = R.anim.modal_activity_open_exit;
- protected Integer animationCloseEnter;
- protected Integer animationCloseExit;
-
- protected Boolean backPressToClose;
- protected Integer stringResCopiedToClipboard;
-
- protected Boolean webViewSupportZoom;
- protected Boolean webViewMediaPlaybackRequiresUserGesture;
- protected Boolean webViewBuiltInZoomControls;
- protected Boolean webViewDisplayZoomControls;
- protected Boolean webViewAllowFileAccess;
- protected Boolean webViewAllowContentAccess;
- protected Boolean webViewLoadWithOverviewMode;
- protected Boolean webViewSaveFormData;
- protected Integer webViewTextZoom;
- protected Boolean webViewUseWideViewPort;
- protected Boolean webViewSupportMultipleWindows;
- protected WebSettings.LayoutAlgorithm webViewLayoutAlgorithm;
- protected String webViewStandardFontFamily;
- protected String webViewFixedFontFamily;
- protected String webViewSansSerifFontFamily;
- protected String webViewSerifFontFamily;
- protected String webViewCursiveFontFamily;
- protected String webViewFantasyFontFamily;
- protected Integer webViewMinimumFontSize;
- protected Integer webViewMinimumLogicalFontSize;
- protected Integer webViewDefaultFontSize;
- protected Integer webViewDefaultFixedFontSize;
- protected Boolean webViewLoadsImagesAutomatically;
- protected Boolean webViewBlockNetworkImage;
- protected Boolean webViewBlockNetworkLoads;
- protected Boolean webViewJavaScriptEnabled;
- protected Boolean webViewAllowUniversalAccessFromFileURLs;
- protected Boolean webViewAllowFileAccessFromFileURLs;
- protected String webViewGeolocationDatabasePath;
- protected Boolean webViewAppCacheEnabled;
- protected Boolean webViewDatabaseEnabled;
- protected Boolean webViewDomStorageEnabled;
- protected Boolean webViewGeolocationEnabled;
- protected Boolean webViewJavaScriptCanOpenWindowsAutomatically;
- protected String webViewDefaultTextEncodingName;
- protected String webViewUserAgentString;
- protected Boolean webViewUserAgentAppend;
- protected Boolean webViewNeedInitialFocus;
- protected Integer webViewCacheMode;
- protected Integer webViewMixedContentMode;
- protected Boolean webViewOffscreenPreRaster;
- protected Boolean webViewAppJumpEnabled;
- protected Boolean webViewCookieEnabled;
- protected Boolean webViewCameraEnabled;
- protected Boolean webViewAudioEnabled;
-
- protected String injectJavaScript;
- protected Boolean injectJavaScriptMainPage;
-
- protected Map> injectCookies;
-
- protected String mimeType;
- protected String encoding;
- protected String data;
- protected String url;
- protected Map extraHeaders;
- protected Boolean extraHeadersMainPage;
-
- public Builder(@NonNull Activity activity) {
- this.context = activity;
- Base.initialize(activity);
- }
-
- /**
- * If you use context instead of activity, AwesomeWebView won't be able to override activity
- * animation.
- * Try to create builder with Activity if it's possible.
- */
- public Builder(@NonNull Context context) {
- this.context = context;
- Base.initialize(context);
- }
-
- public Builder setWebViewListener(WebViewListener listener) {
- listeners.clear();
- listeners.add(listener);
- return this;
- }
-
- public Builder addWebViewListener(WebViewListener listener) {
- listeners.add(listener);
- return this;
- }
-
- public Builder removeWebViewListener(WebViewListener listener) {
- listeners.remove(listener);
- return this;
- }
-
- public Builder rtl(boolean rtl) {
- this.rtl = rtl;
- return this;
- }
-
- public Builder theme(@StyleRes int theme) {
- this.theme = theme;
- return this;
- }
-
- public Builder statusBarColor(@ColorInt int color) {
- this.statusBarColor = color;
- return this;
- }
-
- public Builder statusBarColorRes(@ColorRes int colorRes) {
- this.statusBarColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder statusBarIconDark(boolean statusBarIconDark) {
- this.statusBarIconDark = statusBarIconDark;
- return this;
- }
-
- public Builder toolbarColor(@ColorInt int color) {
- this.toolbarColor = color;
- return this;
- }
-
- public Builder toolbarVisible(boolean toolbarVisible) {
- this.toolbarVisible = toolbarVisible;
- return this;
- }
-
- public Builder toolbarColorRes(@ColorRes int colorRes) {
- this.toolbarColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder iconDefaultColor(@ColorInt int color) {
- this.iconDefaultColor = color;
- return this;
- }
-
- public Builder iconDefaultColorRes(@ColorRes int color) {
- this.iconDefaultColor = Res.getColor(color);
- return this;
- }
-
- public Builder iconDisabledColor(@ColorInt int color) {
- this.iconDisabledColor = color;
- return this;
- }
-
- public Builder iconDisabledColorRes(@ColorRes int colorRes) {
- this.iconDisabledColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder iconPressedColor(@ColorInt int color) {
- this.iconPressedColor = color;
- return this;
- }
-
- public Builder iconPressedColorRes(@ColorRes int colorRes) {
- this.iconPressedColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder iconSelector(@DrawableRes int selectorRes) {
- this.iconSelector = selectorRes;
- return this;
- }
-
- public Builder showIconClose(boolean showIconClose) {
- this.showIconClose = showIconClose;
- return this;
- }
-
- public Builder disableIconClose(boolean disableIconClose) {
- this.disableIconClose = disableIconClose;
- return this;
- }
-
- public Builder showIconBack(boolean showIconBack) {
- this.showIconBack = showIconBack;
- return this;
- }
-
- public Builder disableIconBack(boolean disableIconBack) {
- this.disableIconBack = disableIconBack;
- return this;
- }
-
- public Builder showIconForward(boolean showIconForward) {
- this.showIconForward = showIconForward;
- return this;
- }
-
- public Builder disableIconForward(boolean disableIconForward) {
- this.disableIconForward = disableIconForward;
- return this;
- }
-
- public Builder showIconMenu(boolean showIconMenu) {
- this.showIconMenu = showIconMenu;
- return this;
- }
-
- public Builder disableIconMenu(boolean disableIconMenu) {
- this.disableIconMenu = disableIconMenu;
- return this;
- }
-
- public Builder showDivider(boolean showDivider) {
- this.showDivider = showDivider;
- return this;
- }
-
- public Builder gradientDivider(boolean gradientDivider) {
- this.gradientDivider = gradientDivider;
- return this;
- }
-
- public Builder dividerColor(@ColorInt int color) {
- this.dividerColor = color;
- return this;
- }
-
- public Builder dividerColorRes(@ColorRes int colorRes) {
- this.dividerColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder dividerHeight(float height) {
- this.dividerHeight = height;
- return this;
- }
-
- public Builder dividerHeight(int height) {
- this.dividerHeight = (float) height;
- return this;
- }
-
- public Builder dividerHeightRes(@DimenRes int height) {
- this.dividerHeight = Res.getDimension(height);
- return this;
- }
-
- public Builder showProgressBar(boolean showProgressBar) {
- this.showProgressBar = showProgressBar;
- return this;
- }
-
- public Builder progressBarColor(@ColorInt int color) {
- this.progressBarColor = color;
- return this;
- }
-
- public Builder progressBarColorRes(@ColorRes int colorRes) {
- this.progressBarColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder progressBarHeight(float height) {
- this.progressBarHeight = height;
- return this;
- }
-
- public Builder progressBarHeight(int height) {
- this.progressBarHeight = (float) height;
- return this;
- }
-
- public Builder progressBarHeightRes(@DimenRes int height) {
- this.progressBarHeight = Res.getDimension(height);
- return this;
- }
-
- public Builder progressBarPosition(@NonNull Position position) {
- this.progressBarPosition = position;
- return this;
- }
-
- public Builder titleDefault(@NonNull String title) {
- this.titleDefault = title;
- return this;
- }
-
- public Builder titleDefaultRes(@StringRes int stringRes) {
- this.titleDefault = Res.getString(stringRes);
- return this;
- }
-
- public Builder updateTitleFromHtml(boolean updateTitleFromHtml) {
- this.updateTitleFromHtml = updateTitleFromHtml;
- return this;
- }
-
- public Builder titleSize(float titleSize) {
- this.titleSize = titleSize;
- return this;
- }
-
- public Builder titleSize(int titleSize) {
- this.titleSize = (float) titleSize;
- return this;
- }
-
- public Builder titleSizeRes(@DimenRes int titleSize) {
- this.titleSize = Res.getDimension(titleSize);
- return this;
- }
-
- public Builder titleFont(String titleFont) {
- this.titleFont = titleFont;
- return this;
- }
-
- public Builder titleColor(@ColorInt int color) {
- this.titleColor = color;
- return this;
- }
-
- public Builder titleColorRes(@ColorRes int colorRes) {
- this.titleColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder showUrl(boolean showUrl) {
- this.showUrl = showUrl;
- return this;
- }
-
- public Builder urlSize(float urlSize) {
- this.urlSize = urlSize;
- return this;
- }
-
- public Builder urlSize(int urlSize) {
- this.urlSize = (float) urlSize;
- return this;
- }
-
- public Builder urlSizeRes(@DimenRes int urlSize) {
- this.urlSize = Res.getDimension(urlSize);
- return this;
- }
-
- public Builder urlFont(String urlFont) {
- this.urlFont = urlFont;
- return this;
- }
-
- public Builder urlColor(@ColorInt int color) {
- this.urlColor = color;
- return this;
- }
-
- public Builder urlColorRes(@ColorRes int colorRes) {
- this.urlColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder menuColor(@ColorInt int color) {
- this.menuColor = color;
- return this;
- }
-
- public Builder menuColorRes(@ColorRes int colorRes) {
- this.menuColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder menuTextGravity(int gravity) {
- this.menuTextGravity = gravity;
- return this;
- }
-
- public Builder menuTextPaddingLeft(float menuTextPaddingLeft) {
- this.menuTextPaddingLeft = menuTextPaddingLeft;
- return this;
- }
-
- public Builder menuTextPaddingLeft(int menuTextPaddingLeft) {
- this.menuTextPaddingLeft = (float) menuTextPaddingLeft;
- return this;
- }
-
- public Builder menuTextPaddingLeftRes(@DimenRes int menuTextPaddingLeft) {
- this.menuTextPaddingLeft = Res.getDimension(menuTextPaddingLeft);
- return this;
- }
-
- public Builder menuTextPaddingRight(float menuTextPaddingRight) {
- this.menuTextPaddingRight = menuTextPaddingRight;
- return this;
- }
-
- public Builder menuTextPaddingRight(int menuTextPaddingRight) {
- this.menuTextPaddingRight = (float) menuTextPaddingRight;
- return this;
- }
-
- public Builder menuTextPaddingRightRes(@DimenRes int menuTextPaddingRight) {
- this.menuTextPaddingRight = Res.getDimension(menuTextPaddingRight);
- return this;
- }
-
- public Builder menuDropShadowColor(@ColorInt int color) {
- this.menuDropShadowColor = color;
- return this;
- }
-
- public Builder menuDropShadowColorRes(@ColorRes int colorRes) {
- this.menuDropShadowColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder menuDropShadowSize(float menuDropShadowSize) {
- this.menuDropShadowSize = menuDropShadowSize;
- return this;
- }
-
- public Builder menuDropShadowSize(int menuDropShadowSize) {
- this.menuDropShadowSize = (float) menuDropShadowSize;
- return this;
- }
-
- public Builder menuDropShadowSizeRes(@DimenRes int menuDropShadowSize) {
- this.menuDropShadowSize = Res.getDimension(menuDropShadowSize);
- return this;
- }
-
- public Builder menuSelector(@DrawableRes int selectorRes) {
- this.menuSelector = selectorRes;
- return this;
- }
-
- public Builder menuTextSize(float menuTextSize) {
- this.menuTextSize = menuTextSize;
- return this;
- }
-
- public Builder menuTextSize(int menuTextSize) {
- this.menuTextSize = (float) menuTextSize;
- return this;
- }
-
- public Builder menuTextSizeRes(@DimenRes int menuTextSize) {
- this.menuTextSize = Res.getDimension(menuTextSize);
- return this;
- }
-
- public Builder menuTextFont(String menuTextFont) {
- this.menuTextFont = menuTextFont;
- return this;
- }
-
- public Builder menuTextColor(@ColorInt int color) {
- this.menuTextColor = color;
- return this;
- }
-
- public Builder menuTextColorRes(@ColorRes int colorRes) {
- this.menuTextColor = Res.getColor(colorRes);
- return this;
- }
-
- public Builder showMenuRefresh(boolean showMenuRefresh) {
- this.showMenuRefresh = showMenuRefresh;
- return this;
- }
-
- public Builder stringResRefresh(@StringRes int stringResRefresh) {
- this.stringResRefresh = stringResRefresh;
- return this;
- }
-
- public Builder showMenuFind(boolean showMenuFind) {
- this.showMenuFind = showMenuFind;
- return this;
- }
-
- public Builder stringResFind(@StringRes int stringResFind) {
- this.stringResFind = stringResFind;
- return this;
- }
-
- public Builder showMenuShareVia(boolean showMenuShareVia) {
- this.showMenuShareVia = showMenuShareVia;
- return this;
- }
-
- public Builder stringResShareVia(@StringRes int stringResShareVia) {
- this.stringResShareVia = stringResShareVia;
- return this;
- }
-
- public Builder showMenuCopyLink(boolean showMenuCopyLink) {
- this.showMenuCopyLink = showMenuCopyLink;
- return this;
- }
-
- public Builder stringResCopyLink(@StringRes int stringResCopyLink) {
- this.stringResCopyLink = stringResCopyLink;
- return this;
- }
-
- public Builder showMenuOpenWith(boolean showMenuOpenWith) {
- this.showMenuOpenWith = showMenuOpenWith;
- return this;
- }
-
- public Builder stringResOpenWith(@StringRes int stringResOpenWith) {
- this.stringResOpenWith = stringResOpenWith;
- return this;
- }
-
- public Builder showMenuSavePhoto(boolean showMenuSavePhoto) {
- this.showMenuSavePhoto = showMenuSavePhoto;
- return this;
- }
-
- public Builder stringResSavePhoto(@StringRes int stringResSavePhoto) {
- this.stringResSavePhoto = stringResSavePhoto;
- return this;
- }
-
- public Builder showToastPhotoSavedOrFailed(boolean showToastPhotoSavedOrFailed) {
- this.showToastPhotoSavedOrFailed = showToastPhotoSavedOrFailed;
- return this;
- }
-
- public Builder stringResPhotoSavedTo(@StringRes int stringResPhotoSavedTo) {
- this.stringResPhotoSavedTo = stringResPhotoSavedTo;
- return this;
- }
-
- public Builder stringResPhotoSaveFailed(@StringRes int stringResPhotoSaveFailed) {
- this.stringResPhotoSaveFailed = stringResPhotoSaveFailed;
- return this;
- }
-
- public Builder fileChooserEnabled(boolean fileChooserEnabled) {
- this.fileChooserEnabled = fileChooserEnabled;
- return this;
- }
-
- public Builder stringResFileChooserTitle(@StringRes int stringResFileChooserTitle) {
- this.stringResFileChooserTitle = stringResFileChooserTitle;
- return this;
- }
-
- public Builder customMenus(@NonNull List customMenus) {
- this.customMenus = customMenus;
- return this;
- }
-
- public Builder addCustomMenu(@NonNull CustomMenu customMenu) {
- if (customMenus == null) {
- customMenus = new ArrayList<>(1);
- }
- customMenus.add(customMenu);
- return this;
- }
-
- public Builder setCustomAnimations(@AnimRes int animationOpenEnter,
- @AnimRes int animationOpenExit, @AnimRes int animationCloseEnter,
- @AnimRes int animationCloseExit) {
- this.animationOpenEnter = animationOpenEnter;
- this.animationOpenExit = animationOpenExit;
- this.animationCloseEnter = animationCloseEnter;
- this.animationCloseExit = animationCloseExit;
- return this;
- }
-
- /**
- * @deprecated As of release 1.0.1, replaced by {@link #setCustomAnimations(int, int, int, int)}
- */
- public Builder setCloseAnimations(@AnimRes int animationCloseEnter,
- @AnimRes int animationCloseExit) {
- this.animationCloseEnter = animationCloseEnter;
- this.animationCloseExit = animationCloseExit;
- return this;
- }
-
- public Builder backPressToClose(boolean backPressToClose) {
- this.backPressToClose = backPressToClose;
- return this;
- }
-
- public Builder stringResCopiedToClipboard(@StringRes int stringResCopiedToClipboard) {
- this.stringResCopiedToClipboard = stringResCopiedToClipboard;
- return this;
- }
-
- public Builder webViewSupportZoom(boolean webViewSupportZoom) {
- this.webViewSupportZoom = webViewSupportZoom;
- return this;
- }
-
- public Builder webViewMediaPlaybackRequiresUserGesture(
- boolean webViewMediaPlaybackRequiresUserGesture) {
- this.webViewMediaPlaybackRequiresUserGesture = webViewMediaPlaybackRequiresUserGesture;
- return this;
- }
-
- public Builder webViewBuiltInZoomControls(boolean webViewBuiltInZoomControls) {
- this.webViewBuiltInZoomControls = webViewBuiltInZoomControls;
- return this;
- }
-
- public Builder webViewDisplayZoomControls(boolean webViewDisplayZoomControls) {
- this.webViewDisplayZoomControls = webViewDisplayZoomControls;
- return this;
- }
-
- public Builder webViewAllowFileAccess(boolean webViewAllowFileAccess) {
- this.webViewAllowFileAccess = webViewAllowFileAccess;
- return this;
- }
-
- public Builder webViewAllowContentAccess(boolean webViewAllowContentAccess) {
- this.webViewAllowContentAccess = webViewAllowContentAccess;
- return this;
- }
-
- public Builder webViewLoadWithOverviewMode(boolean webViewLoadWithOverviewMode) {
- this.webViewLoadWithOverviewMode = webViewLoadWithOverviewMode;
- return this;
- }
-
- public Builder webViewSaveFormData(boolean webViewSaveFormData) {
- this.webViewSaveFormData = webViewSaveFormData;
- return this;
- }
-
- public Builder webViewTextZoom(int webViewTextZoom) {
- this.webViewTextZoom = webViewTextZoom;
- return this;
- }
-
- public Builder webViewUseWideViewPort(boolean webViewUseWideViewPort) {
- this.webViewUseWideViewPort = webViewUseWideViewPort;
- return this;
- }
-
- public Builder webViewSupportMultipleWindows(boolean webViewSupportMultipleWindows) {
- this.webViewSupportMultipleWindows = webViewSupportMultipleWindows;
- return this;
- }
-
- public Builder webViewLayoutAlgorithm(WebSettings.LayoutAlgorithm webViewLayoutAlgorithm) {
- this.webViewLayoutAlgorithm = webViewLayoutAlgorithm;
- return this;
- }
-
- public Builder webViewStandardFontFamily(String webViewStandardFontFamily) {
- this.webViewStandardFontFamily = webViewStandardFontFamily;
- return this;
- }
-
- public Builder webViewFixedFontFamily(String webViewFixedFontFamily) {
- this.webViewFixedFontFamily = webViewFixedFontFamily;
- return this;
- }
-
- public Builder webViewSansSerifFontFamily(String webViewSansSerifFontFamily) {
- this.webViewSansSerifFontFamily = webViewSansSerifFontFamily;
- return this;
- }
-
- public Builder webViewSerifFontFamily(String webViewSerifFontFamily) {
- this.webViewSerifFontFamily = webViewSerifFontFamily;
- return this;
- }
-
- public Builder webViewCursiveFontFamily(String webViewCursiveFontFamily) {
- this.webViewCursiveFontFamily = webViewCursiveFontFamily;
- return this;
- }
-
- public Builder webViewFantasyFontFamily(String webViewFantasyFontFamily) {
- this.webViewFantasyFontFamily = webViewFantasyFontFamily;
- return this;
- }
-
- public Builder webViewMinimumFontSize(int webViewMinimumFontSize) {
- this.webViewMinimumFontSize = webViewMinimumFontSize;
- return this;
- }
-
- public Builder webViewMinimumLogicalFontSize(int webViewMinimumLogicalFontSize) {
- this.webViewMinimumLogicalFontSize = webViewMinimumLogicalFontSize;
- return this;
- }
-
- public Builder webViewDefaultFontSize(int webViewDefaultFontSize) {
- this.webViewDefaultFontSize = webViewDefaultFontSize;
- return this;
- }
-
- public Builder webViewDefaultFixedFontSize(int webViewDefaultFixedFontSize) {
- this.webViewDefaultFixedFontSize = webViewDefaultFixedFontSize;
- return this;
- }
-
- public Builder webViewLoadsImagesAutomatically(boolean webViewLoadsImagesAutomatically) {
- this.webViewLoadsImagesAutomatically = webViewLoadsImagesAutomatically;
- return this;
- }
-
- public Builder webViewBlockNetworkImage(boolean webViewBlockNetworkImage) {
- this.webViewBlockNetworkImage = webViewBlockNetworkImage;
- return this;
- }
-
- public Builder webViewBlockNetworkLoads(boolean webViewBlockNetworkLoads) {
- this.webViewBlockNetworkLoads = webViewBlockNetworkLoads;
- return this;
- }
-
- public Builder webViewJavaScriptEnabled(boolean webViewJavaScriptEnabled) {
- this.webViewJavaScriptEnabled = webViewJavaScriptEnabled;
- return this;
- }
-
- public Builder webViewAllowUniversalAccessFromFileURLs(
- boolean webViewAllowUniversalAccessFromFileURLs) {
- this.webViewAllowUniversalAccessFromFileURLs = webViewAllowUniversalAccessFromFileURLs;
- return this;
- }
-
- public Builder webViewAllowFileAccessFromFileURLs(boolean webViewAllowFileAccessFromFileURLs) {
- this.webViewAllowFileAccessFromFileURLs = webViewAllowFileAccessFromFileURLs;
- return this;
- }
-
- public Builder webViewGeolocationDatabasePath(String webViewGeolocationDatabasePath) {
- this.webViewGeolocationDatabasePath = webViewGeolocationDatabasePath;
- return this;
- }
-
- public Builder webViewAppCacheEnabled(boolean webViewAppCacheEnabled) {
- this.webViewAppCacheEnabled = webViewAppCacheEnabled;
- return this;
- }
-
- public Builder webViewDatabaseEnabled(boolean webViewDatabaseEnabled) {
- this.webViewDatabaseEnabled = webViewDatabaseEnabled;
- return this;
- }
-
- public Builder webViewDomStorageEnabled(boolean webViewDomStorageEnabled) {
- this.webViewDomStorageEnabled = webViewDomStorageEnabled;
- return this;
- }
-
- public Builder webViewGeolocationEnabled(boolean webViewGeolocationEnabled) {
- this.webViewGeolocationEnabled = webViewGeolocationEnabled;
- return this;
- }
-
- public Builder webViewJavaScriptCanOpenWindowsAutomatically(
- boolean webViewJavaScriptCanOpenWindowsAutomatically) {
- this.webViewJavaScriptCanOpenWindowsAutomatically =
- webViewJavaScriptCanOpenWindowsAutomatically;
- return this;
- }
-
- public Builder webViewDefaultTextEncodingName(String webViewDefaultTextEncodingName) {
- this.webViewDefaultTextEncodingName = webViewDefaultTextEncodingName;
- return this;
- }
-
- public Builder webViewUserAgentString(String webViewUserAgentString) {
- this.webViewUserAgentString = webViewUserAgentString;
- return this;
- }
-
- public Builder webViewUserAgentAppend(boolean webViewUserAgentAppend) {
- this.webViewUserAgentAppend = webViewUserAgentAppend;
- return this;
- }
-
- public Builder webViewNeedInitialFocus(boolean webViewNeedInitialFocus) {
- this.webViewNeedInitialFocus = webViewNeedInitialFocus;
- return this;
- }
-
- public Builder webViewCacheMode(int webViewCacheMode) {
- this.webViewCacheMode = webViewCacheMode;
- return this;
- }
-
- public Builder webViewMixedContentMode(int webViewMixedContentMode) {
- this.webViewMixedContentMode = webViewMixedContentMode;
- return this;
- }
-
- public Builder webViewOffscreenPreRaster(boolean webViewOffscreenPreRaster) {
- this.webViewOffscreenPreRaster = webViewOffscreenPreRaster;
- return this;
- }
-
- public Builder webViewAppJumpEnabled(boolean webViewAppJumpEnabled) {
- this.webViewAppJumpEnabled = webViewAppJumpEnabled;
- return this;
- }
-
- public Builder webViewCookieEnabled(boolean webViewCookieEnabled) {
- this.webViewCookieEnabled = webViewCookieEnabled;
- return this;
- }
-
- public Builder webViewCameraEnabled(boolean webViewCameraEnabled) {
- this.webViewCameraEnabled = webViewCameraEnabled;
- return this;
- }
-
- public Builder webViewAudioEnabled(boolean webViewAudioEnabled) {
- this.webViewAudioEnabled = webViewAudioEnabled;
- return this;
- }
-
- public Builder setHeader(Map extraHeaders) {
- this.extraHeaders = extraHeaders;
- return this;
- }
-
- public Builder headersMainPage(boolean extraHeadersMainPage) {
- this.extraHeadersMainPage = extraHeadersMainPage;
- return this;
- }
-
- /**
- * @deprecated As of release 1.1.1, replaced by {@link #webViewUserAgentString(String)}
- * Use setUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101
- * Firefox/4.0") instead
- */
- public Builder webViewDesktopMode(boolean webViewDesktopMode) {
- return webViewUserAgentString(
- "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0");
- }
-
- public Builder injectJavaScript(String injectJavaScript) {
- this.injectJavaScript = injectJavaScript;
- return this;
- }
-
- public Builder injectJavaScriptMainPage(boolean injectJavaScriptMainPage) {
- this.injectJavaScriptMainPage = injectJavaScriptMainPage;
- return this;
- }
-
- public Builder injectCookies(Map> injectCookies) {
- this.injectCookies = injectCookies;
- return this;
- }
-
- public void load(@StringRes int dataRes) {
- load(Res.getString(dataRes));
- }
-
- public void load(String data) {
- load(data, "text/html", "UTF-8");
- }
-
- public void load(String data, String mimeType, String encoding) {
- this.mimeType = mimeType;
- this.encoding = encoding;
- show(null, data);
- }
-
- public void show(@StringRes int urlRes) {
- show(Res.getString(urlRes));
- }
-
- public void show(@NonNull String url) {
- show(url, null);
- }
-
- protected void show(String url, String data) {
- this.url = url;
- this.data = data;
- this.key = System.identityHashCode(this);
-
- if (!listeners.isEmpty()) new BroadCastManager(context, key, listeners);
-
- Intent intent = new Intent(context, AwesomeWebViewActivity.class);
- intent.putExtra("builder", this);
-
- Ctx.startActivity(intent);
-
- if (context instanceof Activity) {
- ((Activity) context).overridePendingTransition(animationOpenEnter, animationOpenExit);
- }
- }
- }
-}
diff --git a/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebViewActivity.java b/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebViewActivity.java
deleted file mode 100644
index 693a21f..0000000
--- a/library/src/main/java/com/wuadam/awesomewebview/AwesomeWebViewActivity.java
+++ /dev/null
@@ -1,1748 +0,0 @@
-package com.wuadam.awesomewebview;
-
-import android.Manifest;
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.GradientDrawable;
-import android.graphics.drawable.StateListDrawable;
-import android.net.MailTo;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Message;
-import android.provider.MediaStore;
-import androidx.annotation.DrawableRes;
-import androidx.annotation.RequiresApi;
-import com.google.android.material.appbar.AppBarLayout;
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import com.google.android.material.snackbar.Snackbar;
-import androidx.core.content.ContextCompat;
-import androidx.core.content.FileProvider;
-import androidx.appcompat.app.AlertDialog;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.AppCompatImageButton;
-import androidx.appcompat.widget.Toolbar;
-import android.util.TypedValue;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowManager;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.webkit.CookieManager;
-import android.webkit.CookieSyncManager;
-import android.webkit.DownloadListener;
-import android.webkit.GeolocationPermissions;
-import android.webkit.PermissionRequest;
-import android.webkit.ValueCallback;
-import android.webkit.WebChromeClient;
-import android.webkit.WebSettings;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-import android.widget.FrameLayout;
-import android.widget.ImageButton;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import com.thefinestartist.converters.UnitConverter;
-import com.thefinestartist.utils.etc.APILevel;
-import com.thefinestartist.utils.service.ClipboardManagerUtil;
-import com.thefinestartist.utils.ui.DisplayUtil;
-import com.thefinestartist.utils.ui.ViewUtil;
-import com.wuadam.awesomewebview.enums.Position;
-import com.wuadam.awesomewebview.helpers.BitmapHelper;
-import com.wuadam.awesomewebview.helpers.ColorHelper;
-import com.wuadam.awesomewebview.helpers.DownPicUtil;
-import com.wuadam.awesomewebview.helpers.PermissionHelper;
-import com.wuadam.awesomewebview.helpers.TypefaceHelper;
-import com.wuadam.awesomewebview.helpers.UrlParser;
-import com.wuadam.awesomewebview.jsInterface.CommonJsHelper;
-import com.wuadam.awesomewebview.listeners.BroadCastManager;
-import com.wuadam.awesomewebview.objects.CustomMenu;
-import com.wuadam.awesomewebview.views.ShadowLayout;
-import com.wuadam.awesomewebview.views.VideoEnabledWebChromeClient;
-import com.wuadam.awesomewebview.views.VideoEnabledWebView;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-//MailTo Imports
-
-/**
- * Created by Leonardo on 11/14/15.
- */
-public class AwesomeWebViewActivity extends AppCompatActivity
- implements View.OnClickListener, Handler.Callback {
-
- protected int key;
-
- protected boolean rtl;
- protected int theme;
-
- protected int statusBarColor;
- protected boolean statusBarIconDark;
-
- protected int toolbarColor;
- protected boolean toolbarVisible;
-
- protected int iconDefaultColor;
- protected int iconDisabledColor;
- protected int iconPressedColor;
- protected int iconSelector;
-
- protected boolean showIconClose;
- protected boolean disableIconClose;
- protected boolean showIconBack;
- protected boolean disableIconBack;
- protected boolean showIconForward;
- protected boolean disableIconForward;
- protected boolean showIconMenu;
- protected boolean disableIconMenu;
-
- protected boolean showDivider;
- protected boolean gradientDivider;
- protected int dividerColor;
- protected float dividerHeight;
-
- protected boolean showProgressBar;
- protected int progressBarColor;
- protected float progressBarHeight;
- protected Position progressBarPosition;
-
- protected String titleDefault;
- protected boolean updateTitleFromHtml;
- protected float titleSize;
- protected String titleFont;
- protected int titleColor;
-
- protected boolean showUrl;
- protected float urlSize;
- protected String urlFont;
- protected int urlColor;
-
- protected int menuColor;
- protected int menuDropShadowColor;
- protected float menuDropShadowSize;
- protected int menuSelector;
-
- protected float menuTextSize;
- protected String menuTextFont;
- protected int menuTextColor;
-
- protected int menuTextGravity;
- protected float menuTextPaddingLeft;
- protected float menuTextPaddingRight;
-
- protected boolean showMenuRefresh;
- protected int stringResRefresh;
- protected boolean showMenuFind;
- protected int stringResFind;
- protected boolean showMenuShareVia;
- protected int stringResShareVia;
- protected boolean showMenuCopyLink;
- protected int stringResCopyLink;
- protected boolean showMenuOpenWith;
- protected int stringResOpenWith;
- protected boolean showMenuSavePhoto;
- protected int stringResSavePhoto;
- protected boolean showToastPhotoSavedOrFailed;
- protected int stringResPhotoSavedTo;
- protected int stringResPhotoSaveFailed;
- protected boolean fileChooserEnabled;
- protected int stringResFileChooserTitle;
-
- protected List customMenus;
-
- protected int animationCloseEnter;
- protected int animationCloseExit;
-
- protected boolean backPressToClose;
- protected int stringResCopiedToClipboard;
-
- protected Boolean webViewSupportZoom;
- protected Boolean webViewMediaPlaybackRequiresUserGesture;
- protected Boolean webViewBuiltInZoomControls;
- protected Boolean webViewDisplayZoomControls;
- protected Boolean webViewAllowFileAccess;
- protected Boolean webViewAllowContentAccess;
- protected Boolean webViewLoadWithOverviewMode;
- protected Boolean webViewSaveFormData;
- protected Integer webViewTextZoom;
- protected Boolean webViewUseWideViewPort;
- protected Boolean webViewSupportMultipleWindows;
- protected WebSettings.LayoutAlgorithm webViewLayoutAlgorithm;
- protected String webViewStandardFontFamily;
- protected String webViewFixedFontFamily;
- protected String webViewSansSerifFontFamily;
- protected String webViewSerifFontFamily;
- protected String webViewCursiveFontFamily;
- protected String webViewFantasyFontFamily;
- protected Integer webViewMinimumFontSize;
- protected Integer webViewMinimumLogicalFontSize;
- protected Integer webViewDefaultFontSize;
- protected Integer webViewDefaultFixedFontSize;
- protected Boolean webViewLoadsImagesAutomatically;
- protected Boolean webViewBlockNetworkImage;
- protected Boolean webViewBlockNetworkLoads;
- protected Boolean webViewJavaScriptEnabled;
- protected Boolean webViewAllowUniversalAccessFromFileURLs;
- protected Boolean webViewAllowFileAccessFromFileURLs;
- protected String webViewGeolocationDatabasePath;
- protected Boolean webViewAppCacheEnabled;
- protected Boolean webViewDatabaseEnabled;
- protected Boolean webViewDomStorageEnabled;
- protected Boolean webViewGeolocationEnabled;
- protected Boolean webViewJavaScriptCanOpenWindowsAutomatically;
- protected String webViewDefaultTextEncodingName;
- protected String webViewUserAgentString;
- protected Boolean webViewUserAgentAppend;
- protected Boolean webViewNeedInitialFocus;
- protected Integer webViewCacheMode;
- protected Integer webViewMixedContentMode;
- protected Boolean webViewOffscreenPreRaster;
- protected Boolean webViewAppJumpEnabled;
- protected Boolean webViewCookieEnabled;
- protected Boolean webViewCameraEnabled;
- protected Boolean webViewAudioEnabled;
-
- protected String filePickerCamMessage;
- protected ValueCallback filePickerFileMessage;
- protected ValueCallback filePickerFilePath;
- protected final static int FILE_PICKER_REQ_CODE = 1;
- protected String FILE_TYPE = "*/*";
-
- protected String injectJavaScript;
- protected Boolean injectJavaScriptMainPage;
-
- protected Map> injectCookies;
-
- protected String mimeType;
- protected String encoding;
- protected String data;
- protected String url;
- protected Map extraHeaders;
- protected Boolean extraHeadersMainPage;
- protected CoordinatorLayout coordinatorLayout;
- protected AppBarLayout appBar;
- protected Toolbar toolbar;
- protected RelativeLayout toolbarLayout;
- protected TextView title;
- protected TextView urlTv;
- protected AppCompatImageButton close;
- protected AppCompatImageButton back;
- protected AppCompatImageButton forward;
- protected AppCompatImageButton more;
- protected WebView webView;
- protected WebChromeClient webChromeClient;
- protected WebViewClient webViewClient;
- protected View gradient;
- protected View divider;
- protected ProgressBar progressBar;
- protected RelativeLayout menuLayout;
- protected ShadowLayout shadowLayout;
- protected LinearLayout menuBackground;
- protected LinearLayout menuRefresh;
- protected TextView menuRefreshTv;
- protected LinearLayout menuFind;
- protected TextView menuFindTv;
- protected LinearLayout menuShareVia;
- protected TextView menuShareViaTv;
- protected LinearLayout menuCopyLink;
- protected TextView menuCopyLinkTv;
- protected LinearLayout menuOpenWith;
- protected TextView menuOpenWithTv;
- protected FrameLayout webLayout;
- DownloadListener downloadListener = new DownloadListener() {
- @Override
- public void onDownloadStart(String url, String userAgent, String contentDisposition,
- String mimetype, long contentLength) {
- BroadCastManager.onDownloadStart(AwesomeWebViewActivity.this, key, url, userAgent,
- contentDisposition, mimetype, contentLength);
- }
- };
-
- protected Handler handler = new Handler(this);
- protected final int MSG_CLICK_ON_WEBVIEW = 1;
- protected final int MSG_CLICK_ON_URL = 2;
-
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- protected void initializeOptions() {
- Intent intent = getIntent();
- if (intent == null) return;
-
- AwesomeWebView.Builder builder = (AwesomeWebView.Builder) intent.getSerializableExtra("builder");
-
- // set theme before resolving attributes depending on those
- setTheme(builder.theme != null ? builder.theme : 0);
-
- // resolve themed attributes
- TypedValue typedValue = new TypedValue();
- TypedArray typedArray = obtainStyledAttributes(typedValue.data, new int[]{
- android.R.attr.colorPrimaryDark, android.R.attr.colorPrimary, android.R.attr.colorAccent,
- android.R.attr.textColorPrimary, android.R.attr.textColorSecondary,
- android.R.attr.selectableItemBackground, android.R.attr.selectableItemBackgroundBorderless
- });
- int colorPrimaryDark = typedArray.getColor(0, ContextCompat.getColor(this, R.color.finestGray));
- int colorPrimary = typedArray.getColor(1, ContextCompat.getColor(this, R.color.finestWhite));
- int colorAccent = typedArray.getColor(2, ContextCompat.getColor(this, R.color.finestBlack));
- int textColorPrimary =
- typedArray.getColor(3, ContextCompat.getColor(this, R.color.finestBlack));
- int textColorSecondary =
- typedArray.getColor(4, ContextCompat.getColor(this, R.color.finestSilver));
- int selectableItemBackground =
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? typedArray.getResourceId(5, 0)
- : R.drawable.selector_light_theme;
- int selectableItemBackgroundBorderless =
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? typedArray.getResourceId(6, 0)
- : R.drawable.selector_light_theme;
- typedArray.recycle();
-
- key = builder.key;
-
- rtl = builder.rtl != null ? builder.rtl : getResources().getBoolean(R.bool.is_right_to_left);
-
- statusBarColor = builder.statusBarColor != null ? builder.statusBarColor : colorPrimaryDark;
- statusBarIconDark = builder.statusBarIconDark != null ? builder.statusBarIconDark : false;
-
- toolbarColor = builder.toolbarColor != null ? builder.toolbarColor : colorPrimary;
- toolbarVisible = builder.toolbarVisible != null ? builder.toolbarVisible : true;
-
- iconDefaultColor = builder.iconDefaultColor != null ? builder.iconDefaultColor : colorAccent;
- iconDisabledColor = builder.iconDisabledColor != null ? builder.iconDisabledColor
- : ColorHelper.disableColor(iconDefaultColor);
- iconPressedColor =
- builder.iconPressedColor != null ? builder.iconPressedColor : iconDefaultColor;
- iconSelector =
- builder.iconSelector != null ? builder.iconSelector : selectableItemBackgroundBorderless;
-
- showIconClose = builder.showIconClose != null ? builder.showIconClose : true;
- disableIconClose = builder.disableIconClose != null ? builder.disableIconClose : false;
- showIconBack = builder.showIconBack != null ? builder.showIconBack : true;
- disableIconBack = builder.disableIconBack != null ? builder.disableIconBack : false;
- showIconForward = builder.showIconForward != null ? builder.showIconForward : true;
- disableIconForward = builder.disableIconForward != null ? builder.disableIconForward : false;
- showIconMenu = builder.showIconMenu != null ? builder.showIconMenu : true;
- disableIconMenu = builder.disableIconMenu != null ? builder.disableIconMenu : false;
-
- showDivider = builder.showDivider != null ? builder.showDivider : true;
- gradientDivider = builder.gradientDivider != null ? builder.gradientDivider : true;
- dividerColor = builder.dividerColor != null ? builder.dividerColor
- : ContextCompat.getColor(this, R.color.finestBlack10);
- dividerHeight = builder.dividerHeight != null ? builder.dividerHeight
- : getResources().getDimension(R.dimen.defaultDividerHeight);
-
- showProgressBar = builder.showProgressBar != null ? builder.showProgressBar : true;
- progressBarColor = builder.progressBarColor != null ? builder.progressBarColor : colorAccent;
- progressBarHeight = builder.progressBarHeight != null ? builder.progressBarHeight
- : getResources().getDimension(R.dimen.defaultProgressBarHeight);
- progressBarPosition = builder.progressBarPosition != null ? builder.progressBarPosition
- : Position.BOTTOM_OF_TOOLBAR;
-
- titleDefault = builder.titleDefault;
- updateTitleFromHtml = builder.updateTitleFromHtml != null ? builder.updateTitleFromHtml : true;
- titleSize = builder.titleSize != null ? builder.titleSize
- : getResources().getDimension(R.dimen.defaultTitleSize);
- titleFont = builder.titleFont != null ? builder.titleFont : "Roboto-Medium.ttf";
- titleColor = builder.titleColor != null ? builder.titleColor : textColorPrimary;
-
- showUrl = builder.showUrl != null ? builder.showUrl : true;
- urlSize = builder.urlSize != null ? builder.urlSize
- : getResources().getDimension(R.dimen.defaultUrlSize);
- urlFont = builder.urlFont != null ? builder.urlFont : "Roboto-Regular.ttf";
- urlColor = builder.urlColor != null ? builder.urlColor : textColorSecondary;
-
- menuColor = builder.menuColor != null ? builder.menuColor
- : ContextCompat.getColor(this, R.color.finestWhite);
- menuDropShadowColor = builder.menuDropShadowColor != null ? builder.menuDropShadowColor
- : ContextCompat.getColor(this, R.color.finestBlack10);
- menuDropShadowSize = builder.menuDropShadowSize != null ? builder.menuDropShadowSize
- : getResources().getDimension(R.dimen.defaultMenuDropShadowSize);
- menuSelector = builder.menuSelector != null ? builder.menuSelector : selectableItemBackground;
-
- menuTextSize = builder.menuTextSize != null ? builder.menuTextSize
- : getResources().getDimension(R.dimen.defaultMenuTextSize);
- menuTextFont = builder.menuTextFont != null ? builder.menuTextFont : "Roboto-Regular.ttf";
- menuTextColor = builder.menuTextColor != null ? builder.menuTextColor
- : ContextCompat.getColor(this, R.color.finestBlack);
-
- menuTextGravity = builder.menuTextGravity != null ? builder.menuTextGravity
- : Gravity.CENTER_VERTICAL | Gravity.START;
- menuTextPaddingLeft = builder.menuTextPaddingLeft != null ? builder.menuTextPaddingLeft
- : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingRight)
- : getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft);
- menuTextPaddingRight = builder.menuTextPaddingRight != null ? builder.menuTextPaddingRight
- : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft)
- : getResources().getDimension(R.dimen.defaultMenuTextPaddingRight);
-
- showMenuRefresh = builder.showMenuRefresh != null ? builder.showMenuRefresh : true;
- stringResRefresh =
- builder.stringResRefresh != null ? builder.stringResRefresh : R.string.refresh;
- showMenuFind = builder.showMenuFind != null ? builder.showMenuFind : false;
- stringResFind = builder.stringResFind != null ? builder.stringResFind : R.string.find;
- showMenuShareVia = builder.showMenuShareVia != null ? builder.showMenuShareVia : true;
- stringResShareVia =
- builder.stringResShareVia != null ? builder.stringResShareVia : R.string.share_via;
- showMenuCopyLink = builder.showMenuCopyLink != null ? builder.showMenuCopyLink : true;
- stringResCopyLink =
- builder.stringResCopyLink != null ? builder.stringResCopyLink : R.string.copy_link;
- showMenuOpenWith = builder.showMenuOpenWith != null ? builder.showMenuOpenWith : true;
- stringResOpenWith =
- builder.stringResOpenWith != null ? builder.stringResOpenWith : R.string.open_with;
- showMenuSavePhoto = builder.showMenuSavePhoto != null ? builder.showMenuSavePhoto : true;
- stringResSavePhoto =
- builder.stringResSavePhoto != null ? builder.stringResSavePhoto : R.string.save_photo;
- showToastPhotoSavedOrFailed = builder.showToastPhotoSavedOrFailed != null ? builder.showToastPhotoSavedOrFailed : true;
- stringResPhotoSavedTo =
- builder.stringResPhotoSavedTo != null ? builder.stringResPhotoSavedTo : R.string.photo_saved_to;
- stringResPhotoSaveFailed =
- builder.stringResPhotoSaveFailed != null ? builder.stringResPhotoSaveFailed : R.string.photo_save_failed;
- fileChooserEnabled = builder.fileChooserEnabled != null ? builder.fileChooserEnabled : true;
- stringResFileChooserTitle =
- builder.stringResFileChooserTitle != null ? builder.stringResFileChooserTitle : R.string.file_chooser;
-
- customMenus = builder.customMenus != null? builder.customMenus: new ArrayList(0);
-
- animationCloseEnter = builder.animationCloseEnter != null ? builder.animationCloseEnter
- : R.anim.modal_activity_close_enter;
- animationCloseExit = builder.animationCloseExit != null ? builder.animationCloseExit
- : R.anim.modal_activity_close_exit;
-
- backPressToClose = builder.backPressToClose != null ? builder.backPressToClose : false;
- stringResCopiedToClipboard =
- builder.stringResCopiedToClipboard != null ? builder.stringResCopiedToClipboard
- : R.string.copied_to_clipboard;
-
- webViewSupportZoom = builder.webViewSupportZoom;
- webViewMediaPlaybackRequiresUserGesture = builder.webViewMediaPlaybackRequiresUserGesture;
- webViewBuiltInZoomControls =
- builder.webViewBuiltInZoomControls != null ? builder.webViewBuiltInZoomControls : false;
- webViewDisplayZoomControls =
- builder.webViewDisplayZoomControls != null ? builder.webViewDisplayZoomControls : false;
- webViewAllowFileAccess =
- builder.webViewAllowFileAccess != null ? builder.webViewAllowFileAccess : true;
- webViewAllowContentAccess = builder.webViewAllowContentAccess;
- webViewLoadWithOverviewMode =
- builder.webViewLoadWithOverviewMode != null ? builder.webViewLoadWithOverviewMode : true;
- webViewSaveFormData = builder.webViewSaveFormData;
- webViewTextZoom = builder.webViewTextZoom;
- webViewUseWideViewPort = builder.webViewUseWideViewPort;
- webViewSupportMultipleWindows = builder.webViewSupportMultipleWindows;
- webViewLayoutAlgorithm = builder.webViewLayoutAlgorithm;
- webViewStandardFontFamily = builder.webViewStandardFontFamily;
- webViewFixedFontFamily = builder.webViewFixedFontFamily;
- webViewSansSerifFontFamily = builder.webViewSansSerifFontFamily;
- webViewSerifFontFamily = builder.webViewSerifFontFamily;
- webViewCursiveFontFamily = builder.webViewCursiveFontFamily;
- webViewFantasyFontFamily = builder.webViewFantasyFontFamily;
- webViewMinimumFontSize = builder.webViewMinimumFontSize;
- webViewMinimumLogicalFontSize = builder.webViewMinimumLogicalFontSize;
- webViewDefaultFontSize = builder.webViewDefaultFontSize;
- webViewDefaultFixedFontSize = builder.webViewDefaultFixedFontSize;
- webViewLoadsImagesAutomatically = builder.webViewLoadsImagesAutomatically;
- webViewBlockNetworkImage = builder.webViewBlockNetworkImage;
- webViewBlockNetworkLoads = builder.webViewBlockNetworkLoads;
- webViewJavaScriptEnabled =
- builder.webViewJavaScriptEnabled != null ? builder.webViewJavaScriptEnabled : true;
- webViewAllowUniversalAccessFromFileURLs = builder.webViewAllowUniversalAccessFromFileURLs;
- webViewAllowFileAccessFromFileURLs = builder.webViewAllowFileAccessFromFileURLs;
- webViewGeolocationDatabasePath = builder.webViewGeolocationDatabasePath;
- webViewAppCacheEnabled =
- builder.webViewAppCacheEnabled != null ? builder.webViewAppCacheEnabled : true;
- webViewDatabaseEnabled = builder.webViewDatabaseEnabled;
- webViewDomStorageEnabled =
- builder.webViewDomStorageEnabled != null ? builder.webViewDomStorageEnabled : true;
- webViewGeolocationEnabled = builder.webViewGeolocationEnabled;
- webViewJavaScriptCanOpenWindowsAutomatically =
- builder.webViewJavaScriptCanOpenWindowsAutomatically;
- webViewDefaultTextEncodingName = builder.webViewDefaultTextEncodingName;
- webViewUserAgentString = builder.webViewUserAgentString;
- webViewUserAgentAppend = builder.webViewUserAgentAppend;
- webViewNeedInitialFocus = builder.webViewNeedInitialFocus;
- webViewCacheMode = builder.webViewCacheMode;
- webViewMixedContentMode = builder.webViewMixedContentMode;
- webViewOffscreenPreRaster = builder.webViewOffscreenPreRaster;
- webViewAppJumpEnabled = builder.webViewAppJumpEnabled != null ? builder.webViewAppJumpEnabled : true;
- webViewCookieEnabled = builder.webViewCookieEnabled != null ? builder.webViewCookieEnabled : true;
- webViewCameraEnabled = builder.webViewCameraEnabled != null ? builder.webViewCameraEnabled : true;
- webViewAudioEnabled = builder.webViewAudioEnabled != null ? builder.webViewAudioEnabled : true;
-
- injectJavaScript = builder.injectJavaScript;
- injectJavaScriptMainPage = builder.injectJavaScriptMainPage != null ? builder.injectJavaScriptMainPage : true;
- extraHeadersMainPage = builder.extraHeadersMainPage != null ? builder.extraHeadersMainPage : true;
- injectCookies = builder.injectCookies;
-
- mimeType = builder.mimeType;
- encoding = builder.encoding;
- data = builder.data;
- url = builder.url;
- extraHeaders = builder.extraHeaders;
- }
-
- protected void bindViews() {
- coordinatorLayout = findViewById(R.id.coordinatorLayout);
-
- appBar = findViewById(R.id.appBar);
- toolbar = findViewById(R.id.toolbar);
- toolbarLayout = findViewById(R.id.toolbarLayout);
-
- title = findViewById(R.id.title);
- urlTv = findViewById(R.id.url);
-
- close = findViewById(R.id.close);
- back = findViewById(R.id.back);
- forward = findViewById(R.id.forward);
- more = findViewById(R.id.more);
-
- close.setOnClickListener(this);
- back.setOnClickListener(this);
- forward.setOnClickListener(this);
- more.setOnClickListener(this);
-
- gradient = findViewById(R.id.gradient);
- divider = findViewById(R.id.divider);
- progressBar = findViewById(R.id.progressBar);
-
- menuLayout = findViewById(R.id.menuLayout);
- shadowLayout = findViewById(R.id.shadowLayout);
- menuBackground = findViewById(R.id.menuBackground);
-
- menuRefresh = findViewById(R.id.menuRefresh);
- menuRefreshTv = findViewById(R.id.menuRefreshTv);
- menuFind = findViewById(R.id.menuFind);
- menuFindTv = findViewById(R.id.menuFindTv);
- menuShareVia = findViewById(R.id.menuShareVia);
- menuShareViaTv = findViewById(R.id.menuShareViaTv);
- menuCopyLink = findViewById(R.id.menuCopyLink);
- menuCopyLinkTv = findViewById(R.id.menuCopyLinkTv);
- menuOpenWith = findViewById(R.id.menuOpenWith);
- menuOpenWithTv = findViewById(R.id.menuOpenWithTv);
-
- webLayout = findViewById(R.id.webLayout);
- webView = buildWebView();
- webLayout.addView(webView);
- }
-
- protected void layoutViews() {
- if (!toolbarVisible) {
- setSupportActionBar(toolbar);
- toolbar.setVisibility(View.GONE);
- }
-
- { // AppBar
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- if (!gradientDivider) toolbarHeight += dividerHeight;
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) toolbarHeight);
- appBar.setLayoutParams(params);
- coordinatorLayout.requestLayout();
- }
-
- { // Toolbar
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- LinearLayout.LayoutParams params =
- new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) toolbarHeight);
- toolbarLayout.setMinimumHeight((int) toolbarHeight);
- toolbarLayout.setLayoutParams(params);
- coordinatorLayout.requestLayout();
- }
-
- { // TextViews
- int maxWidth = getMaxWidth();
- title.setMaxWidth(maxWidth);
- urlTv.setMaxWidth(maxWidth);
- requestCenterLayout();
- }
-
- { // Icons
- updateIcon(close, rtl ? R.drawable.more : R.drawable.close);
- updateIcon(back, R.drawable.back);
- updateIcon(forward, R.drawable.forward);
- updateIcon(more, rtl ? R.drawable.close : R.drawable.more);
- }
-
- { // Divider
- if (gradientDivider) {
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- CoordinatorLayout.LayoutParams params =
- (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- gradient.setLayoutParams(params);
- }
- }
-
- { // ProgressBar
- progressBar.setMinimumHeight((int) progressBarHeight);
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) progressBarHeight);
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- switch (progressBarPosition) {
- case TOP_OF_TOOLBAR:
- params.setMargins(0, 0, 0, 0);
- break;
- case BOTTOM_OF_TOOLBAR:
- params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
- break;
- case TOP_OF_WEBVIEW:
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- break;
- case BOTTOM_OF_WEBVIEW:
- params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
- break;
- }
- progressBar.setLayoutParams(params);
- }
-
- { // WebLayout
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- int statusBarHeight = toolbarVisible? DisplayUtil.getStatusBarHeight(): 0;
- int screenHeight = DisplayUtil.getHeight();
- float webLayoutMinimumHeight = screenHeight - toolbarHeight - statusBarHeight;
- if (showDivider && !gradientDivider) webLayoutMinimumHeight -= dividerHeight;
- webLayout.setMinimumHeight((int) webLayoutMinimumHeight);
-
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.MATCH_PARENT);
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- webLayout.setLayoutParams(params);
- }
- }
-
- @SuppressLint("SetJavaScriptEnabled")
- protected void initializeViews() {
- if (! toolbarVisible) {
- setSupportActionBar(toolbar);
- toolbar.setVisibility(View.GONE);
- }
-
- { // StatusBar
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- Window window = getWindow();
- window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- window.setStatusBarColor(statusBarColor);
- }
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- Window window = getWindow();
- if (statusBarIconDark) {
- window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
- } else {
- window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
- }
- }
- }
-
- { // Toolbar
- toolbar.setBackgroundColor(toolbarColor);
- }
-
- { // TextViews
- title.setText(titleDefault);
- title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
- title.setTypeface(TypefaceHelper.get(this, titleFont));
- title.setTextColor(titleColor);
-
- urlTv.setVisibility(showUrl ? View.VISIBLE : View.GONE);
- urlTv.setText(UrlParser.getHost(url));
- urlTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize);
- urlTv.setTypeface(TypefaceHelper.get(this, urlFont));
- urlTv.setTextColor(urlColor);
-
- requestCenterLayout();
- }
-
- { // Icons
- close.setBackgroundResource(iconSelector);
- back.setBackgroundResource(iconSelector);
- forward.setBackgroundResource(iconSelector);
- more.setBackgroundResource(iconSelector);
-
- close.setVisibility(showIconClose ? View.VISIBLE : View.GONE);
- close.setEnabled(!disableIconClose);
-
- if ((showMenuRefresh
- || showMenuFind
- || showMenuShareVia
- || showMenuCopyLink
- || showMenuOpenWith
- || customMenus.size() > 0) && showIconMenu) {
- more.setVisibility(View.VISIBLE);
- } else {
- more.setVisibility(View.GONE);
- }
- more.setEnabled(!disableIconMenu);
- }
-
- { // Cookie
- if (webViewCookieEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
- }
- }
-
- { // WebView
- webChromeClient = buildWebChromeClient();
- webViewClient = buildWebViewClient();
-
- webView.setWebChromeClient(webChromeClient);
- webView.setWebViewClient(webViewClient);
- webView.setDownloadListener(downloadListener);
-
- webView.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- final WebView.HitTestResult hitTestResult = webView.getHitTestResult();
- // 如果是图片类型或者是带有图片链接的类型
- if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE ||
- hitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
- if (!showMenuSavePhoto) {
- return false;
- }
- // 弹出保存图片的对话框
- AlertDialog.Builder builder = new AlertDialog.Builder(AwesomeWebViewActivity.this);
- final String items[] = {getResources().getString(stringResSavePhoto)};
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- PermissionHelper.CheckPermissions(AwesomeWebViewActivity.this, new PermissionHelper.CheckPermissionListener() {
- @Override
- public void onAllGranted(boolean sync) {
- String url = hitTestResult.getExtra();
- // 下载图片到本地
- CookieSyncManager.createInstance(AwesomeWebViewActivity.this);
- CookieSyncManager.getInstance().sync();
- CookieManager cookieManager = CookieManager.getInstance();
- String cookie = cookieManager.getCookie(webView.getUrl());
- DownPicUtil.downPic(url, webView.getSettings().getUserAgentString(), webView.getUrl(), cookie, new DownPicUtil.DownFinishListener() {
-
- @Override
- public void onDownFinish(String path) {
- if (showToastPhotoSavedOrFailed) {
- Toast.makeText(AwesomeWebViewActivity.this, getResources().getString(stringResPhotoSavedTo) + path, Toast.LENGTH_LONG).show();
- }
- // 最后通知图库更新
- getApplicationContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));
- }
-
- @Override
- public void onError() {
- if (showToastPhotoSavedOrFailed) {
- Toast.makeText(AwesomeWebViewActivity.this, getResources().getString(stringResPhotoSaveFailed), Toast.LENGTH_LONG).show();
- }
- }
- });
- }
-
- @Override
- public void onPartlyGranted(List permissionsDenied, boolean sync) {
-
- }
- }, Manifest.permission.WRITE_EXTERNAL_STORAGE);
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- return true;
- }
- return false;
- }
- });
-
- webView.setOnTouchListener(new View.OnTouchListener() {
- private float xDown, yDown;
- private long timeDown;
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (v == webView && event.getAction() == MotionEvent.ACTION_DOWN) {
- xDown = event.getX();
- yDown = event.getY();
- timeDown = System.currentTimeMillis();
- } else if (v == webView && event.getAction() == MotionEvent.ACTION_UP){
- if (Math.abs(xDown - event.getX()) < 50 && Math.abs(yDown - event.getY()) < 50 && System.currentTimeMillis() - timeDown < 200) {
- // https://stackoverflow.com/a/5125620
- handler.sendEmptyMessageDelayed(MSG_CLICK_ON_WEBVIEW, 500);
- }
- }
- return false;
- }
- });
-
- WebSettings settings = webView.getSettings();
-
- if (webViewSupportZoom != null) settings.setSupportZoom(webViewSupportZoom);
- if (webViewMediaPlaybackRequiresUserGesture != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- settings.setMediaPlaybackRequiresUserGesture(webViewMediaPlaybackRequiresUserGesture);
- }
- if (webViewBuiltInZoomControls != null) {
- settings.setBuiltInZoomControls(webViewBuiltInZoomControls);
-
- if (webViewBuiltInZoomControls) {
- // Remove NestedScrollView to enable BuiltInZoomControls
- ((ViewGroup) webView.getParent()).removeAllViews();
- }
- }
- if (webViewDisplayZoomControls != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- settings.setDisplayZoomControls(webViewDisplayZoomControls);
- }
-
- if (webViewAllowFileAccess != null) settings.setAllowFileAccess(webViewAllowFileAccess);
- if (webViewAllowContentAccess != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- settings.setAllowContentAccess(webViewAllowContentAccess);
- }
- if (webViewLoadWithOverviewMode != null) {
- settings.setLoadWithOverviewMode(webViewLoadWithOverviewMode);
- }
- if (webViewSaveFormData != null) settings.setSaveFormData(webViewSaveFormData);
- if (webViewTextZoom != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- settings.setTextZoom(webViewTextZoom);
- }
- if (webViewUseWideViewPort != null) settings.setUseWideViewPort(webViewUseWideViewPort);
- if (webViewSupportMultipleWindows != null) {
- settings.setSupportMultipleWindows(webViewSupportMultipleWindows);
- }
- if (webViewLayoutAlgorithm != null) settings.setLayoutAlgorithm(webViewLayoutAlgorithm);
- if (webViewStandardFontFamily != null) {
- settings.setStandardFontFamily(webViewStandardFontFamily);
- }
- if (webViewFixedFontFamily != null) settings.setFixedFontFamily(webViewFixedFontFamily);
- if (webViewSansSerifFontFamily != null) {
- settings.setSansSerifFontFamily(webViewSansSerifFontFamily);
- }
- if (webViewSerifFontFamily != null) settings.setSerifFontFamily(webViewSerifFontFamily);
- if (webViewCursiveFontFamily != null)
- settings.setCursiveFontFamily(webViewCursiveFontFamily);
- if (webViewFantasyFontFamily != null)
- settings.setFantasyFontFamily(webViewFantasyFontFamily);
- if (webViewMinimumFontSize != null) settings.setMinimumFontSize(webViewMinimumFontSize);
- if (webViewMinimumLogicalFontSize != null) {
- settings.setMinimumLogicalFontSize(webViewMinimumLogicalFontSize);
- }
- if (webViewDefaultFontSize != null) settings.setDefaultFontSize(webViewDefaultFontSize);
- if (webViewDefaultFixedFontSize != null) {
- settings.setDefaultFixedFontSize(webViewDefaultFixedFontSize);
- }
- if (webViewLoadsImagesAutomatically != null) {
- settings.setLoadsImagesAutomatically(webViewLoadsImagesAutomatically);
- }
- if (webViewBlockNetworkImage != null)
- settings.setBlockNetworkImage(webViewBlockNetworkImage);
- if (webViewBlockNetworkLoads != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
- settings.setBlockNetworkLoads(webViewBlockNetworkLoads);
- }
- if (webViewJavaScriptEnabled != null)
- settings.setJavaScriptEnabled(webViewJavaScriptEnabled);
- if (webViewAllowUniversalAccessFromFileURLs != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- settings.setAllowUniversalAccessFromFileURLs(webViewAllowUniversalAccessFromFileURLs);
- }
- if (webViewAllowFileAccessFromFileURLs != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- settings.setAllowFileAccessFromFileURLs(webViewAllowFileAccessFromFileURLs);
- }
- if (webViewGeolocationDatabasePath != null) {
- settings.setGeolocationDatabasePath(webViewGeolocationDatabasePath);
- }
- if (webViewAppCacheEnabled != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
- if (webViewAppCacheEnabled) {
- settings.setCacheMode(WebSettings.LOAD_DEFAULT);
- } else {
- settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
- }
- }
- if (webViewDatabaseEnabled != null) settings.setDatabaseEnabled(webViewDatabaseEnabled);
- if (webViewDomStorageEnabled != null)
- settings.setDomStorageEnabled(webViewDomStorageEnabled);
- if (webViewGeolocationEnabled != null) {
- settings.setGeolocationEnabled(webViewGeolocationEnabled);
- }
- if (webViewJavaScriptCanOpenWindowsAutomatically != null) {
- settings.setJavaScriptCanOpenWindowsAutomatically(
- webViewJavaScriptCanOpenWindowsAutomatically);
- }
- if (webViewDefaultTextEncodingName != null) {
- settings.setDefaultTextEncodingName(webViewDefaultTextEncodingName);
- }
- if (webViewUserAgentString != null) {
- settings.setUserAgentString(webViewUserAgentAppend? settings.getUserAgentString() + " " + webViewUserAgentString: webViewUserAgentString);
- }
- if (webViewNeedInitialFocus != null)
- settings.setNeedInitialFocus(webViewNeedInitialFocus);
- if (webViewCacheMode != null) settings.setCacheMode(webViewCacheMode);
- if (webViewMixedContentMode != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- settings.setMixedContentMode(webViewMixedContentMode);
- }
- if (webViewOffscreenPreRaster != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- settings.setOffscreenPreRaster(webViewOffscreenPreRaster);
- }
-
- // // Other webview options
- // webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
- // webView.setScrollbarFadingEnabled(false);
- // //Additional Webview Properties
- // webView.setSoundEffectsEnabled(true);
- // webView.setHorizontalFadingEdgeEnabled(false);
- // webView.setKeepScreenOn(true);
- // webView.setScrollbarFadingEnabled(true);
- // webView.setVerticalFadingEdgeEnabled(false);
- }
-
- { // Divider
- gradient.setVisibility(showDivider && gradientDivider ? View.VISIBLE : View.GONE);
- divider.setVisibility(showDivider && !gradientDivider ? View.VISIBLE : View.GONE);
- if (gradientDivider) {
- int dividerWidth = DisplayUtil.getWidth();
- Bitmap bitmap =
- BitmapHelper.getGradientBitmap(dividerWidth, (int) dividerHeight, dividerColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- ViewUtil.setBackground(gradient, drawable);
-
- CoordinatorLayout.LayoutParams params =
- (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
- params.height = (int) dividerHeight;
- gradient.setLayoutParams(params);
- } else {
- divider.setBackgroundColor(dividerColor);
-
- LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) divider.getLayoutParams();
- params.height = (int) dividerHeight;
- divider.setLayoutParams(params);
- }
- }
-
- { // ProgressBar
- progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
- progressBar.getProgressDrawable().setColorFilter(progressBarColor, PorterDuff.Mode.SRC_IN);
- progressBar.setMinimumHeight((int) progressBarHeight);
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) progressBarHeight);
- float toolbarHeight = toolbarVisible? getResources().getDimension(R.dimen.toolbarHeight): 0;
- switch (progressBarPosition) {
- case TOP_OF_TOOLBAR:
- params.setMargins(0, 0, 0, 0);
- break;
- case BOTTOM_OF_TOOLBAR:
- params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
- break;
- case TOP_OF_WEBVIEW:
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- break;
- case BOTTOM_OF_WEBVIEW:
- params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
- break;
- }
- progressBar.setLayoutParams(params);
- }
-
- { // Menu
- GradientDrawable drawable = new GradientDrawable();
- drawable.setCornerRadius(getResources().getDimension(R.dimen.defaultMenuCornerRadius));
- drawable.setColor(menuColor);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- menuBackground.setBackground(drawable);
- } else {
- menuBackground.setBackgroundDrawable(drawable);
- }
-
- shadowLayout.setShadowColor(menuDropShadowColor);
- shadowLayout.setShadowSize(menuDropShadowSize);
-
- RelativeLayout.LayoutParams params =
- new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- int margin =
- (int) (getResources().getDimension(R.dimen.defaultMenuLayoutMargin) - menuDropShadowSize);
- params.setMargins(0, margin, margin, 0);
- params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- params.addRule(rtl ? RelativeLayout.ALIGN_PARENT_LEFT : RelativeLayout.ALIGN_PARENT_RIGHT);
- shadowLayout.setLayoutParams(params);
-
- menuRefresh.setVisibility(showMenuRefresh ? View.VISIBLE : View.GONE);
- menuRefresh.setBackgroundResource(menuSelector);
- menuRefresh.setGravity(menuTextGravity);
- menuRefreshTv.setText(stringResRefresh);
- menuRefreshTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuRefreshTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuRefreshTv.setTextColor(menuTextColor);
- menuRefreshTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuFind.setVisibility(showMenuFind ? View.VISIBLE : View.GONE);
- menuFind.setBackgroundResource(menuSelector);
- menuFind.setGravity(menuTextGravity);
- menuFindTv.setText(stringResFind);
- menuFindTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuFindTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuFindTv.setTextColor(menuTextColor);
- menuFindTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuShareVia.setVisibility(showMenuShareVia ? View.VISIBLE : View.GONE);
- menuShareVia.setBackgroundResource(menuSelector);
- menuShareVia.setGravity(menuTextGravity);
- menuShareViaTv.setText(stringResShareVia);
- menuShareViaTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuShareViaTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuShareViaTv.setTextColor(menuTextColor);
- menuShareViaTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuCopyLink.setVisibility(showMenuCopyLink ? View.VISIBLE : View.GONE);
- menuCopyLink.setBackgroundResource(menuSelector);
- menuCopyLink.setGravity(menuTextGravity);
- menuCopyLinkTv.setText(stringResCopyLink);
- menuCopyLinkTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuCopyLinkTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuCopyLinkTv.setTextColor(menuTextColor);
- menuCopyLinkTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuOpenWith.setVisibility(showMenuOpenWith ? View.VISIBLE : View.GONE);
- menuOpenWith.setBackgroundResource(menuSelector);
- menuOpenWith.setGravity(menuTextGravity);
- menuOpenWithTv.setText(stringResOpenWith);
- menuOpenWithTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuOpenWithTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuOpenWithTv.setTextColor(menuTextColor);
- menuOpenWithTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- for (final CustomMenu customMenu: customMenus) {
- View customMenuRoot = LayoutInflater.from(AwesomeWebViewActivity.this).inflate(R.layout.view_custom_menu, null, false);
- LinearLayout customMenuLayout = customMenuRoot.findViewById(R.id.customMenuLayout);
- TextView customMenuTv = customMenuLayout.findViewById(R.id.customMenu);
- customMenuLayout.setBackgroundResource(menuSelector);
- customMenuLayout.setGravity(menuTextGravity);
- customMenuTv.setText(customMenu.getTitleRes());
- customMenuTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- customMenuTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- customMenuTv.setTextColor(menuTextColor);
- customMenuTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- customMenuLayout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- BroadCastManager.onCustomMenuClick(AwesomeWebViewActivity.this, key, customMenu.getCode());
- hideMenu();
- }
- });
-
- menuBackground.addView(customMenuRoot, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- }
- }
- }
-
- protected WebView buildWebView() {
- return new VideoEnabledWebView(this);
- }
-
- protected WebChromeClient buildWebChromeClient() {
- // Initialize the VideoEnabledWebChromeClient and set event handlers
- View nonVideoLayout = webLayout; // Your own view, read class comments
- ViewGroup videoLayout = (ViewGroup) findViewById(R.id.videoLayout); // Your own view, read class comments
- //noinspection all
- View loadingView = getLayoutInflater().inflate(R.layout.view_loading_video, null); // Your own view, read class comments
- MyWebChromeClient webChromeClient = new MyWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView);
- webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback() {
- @Override
- public void toggledFullscreen(boolean fullscreen) {
- // Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
- if (fullscreen) {
- WindowManager.LayoutParams attrs = getWindow().getAttributes();
- attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
- attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
- getWindow().setAttributes(attrs);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- //noinspection all
- getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
- }
- } else {
- WindowManager.LayoutParams attrs = getWindow().getAttributes();
- attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
- attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
- getWindow().setAttributes(attrs);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- //noinspection all
- getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
- }
- }
-
- }
- });
- return webChromeClient;
- }
-
- protected WebViewClient buildWebViewClient() {
- return new MyWebViewClient();
- }
-
- protected void injectCookie() {
- if (injectCookies != null && injectCookies.size() > 0) {
- // https://blog.csdn.net/juhua2012/article/details/52249720
- CookieSyncManager.createInstance(this);
- CookieSyncManager.getInstance().sync();
-
- CookieManager cookieManager = CookieManager.getInstance();
- cookieManager.setAcceptCookie(true);
- for (String url: injectCookies.keySet()) {
- Map cookie = injectCookies.get(url);
- if (cookie == null || cookie.size() == 0) {
- continue;
- }
- for (String key: cookie.keySet()) {
- String value = cookie.get(key);
- String cookieStr = key + "=" + value;
- cookieManager.setCookie(url, cookieStr);
- }
- }
- CookieSyncManager.getInstance().sync();
- }
- }
-
- protected void addJavascriptInterface() {
- CommonJsHelper.getInstance().addJavascriptInterface(webView);
- }
-
- protected void load() {
- if (data != null) {
- webView.loadData(data, mimeType, encoding);
- } else if (url != null) {
- if (extraHeaders == null) {
- webView.loadUrl(url);
- } else {
- webView.loadUrl(url, extraHeaders);
- }
- }
- }
-
- protected int getMaxWidth() {
- if (forward.getVisibility() == View.VISIBLE) {
- return DisplayUtil.getWidth() - UnitConverter.dpToPx(100);
- } else {
- return DisplayUtil.getWidth() - UnitConverter.dpToPx(52);
- }
- }
-
- protected void updateIcon(ImageButton icon, @DrawableRes int drawableRes) {
- StateListDrawable states = new StateListDrawable();
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconPressedColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[]{android.R.attr.state_pressed}, drawable);
- }
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDisabledColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[]{-android.R.attr.state_enabled}, drawable);
- }
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDefaultColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[]{}, drawable);
- }
- icon.setImageDrawable(states);
-
- // int[][] states = new int[][]{
- // new int[]{-android.R.attr.state_enabled}, // disabled
- // new int[]{android.R.attr.state_pressed}, // pressed
- // new int[]{} // default
- // };
- //
- // int[] colors = new int[]{
- // iconDisabledColor,
- // iconPressedColor,
- // iconDefaultColor
- // };
- //
- // ColorStateList colorStateList = new ColorStateList(states, colors);
- //
- // Drawable drawable = ContextCompat.getDrawable(this, drawableRes);
- // if (APILevel.require(21)) {
- // VectorDrawable vectorDrawable = (VectorDrawable) drawable;
- // vectorDrawable.setTintList(colorStateList);
- // icon.setImageDrawable(vectorDrawable);
- // } else {
- // VectorDrawableCompat vectorDrawable = (VectorDrawableCompat) drawable;
- // vectorDrawable.setTintList(colorStateList);
- // icon.setImageDrawable(vectorDrawable);
- // }
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initializeOptions();
-
- setContentView(R.layout.awesome_web_view);
- bindViews();
- layoutViews();
- initializeViews();
- injectCookie();
- addJavascriptInterface();
- load();
- }
-
- @Override
- public void onBackPressed() {
- if (webChromeClient instanceof MyWebChromeClient && ((MyWebChromeClient)webChromeClient).onBackPressed()) {
- return;
- }
- if (menuLayout.getVisibility() == View.VISIBLE) {
- hideMenu();
- } else if (backPressToClose || !webView.canGoBack()) {
- exitActivity();
- } else {
- webView.goBack();
- }
- }
-
- @Override
- public void onClick(View v) {
- int viewId = v.getId();
- if (viewId == R.id.close) {
- if (rtl) {
- showMenu();
- } else {
- exitActivity();
- }
- } else if (viewId == R.id.back) {
- if (rtl) {
- webView.goForward();
- } else {
- webView.goBack();
- }
- } else if (viewId == R.id.forward) {
- if (rtl) {
- webView.goBack();
- } else {
- webView.goForward();
- }
- } else if (viewId == R.id.more) {
- if (rtl) {
- exitActivity();
- } else {
- showMenu();
- }
- } else if (viewId == R.id.menuLayout) {
- hideMenu();
- } else if (viewId == R.id.menuRefresh) {
- webView.reload();
- hideMenu();
- } else if (viewId == R.id.menuFind) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
- webView.showFindDialog("", true);
- hideMenu();
- } else if (viewId == R.id.menuShareVia) {
- Intent sendIntent = new Intent();
- sendIntent.setAction(Intent.ACTION_SEND);
- sendIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
- sendIntent.setType("text/plain");
- startActivity(Intent.createChooser(sendIntent, getResources().getString(stringResShareVia)));
-
- hideMenu();
- } else if (viewId == R.id.menuCopyLink) {
- ClipboardManagerUtil.setText(webView.getUrl());
-
- Snackbar snackbar = Snackbar.make(coordinatorLayout, getString(stringResCopiedToClipboard),
- Snackbar.LENGTH_LONG);
- View snackbarView = snackbar.getView();
- snackbarView.setBackgroundColor(toolbarColor);
- if (snackbarView instanceof ViewGroup) updateChildTextView((ViewGroup) snackbarView);
- snackbar.show();
-
- hideMenu();
- } else if (viewId == R.id.menuOpenWith) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()));
- startActivity(browserIntent);
-
- hideMenu();
- }
- }
-
- protected void updateChildTextView(ViewGroup viewGroup) {
- if (viewGroup == null || viewGroup.getChildCount() == 0) return;
-
- for (int i = 0; i < viewGroup.getChildCount(); i++) {
- View view = viewGroup.getChildAt(i);
- if (view instanceof TextView) {
- TextView textView = (TextView) view;
- textView.setTextColor(titleColor);
- textView.setTypeface(TypefaceHelper.get(this, titleFont));
- textView.setLineSpacing(0, 1.1f);
- textView.setIncludeFontPadding(false);
- }
-
- if (view instanceof ViewGroup) updateChildTextView((ViewGroup) view);
- }
- }
-
- protected void showMenu() {
- menuLayout.setVisibility(View.VISIBLE);
- Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_show);
- shadowLayout.startAnimation(popupAnim);
- }
-
- protected void hideMenu() {
- Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_hide);
- shadowLayout.startAnimation(popupAnim);
- popupAnim.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- menuLayout.setVisibility(View.GONE);
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- });
- }
-
- protected void exitActivity() {
- super.onBackPressed();
- overridePendingTransition(animationCloseEnter, animationCloseExit);
- }
-
- protected void requestCenterLayout() {
- int maxWidth;
- if (webView.canGoBack() || webView.canGoForward()) {
- maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 4;
- } else {
- maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 2;
- }
-
- title.setMaxWidth(maxWidth);
- urlTv.setMaxWidth(maxWidth);
- title.requestLayout();
- urlTv.requestLayout();
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
-
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- layoutViews();
- } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- layoutViews();
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- BroadCastManager.unregister(AwesomeWebViewActivity.this, key);
- if (webView == null) return;
- if (APILevel.require(11)) webView.onPause();
- destroyWebView();
- }
-
- // Wait for zoom control to fade away
- // https://code.google.com/p/android/issues/detail?id=15694
- // http://stackoverflow.com/a/5966151/1797648
- protected void destroyWebView() {
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- if (webView != null) webView.destroy();
- }
- }, ViewConfiguration.getZoomControlsTimeout() + 1000L);
- }
-
- @Override
- public boolean handleMessage(Message msg) {
- if (msg.what == MSG_CLICK_ON_URL){
- handler.removeMessages(MSG_CLICK_ON_WEBVIEW);
- return true;
- }
- if (msg.what == MSG_CLICK_ON_WEBVIEW){
- final WebView.HitTestResult hitTestResult = webView.getHitTestResult();
- // 如果是图片类型或者是带有图片链接的类型
- if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE ||
- hitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
- BroadCastManager.onClickImage(AwesomeWebViewActivity.this, key, hitTestResult.getExtra());
- }
- return true;
- }
- return false;
- }
-
- public class MyWebChromeClient extends VideoEnabledWebChromeClient {
-
- public MyWebChromeClient(View activityNonVideoView, ViewGroup activityVideoView, View loadingView, WebView webView) {
- super(activityNonVideoView, activityVideoView, loadingView, webView);
- }
-
- @Override
- public void onProgressChanged(WebView view, int progress) {
- BroadCastManager.onProgressChanged(AwesomeWebViewActivity.this, key, progress);
-
- if (progress == 100) progress = 0;
- progressBar.setProgress(progress);
- }
-
- @Override
- public void onReceivedTitle(WebView view, String title) {
- BroadCastManager.onReceivedTitle(AwesomeWebViewActivity.this, key, title);
- }
-
- @Override
- public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
- BroadCastManager.onReceivedTouchIconUrl(AwesomeWebViewActivity.this, key, url, precomposed);
- }
-
- @Override
- public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {
- PermissionHelper.CheckPermissions(AwesomeWebViewActivity.this, new PermissionHelper.CheckPermissionListener() {
- @Override
- public void onAllGranted(boolean sync) {
- callback.invoke(origin, true, true);
- }
-
- @Override
- public void onPartlyGranted(List permissionsDenied, boolean sync) {
- callback.invoke(origin, false, false);
- }
- }, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION);
- }
-
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- @Override
- public void onPermissionRequest(final PermissionRequest request) {
- for (String res : request.getResources()) {
- if (res.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
- if (!webViewAudioEnabled) {
- request.deny();
- return;
- }
- }
- if (res.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
- if (!webViewCameraEnabled) {
- request.deny();
- return;
- }
- }
- }
-
- PermissionHelper.CheckPermissions(AwesomeWebViewActivity.this, new PermissionHelper.CheckPermissionListener() {
- @Override
- public void onAllGranted(boolean sync) {
- request.grant(request.getResources());
- }
-
- @Override
- public void onPartlyGranted(List permissionsDenied, boolean sync) {
- request.deny();
- }
- }, parsePermission(request.getResources()));
- }
-
- //Handling input[type="file"] requests for android API 16+
- public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) {
- handler.sendEmptyMessage(MSG_CLICK_ON_URL);
-
- if (!fileChooserEnabled) {
- uploadMsg.onReceiveValue(null);
- return;
- }
- filePickerFileMessage = uploadMsg;
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- i.setType(acceptType);
- startActivityForResult(Intent.createChooser(i, getResources().getString(stringResFileChooserTitle)), FILE_PICKER_REQ_CODE);
- }
-
- //Handling input[type="file"] requests for android API 21+
- @Override
- public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, final FileChooserParams fileChooserParams) {
- handler.sendEmptyMessage(MSG_CLICK_ON_URL);
-
- if (!fileChooserEnabled) {
- filePathCallback.onReceiveValue(null);
- return true;
- }
- if (filePickerFilePath != null) {
- filePickerFilePath.onReceiveValue(null);
- }
- filePickerFilePath = filePathCallback;
-
- //Checking permission for storage and camera for writing and uploading images
- String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
- PermissionHelper.CheckPermissions(AwesomeWebViewActivity.this, new PermissionHelper.CheckPermissionListener() {
- @Override
- public void onAllGranted(boolean sync) {
- final Intent takePictureIntent = createCameraCaptureIntent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP? fileChooserParams.getAcceptTypes(): null);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && fileChooserParams.isCaptureEnabled() && fileChooserParams.getMode() == FileChooserParams.MODE_OPEN) {
- // capture="camera" and without multiple
- if (takePictureIntent != null) {
- startActivityForResult(takePictureIntent, FILE_PICKER_REQ_CODE);
- } else {
- if (filePickerFilePath != null) {
- filePickerFilePath.onReceiveValue(null);
- filePickerFilePath = null;
- }
- }
- return;
- }
- final Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
- contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
- contentSelectionIntent.setType(FILE_TYPE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- contentSelectionIntent.putExtra(Intent.EXTRA_MIME_TYPES, fileChooserParams.getAcceptTypes());
- }
- Intent[] intentArray;
- if (takePictureIntent != null) {
- intentArray = new Intent[]{takePictureIntent};
- } else {
- intentArray = new Intent[0];
- }
- Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
- chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
- chooserIntent.putExtra(Intent.EXTRA_TITLE, getResources().getString(stringResFileChooserTitle));
- chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
- startActivityForResult(chooserIntent, FILE_PICKER_REQ_CODE);
- }
-
- @Override
- public void onPartlyGranted(List permissionsDenied, boolean sync) {
- if (filePickerFilePath != null) {
- filePickerFilePath.onReceiveValue(null);
- filePickerFilePath = null;
- }
- }
- }, perms);
- return true;
- }
- }
-
- private Intent createCameraCaptureIntent(String[] mimeTypes) {
- boolean isVideo = false;
- if (mimeTypes != null && mimeTypes.length == 1 && mimeTypes[0] != null && mimeTypes[0].startsWith("video")) {
- isVideo = true;
- }
- Intent takePictureIntent = new Intent(isVideo? MediaStore.ACTION_VIDEO_CAPTURE: MediaStore.ACTION_IMAGE_CAPTURE);
- if (takePictureIntent.resolveActivity(AwesomeWebViewActivity.this.getPackageManager()) != null) {
- File imageVideoFile = null;
- try {
- imageVideoFile = createImageOrVideo(isVideo);
- } catch (IOException ex) {
-// Log.e("", "Image file creation failed", ex);
- ex.printStackTrace();
- }
- if (imageVideoFile != null) {
- filePickerCamMessage = "file:" + imageVideoFile.getAbsolutePath();
-
- Uri photoUri = FileProvider.getUriForFile(
- this,
- getPackageName() + ".awesome_web_view.file_provider",
- imageVideoFile);
-
- takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
- } else {
- takePictureIntent = null;
- }
- }
- return takePictureIntent;
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
- super.onActivityResult(requestCode, resultCode, intent);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-// getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
-// getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimary));
- Uri[] results = null;
- if (resultCode == Activity.RESULT_OK) {
- if (requestCode == FILE_PICKER_REQ_CODE) {
- if (null == filePickerFilePath) {
- return;
- }
- if (intent == null || intent.getDataString() == null) {
- if (filePickerCamMessage != null) {
- results = new Uri[]{Uri.parse(filePickerCamMessage)};
- }
- } else {
- String dataString = intent.getDataString();
- if (dataString != null) {
- results = new Uri[]{Uri.parse(dataString)};
- }
- }
- }
- }
- filePickerFilePath.onReceiveValue(results);
- filePickerFilePath = null;
- } else {
- if (requestCode == FILE_PICKER_REQ_CODE) {
- if (null == filePickerFileMessage) return;
- Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
- filePickerFileMessage.onReceiveValue(result);
- filePickerFileMessage = null;
- }
- }
- }
-
- //Creating image or video file for upload
- protected File createImageOrVideo(boolean isVideo) throws IOException {
- @SuppressLint("SimpleDateFormat")
- String file_name = new SimpleDateFormat("yyyy_mm_ss").format(new Date());
- String new_name = "file_" + file_name + "_";
- File sd_directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
- return File.createTempFile(new_name, isVideo? ".mp4": ".jpg", sd_directory);
- }
-
- public class MyWebViewClient extends WebViewClient {
-
- @Override
- public void onPageStarted(WebView view, String url, Bitmap favicon) {
- BroadCastManager.onPageStarted(AwesomeWebViewActivity.this, key, url);
- if (!url.contains("docs.google.com") && url.endsWith(".pdf")) {
- webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
- }
- }
-
- @Override
- public void onPageFinished(WebView view, String url) {
- BroadCastManager.onPageFinished(AwesomeWebViewActivity.this, key, url);
-
- if (updateTitleFromHtml) title.setText(view.getTitle());
- urlTv.setText(UrlParser.getHost(url));
- requestCenterLayout();
-
- if (view.canGoBack() || view.canGoForward()) {
- back.setVisibility(showIconBack ? View.VISIBLE : View.GONE);
- forward.setVisibility(showIconForward ? View.VISIBLE : View.GONE);
- back.setEnabled(!disableIconBack && (rtl ? view.canGoForward() : view.canGoBack()));
- forward.setEnabled(!disableIconForward && (rtl ? view.canGoBack() : view.canGoForward()));
- } else {
- back.setVisibility(View.GONE);
- forward.setVisibility(View.GONE);
- }
-
- if (injectJavaScript != null) {
- if (injectJavaScriptMainPage && !url.equals(AwesomeWebViewActivity.this.url)) {
- return;
- }
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- webView.evaluateJavascript(injectJavaScript, null);
- } else {
- webView.loadUrl(injectJavaScript);
- }
- }
- }
-
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- handler.sendEmptyMessage(MSG_CLICK_ON_URL);
-
- if (url.endsWith(".mp4")) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(url), "video/*");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- view.getContext().startActivity(intent);
- // If we return true, onPageStarted, onPageFinished won't be called.
- return true;
- } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url
- .startsWith("mms:") || url.startsWith("mmsto:")) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- view.getContext().startActivity(intent);
- return true; // If we return true, onPageStarted, onPageFinished won't be called.
- }
- /*******************************************************
- * Added in support for mailto:
- *******************************************************/
- else if (url.startsWith("mailto:")) {
-
- MailTo mt = MailTo.parse(url);
-
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
-
- emailIntent.setType("text/html");
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
- emailIntent.putExtra(Intent.EXTRA_CC, mt.getCc());
- emailIntent.putExtra(Intent.EXTRA_TEXT, mt.getBody());
-
- startActivity(emailIntent);
-
- return true;
- } else if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {
- if (extraHeaders == null || extraHeadersMainPage && !url.equals(AwesomeWebViewActivity.this.url)) {
- return super.shouldOverrideUrlLoading(view, url);
- } else {
- view.loadUrl(url, extraHeaders);
- return true;
- }
- } else {
- if (webViewAppJumpEnabled) {
- try {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- view.getContext().startActivity(intent);
- return true; // If we return true, onPageStarted, onPageFinished won't be called.
- } catch (Exception exception) {
- exception.printStackTrace();
- return true;
- }
- } else {
- return super.shouldOverrideUrlLoading(view, url);
- }
- }
- }
-
- @Override
- public void onLoadResource(WebView view, String url) {
- BroadCastManager.onLoadResource(AwesomeWebViewActivity.this, key, url);
- }
-
- @Override
- public void onPageCommitVisible(WebView view, String url) {
- BroadCastManager.onPageCommitVisible(AwesomeWebViewActivity.this, key, url);
- }
- }
-
- protected String[] parsePermission(String[] resource) {
- List permissions = new ArrayList<>();
- for (String res : resource) {
- if (res.equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
- permissions.add(Manifest.permission.RECORD_AUDIO);
- }
- if (res.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
- permissions.add(Manifest.permission.CAMERA);
- }
- }
-
- String[] result = new String[permissions.size()];
- for (int i = 0; i < permissions.size(); i++) {
- result[i] = permissions.get(i);
- }
- return result;
- }
-}
diff --git a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt
new file mode 100644
index 0000000..52ac630
--- /dev/null
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebView.kt
@@ -0,0 +1,1020 @@
+package kr.lunaticbum.awesomewebview
+
+import android.app.Activity
+import android.content.Context
+import android.content.Intent
+import android.webkit.WebSettings.LayoutAlgorithm
+import androidx.annotation.AnimRes
+import androidx.annotation.ColorInt
+import androidx.annotation.ColorRes
+import androidx.annotation.DimenRes
+import androidx.annotation.DrawableRes
+import androidx.annotation.StringRes
+import androidx.annotation.StyleRes
+import kr.lunaticbum.Base.initialize
+import kr.lunaticbum.awesomewebview.enums.Position
+import kr.lunaticbum.awesomewebview.listeners.BroadCastManager
+import kr.lunaticbum.awesomewebview.listeners.WebViewListener
+import kr.lunaticbum.awesomewebview.objects.CustomMenu
+import kr.lunaticbum.utils.content.ContextUtil
+import kr.lunaticbum.utils.content.ResourcesUtil.getColor
+import kr.lunaticbum.utils.content.ResourcesUtil.getDimension
+import kr.lunaticbum.utils.content.ResourcesUtil.getString
+import java.io.Serializable
+
+/**
+ * Created by Leonardo on 11/21/15.
+ */
+class AwesomeWebView {
+ class Builder : Serializable {
+ @Transient
+ val context: Context
+
+ @Transient
+ var listeners: MutableList = ArrayList()
+
+ var key: Int? = null
+
+ var rtl: Boolean? = null
+ var theme: Int? = null
+
+ var statusBarColor: Int? = null
+ var statusBarIconDark: Boolean? = null
+
+ var toolbarColor: Int? = null
+ var toolbarVisible: Boolean? = null
+
+ var iconDefaultColor: Int? = null
+ var iconDisabledColor: Int? = null
+ var iconPressedColor: Int? = null
+ var iconSelector: Int? = null
+
+ var showIconClose: Boolean? = null
+ var disableIconClose: Boolean? = null
+ var showIconBack: Boolean? = null
+ var disableIconBack: Boolean? = null
+ var showIconForward: Boolean? = null
+ var disableIconForward: Boolean? = null
+ var showIconMenu: Boolean? = null
+ var disableIconMenu: Boolean? = null
+
+ var showDivider: Boolean? = null
+ var gradientDivider: Boolean? = null
+ var dividerColor: Int? = null
+ var dividerHeight: Float? = null
+
+ var showProgressBar: Boolean? = null
+ var progressBarColor: Int? = null
+ var progressBarHeight: Float? = null
+ var progressBarPosition: Position? = null
+
+ var titleDefault: String? = null
+ var updateTitleFromHtml: Boolean? = null
+ var titleSize: Float? = null
+ var titleFont: String? = null
+ var titleColor: Int? = null
+
+ var showUrl: Boolean? = null
+ var urlSize: Float? = null
+ var urlFont: String? = null
+ var urlColor: Int? = null
+
+ var menuColor: Int? = null
+ var menuDropShadowColor: Int? = null
+ var menuDropShadowSize: Float? = null
+ var menuSelector: Int? = null
+
+ var menuTextSize: Float? = null
+ var menuTextFont: String? = null
+ var menuTextColor: Int? = null
+
+ var menuTextGravity: Int? = null
+ var menuTextPaddingLeft: Float? = null
+ var menuTextPaddingRight: Float? = null
+
+ var showMenuRefresh: Boolean? = null
+ var stringResRefresh: Int? = null
+ var showMenuFind: Boolean? = null
+ var stringResFind: Int? = null
+ var showMenuShareVia: Boolean? = null
+ var stringResShareVia: Int? = null
+ var showMenuCopyLink: Boolean? = null
+ var stringResCopyLink: Int? = null
+ var showMenuOpenWith: Boolean? = null
+ var stringResOpenWith: Int? = null
+ var showMenuSavePhoto: Boolean? = null
+ var stringResSavePhoto: Int? = null
+ var showToastPhotoSavedOrFailed: Boolean? = null
+ var stringResPhotoSavedTo: Int? = null
+ var stringResPhotoSaveFailed: Int? = null
+ var fileChooserEnabled: Boolean? = null
+ var stringResFileChooserTitle: Int? = null
+
+ var customMenus: MutableList? = ArrayList()
+
+ var animationOpenEnter: Int = R.anim.modal_activity_open_enter
+ var animationOpenExit: Int = R.anim.modal_activity_open_exit
+ var animationCloseEnter: Int? = null
+ var animationCloseExit: Int? = null
+
+ var backPressToClose: Boolean? = null
+ var stringResCopiedToClipboard: Int? = null
+
+ var webViewSupportZoom: Boolean? = null
+ var webViewMediaPlaybackRequiresUserGesture: Boolean? = null
+ var webViewBuiltInZoomControls: Boolean? = null
+ var webViewDisplayZoomControls: Boolean? = null
+ var webViewAllowFileAccess: Boolean? = null
+ var webViewAllowContentAccess: Boolean? = null
+ var webViewLoadWithOverviewMode: Boolean? = null
+ var webViewSaveFormData: Boolean? = null
+ var webViewTextZoom: Int? = null
+ var webViewUseWideViewPort: Boolean? = null
+ var webViewSupportMultipleWindows: Boolean? = null
+ var webViewLayoutAlgorithm: LayoutAlgorithm? = null
+ var webViewStandardFontFamily: String? = null
+ var webViewFixedFontFamily: String? = null
+ var webViewSansSerifFontFamily: String? = null
+ var webViewSerifFontFamily: String? = null
+ var webViewCursiveFontFamily: String? = null
+ var webViewFantasyFontFamily: String? = null
+ var webViewMinimumFontSize: Int? = null
+ var webViewMinimumLogicalFontSize: Int? = null
+ var webViewDefaultFontSize: Int? = null
+ var webViewDefaultFixedFontSize: Int? = null
+ var webViewLoadsImagesAutomatically: Boolean? = null
+ var webViewBlockNetworkImage: Boolean? = null
+ var webViewBlockNetworkLoads: Boolean? = null
+ var webViewJavaScriptEnabled: Boolean? = null
+ var webViewAllowUniversalAccessFromFileURLs: Boolean? = null
+ var webViewAllowFileAccessFromFileURLs: Boolean? = null
+ var webViewGeolocationDatabasePath: String? = null
+ var webViewAppCacheEnabled: Boolean? = null
+ var webViewDatabaseEnabled: Boolean? = null
+ var webViewDomStorageEnabled: Boolean? = null
+ var webViewGeolocationEnabled: Boolean? = null
+ var webViewJavaScriptCanOpenWindowsAutomatically: Boolean? = null
+ var webViewDefaultTextEncodingName: String? = null
+ var webViewUserAgentString: String? = null
+ var webViewUserAgentAppend: Boolean? = null
+ var webViewNeedInitialFocus: Boolean? = null
+ var webViewCacheMode: Int? = null
+ var webViewMixedContentMode: Int? = null
+ var webViewOffscreenPreRaster: Boolean? = null
+ var webViewAppJumpEnabled: Boolean? = null
+ var webViewCookieEnabled: Boolean? = null
+ var webViewCameraEnabled: Boolean? = null
+ var webViewAudioEnabled: Boolean? = null
+
+ var injectJavaScript: String? = null
+ var injectJavaScriptMainPage: Boolean? = null
+
+ var injectCookies: Map>? = null
+
+ var mimeType: String? = null
+ var encoding: String? = null
+ var data: String? = null
+ var url: String? = null
+ var extraHeaders: Map? = null
+ var extraHeadersMainPage: Boolean? = null
+
+ constructor(activity: Activity) {
+ this.context = activity
+ initialize(activity)
+ }
+
+ /**
+ * If you use context instead of activity, AwesomeWebView won't be able to override activity
+ * animation.
+ * Try to create builder with Activity if it's possible.
+ */
+ constructor(context: Context) {
+ this.context = context
+ initialize(context)
+ }
+
+ fun setWebViewListener(listener: WebViewListener): Builder {
+ listeners.clear()
+ listeners.add(listener)
+ return this
+ }
+
+ fun addWebViewListener(listener: WebViewListener): Builder {
+ listeners.add(listener)
+ return this
+ }
+
+ fun removeWebViewListener(listener: WebViewListener): Builder {
+ listeners.remove(listener)
+ return this
+ }
+
+ fun rtl(rtl: Boolean): Builder {
+ this.rtl = rtl
+ return this
+ }
+
+ fun theme(@StyleRes theme: Int): Builder {
+ this.theme = theme
+ return this
+ }
+
+ fun statusBarColor(@ColorInt color: Int): Builder {
+ this.statusBarColor = color
+ return this
+ }
+
+ fun statusBarColorRes(@ColorRes colorRes: Int): Builder {
+ this.statusBarColor = getColor(colorRes)
+ return this
+ }
+
+ fun statusBarIconDark(statusBarIconDark: Boolean): Builder {
+ this.statusBarIconDark = statusBarIconDark
+ return this
+ }
+
+ fun toolbarColor(@ColorInt color: Int): Builder {
+ this.toolbarColor = color
+ return this
+ }
+
+ fun toolbarVisible(toolbarVisible: Boolean): Builder {
+ this.toolbarVisible = toolbarVisible
+ return this
+ }
+
+ fun toolbarColorRes(@ColorRes colorRes: Int): Builder {
+ this.toolbarColor = getColor(colorRes)
+ return this
+ }
+
+ fun iconDefaultColor(@ColorInt color: Int): Builder {
+ this.iconDefaultColor = color
+ return this
+ }
+
+ fun iconDefaultColorRes(@ColorRes color: Int): Builder {
+ this.iconDefaultColor = getColor(color)
+ return this
+ }
+
+ fun iconDisabledColor(@ColorInt color: Int): Builder {
+ this.iconDisabledColor = color
+ return this
+ }
+
+ fun iconDisabledColorRes(@ColorRes colorRes: Int): Builder {
+ this.iconDisabledColor = getColor(colorRes)
+ return this
+ }
+
+ fun iconPressedColor(@ColorInt color: Int): Builder {
+ this.iconPressedColor = color
+ return this
+ }
+
+ fun iconPressedColorRes(@ColorRes colorRes: Int): Builder {
+ this.iconPressedColor = getColor(colorRes)
+ return this
+ }
+
+ fun iconSelector(@DrawableRes selectorRes: Int): Builder {
+ this.iconSelector = selectorRes
+ return this
+ }
+
+ fun showIconClose(showIconClose: Boolean): Builder {
+ this.showIconClose = showIconClose
+ return this
+ }
+
+ fun disableIconClose(disableIconClose: Boolean): Builder {
+ this.disableIconClose = disableIconClose
+ return this
+ }
+
+ fun showIconBack(showIconBack: Boolean): Builder {
+ this.showIconBack = showIconBack
+ return this
+ }
+
+ fun disableIconBack(disableIconBack: Boolean): Builder {
+ this.disableIconBack = disableIconBack
+ return this
+ }
+
+ fun showIconForward(showIconForward: Boolean): Builder {
+ this.showIconForward = showIconForward
+ return this
+ }
+
+ fun disableIconForward(disableIconForward: Boolean): Builder {
+ this.disableIconForward = disableIconForward
+ return this
+ }
+
+ fun showIconMenu(showIconMenu: Boolean): Builder {
+ this.showIconMenu = showIconMenu
+ return this
+ }
+
+ fun disableIconMenu(disableIconMenu: Boolean): Builder {
+ this.disableIconMenu = disableIconMenu
+ return this
+ }
+
+ fun showDivider(showDivider: Boolean): Builder {
+ this.showDivider = showDivider
+ return this
+ }
+
+ fun gradientDivider(gradientDivider: Boolean): Builder {
+ this.gradientDivider = gradientDivider
+ return this
+ }
+
+ fun dividerColor(@ColorInt color: Int): Builder {
+ this.dividerColor = color
+ return this
+ }
+
+ fun dividerColorRes(@ColorRes colorRes: Int): Builder {
+ this.dividerColor = getColor(colorRes)
+ return this
+ }
+
+ fun dividerHeight(height: Float): Builder {
+ this.dividerHeight = height
+ return this
+ }
+
+ fun dividerHeight(height: Int): Builder {
+ this.dividerHeight = height.toFloat()
+ return this
+ }
+
+ fun dividerHeightRes(@DimenRes height: Int): Builder {
+ this.dividerHeight = getDimension(height)
+ return this
+ }
+
+ fun showProgressBar(showProgressBar: Boolean): Builder {
+ this.showProgressBar = showProgressBar
+ return this
+ }
+
+ fun progressBarColor(@ColorInt color: Int): Builder {
+ this.progressBarColor = color
+ return this
+ }
+
+ fun progressBarColorRes(@ColorRes colorRes: Int): Builder {
+ this.progressBarColor = getColor(colorRes)
+ return this
+ }
+
+ fun progressBarHeight(height: Float): Builder {
+ this.progressBarHeight = height
+ return this
+ }
+
+ fun progressBarHeight(height: Int): Builder {
+ this.progressBarHeight = height.toFloat()
+ return this
+ }
+
+ fun progressBarHeightRes(@DimenRes height: Int): Builder {
+ this.progressBarHeight = getDimension(height)
+ return this
+ }
+
+ fun progressBarPosition(position: Position): Builder {
+ this.progressBarPosition = position
+ return this
+ }
+
+ fun titleDefault(title: String): Builder {
+ this.titleDefault = title
+ return this
+ }
+
+ fun titleDefaultRes(@StringRes stringRes: Int): Builder {
+ this.titleDefault = getString(stringRes)
+ return this
+ }
+
+ fun updateTitleFromHtml(updateTitleFromHtml: Boolean): Builder {
+ this.updateTitleFromHtml = updateTitleFromHtml
+ return this
+ }
+
+ fun titleSize(titleSize: Float): Builder {
+ this.titleSize = titleSize
+ return this
+ }
+
+ fun titleSize(titleSize: Int): Builder {
+ this.titleSize = titleSize.toFloat()
+ return this
+ }
+
+ fun titleSizeRes(@DimenRes titleSize: Int): Builder {
+ this.titleSize = getDimension(titleSize)
+ return this
+ }
+
+ fun titleFont(titleFont: String?): Builder {
+ this.titleFont = titleFont
+ return this
+ }
+
+ fun titleColor(@ColorInt color: Int): Builder {
+ this.titleColor = color
+ return this
+ }
+
+ fun titleColorRes(@ColorRes colorRes: Int): Builder {
+ this.titleColor = getColor(colorRes)
+ return this
+ }
+
+ fun showUrl(showUrl: Boolean): Builder {
+ this.showUrl = showUrl
+ return this
+ }
+
+ fun urlSize(urlSize: Float): Builder {
+ this.urlSize = urlSize
+ return this
+ }
+
+ fun urlSize(urlSize: Int): Builder {
+ this.urlSize = urlSize.toFloat()
+ return this
+ }
+
+ fun urlSizeRes(@DimenRes urlSize: Int): Builder {
+ this.urlSize = getDimension(urlSize)
+ return this
+ }
+
+ fun urlFont(urlFont: String?): Builder {
+ this.urlFont = urlFont
+ return this
+ }
+
+ fun urlColor(@ColorInt color: Int): Builder {
+ this.urlColor = color
+ return this
+ }
+
+ fun urlColorRes(@ColorRes colorRes: Int): Builder {
+ this.urlColor = getColor(colorRes)
+ return this
+ }
+
+ fun menuColor(@ColorInt color: Int): Builder {
+ this.menuColor = color
+ return this
+ }
+
+ fun menuColorRes(@ColorRes colorRes: Int): Builder {
+ this.menuColor = getColor(colorRes)
+ return this
+ }
+
+ fun menuTextGravity(gravity: Int): Builder {
+ this.menuTextGravity = gravity
+ return this
+ }
+
+ fun menuTextPaddingLeft(menuTextPaddingLeft: Float): Builder {
+ this.menuTextPaddingLeft = menuTextPaddingLeft
+ return this
+ }
+
+ fun menuTextPaddingLeft(menuTextPaddingLeft: Int): Builder {
+ this.menuTextPaddingLeft = menuTextPaddingLeft.toFloat()
+ return this
+ }
+
+ fun menuTextPaddingLeftRes(@DimenRes menuTextPaddingLeft: Int): Builder {
+ this.menuTextPaddingLeft = getDimension(menuTextPaddingLeft)
+ return this
+ }
+
+ fun menuTextPaddingRight(menuTextPaddingRight: Float): Builder {
+ this.menuTextPaddingRight = menuTextPaddingRight
+ return this
+ }
+
+ fun menuTextPaddingRight(menuTextPaddingRight: Int): Builder {
+ this.menuTextPaddingRight = menuTextPaddingRight.toFloat()
+ return this
+ }
+
+ fun menuTextPaddingRightRes(@DimenRes menuTextPaddingRight: Int): Builder {
+ this.menuTextPaddingRight = getDimension(menuTextPaddingRight)
+ return this
+ }
+
+ fun menuDropShadowColor(@ColorInt color: Int): Builder {
+ this.menuDropShadowColor = color
+ return this
+ }
+
+ fun menuDropShadowColorRes(@ColorRes colorRes: Int): Builder {
+ this.menuDropShadowColor = getColor(colorRes)
+ return this
+ }
+
+ fun menuDropShadowSize(menuDropShadowSize: Float): Builder {
+ this.menuDropShadowSize = menuDropShadowSize
+ return this
+ }
+
+ fun menuDropShadowSize(menuDropShadowSize: Int): Builder {
+ this.menuDropShadowSize = menuDropShadowSize.toFloat()
+ return this
+ }
+
+ fun menuDropShadowSizeRes(@DimenRes menuDropShadowSize: Int): Builder {
+ this.menuDropShadowSize = getDimension(menuDropShadowSize)
+ return this
+ }
+
+ fun menuSelector(@DrawableRes selectorRes: Int): Builder {
+ this.menuSelector = selectorRes
+ return this
+ }
+
+ fun menuTextSize(menuTextSize: Float): Builder {
+ this.menuTextSize = menuTextSize
+ return this
+ }
+
+ fun menuTextSize(menuTextSize: Int): Builder {
+ this.menuTextSize = menuTextSize.toFloat()
+ return this
+ }
+
+ fun menuTextSizeRes(@DimenRes menuTextSize: Int): Builder {
+ this.menuTextSize = getDimension(menuTextSize)
+ return this
+ }
+
+ fun menuTextFont(menuTextFont: String?): Builder {
+ this.menuTextFont = menuTextFont
+ return this
+ }
+
+ fun menuTextColor(@ColorInt color: Int): Builder {
+ this.menuTextColor = color
+ return this
+ }
+
+ fun menuTextColorRes(@ColorRes colorRes: Int): Builder {
+ this.menuTextColor = getColor(colorRes)
+ return this
+ }
+
+ fun showMenuRefresh(showMenuRefresh: Boolean): Builder {
+ this.showMenuRefresh = showMenuRefresh
+ return this
+ }
+
+ fun stringResRefresh(@StringRes stringResRefresh: Int): Builder {
+ this.stringResRefresh = stringResRefresh
+ return this
+ }
+
+ fun showMenuFind(showMenuFind: Boolean): Builder {
+ this.showMenuFind = showMenuFind
+ return this
+ }
+
+ fun stringResFind(@StringRes stringResFind: Int): Builder {
+ this.stringResFind = stringResFind
+ return this
+ }
+
+ fun showMenuShareVia(showMenuShareVia: Boolean): Builder {
+ this.showMenuShareVia = showMenuShareVia
+ return this
+ }
+
+ fun stringResShareVia(@StringRes stringResShareVia: Int): Builder {
+ this.stringResShareVia = stringResShareVia
+ return this
+ }
+
+ fun showMenuCopyLink(showMenuCopyLink: Boolean): Builder {
+ this.showMenuCopyLink = showMenuCopyLink
+ return this
+ }
+
+ fun stringResCopyLink(@StringRes stringResCopyLink: Int): Builder {
+ this.stringResCopyLink = stringResCopyLink
+ return this
+ }
+
+ fun showMenuOpenWith(showMenuOpenWith: Boolean): Builder {
+ this.showMenuOpenWith = showMenuOpenWith
+ return this
+ }
+
+ fun stringResOpenWith(@StringRes stringResOpenWith: Int): Builder {
+ this.stringResOpenWith = stringResOpenWith
+ return this
+ }
+
+ fun showMenuSavePhoto(showMenuSavePhoto: Boolean): Builder {
+ this.showMenuSavePhoto = showMenuSavePhoto
+ return this
+ }
+
+ fun stringResSavePhoto(@StringRes stringResSavePhoto: Int): Builder {
+ this.stringResSavePhoto = stringResSavePhoto
+ return this
+ }
+
+ fun showToastPhotoSavedOrFailed(showToastPhotoSavedOrFailed: Boolean): Builder {
+ this.showToastPhotoSavedOrFailed = showToastPhotoSavedOrFailed
+ return this
+ }
+
+ fun stringResPhotoSavedTo(@StringRes stringResPhotoSavedTo: Int): Builder {
+ this.stringResPhotoSavedTo = stringResPhotoSavedTo
+ return this
+ }
+
+ fun stringResPhotoSaveFailed(@StringRes stringResPhotoSaveFailed: Int): Builder {
+ this.stringResPhotoSaveFailed = stringResPhotoSaveFailed
+ return this
+ }
+
+ fun fileChooserEnabled(fileChooserEnabled: Boolean): Builder {
+ this.fileChooserEnabled = fileChooserEnabled
+ return this
+ }
+
+ fun stringResFileChooserTitle(@StringRes stringResFileChooserTitle: Int): Builder {
+ this.stringResFileChooserTitle = stringResFileChooserTitle
+ return this
+ }
+
+ fun customMenus(customMenus: MutableList): Builder {
+ this.customMenus = customMenus
+ return this
+ }
+
+ fun addCustomMenu(customMenu: CustomMenu): Builder {
+ if (customMenus == null) {
+ customMenus = ArrayList(1)
+ }
+ customMenus!!.add(customMenu)
+ return this
+ }
+
+ fun setCustomAnimations(
+ @AnimRes animationOpenEnter: Int,
+ @AnimRes animationOpenExit: Int, @AnimRes animationCloseEnter: Int,
+ @AnimRes animationCloseExit: Int
+ ): Builder {
+ this.animationOpenEnter = animationOpenEnter
+ this.animationOpenExit = animationOpenExit
+ this.animationCloseEnter = animationCloseEnter
+ this.animationCloseExit = animationCloseExit
+ return this
+ }
+
+
+ @Deprecated("As of release 1.0.1, replaced by {@link #setCustomAnimations(int, int, int, int)}")
+ fun setCloseAnimations(
+ @AnimRes animationCloseEnter: Int,
+ @AnimRes animationCloseExit: Int
+ ): Builder {
+ this.animationCloseEnter = animationCloseEnter
+ this.animationCloseExit = animationCloseExit
+ return this
+ }
+
+ fun backPressToClose(backPressToClose: Boolean): Builder {
+ this.backPressToClose = backPressToClose
+ return this
+ }
+
+ fun stringResCopiedToClipboard(@StringRes stringResCopiedToClipboard: Int): Builder {
+ this.stringResCopiedToClipboard = stringResCopiedToClipboard
+ return this
+ }
+
+ fun webViewSupportZoom(webViewSupportZoom: Boolean): Builder {
+ this.webViewSupportZoom = webViewSupportZoom
+ return this
+ }
+
+ fun webViewMediaPlaybackRequiresUserGesture(
+ webViewMediaPlaybackRequiresUserGesture: Boolean
+ ): Builder {
+ this.webViewMediaPlaybackRequiresUserGesture = webViewMediaPlaybackRequiresUserGesture
+ return this
+ }
+
+ fun webViewBuiltInZoomControls(webViewBuiltInZoomControls: Boolean): Builder {
+ this.webViewBuiltInZoomControls = webViewBuiltInZoomControls
+ return this
+ }
+
+ fun webViewDisplayZoomControls(webViewDisplayZoomControls: Boolean): Builder {
+ this.webViewDisplayZoomControls = webViewDisplayZoomControls
+ return this
+ }
+
+ fun webViewAllowFileAccess(webViewAllowFileAccess: Boolean): Builder {
+ this.webViewAllowFileAccess = webViewAllowFileAccess
+ return this
+ }
+
+ fun webViewAllowContentAccess(webViewAllowContentAccess: Boolean): Builder {
+ this.webViewAllowContentAccess = webViewAllowContentAccess
+ return this
+ }
+
+ fun webViewLoadWithOverviewMode(webViewLoadWithOverviewMode: Boolean): Builder {
+ this.webViewLoadWithOverviewMode = webViewLoadWithOverviewMode
+ return this
+ }
+
+ fun webViewSaveFormData(webViewSaveFormData: Boolean): Builder {
+ this.webViewSaveFormData = webViewSaveFormData
+ return this
+ }
+
+ fun webViewTextZoom(webViewTextZoom: Int): Builder {
+ this.webViewTextZoom = webViewTextZoom
+ return this
+ }
+
+ fun webViewUseWideViewPort(webViewUseWideViewPort: Boolean): Builder {
+ this.webViewUseWideViewPort = webViewUseWideViewPort
+ return this
+ }
+
+ fun webViewSupportMultipleWindows(webViewSupportMultipleWindows: Boolean): Builder {
+ this.webViewSupportMultipleWindows = webViewSupportMultipleWindows
+ return this
+ }
+
+ fun webViewLayoutAlgorithm(webViewLayoutAlgorithm: LayoutAlgorithm?): Builder {
+ this.webViewLayoutAlgorithm = webViewLayoutAlgorithm
+ return this
+ }
+
+ fun webViewStandardFontFamily(webViewStandardFontFamily: String?): Builder {
+ this.webViewStandardFontFamily = webViewStandardFontFamily
+ return this
+ }
+
+ fun webViewFixedFontFamily(webViewFixedFontFamily: String?): Builder {
+ this.webViewFixedFontFamily = webViewFixedFontFamily
+ return this
+ }
+
+ fun webViewSansSerifFontFamily(webViewSansSerifFontFamily: String?): Builder {
+ this.webViewSansSerifFontFamily = webViewSansSerifFontFamily
+ return this
+ }
+
+ fun webViewSerifFontFamily(webViewSerifFontFamily: String?): Builder {
+ this.webViewSerifFontFamily = webViewSerifFontFamily
+ return this
+ }
+
+ fun webViewCursiveFontFamily(webViewCursiveFontFamily: String?): Builder {
+ this.webViewCursiveFontFamily = webViewCursiveFontFamily
+ return this
+ }
+
+ fun webViewFantasyFontFamily(webViewFantasyFontFamily: String?): Builder {
+ this.webViewFantasyFontFamily = webViewFantasyFontFamily
+ return this
+ }
+
+ fun webViewMinimumFontSize(webViewMinimumFontSize: Int): Builder {
+ this.webViewMinimumFontSize = webViewMinimumFontSize
+ return this
+ }
+
+ fun webViewMinimumLogicalFontSize(webViewMinimumLogicalFontSize: Int): Builder {
+ this.webViewMinimumLogicalFontSize = webViewMinimumLogicalFontSize
+ return this
+ }
+
+ fun webViewDefaultFontSize(webViewDefaultFontSize: Int): Builder {
+ this.webViewDefaultFontSize = webViewDefaultFontSize
+ return this
+ }
+
+ fun webViewDefaultFixedFontSize(webViewDefaultFixedFontSize: Int): Builder {
+ this.webViewDefaultFixedFontSize = webViewDefaultFixedFontSize
+ return this
+ }
+
+ fun webViewLoadsImagesAutomatically(webViewLoadsImagesAutomatically: Boolean): Builder {
+ this.webViewLoadsImagesAutomatically = webViewLoadsImagesAutomatically
+ return this
+ }
+
+ fun webViewBlockNetworkImage(webViewBlockNetworkImage: Boolean): Builder {
+ this.webViewBlockNetworkImage = webViewBlockNetworkImage
+ return this
+ }
+
+ fun webViewBlockNetworkLoads(webViewBlockNetworkLoads: Boolean): Builder {
+ this.webViewBlockNetworkLoads = webViewBlockNetworkLoads
+ return this
+ }
+
+ fun webViewJavaScriptEnabled(webViewJavaScriptEnabled: Boolean): Builder {
+ this.webViewJavaScriptEnabled = webViewJavaScriptEnabled
+ return this
+ }
+
+ fun webViewAllowUniversalAccessFromFileURLs(
+ webViewAllowUniversalAccessFromFileURLs: Boolean
+ ): Builder {
+ this.webViewAllowUniversalAccessFromFileURLs = webViewAllowUniversalAccessFromFileURLs
+ return this
+ }
+
+ fun webViewAllowFileAccessFromFileURLs(webViewAllowFileAccessFromFileURLs: Boolean): Builder {
+ this.webViewAllowFileAccessFromFileURLs = webViewAllowFileAccessFromFileURLs
+ return this
+ }
+
+ fun webViewGeolocationDatabasePath(webViewGeolocationDatabasePath: String?): Builder {
+ this.webViewGeolocationDatabasePath = webViewGeolocationDatabasePath
+ return this
+ }
+
+ fun webViewAppCacheEnabled(webViewAppCacheEnabled: Boolean): Builder {
+ this.webViewAppCacheEnabled = webViewAppCacheEnabled
+ return this
+ }
+
+ fun webViewDatabaseEnabled(webViewDatabaseEnabled: Boolean): Builder {
+ this.webViewDatabaseEnabled = webViewDatabaseEnabled
+ return this
+ }
+
+ fun webViewDomStorageEnabled(webViewDomStorageEnabled: Boolean): Builder {
+ this.webViewDomStorageEnabled = webViewDomStorageEnabled
+ return this
+ }
+
+ fun webViewGeolocationEnabled(webViewGeolocationEnabled: Boolean): Builder {
+ this.webViewGeolocationEnabled = webViewGeolocationEnabled
+ return this
+ }
+
+ fun webViewJavaScriptCanOpenWindowsAutomatically(
+ webViewJavaScriptCanOpenWindowsAutomatically: Boolean
+ ): Builder {
+ this.webViewJavaScriptCanOpenWindowsAutomatically =
+ webViewJavaScriptCanOpenWindowsAutomatically
+ return this
+ }
+
+ fun webViewDefaultTextEncodingName(webViewDefaultTextEncodingName: String?): Builder {
+ this.webViewDefaultTextEncodingName = webViewDefaultTextEncodingName
+ return this
+ }
+
+ fun webViewUserAgentString(webViewUserAgentString: String?): Builder {
+ this.webViewUserAgentString = webViewUserAgentString
+ return this
+ }
+
+ fun webViewUserAgentAppend(webViewUserAgentAppend: Boolean): Builder {
+ this.webViewUserAgentAppend = webViewUserAgentAppend
+ return this
+ }
+
+ fun webViewNeedInitialFocus(webViewNeedInitialFocus: Boolean): Builder {
+ this.webViewNeedInitialFocus = webViewNeedInitialFocus
+ return this
+ }
+
+ fun webViewCacheMode(webViewCacheMode: Int): Builder {
+ this.webViewCacheMode = webViewCacheMode
+ return this
+ }
+
+ fun webViewMixedContentMode(webViewMixedContentMode: Int): Builder {
+ this.webViewMixedContentMode = webViewMixedContentMode
+ return this
+ }
+
+ fun webViewOffscreenPreRaster(webViewOffscreenPreRaster: Boolean): Builder {
+ this.webViewOffscreenPreRaster = webViewOffscreenPreRaster
+ return this
+ }
+
+ fun webViewAppJumpEnabled(webViewAppJumpEnabled: Boolean): Builder {
+ this.webViewAppJumpEnabled = webViewAppJumpEnabled
+ return this
+ }
+
+ fun webViewCookieEnabled(webViewCookieEnabled: Boolean): Builder {
+ this.webViewCookieEnabled = webViewCookieEnabled
+ return this
+ }
+
+ fun webViewCameraEnabled(webViewCameraEnabled: Boolean): Builder {
+ this.webViewCameraEnabled = webViewCameraEnabled
+ return this
+ }
+
+ fun webViewAudioEnabled(webViewAudioEnabled: Boolean): Builder {
+ this.webViewAudioEnabled = webViewAudioEnabled
+ return this
+ }
+
+ fun setHeader(extraHeaders: Map?): Builder {
+ this.extraHeaders = extraHeaders
+ return this
+ }
+
+ fun headersMainPage(extraHeadersMainPage: Boolean): Builder {
+ this.extraHeadersMainPage = extraHeadersMainPage
+ return this
+ }
+
+
+// @Deprecated(
+// """As of release 1.1.1, replaced by {@link #webViewUserAgentString(String)"}
+// Use setUserAgentString("Mozilla /
+// 5.0(X11 ; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101\n" + " Firefox/4.0") instead")
+ fun webViewDesktopMode(webViewDesktopMode: Boolean): Builder {
+ return webViewUserAgentString(
+ "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0"
+ )
+ }
+
+ fun injectJavaScript(injectJavaScript: String?): Builder {
+ this.injectJavaScript = injectJavaScript
+ return this
+ }
+
+ fun injectJavaScriptMainPage(injectJavaScriptMainPage: Boolean): Builder {
+ this.injectJavaScriptMainPage = injectJavaScriptMainPage
+ return this
+ }
+
+ fun injectCookies(injectCookies: Map>?): Builder {
+ this.injectCookies = injectCookies
+ return this
+ }
+
+ fun load(@StringRes dataRes: Int) {
+ load(getString(dataRes))
+ }
+
+ @JvmOverloads
+ fun load(data: String?, mimeType: String? = "text/html", encoding: String? = "UTF-8") {
+ this.mimeType = mimeType
+ this.encoding = encoding
+ show(null, data)
+ }
+
+ fun show(@StringRes urlRes: Int) {
+ show(getString(urlRes))
+ }
+
+ fun show(url: String) {
+ show(url, null)
+ }
+
+ fun show(url: String?, data: String?) {
+ this.url = url
+ this.data = data
+ this.key = System.identityHashCode(this)
+
+ if (!listeners.isEmpty()) BroadCastManager(context, key!!, listeners)
+
+ val intent = Intent(
+ context,
+ AwesomeWebViewActivity::class.java
+ )
+ intent.putExtra("builder", this)
+
+ ContextUtil.startActivity(intent)
+
+ if (context is Activity) {
+ context.overridePendingTransition(animationOpenEnter, animationOpenExit)
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt
new file mode 100644
index 0000000..af3c112
--- /dev/null
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/AwesomeWebViewActivity.kt
@@ -0,0 +1,1948 @@
+package kr.lunaticbum.awesomewebview
+
+import android.Manifest
+import android.annotation.SuppressLint
+import android.content.Intent
+import android.content.res.Configuration
+import android.graphics.Bitmap
+import android.graphics.PorterDuff
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.GradientDrawable
+import android.graphics.drawable.StateListDrawable
+import android.net.MailTo
+import android.net.Uri
+import android.os.Build
+import android.os.Bundle
+import android.os.Environment
+import android.os.Handler
+import android.os.Message
+import android.provider.MediaStore
+import android.util.TypedValue
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.view.MotionEvent
+import android.view.View
+import android.view.View.OnLongClickListener
+import android.view.View.OnTouchListener
+import android.view.ViewConfiguration
+import android.view.ViewGroup
+import android.view.WindowManager
+import android.view.animation.Animation
+import android.view.animation.AnimationUtils
+import android.webkit.CookieManager
+import android.webkit.CookieSyncManager
+import android.webkit.DownloadListener
+import android.webkit.GeolocationPermissions
+import android.webkit.PermissionRequest
+import android.webkit.ValueCallback
+import android.webkit.WebChromeClient
+import android.webkit.WebResourceRequest
+import android.webkit.WebResourceResponse
+import android.webkit.WebSettings
+import android.webkit.WebSettings.LayoutAlgorithm
+import android.webkit.WebView
+import android.webkit.WebView.HitTestResult
+import android.webkit.WebViewClient
+import android.widget.FrameLayout
+import android.widget.ImageButton
+import android.widget.LinearLayout
+import android.widget.ProgressBar
+import android.widget.RelativeLayout
+import android.widget.TextView
+import android.widget.Toast
+import androidx.annotation.DrawableRes
+import androidx.annotation.RequiresApi
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.AppCompatImageButton
+import androidx.appcompat.widget.Toolbar
+import androidx.coordinatorlayout.widget.CoordinatorLayout
+import androidx.core.content.ContextCompat
+import androidx.core.content.FileProvider
+import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.snackbar.Snackbar
+import kr.lunaticbum.awesomewebview.databinding.AwesomeWebViewBinding
+import kr.lunaticbum.awesomewebview.enums.Position
+import kr.lunaticbum.awesomewebview.helpers.BitmapHelper
+import kr.lunaticbum.awesomewebview.helpers.ColorHelper
+import kr.lunaticbum.awesomewebview.helpers.DownPicUtil
+import kr.lunaticbum.awesomewebview.helpers.DownPicUtil.DownFinishListener
+import kr.lunaticbum.awesomewebview.helpers.PermissionHelper
+import kr.lunaticbum.awesomewebview.helpers.PermissionHelper.CheckPermissionListener
+import kr.lunaticbum.awesomewebview.helpers.TypefaceHelper
+import kr.lunaticbum.awesomewebview.helpers.UrlParser
+import kr.lunaticbum.awesomewebview.jsInterface.CommonJsHelper
+import kr.lunaticbum.awesomewebview.listeners.BroadCastManager
+import kr.lunaticbum.awesomewebview.objects.CustomMenu
+import kr.lunaticbum.awesomewebview.views.ShadowLayout
+import kr.lunaticbum.awesomewebview.views.VideoEnabledWebChromeClient
+import kr.lunaticbum.awesomewebview.views.VideoEnabledWebView
+import kr.lunaticbum.converters.UnitConverter
+import kr.lunaticbum.utils.etc.APILevel
+import kr.lunaticbum.utils.log.LogUtil
+import kr.lunaticbum.utils.service.ClipboardManagerUtil
+import kr.lunaticbum.utils.ui.DisplayUtil
+import kr.lunaticbum.utils.ui.ViewUtil
+import java.io.File
+import java.io.IOException
+import java.text.SimpleDateFormat
+import java.util.Date
+import kotlin.math.abs
+
+
+class AwesomeWebViewActivity : AppCompatActivity(), View.OnClickListener,
+ Handler.Callback {
+ protected var key: Int = 0
+
+ protected var rtl: Boolean = false
+ var mTheme: Int = 0
+
+ protected var statusBarColor: Int = 0
+ protected var statusBarIconDark: Boolean = false
+
+ protected var toolbarColor: Int = 0
+ protected var toolbarVisible: Boolean = false
+
+ protected var iconDefaultColor: Int = 0
+ protected var iconDisabledColor: Int = 0
+ protected var iconPressedColor: Int = 0
+ protected var iconSelector: Int = 0
+
+ protected var showIconClose: Boolean = false
+ protected var disableIconClose: Boolean = false
+ protected var showIconBack: Boolean = false
+ protected var disableIconBack: Boolean = false
+ protected var showIconForward: Boolean = false
+ protected var disableIconForward: Boolean = false
+ protected var showIconMenu: Boolean = false
+ protected var disableIconMenu: Boolean = false
+
+ protected var showDivider: Boolean = false
+ protected var gradientDivider: Boolean = false
+ protected var dividerColor: Int = 0
+ protected var dividerHeight: Float = 0f
+
+ protected var showProgressBar: Boolean = false
+ protected var progressBarColor: Int = 0
+ protected var progressBarHeight: Float = 0f
+ protected var progressBarPosition: Position? = null
+
+ protected var titleDefault: String? = null
+ protected var updateTitleFromHtml: Boolean = false
+ protected var titleSize: Float = 0f
+ protected var titleFont: String? = null
+ var mTitleColor: Int = 0
+
+ protected var showUrl: Boolean = false
+ protected var urlSize: Float = 0f
+ protected var urlFont: String? = null
+ protected var urlColor: Int = 0
+
+ protected var menuColor: Int = 0
+ protected var menuDropShadowColor: Int = 0
+ protected var menuDropShadowSize: Float = 0f
+ protected var menuSelector: Int = 0
+
+ protected var menuTextSize: Float = 0f
+ protected var menuTextFont: String? = null
+ protected var menuTextColor: Int = 0
+
+ protected var menuTextGravity: Int = 0
+ protected var menuTextPaddingLeft: Float = 0f
+ protected var menuTextPaddingRight: Float = 0f
+
+ protected var showMenuRefresh: Boolean = false
+ protected var stringResRefresh: Int = 0
+ protected var showMenuFind: Boolean = false
+ protected var stringResFind: Int = 0
+ protected var showMenuShareVia: Boolean = false
+ protected var stringResShareVia: Int = 0
+ protected var showMenuCopyLink: Boolean = false
+ protected var stringResCopyLink: Int = 0
+ protected var showMenuOpenWith: Boolean = false
+ protected var stringResOpenWith: Int = 0
+ protected var showMenuSavePhoto: Boolean = false
+ protected var stringResSavePhoto: Int = 0
+ protected var showToastPhotoSavedOrFailed: Boolean = false
+ protected var stringResPhotoSavedTo: Int = 0
+ protected var stringResPhotoSaveFailed: Int = 0
+ protected var fileChooserEnabled: Boolean = false
+ protected var stringResFileChooserTitle: Int = 0
+
+ protected var customMenus: List? = null
+
+ protected var animationCloseEnter: Int = 0
+ protected var animationCloseExit: Int = 0
+
+ protected var backPressToClose: Boolean = false
+ protected var stringResCopiedToClipboard: Int = 0
+
+ protected var webViewSupportZoom: Boolean? = null
+ protected var webViewMediaPlaybackRequiresUserGesture: Boolean? = null
+ protected var webViewBuiltInZoomControls: Boolean? = null
+ protected var webViewDisplayZoomControls: Boolean? = null
+ protected var webViewAllowFileAccess: Boolean? = null
+ protected var webViewAllowContentAccess: Boolean? = null
+ protected var webViewLoadWithOverviewMode: Boolean? = null
+ protected var webViewSaveFormData: Boolean? = null
+ protected var webViewTextZoom: Int? = null
+ protected var webViewUseWideViewPort: Boolean? = null
+ protected var webViewSupportMultipleWindows: Boolean? = null
+ protected var webViewLayoutAlgorithm: LayoutAlgorithm? = null
+ protected var webViewStandardFontFamily: String? = null
+ protected var webViewFixedFontFamily: String? = null
+ protected var webViewSansSerifFontFamily: String? = null
+ protected var webViewSerifFontFamily: String? = null
+ protected var webViewCursiveFontFamily: String? = null
+ protected var webViewFantasyFontFamily: String? = null
+ protected var webViewMinimumFontSize: Int? = null
+ protected var webViewMinimumLogicalFontSize: Int? = null
+ protected var webViewDefaultFontSize: Int? = null
+ protected var webViewDefaultFixedFontSize: Int? = null
+ protected var webViewLoadsImagesAutomatically: Boolean? = null
+ protected var webViewBlockNetworkImage: Boolean? = null
+ protected var webViewBlockNetworkLoads: Boolean? = null
+ protected var webViewJavaScriptEnabled: Boolean? = null
+ protected var webViewAllowUniversalAccessFromFileURLs: Boolean? = null
+ protected var webViewAllowFileAccessFromFileURLs: Boolean? = null
+ protected var webViewGeolocationDatabasePath: String? = null
+ protected var webViewAppCacheEnabled: Boolean? = null
+ protected var webViewDatabaseEnabled: Boolean? = null
+ protected var webViewDomStorageEnabled: Boolean? = null
+ protected var webViewGeolocationEnabled: Boolean? = null
+ protected var webViewJavaScriptCanOpenWindowsAutomatically: Boolean? = null
+ protected var webViewDefaultTextEncodingName: String? = null
+ protected var webViewUserAgentString: String? = null
+ protected var webViewUserAgentAppend: Boolean? = null
+ protected var webViewNeedInitialFocus: Boolean? = null
+ protected var webViewCacheMode: Int? = null
+ protected var webViewMixedContentMode: Int? = null
+ protected var webViewOffscreenPreRaster: Boolean? = null
+ protected var webViewAppJumpEnabled: Boolean? = null
+ protected var webViewCookieEnabled: Boolean? = null
+ protected var webViewCameraEnabled: Boolean? = null
+ protected var webViewAudioEnabled: Boolean? = null
+
+ protected var filePickerCamMessage: String? = null
+ protected var filePickerFileMessage: ValueCallback? = null
+ protected var filePickerFilePath: ValueCallback>? = null
+ protected var FILE_TYPE: String = "*/*"
+
+ protected var injectJavaScript: String? = null
+ protected var injectJavaScriptMainPage: Boolean? = null
+
+ protected var injectCookies: Map>? = null
+
+ protected var mimeType: String? = null
+ protected var encoding: String? = null
+ protected var data: String? = null
+ protected var url: String? = null
+ protected var extraHeaders: Map? = null
+ protected var extraHeadersMainPage: Boolean? = null
+ protected var appBar: AppBarLayout? = null
+ protected var toolbar: Toolbar? = null
+ protected var toolbarLayout: RelativeLayout? = null
+ protected var title: TextView? = null
+ protected var urlTv: TextView? = null
+ protected var close: AppCompatImageButton? = null
+ protected var back: AppCompatImageButton? = null
+ protected var forward: AppCompatImageButton? = null
+ protected var more: AppCompatImageButton? = null
+ protected var webView: WebView? = null
+ protected var webChromeClient: WebChromeClient? = null
+ protected var webViewClient: WebViewClient? = null
+ protected var gradient: View? = null
+ protected var divider: View? = null
+ protected var progressBar: ProgressBar? = null
+ protected var menuLayout: RelativeLayout? = null
+ protected var shadowLayout: ShadowLayout? = null
+ protected var menuBackground: LinearLayout? = null
+ protected var menuRefresh: LinearLayout? = null
+ protected var menuRefreshTv: TextView? = null
+ protected var menuFind: LinearLayout? = null
+ protected var menuFindTv: TextView? = null
+ protected var menuShareVia: LinearLayout? = null
+ protected var menuShareViaTv: TextView? = null
+ protected var menuCopyLink: LinearLayout? = null
+ protected var menuCopyLinkTv: TextView? = null
+ protected var menuOpenWith: LinearLayout? = null
+ protected var menuOpenWithTv: TextView? = null
+ protected var webLayout: FrameLayout? = null
+ var downloadListener: DownloadListener =
+ DownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
+ BroadCastManager.onDownloadStart(
+ this@AwesomeWebViewActivity, key, url, userAgent,
+ contentDisposition, mimetype, contentLength
+ )
+ }
+
+ protected var handler: Handler = Handler(this)
+ protected val MSG_CLICK_ON_WEBVIEW: Int = 1
+ protected val MSG_CLICK_ON_URL: Int = 2
+
+ @SuppressLint("ResourceType")
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ protected fun initializeOptions() {
+ val intent = intent ?: return
+
+ val builder = intent.getSerializableExtra("builder") as AwesomeWebView.Builder?
+
+ // set theme before resolving attributes depending on those
+ setTheme(builder?.theme ?: 0)
+
+ // resolve themed attributes
+ val typedValue = TypedValue()
+ val typedArray = obtainStyledAttributes(
+ typedValue.data, intArrayOf(
+ android.R.attr.colorPrimaryDark,
+ android.R.attr.colorPrimary,
+ android.R.attr.colorAccent,
+ android.R.attr.textColorPrimary,
+ android.R.attr.textColorSecondary,
+ android.R.attr.selectableItemBackground,
+ android.R.attr.selectableItemBackgroundBorderless
+ )
+ )
+ val colorPrimaryDark = typedArray.getColor(
+ 0, ContextCompat.getColor(
+ this, R.color.finestGray
+ )
+ )
+ val colorPrimary = typedArray.getColor(1, ContextCompat.getColor(this, R.color.finestWhite))
+ val colorAccent = typedArray.getColor(2, ContextCompat.getColor(this, R.color.finestBlack))
+ val textColorPrimary =
+ typedArray.getColor(3, ContextCompat.getColor(this, R.color.finestBlack))
+ val textColorSecondary =
+ typedArray.getColor(4, ContextCompat.getColor(this, R.color.finestSilver))
+ val selectableItemBackground =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) typedArray.getResourceId(
+ 5,
+ 0
+ )
+ else R.drawable.selector_light_theme
+ val selectableItemBackgroundBorderless =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) typedArray.getResourceId(
+ 6,
+ 0
+ )
+ else R.drawable.selector_light_theme
+ typedArray.recycle()
+
+ key = builder?.key ?: 0
+
+ rtl =
+ if (builder?.rtl != null) builder!!.rtl!! else resources.getBoolean(R.bool.is_right_to_left)
+
+ statusBarColor =
+ if (builder?.statusBarColor != null) builder!!.statusBarColor!! else colorPrimaryDark
+ statusBarIconDark =
+ if (builder?.statusBarIconDark != null) builder!!.statusBarIconDark!! else false
+
+ toolbarColor = if (builder?.toolbarColor != null) builder?.toolbarColor!! else colorPrimary
+ toolbarVisible = if (builder?.toolbarVisible != null) builder?.toolbarVisible!! else true
+
+ iconDefaultColor =
+ if (builder?.iconDefaultColor != null) builder?.iconDefaultColor!! else colorAccent
+ iconDisabledColor = if (builder?.iconDisabledColor != null) builder?.iconDisabledColor!!
+ else ColorHelper.disableColor(iconDefaultColor)
+ iconPressedColor =
+ if (builder?.iconPressedColor != null) builder?.iconPressedColor!! else iconDefaultColor
+ iconSelector =
+ if (builder?.iconSelector != null) builder?.iconSelector!! else selectableItemBackgroundBorderless
+
+ showIconClose = if (builder?.showIconClose != null) builder?.showIconClose!! else true
+ disableIconClose = if (builder?.disableIconClose != null) builder?.disableIconClose!! else false
+ showIconBack = if (builder?.showIconBack != null) builder?.showIconBack!! else true
+ disableIconBack = if (builder?.disableIconBack != null) builder?.disableIconBack!! else false
+ showIconForward = if (builder?.showIconForward != null) builder?.showIconForward!! else true
+ disableIconForward =
+ if (builder?.disableIconForward != null) builder?.disableIconForward!! else false
+ showIconMenu = if (builder?.showIconMenu != null) builder?.showIconMenu!! else true
+ disableIconMenu = if (builder?.disableIconMenu != null) builder?.disableIconMenu!! else false
+
+ showDivider = if (builder?.showDivider != null) builder?.showDivider!! else true
+ gradientDivider = if (builder?.gradientDivider != null) builder?.gradientDivider!! else true
+ dividerColor = if (builder?.dividerColor != null) builder?.dividerColor!!
+ else ContextCompat.getColor(this, R.color.finestBlack10)
+ dividerHeight = if (builder?.dividerHeight != null) builder?.dividerHeight!!
+ else resources.getDimension(R.dimen.defaultDividerHeight)
+
+ showProgressBar = if (builder?.showProgressBar != null) builder?.showProgressBar!! else true
+ progressBarColor =
+ if (builder?.progressBarColor != null) builder?.progressBarColor!! else colorAccent
+ progressBarHeight = if (builder?.progressBarHeight != null) builder?.progressBarHeight!!
+ else resources.getDimension(R.dimen.defaultProgressBarHeight)
+ progressBarPosition = if (builder?.progressBarPosition != null) builder?.progressBarPosition
+ else Position.BOTTOM_OF_TOOLBAR
+
+ titleDefault = builder?.titleDefault
+ updateTitleFromHtml =
+ if (builder?.updateTitleFromHtml != null) builder?.updateTitleFromHtml!! else true
+ titleSize = if (builder?.titleSize != null) builder?.titleSize!!
+ else resources.getDimension(R.dimen.defaultTitleSize)
+ titleFont = if (builder?.titleFont != null) builder?.titleFont!! else "Roboto-Medium.ttf"
+ mTitleColor = if (builder?.titleColor != null) builder?.titleColor!! else textColorPrimary
+
+ showUrl = if (builder?.showUrl != null) builder?.showUrl!! else true
+ urlSize = if (builder?.urlSize != null) builder?.urlSize!!
+ else resources.getDimension(R.dimen.defaultUrlSize)
+ urlFont = if (builder?.urlFont != null) builder?.urlFont!! else "Roboto-Regular.ttf"
+ urlColor = if (builder?.urlColor != null) builder?.urlColor!! else textColorSecondary
+
+ menuColor = if (builder?.menuColor != null) builder?.menuColor!!
+ else ContextCompat.getColor(this, R.color.finestWhite)
+ menuDropShadowColor = if (builder?.menuDropShadowColor != null) builder?.menuDropShadowColor!!
+ else ContextCompat.getColor(this, R.color.finestBlack10)
+ menuDropShadowSize = if (builder?.menuDropShadowSize != null) builder?.menuDropShadowSize!!
+ else resources.getDimension(R.dimen.defaultMenuDropShadowSize)
+ menuSelector =
+ if (builder?.menuSelector != null) builder?.menuSelector!! else selectableItemBackground
+
+ menuTextSize = if (builder?.menuTextSize != null) builder?.menuTextSize!!
+ else resources.getDimension(R.dimen.defaultMenuTextSize)
+ menuTextFont =
+ if (builder?.menuTextFont != null) builder?.menuTextFont else "Roboto-Regular.ttf"
+ menuTextColor = if (builder?.menuTextColor != null) builder?.menuTextColor!!
+ else ContextCompat.getColor(this, R.color.finestBlack)
+
+ menuTextGravity = if (builder?.menuTextGravity != null) builder?.menuTextGravity!!
+ else Gravity.CENTER_VERTICAL or Gravity.START
+ menuTextPaddingLeft = if (builder?.menuTextPaddingLeft != null) builder?.menuTextPaddingLeft!!
+ else if (rtl) resources.getDimension(R.dimen.defaultMenuTextPaddingRight)
+ else resources.getDimension(R.dimen.defaultMenuTextPaddingLeft)
+ menuTextPaddingRight =
+ if (builder?.menuTextPaddingRight != null) builder?.menuTextPaddingRight!!
+ else if (rtl) resources.getDimension(R.dimen.defaultMenuTextPaddingLeft)
+ else resources.getDimension(R.dimen.defaultMenuTextPaddingRight)
+
+ showMenuRefresh = if (builder?.showMenuRefresh != null) builder?.showMenuRefresh!! else true
+ stringResRefresh =
+ if (builder?.stringResRefresh != null) builder?.stringResRefresh!! else R.string.refresh
+ showMenuFind = if (builder?.showMenuFind != null) builder?.showMenuFind!! else false
+ stringResFind = if (builder?.stringResFind != null) builder?.stringResFind!! else R.string.find
+ showMenuShareVia = if (builder?.showMenuShareVia != null) builder?.showMenuShareVia!! else true
+ stringResShareVia =
+ if (builder?.stringResShareVia != null) builder?.stringResShareVia!! else R.string.share_via
+ showMenuCopyLink = if (builder?.showMenuCopyLink != null) builder?.showMenuCopyLink!! else true
+ stringResCopyLink =
+ if (builder?.stringResCopyLink != null) builder?.stringResCopyLink!! else R.string.copy_link
+ showMenuOpenWith = if (builder?.showMenuOpenWith != null) builder?.showMenuOpenWith!! else true
+ stringResOpenWith =
+ if (builder?.stringResOpenWith != null) builder?.stringResOpenWith!! else R.string.open_with
+ showMenuSavePhoto =
+ if (builder?.showMenuSavePhoto != null) builder?.showMenuSavePhoto!! else true
+ stringResSavePhoto =
+ if (builder?.stringResSavePhoto != null) builder?.stringResSavePhoto!! else R.string.save_photo
+ showToastPhotoSavedOrFailed =
+ if (builder?.showToastPhotoSavedOrFailed != null) builder?.showToastPhotoSavedOrFailed!! else true
+ stringResPhotoSavedTo =
+ if (builder?.stringResPhotoSavedTo != null) builder?.stringResPhotoSavedTo!! else R.string.photo_saved_to
+ stringResPhotoSaveFailed =
+ if (builder?.stringResPhotoSaveFailed != null) builder?.stringResPhotoSaveFailed!! else R.string.photo_save_failed
+ fileChooserEnabled =
+ if (builder?.fileChooserEnabled != null) builder?.fileChooserEnabled!! else true
+ stringResFileChooserTitle =
+ if (builder?.stringResFileChooserTitle != null) builder?.stringResFileChooserTitle!! else R.string.file_chooser
+
+ customMenus = if (builder?.customMenus != null) builder?.customMenus!! else ArrayList(0)
+
+ animationCloseEnter = if (builder?.animationCloseEnter != null) builder?.animationCloseEnter!!
+ else R.anim.modal_activity_close_enter
+ animationCloseExit = if (builder?.animationCloseExit != null) builder?.animationCloseExit!!
+ else R.anim.modal_activity_close_exit
+
+ backPressToClose = if (builder?.backPressToClose != null) builder?.backPressToClose!! else false
+ stringResCopiedToClipboard =
+ if (builder?.stringResCopiedToClipboard != null) builder?.stringResCopiedToClipboard!!
+ else R.string.copied_to_clipboard
+
+ webViewSupportZoom = builder?.webViewSupportZoom
+ webViewMediaPlaybackRequiresUserGesture = builder?.webViewMediaPlaybackRequiresUserGesture
+ webViewBuiltInZoomControls =
+ if (builder?.webViewBuiltInZoomControls != null) builder?.webViewBuiltInZoomControls else false
+ webViewDisplayZoomControls =
+ if (builder?.webViewDisplayZoomControls != null) builder?.webViewDisplayZoomControls else false
+ webViewAllowFileAccess =
+ if (builder?.webViewAllowFileAccess != null) builder?.webViewAllowFileAccess else true
+ webViewAllowContentAccess = builder?.webViewAllowContentAccess
+ webViewLoadWithOverviewMode =
+ if (builder?.webViewLoadWithOverviewMode != null) builder?.webViewLoadWithOverviewMode else true
+ webViewSaveFormData = builder?.webViewSaveFormData
+ webViewTextZoom = builder?.webViewTextZoom
+ webViewUseWideViewPort = builder?.webViewUseWideViewPort
+ webViewSupportMultipleWindows = builder?.webViewSupportMultipleWindows
+ webViewLayoutAlgorithm = builder?.webViewLayoutAlgorithm
+ webViewStandardFontFamily = builder?.webViewStandardFontFamily
+ webViewFixedFontFamily = builder?.webViewFixedFontFamily
+ webViewSansSerifFontFamily = builder?.webViewSansSerifFontFamily
+ webViewSerifFontFamily = builder?.webViewSerifFontFamily
+ webViewCursiveFontFamily = builder?.webViewCursiveFontFamily
+ webViewFantasyFontFamily = builder?.webViewFantasyFontFamily
+ webViewMinimumFontSize = builder?.webViewMinimumFontSize
+ webViewMinimumLogicalFontSize = builder?.webViewMinimumLogicalFontSize
+ webViewDefaultFontSize = builder?.webViewDefaultFontSize
+ webViewDefaultFixedFontSize = builder?.webViewDefaultFixedFontSize
+ webViewLoadsImagesAutomatically = builder?.webViewLoadsImagesAutomatically
+ webViewBlockNetworkImage = builder?.webViewBlockNetworkImage
+ webViewBlockNetworkLoads = builder?.webViewBlockNetworkLoads
+ webViewJavaScriptEnabled =
+ if (builder?.webViewJavaScriptEnabled != null) builder?.webViewJavaScriptEnabled else true
+ webViewAllowUniversalAccessFromFileURLs = builder?.webViewAllowUniversalAccessFromFileURLs
+ webViewAllowFileAccessFromFileURLs = builder?.webViewAllowFileAccessFromFileURLs
+ webViewGeolocationDatabasePath = builder?.webViewGeolocationDatabasePath
+ webViewAppCacheEnabled =
+ if (builder?.webViewAppCacheEnabled != null) builder?.webViewAppCacheEnabled else true
+ webViewDatabaseEnabled = builder?.webViewDatabaseEnabled
+ webViewDomStorageEnabled =
+ if (builder?.webViewDomStorageEnabled != null) builder?.webViewDomStorageEnabled else true
+ webViewGeolocationEnabled = builder?.webViewGeolocationEnabled
+ webViewJavaScriptCanOpenWindowsAutomatically =
+ builder?.webViewJavaScriptCanOpenWindowsAutomatically
+ webViewDefaultTextEncodingName = builder?.webViewDefaultTextEncodingName
+ webViewUserAgentString = builder?.webViewUserAgentString
+ webViewUserAgentAppend = builder?.webViewUserAgentAppend
+ webViewNeedInitialFocus = builder?.webViewNeedInitialFocus
+ webViewCacheMode = builder?.webViewCacheMode
+ webViewMixedContentMode = builder?.webViewMixedContentMode
+ webViewOffscreenPreRaster = builder?.webViewOffscreenPreRaster
+ webViewAppJumpEnabled =
+ if (builder?.webViewAppJumpEnabled != null) builder?.webViewAppJumpEnabled else true
+ webViewCookieEnabled =
+ if (builder?.webViewCookieEnabled != null) builder?.webViewCookieEnabled else true
+ webViewCameraEnabled =
+ if (builder?.webViewCameraEnabled != null) builder?.webViewCameraEnabled else true
+ webViewAudioEnabled =
+ if (builder?.webViewAudioEnabled != null) builder?.webViewAudioEnabled else true
+
+ injectJavaScript = builder?.injectJavaScript
+ injectJavaScriptMainPage =
+ if (builder?.injectJavaScriptMainPage != null) builder?.injectJavaScriptMainPage else true
+ extraHeadersMainPage =
+ if (builder?.extraHeadersMainPage != null) builder?.extraHeadersMainPage else true
+ injectCookies = builder?.injectCookies
+
+ mimeType = builder?.mimeType
+ encoding = builder?.encoding
+ data = builder?.data
+ url = builder?.url
+ extraHeaders = builder?.extraHeaders
+ }
+
+ protected fun bindViews() {
+ appBar = findViewById(R.id.appBar)
+ toolbar = findViewById(R.id.toolbar)
+ toolbarLayout = findViewById(R.id.toolbarLayout)
+
+ title = findViewById(R.id.title)
+ urlTv = findViewById(R.id.url)
+
+ close = findViewById(R.id.close)
+ back = findViewById(R.id.back)
+ forward = findViewById(R.id.forward)
+ more = findViewById(R.id.more)
+
+ close?.setOnClickListener(this)
+ back?.setOnClickListener(this)
+ forward?.setOnClickListener(this)
+ more?.setOnClickListener(this)
+
+ gradient = findViewById(R.id.gradient)
+ divider = findViewById(R.id.divider)
+ progressBar = findViewById(R.id.progressBar)
+
+ menuLayout = findViewById(R.id.menuLayout)
+ shadowLayout = findViewById(R.id.shadowLayout)
+ menuBackground = findViewById(R.id.menuBackground)
+
+ menuRefresh = findViewById(R.id.menuRefresh)
+ menuRefreshTv = findViewById(R.id.menuRefreshTv)
+ menuFind = findViewById(R.id.menuFind)
+ menuFindTv = findViewById(R.id.menuFindTv)
+ menuShareVia = findViewById(R.id.menuShareVia)
+ menuShareViaTv = findViewById(R.id.menuShareViaTv)
+ menuCopyLink = findViewById(R.id.menuCopyLink)
+ menuCopyLinkTv = findViewById(R.id.menuCopyLinkTv)
+ menuOpenWith = findViewById(R.id.menuOpenWith)
+ menuOpenWithTv = findViewById(R.id.menuOpenWithTv)
+
+ webLayout = findViewById(R.id.webLayout)
+ webView = buildWebView()
+ webLayout?.addView(webView)
+ }
+
+ protected fun layoutViews() {
+ if (!toolbarVisible) {
+ setSupportActionBar(toolbar)
+ toolbar!!.visibility = View.GONE
+ }
+
+ run {
+ // AppBar
+ var toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ if (!gradientDivider) toolbarHeight += dividerHeight
+ val params =
+ CoordinatorLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ toolbarHeight.toInt()
+ )
+ appBar!!.layoutParams = params
+ awesomeWebViewBinding.coordinatorLayout.requestLayout()
+ }
+
+ run {
+ // Toolbar
+ val toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ val params =
+ LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ toolbarHeight.toInt()
+ )
+ toolbarLayout!!.minimumHeight = toolbarHeight.toInt()
+ toolbarLayout!!.layoutParams = params
+ awesomeWebViewBinding.coordinatorLayout.requestLayout()
+ }
+
+ run {
+ // TextViews
+ val maxWidth = this.maxWidth
+ title!!.maxWidth = maxWidth
+ urlTv!!.maxWidth = maxWidth
+ requestCenterLayout()
+ }
+
+ run {
+ // Icons
+ updateIcon(close, if (rtl) R.drawable.more else R.drawable.close)
+ updateIcon(back, R.drawable.back)
+ updateIcon(forward, R.drawable.forward)
+ updateIcon(more, if (rtl) R.drawable.close else R.drawable.more)
+ }
+
+ run { // Divider
+ if (gradientDivider) {
+ val toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ val params =
+ gradient!!.layoutParams as CoordinatorLayout.LayoutParams
+ params.setMargins(0, toolbarHeight.toInt(), 0, 0)
+ gradient!!.layoutParams = params
+ }
+ }
+
+ run {
+ // ProgressBar
+ progressBar!!.minimumHeight = progressBarHeight.toInt()
+ val params =
+ CoordinatorLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ progressBarHeight.toInt()
+ )
+ val toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ when (progressBarPosition!!) {
+ Position.TOP_OF_TOOLBAR -> params.setMargins(
+ 0,
+ 0,
+ 0,
+ 0
+ )
+
+ Position.BOTTOM_OF_TOOLBAR -> params.setMargins(
+ 0,
+ toolbarHeight.toInt() - progressBarHeight.toInt(),
+ 0,
+ 0
+ )
+
+ Position.TOP_OF_WEBVIEW -> params.setMargins(
+ 0,
+ toolbarHeight.toInt(),
+ 0,
+ 0
+ )
+
+ Position.BOTTOM_OF_WEBVIEW -> params.setMargins(
+ 0,
+ DisplayUtil.height - progressBarHeight.toInt(),
+ 0,
+ 0
+ )
+ }
+ progressBar!!.layoutParams = params
+ }
+
+ run {
+ // WebLayout
+ val toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ val statusBarHeight =
+ if (toolbarVisible) DisplayUtil.statusBarHeight else 0
+ val screenHeight = DisplayUtil.height
+ var webLayoutMinimumHeight =
+ screenHeight - toolbarHeight - statusBarHeight
+ if (showDivider && !gradientDivider) webLayoutMinimumHeight -= dividerHeight
+ webLayout!!.minimumHeight = webLayoutMinimumHeight.toInt()
+
+ val params =
+ CoordinatorLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT
+ )
+ params.setMargins(0, toolbarHeight.toInt(), 0, 0)
+ webLayout!!.layoutParams = params
+ }
+ }
+
+ @SuppressLint("SetJavaScriptEnabled")
+ protected fun initializeViews() {
+ if (!toolbarVisible) {
+ setSupportActionBar(toolbar)
+ toolbar!!.visibility = View.GONE
+ }
+
+ run {
+ // StatusBar
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ val window = window
+ window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
+ window.statusBarColor = statusBarColor
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ val window = window
+ if (statusBarIconDark) {
+ window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ } else {
+ window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ }
+ }
+ }
+
+ run { // Toolbar
+ toolbar!!.setBackgroundColor(toolbarColor)
+ }
+
+ run {
+ // TextViews
+ title!!.text = titleDefault
+ title!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize)
+ title!!.setTypeface(TypefaceHelper.get(this, titleFont))
+ title!!.setTextColor(mTitleColor)
+
+ urlTv!!.visibility = if (showUrl) View.VISIBLE else View.GONE
+ urlTv!!.text = UrlParser.getHost(url)
+ urlTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize)
+ urlTv!!.setTypeface(TypefaceHelper.get(this, urlFont))
+ urlTv!!.setTextColor(urlColor)
+ requestCenterLayout()
+ }
+
+ run {
+ // Icons
+ close!!.setBackgroundResource(iconSelector)
+ back!!.setBackgroundResource(iconSelector)
+ forward!!.setBackgroundResource(iconSelector)
+ more!!.setBackgroundResource(iconSelector)
+
+ close!!.visibility = if (showIconClose) View.VISIBLE else View.GONE
+ close!!.isEnabled = !disableIconClose
+
+ if (((showMenuRefresh
+ || showMenuFind
+ || showMenuShareVia
+ || showMenuCopyLink
+ || showMenuOpenWith) || customMenus!!.size > 0) && showIconMenu
+ ) {
+ more!!.visibility = View.VISIBLE
+ } else {
+ more!!.visibility = View.GONE
+ }
+ more!!.isEnabled = !disableIconMenu
+ }
+
+ run { // Cookie
+ if (webViewCookieEnabled!! && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
+ }
+ }
+
+ run {
+ // WebView
+ webChromeClient = buildWebChromeClient()
+ webViewClient = buildWebViewClient()
+
+ webView!!.webChromeClient = webChromeClient
+ webView!!.webViewClient = webViewClient!!
+ webView!!.setDownloadListener(downloadListener)
+
+ webView!!.setOnLongClickListener(OnLongClickListener {
+ val hitTestResult = webView!!.hitTestResult
+ // 如果是图片类型或者是带有图片链接的类型
+ if (hitTestResult.type == HitTestResult.IMAGE_TYPE ||
+ hitTestResult.type == HitTestResult.SRC_IMAGE_ANCHOR_TYPE
+ ) {
+ if (!showMenuSavePhoto) {
+ return@OnLongClickListener false
+ }
+ // 弹出保存图片的对话框
+ val builder =
+ AlertDialog.Builder(this@AwesomeWebViewActivity)
+ val items = arrayOf(
+ resources.getString(stringResSavePhoto)
+ )
+ builder?.setItems(
+ items
+ ) { dialog, which ->
+ PermissionHelper.CheckPermissions(
+ this@AwesomeWebViewActivity,
+ object : CheckPermissionListener {
+ override fun onAllGranted(sync: Boolean) {
+ val url = hitTestResult.extra
+ // 下载图片到本地
+ CookieSyncManager.createInstance(this@AwesomeWebViewActivity)
+ CookieSyncManager.getInstance().sync()
+ val cookieManager =
+ CookieManager.getInstance()
+ val cookie =
+ cookieManager.getCookie(webView!!.url)
+ DownPicUtil.downPic(
+ url,
+ webView!!.settings.userAgentString,
+ webView!!.url,
+ cookie,
+ object : DownFinishListener {
+ override fun onDownFinish(path: String) {
+ if (showToastPhotoSavedOrFailed) {
+ Toast.makeText(
+ this@AwesomeWebViewActivity,
+ resources.getString(
+ stringResPhotoSavedTo
+ ) + path,
+ Toast.LENGTH_LONG
+ ).show()
+ }
+ // 最后通知图库更新
+ applicationContext.sendBroadcast(
+ Intent(
+ Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
+ Uri.parse("file://$path")
+ )
+ )
+ }
+
+ override fun onError() {
+ if (showToastPhotoSavedOrFailed) {
+ Toast.makeText(
+ this@AwesomeWebViewActivity,
+ resources.getString(
+ stringResPhotoSaveFailed
+ ),
+ Toast.LENGTH_LONG
+ ).show()
+ }
+ }
+ })
+ }
+
+ override fun onPartlyGranted(
+ permissionsDenied: List,
+ sync: Boolean
+ ) {
+ }
+ },
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ )
+ }
+ val dialog = builder?.create()
+ dialog?.show()
+ return@OnLongClickListener true
+ }
+ false
+ })
+
+ webView!!.setOnTouchListener(object : OnTouchListener {
+ private var xDown = 0f
+ private var yDown = 0f
+ private var timeDown: Long = 0
+ override fun onTouch(v: View, event: MotionEvent): Boolean {
+ if (v === webView && event.action == MotionEvent.ACTION_DOWN) {
+ xDown = event.x
+ yDown = event.y
+ timeDown = System.currentTimeMillis()
+ } else if (v === webView && event.action == MotionEvent.ACTION_UP) {
+ if (abs((xDown - event.x).toDouble()) < 50 && abs(
+ (yDown - event.y).toDouble()
+ ) < 50 && System.currentTimeMillis() - timeDown < 200
+ ) {
+ // https://stackoverflow.com/a/5125620
+ handler.sendEmptyMessageDelayed(MSG_CLICK_ON_WEBVIEW, 500)
+ }
+ }
+ return false
+ }
+ })
+
+ val settings = webView!!.settings
+
+ if (webViewSupportZoom != null) settings.setSupportZoom(webViewSupportZoom!!)
+ if (webViewMediaPlaybackRequiresUserGesture != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
+ ) {
+ settings.mediaPlaybackRequiresUserGesture =
+ webViewMediaPlaybackRequiresUserGesture!!
+ }
+ if (webViewBuiltInZoomControls != null) {
+ settings.builtInZoomControls = webViewBuiltInZoomControls!!
+
+ if (webViewBuiltInZoomControls!!) {
+ // Remove NestedScrollView to enable BuiltInZoomControls
+ (webView!!.parent as ViewGroup).removeAllViews()
+ }
+ }
+ if (webViewDisplayZoomControls != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
+ ) {
+ settings.displayZoomControls = webViewDisplayZoomControls!!
+ }
+
+ if (webViewAllowFileAccess != null) settings.allowFileAccess = webViewAllowFileAccess!!
+ if (webViewAllowContentAccess != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
+ ) {
+ settings.allowContentAccess = webViewAllowContentAccess!!
+ }
+ if (webViewLoadWithOverviewMode != null) {
+ settings.loadWithOverviewMode = webViewLoadWithOverviewMode!!
+ }
+ if (webViewSaveFormData != null) settings.saveFormData = webViewSaveFormData!!
+ if (webViewTextZoom != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
+ ) {
+ settings.textZoom = webViewTextZoom!!
+ }
+ if (webViewUseWideViewPort != null) settings.useWideViewPort = webViewUseWideViewPort!!
+ if (webViewSupportMultipleWindows != null) {
+ settings.setSupportMultipleWindows(webViewSupportMultipleWindows!!)
+ }
+ if (webViewLayoutAlgorithm != null) settings.layoutAlgorithm = webViewLayoutAlgorithm
+ if (webViewStandardFontFamily != null) {
+ settings.standardFontFamily = webViewStandardFontFamily
+ }
+ if (webViewFixedFontFamily != null) settings.fixedFontFamily = webViewFixedFontFamily
+ if (webViewSansSerifFontFamily != null) {
+ settings.sansSerifFontFamily = webViewSansSerifFontFamily
+ }
+ if (webViewSerifFontFamily != null) settings.serifFontFamily = webViewSerifFontFamily
+ if (webViewCursiveFontFamily != null) settings.cursiveFontFamily =
+ webViewCursiveFontFamily
+ if (webViewFantasyFontFamily != null) settings.fantasyFontFamily =
+ webViewFantasyFontFamily
+ if (webViewMinimumFontSize != null) settings.minimumFontSize = webViewMinimumFontSize!!
+ if (webViewMinimumLogicalFontSize != null) {
+ settings.minimumLogicalFontSize = webViewMinimumLogicalFontSize!!
+ }
+ if (webViewDefaultFontSize != null) settings.defaultFontSize = webViewDefaultFontSize!!
+ if (webViewDefaultFixedFontSize != null) {
+ settings.defaultFixedFontSize = webViewDefaultFixedFontSize!!
+ }
+ if (webViewLoadsImagesAutomatically != null) {
+ settings.loadsImagesAutomatically = webViewLoadsImagesAutomatically!!
+ }
+ if (webViewBlockNetworkImage != null) settings.blockNetworkImage =
+ webViewBlockNetworkImage!!
+ if (webViewBlockNetworkLoads != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
+ settings.blockNetworkLoads = webViewBlockNetworkLoads!!
+ }
+ if (webViewJavaScriptEnabled != null) settings.javaScriptEnabled =
+ webViewJavaScriptEnabled!!
+ if (webViewAllowUniversalAccessFromFileURLs != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
+ ) {
+ settings.allowUniversalAccessFromFileURLs =
+ webViewAllowUniversalAccessFromFileURLs!!
+ }
+ if (webViewAllowFileAccessFromFileURLs != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
+ ) {
+ settings.allowFileAccessFromFileURLs = webViewAllowFileAccessFromFileURLs!!
+ }
+ if (webViewGeolocationDatabasePath != null) {
+ settings.setGeolocationDatabasePath(webViewGeolocationDatabasePath)
+ }
+ if (webViewAppCacheEnabled != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
+ ) {
+ if (webViewAppCacheEnabled!!) {
+ settings.cacheMode = WebSettings.LOAD_DEFAULT
+ } else {
+ settings.cacheMode = WebSettings.LOAD_NO_CACHE
+ }
+ }
+ if (webViewDatabaseEnabled != null) settings.databaseEnabled = webViewDatabaseEnabled!!
+ if (webViewDomStorageEnabled != null) settings.domStorageEnabled =
+ webViewDomStorageEnabled!!
+ if (webViewGeolocationEnabled != null) {
+ settings.setGeolocationEnabled(webViewGeolocationEnabled!!)
+ }
+ if (webViewJavaScriptCanOpenWindowsAutomatically != null) {
+ settings.javaScriptCanOpenWindowsAutomatically =
+ webViewJavaScriptCanOpenWindowsAutomatically!!
+ }
+ if (webViewDefaultTextEncodingName != null) {
+ settings.defaultTextEncodingName = webViewDefaultTextEncodingName
+ }
+ if (webViewUserAgentString != null) {
+ settings.setUserAgentString(if (webViewUserAgentAppend!!) settings.userAgentString + " " + webViewUserAgentString else webViewUserAgentString)
+ }
+ if (webViewNeedInitialFocus != null) settings.setNeedInitialFocus(
+ webViewNeedInitialFocus!!
+ )
+ if (webViewCacheMode != null) settings.cacheMode = webViewCacheMode!!
+ if (webViewMixedContentMode != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
+ ) {
+ settings.mixedContentMode = webViewMixedContentMode!!
+ }
+ if (webViewOffscreenPreRaster != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ settings.offscreenPreRaster = webViewOffscreenPreRaster!!
+ }
+ }
+
+ run {
+ // Divider
+ gradient!!.visibility = if (showDivider && gradientDivider) View.VISIBLE else View.GONE
+ divider!!.visibility = if (showDivider && !gradientDivider) View.VISIBLE else View.GONE
+ if (gradientDivider) {
+ val dividerWidth = DisplayUtil.width
+ val bitmap =
+ BitmapHelper.getGradientBitmap(
+ dividerWidth,
+ dividerHeight.toInt(),
+ dividerColor
+ )
+ val drawable = BitmapDrawable(resources, bitmap)
+ ViewUtil.setBackground(gradient, drawable)
+
+ val params =
+ gradient!!.layoutParams as CoordinatorLayout.LayoutParams
+ params.height = dividerHeight.toInt()
+ gradient!!.layoutParams = params
+ } else {
+ divider!!.setBackgroundColor(dividerColor)
+
+ val params =
+ divider!!.layoutParams as LinearLayout.LayoutParams
+ params.height = dividerHeight.toInt()
+ divider!!.layoutParams = params
+ }
+ }
+
+ run {
+ // ProgressBar
+ progressBar!!.visibility = if (showProgressBar) View.VISIBLE else View.GONE
+ progressBar!!.progressDrawable
+ .setColorFilter(progressBarColor, PorterDuff.Mode.SRC_IN)
+ progressBar!!.minimumHeight = progressBarHeight.toInt()
+ val params =
+ CoordinatorLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ progressBarHeight.toInt()
+ )
+ val toolbarHeight =
+ if (toolbarVisible) resources.getDimension(R.dimen.toolbarHeight) else 0f
+ when (progressBarPosition!!) {
+ Position.TOP_OF_TOOLBAR -> params.setMargins(
+ 0,
+ 0,
+ 0,
+ 0
+ )
+
+ Position.BOTTOM_OF_TOOLBAR -> params.setMargins(
+ 0,
+ toolbarHeight.toInt() - progressBarHeight.toInt(),
+ 0,
+ 0
+ )
+
+ Position.TOP_OF_WEBVIEW -> params.setMargins(
+ 0,
+ toolbarHeight.toInt(),
+ 0,
+ 0
+ )
+
+ Position.BOTTOM_OF_WEBVIEW -> params.setMargins(
+ 0,
+ DisplayUtil.height - progressBarHeight.toInt(),
+ 0,
+ 0
+ )
+ }
+ progressBar!!.layoutParams = params
+ }
+
+ run {
+ // Menu
+ val drawable = GradientDrawable()
+ drawable.cornerRadius = resources.getDimension(R.dimen.defaultMenuCornerRadius)
+ drawable.setColor(menuColor)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ menuBackground!!.background = drawable
+ } else {
+ menuBackground!!.setBackgroundDrawable(drawable)
+ }
+
+ shadowLayout!!.setShadowColor(menuDropShadowColor)
+ shadowLayout!!.setShadowSize(menuDropShadowSize)
+
+ val params =
+ RelativeLayout.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT
+ )
+ val margin =
+ (resources.getDimension(R.dimen.defaultMenuLayoutMargin) - menuDropShadowSize).toInt()
+ params.setMargins(0, margin, margin, 0)
+ params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
+ params.addRule(if (rtl) RelativeLayout.ALIGN_PARENT_LEFT else RelativeLayout.ALIGN_PARENT_RIGHT)
+ shadowLayout!!.layoutParams = params
+
+ menuRefresh!!.visibility = if (showMenuRefresh) View.VISIBLE else View.GONE
+ menuRefresh!!.setBackgroundResource(menuSelector)
+ menuRefresh!!.gravity = menuTextGravity
+ menuRefreshTv!!.setText(stringResRefresh)
+ menuRefreshTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ menuRefreshTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ menuRefreshTv!!.setTextColor(menuTextColor)
+ menuRefreshTv!!.setPadding(
+ menuTextPaddingLeft.toInt(),
+ 0,
+ menuTextPaddingRight.toInt(),
+ 0
+ )
+
+ menuFind!!.visibility = if (showMenuFind) View.VISIBLE else View.GONE
+ menuFind!!.setBackgroundResource(menuSelector)
+ menuFind!!.gravity = menuTextGravity
+ menuFindTv!!.setText(stringResFind)
+ menuFindTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ menuFindTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ menuFindTv!!.setTextColor(menuTextColor)
+ menuFindTv!!.setPadding(menuTextPaddingLeft.toInt(), 0, menuTextPaddingRight.toInt(), 0)
+
+ menuShareVia!!.visibility = if (showMenuShareVia) View.VISIBLE else View.GONE
+ menuShareVia!!.setBackgroundResource(menuSelector)
+ menuShareVia!!.gravity = menuTextGravity
+ menuShareViaTv!!.setText(stringResShareVia)
+ menuShareViaTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ menuShareViaTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ menuShareViaTv!!.setTextColor(menuTextColor)
+ menuShareViaTv!!.setPadding(
+ menuTextPaddingLeft.toInt(),
+ 0,
+ menuTextPaddingRight.toInt(),
+ 0
+ )
+
+ menuCopyLink!!.visibility = if (showMenuCopyLink) View.VISIBLE else View.GONE
+ menuCopyLink!!.setBackgroundResource(menuSelector)
+ menuCopyLink!!.gravity = menuTextGravity
+ menuCopyLinkTv!!.setText(stringResCopyLink)
+ menuCopyLinkTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ menuCopyLinkTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ menuCopyLinkTv!!.setTextColor(menuTextColor)
+ menuCopyLinkTv!!.setPadding(
+ menuTextPaddingLeft.toInt(),
+ 0,
+ menuTextPaddingRight.toInt(),
+ 0
+ )
+
+ menuOpenWith!!.visibility = if (showMenuOpenWith) View.VISIBLE else View.GONE
+ menuOpenWith!!.setBackgroundResource(menuSelector)
+ menuOpenWith!!.gravity = menuTextGravity
+ menuOpenWithTv!!.setText(stringResOpenWith)
+ menuOpenWithTv!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ menuOpenWithTv!!.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ menuOpenWithTv!!.setTextColor(menuTextColor)
+ menuOpenWithTv!!.setPadding(
+ menuTextPaddingLeft.toInt(),
+ 0,
+ menuTextPaddingRight.toInt(),
+ 0
+ )
+ for (customMenu in customMenus!!) {
+ val customMenuRoot =
+ LayoutInflater.from(this@AwesomeWebViewActivity)
+ .inflate(R.layout.view_custom_menu, null, false)
+ val customMenuLayout =
+ customMenuRoot.findViewById(R.id.customMenuLayout)
+ val customMenuTv =
+ customMenuLayout.findViewById(R.id.customMenu)
+ customMenuLayout.setBackgroundResource(menuSelector)
+ customMenuLayout.gravity = menuTextGravity
+ customMenuTv.setText(customMenu.titleRes)
+ customMenuTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize)
+ customMenuTv.setTypeface(TypefaceHelper.get(this, menuTextFont))
+ customMenuTv.setTextColor(menuTextColor)
+ customMenuTv.setPadding(
+ menuTextPaddingLeft.toInt(),
+ 0,
+ menuTextPaddingRight.toInt(),
+ 0
+ )
+
+ customMenuLayout.setOnClickListener {
+ BroadCastManager.onCustomMenuClick(
+ this@AwesomeWebViewActivity,
+ key,
+ customMenu.code
+ )
+ hideMenu()
+ }
+
+ menuBackground!!.addView(
+ customMenuRoot,
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT
+ )
+ }
+ }
+ }
+
+ protected fun buildWebView(): WebView {
+ return VideoEnabledWebView(this)
+ }
+
+ protected fun buildWebChromeClient(): WebChromeClient {
+ // Initialize the VideoEnabledWebChromeClient and set event handlers
+ val nonVideoLayout: View? = webLayout // Your own view, read class comments
+ val videoLayout =
+ findViewById(R.id.videoLayout) as ViewGroup // Your own view, read class comments
+ val loadingView = layoutInflater.inflate(
+ R.layout.view_loading_video,
+ null
+ ) // Your own view, read class comments
+ val webChromeClient = MyWebChromeClient(nonVideoLayout, videoLayout, loadingView, webView)
+ webChromeClient.setOnToggledFullscreen { fullscreen -> // Your code to handle the full-screen change, for example showing and hiding the title bar. Example:
+ if (fullscreen) {
+ val attrs = window.attributes
+ attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN
+ attrs.flags = attrs.flags or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ window.attributes = attrs
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ window.decorView.systemUiVisibility =
+ View.SYSTEM_UI_FLAG_LOW_PROFILE
+ }
+ } else {
+ val attrs = window.attributes
+ attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN.inv()
+ attrs.flags = attrs.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON.inv()
+ window.attributes = attrs
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
+ }
+ }
+ }
+ return webChromeClient
+ }
+
+ protected fun buildWebViewClient(): WebViewClient {
+ return MyWebViewClient()
+ }
+
+ protected fun injectCookie() {
+ if (injectCookies != null && injectCookies!!.size > 0) {
+ // https://blog.csdn.net/juhua2012/article/details/52249720
+ CookieSyncManager.createInstance(this)
+ CookieSyncManager.getInstance().sync()
+
+ val cookieManager = CookieManager.getInstance()
+ cookieManager.setAcceptCookie(true)
+ for (url in injectCookies!!.keys) {
+ val cookie = injectCookies!![url]
+ if (cookie == null || cookie.size == 0) {
+ continue
+ }
+ for (key in cookie.keys) {
+ val value = cookie[key]
+ val cookieStr = "$key=$value"
+ cookieManager.setCookie(url, cookieStr)
+ }
+ }
+ CookieSyncManager.getInstance().sync()
+ }
+ }
+
+ protected fun addJavascriptInterface() {
+ CommonJsHelper.getInstance().addJavascriptInterface(webView)
+ }
+
+ protected fun load() {
+ if (data != null) {
+ webView!!.loadData(data!!, mimeType, encoding)
+ } else if (url != null) {
+ if (extraHeaders == null) {
+ webView!!.loadUrl(url!!)
+ } else {
+ webView!!.loadUrl(url!!, extraHeaders!!)
+ }
+ }
+ }
+
+ protected val maxWidth: Int
+ get() = if (forward!!.visibility == View.VISIBLE) {
+ DisplayUtil.width - UnitConverter.dpToPx(100)
+ } else {
+ DisplayUtil.width - UnitConverter.dpToPx(52)
+ }
+
+ protected fun updateIcon(icon: ImageButton?, @DrawableRes drawableRes: Int) {
+ val states = StateListDrawable()
+ run {
+ val bitmap =
+ BitmapHelper.getColoredBitmap(this, drawableRes, iconPressedColor)
+ val drawable = BitmapDrawable(resources, bitmap)
+ states.addState(intArrayOf(android.R.attr.state_pressed), drawable)
+ }
+ run {
+ val bitmap =
+ BitmapHelper.getColoredBitmap(this, drawableRes, iconDisabledColor)
+ val drawable = BitmapDrawable(resources, bitmap)
+ states.addState(intArrayOf(-android.R.attr.state_enabled), drawable)
+ }
+ run {
+ val bitmap =
+ BitmapHelper.getColoredBitmap(this, drawableRes, iconDefaultColor)
+ val drawable = BitmapDrawable(resources, bitmap)
+ states.addState(intArrayOf(), drawable)
+ }
+ icon!!.setImageDrawable(states)
+
+ // int[][] states = new int[][]{
+ // new int[]{-android.R.attr.state_enabled}, // disabled
+ // new int[]{android.R.attr.state_pressed}, // pressed
+ // new int[]{} // default
+ // };
+ //
+ // int[] colors = new int[]{
+ // iconDisabledColor,
+ // iconPressedColor,
+ // iconDefaultColor
+ // };
+ //
+ // ColorStateList colorStateList = new ColorStateList(states, colors);
+ //
+ // Drawable drawable = ContextCompat.getDrawable(this, drawableRes);
+ // if (APILevel.require(21)) {
+ // VectorDrawable vectorDrawable = (VectorDrawable) drawable;
+ // vectorDrawable.setTintList(colorStateList);
+ // icon.setImageDrawable(vectorDrawable);
+ // } else {
+ // VectorDrawableCompat vectorDrawable = (VectorDrawableCompat) drawable;
+ // vectorDrawable.setTintList(colorStateList);
+ // icon.setImageDrawable(vectorDrawable);
+ // }
+ }
+
+ lateinit var awesomeWebViewBinding: AwesomeWebViewBinding
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ initializeOptions()
+ awesomeWebViewBinding = AwesomeWebViewBinding.inflate(layoutInflater)
+ setContentView(awesomeWebViewBinding.root)
+ bindViews()
+ layoutViews()
+ initializeViews()
+ injectCookie()
+ addJavascriptInterface()
+ load()
+ }
+
+ @SuppressLint("MissingSuperCall")
+ override fun onBackPressed() {
+
+ if (webChromeClient is MyWebChromeClient && (webChromeClient as MyWebChromeClient).onBackPressed()) {
+ return
+ }
+ if (menuLayout!!.visibility == View.VISIBLE) {
+ hideMenu()
+ } else if (backPressToClose || !webView!!.canGoBack()) {
+ exitActivity()
+ } else {
+ webView!!.goBack()
+ }
+ }
+
+ override fun onClick(v: View) {
+ val viewId = v.id
+ if (viewId == R.id.close) {
+ if (rtl) {
+ showMenu()
+ } else {
+ exitActivity()
+ }
+ } else if (viewId == R.id.back) {
+ if (rtl) {
+ webView!!.goForward()
+ } else {
+ webView!!.goBack()
+ }
+ } else if (viewId == R.id.forward) {
+ if (rtl) {
+ webView!!.goBack()
+ } else {
+ webView!!.goForward()
+ }
+ } else if (viewId == R.id.more) {
+ if (rtl) {
+ exitActivity()
+ } else {
+ showMenu()
+ }
+ } else if (viewId == R.id.menuLayout) {
+ hideMenu()
+ } else if (viewId == R.id.menuRefresh) {
+ webView!!.reload()
+ hideMenu()
+ } else if (viewId == R.id.menuFind) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) webView!!.showFindDialog(
+ "",
+ true
+ )
+ hideMenu()
+ } else if (viewId == R.id.menuShareVia) {
+ val sendIntent = Intent()
+ sendIntent.setAction(Intent.ACTION_SEND)
+ sendIntent.putExtra(Intent.EXTRA_TEXT, webView!!.url)
+ sendIntent.setType("text/plain")
+ startActivity(Intent.createChooser(sendIntent, resources.getString(stringResShareVia)))
+
+ hideMenu()
+ } else if (viewId == R.id.menuCopyLink) {
+ ClipboardManagerUtil.text = webView!!.url
+
+ val snackbar = Snackbar.make(
+ coordinatorLayout!!, getString(stringResCopiedToClipboard),
+ Snackbar.LENGTH_LONG
+ )
+ val snackbarView = snackbar.view
+ snackbarView.setBackgroundColor(toolbarColor)
+ if (snackbarView is ViewGroup) updateChildTextView(snackbarView)
+ snackbar.show()
+
+ hideMenu()
+ } else if (viewId == R.id.menuOpenWith) {
+ val browserIntent = Intent(
+ Intent.ACTION_VIEW, Uri.parse(
+ webView!!.url
+ )
+ )
+ startActivity(browserIntent)
+
+ hideMenu()
+ }
+ }
+
+ protected fun updateChildTextView(viewGroup: ViewGroup?) {
+ if (viewGroup == null || viewGroup.childCount == 0) return
+
+ for (i in 0 until viewGroup.childCount) {
+ val view = viewGroup.getChildAt(i)
+ if (view is TextView) {
+ val textView = view
+ textView.setTextColor(mTitleColor)
+ textView.typeface = TypefaceHelper.get(this, titleFont)
+ textView.setLineSpacing(0f, 1.1f)
+ textView.includeFontPadding = false
+ }
+
+ if (view is ViewGroup) updateChildTextView(view)
+ }
+ }
+
+ protected fun showMenu() {
+ menuLayout!!.visibility = View.VISIBLE
+ val popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_show)
+ shadowLayout!!.startAnimation(popupAnim)
+ }
+
+ protected fun hideMenu() {
+ val popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_hide)
+ shadowLayout!!.startAnimation(popupAnim)
+ popupAnim.setAnimationListener(object : Animation.AnimationListener {
+ override fun onAnimationStart(animation: Animation) {
+ }
+
+ override fun onAnimationEnd(animation: Animation) {
+ menuLayout!!.visibility = View.GONE
+ }
+
+ override fun onAnimationRepeat(animation: Animation) {
+ }
+ })
+ }
+
+ protected fun exitActivity() {
+ super.onBackPressed()
+ overridePendingTransition(animationCloseEnter, animationCloseExit)
+ }
+
+ protected fun requestCenterLayout() {
+ val maxWidth = if (webView!!.canGoBack() || webView!!.canGoForward()) {
+ DisplayUtil.width - UnitConverter.dpToPx(48) * 4
+ } else {
+ DisplayUtil.width - UnitConverter.dpToPx(48) * 2
+ }
+
+ title!!.maxWidth = maxWidth
+ urlTv!!.maxWidth = maxWidth
+ title!!.requestLayout()
+ urlTv!!.requestLayout()
+ }
+
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ layoutViews()
+ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ layoutViews()
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ BroadCastManager.unregister(this@AwesomeWebViewActivity, key)
+ if (webView == null) return
+ if (APILevel.require(11)) webView!!.onPause()
+ destroyWebView()
+ }
+
+ // Wait for zoom control to fade away
+ // https://code.google.com/p/android/issues/detail?id=15694
+ // http://stackoverflow.com/a/5966151/1797648
+ protected fun destroyWebView() {
+ Handler().postDelayed(
+ { if (webView != null) webView!!.destroy() },
+ ViewConfiguration.getZoomControlsTimeout() + 1000L
+ )
+ }
+
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == MSG_CLICK_ON_URL) {
+ handler.removeMessages(MSG_CLICK_ON_WEBVIEW)
+ return true
+ }
+ if (msg.what == MSG_CLICK_ON_WEBVIEW) {
+ val hitTestResult = webView!!.hitTestResult
+ // 如果是图片类型或者是带有图片链接的类型
+ if (hitTestResult.type == HitTestResult.IMAGE_TYPE ||
+ hitTestResult.type == HitTestResult.SRC_IMAGE_ANCHOR_TYPE
+ ) {
+ BroadCastManager.onClickImage(this@AwesomeWebViewActivity, key, hitTestResult.extra)
+ }
+ return true
+ }
+ return false
+ }
+
+ inner class MyWebChromeClient(
+ activityNonVideoView: View?,
+ activityVideoView: ViewGroup?,
+ loadingView: View?,
+ webView: WebView?
+ ) :
+ VideoEnabledWebChromeClient(activityNonVideoView, activityVideoView, loadingView, webView) {
+ override fun onProgressChanged(view: WebView, progress: Int) {
+ var progress = progress
+ BroadCastManager.onProgressChanged(this@AwesomeWebViewActivity, key, progress)
+
+ if (progress == 100) progress = 0
+ progressBar!!.progress = progress
+ }
+
+ override fun onReceivedTitle(view: WebView, title: String) {
+ BroadCastManager.onReceivedTitle(this@AwesomeWebViewActivity, key, title)
+ }
+
+ override fun onReceivedTouchIconUrl(view: WebView, url: String, precomposed: Boolean) {
+ BroadCastManager.onReceivedTouchIconUrl(
+ this@AwesomeWebViewActivity,
+ key,
+ url,
+ precomposed
+ )
+ }
+
+ override fun onGeolocationPermissionsShowPrompt(
+ origin: String,
+ callback: GeolocationPermissions.Callback
+ ) {
+ PermissionHelper.CheckPermissions(
+ this@AwesomeWebViewActivity,
+ object : CheckPermissionListener {
+ override fun onAllGranted(sync: Boolean) {
+ callback.invoke(origin, true, true)
+ }
+
+ override fun onPartlyGranted(permissionsDenied: List, sync: Boolean) {
+ callback.invoke(origin, false, false)
+ }
+ },
+ Manifest.permission.ACCESS_COARSE_LOCATION,
+ Manifest.permission.ACCESS_FINE_LOCATION
+ )
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ override fun onPermissionRequest(request: PermissionRequest) {
+ for (res in request.resources) {
+ if (res == PermissionRequest.RESOURCE_AUDIO_CAPTURE) {
+ if (!webViewAudioEnabled!!) {
+ request.deny()
+ return
+ }
+ }
+ if (res == PermissionRequest.RESOURCE_VIDEO_CAPTURE) {
+ if (!webViewCameraEnabled!!) {
+ request.deny()
+ return
+ }
+ }
+ }
+
+ PermissionHelper.CheckPermissions(
+ this@AwesomeWebViewActivity,
+ object : CheckPermissionListener {
+ override fun onAllGranted(sync: Boolean) {
+ request.grant(request.resources)
+ }
+
+ override fun onPartlyGranted(permissionsDenied: List, sync: Boolean) {
+ request.deny()
+ }
+ },
+ *parsePermission(request.resources)
+ )
+ }
+
+ //Handling input[type="file"] requests for android API 16+
+ fun openFileChooser(uploadMsg: ValueCallback, acceptType: String?, capture: String?) {
+ handler.sendEmptyMessage(MSG_CLICK_ON_URL)
+
+ if (!fileChooserEnabled) {
+ uploadMsg.onReceiveValue(null)
+ return
+ }
+ filePickerFileMessage = uploadMsg
+ val i = Intent(Intent.ACTION_GET_CONTENT)
+ i.addCategory(Intent.CATEGORY_OPENABLE)
+ i.setType(acceptType)
+ startActivityForResult(
+ Intent.createChooser(
+ i,
+ resources.getString(stringResFileChooserTitle)
+ ), FILE_PICKER_REQ_CODE
+ )
+ }
+
+ //Handling input[type="file"] requests for android API 21+
+ override fun onShowFileChooser(
+ webView: WebView,
+ filePathCallback: ValueCallback>,
+ fileChooserParams: FileChooserParams
+ ): Boolean {
+ handler.sendEmptyMessage(MSG_CLICK_ON_URL)
+
+ if (!fileChooserEnabled) {
+ filePathCallback.onReceiveValue(null)
+ return true
+ }
+ if (filePickerFilePath != null) {
+ filePickerFilePath!!.onReceiveValue(null)
+ }
+ filePickerFilePath = filePathCallback
+
+ //Checking permission for storage and camera for writing and uploading images
+ val perms =
+ arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
+ PermissionHelper.CheckPermissions(
+ this@AwesomeWebViewActivity,
+ object : CheckPermissionListener {
+ override fun onAllGranted(sync: Boolean) {
+ val takePictureIntent =
+ createCameraCaptureIntent(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) fileChooserParams.acceptTypes else null)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && fileChooserParams.isCaptureEnabled && fileChooserParams.mode == FileChooserParams.MODE_OPEN) {
+ // capture="camera" and without multiple
+ if (takePictureIntent != null) {
+ startActivityForResult(takePictureIntent, FILE_PICKER_REQ_CODE)
+ } else {
+ if (filePickerFilePath != null) {
+ filePickerFilePath!!.onReceiveValue(null)
+ filePickerFilePath = null
+ }
+ }
+ return
+ }
+ val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)
+ contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE)
+ contentSelectionIntent.setType(FILE_TYPE)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ contentSelectionIntent.putExtra(
+ Intent.EXTRA_MIME_TYPES,
+ fileChooserParams.acceptTypes
+ )
+ }
+ val intentArray: Array = if (takePictureIntent != null) {
+ arrayOf(takePictureIntent)
+ } else {
+ arrayOfNulls(0)
+ }
+ val chooserIntent = Intent(Intent.ACTION_CHOOSER)
+ chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
+ chooserIntent.putExtra(
+ Intent.EXTRA_TITLE,
+ resources.getString(stringResFileChooserTitle)
+ )
+ chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray)
+ startActivityForResult(chooserIntent, FILE_PICKER_REQ_CODE)
+ }
+
+ override fun onPartlyGranted(permissionsDenied: List, sync: Boolean) {
+ if (filePickerFilePath != null) {
+ filePickerFilePath!!.onReceiveValue(null)
+ filePickerFilePath = null
+ }
+ }
+ },
+ *perms
+ )
+ return true
+ }
+ }
+
+ private fun createCameraCaptureIntent(mimeTypes: Array?): Intent? {
+ var isVideo = false
+ if (mimeTypes != null && mimeTypes.size == 1 && mimeTypes[0] != null && mimeTypes[0]!!
+ .startsWith("video")
+ ) {
+ isVideo = true
+ }
+ var takePictureIntent: Intent? =
+ Intent(if (isVideo) MediaStore.ACTION_VIDEO_CAPTURE else MediaStore.ACTION_IMAGE_CAPTURE)
+ if (takePictureIntent!!.resolveActivity(this@AwesomeWebViewActivity.packageManager) != null) {
+ var imageVideoFile: File? = null
+ try {
+ imageVideoFile = createImageOrVideo(isVideo)
+ } catch (ex: IOException) {
+// Log.e("", "Image file creation failed", ex);
+ ex.printStackTrace()
+ }
+ if (imageVideoFile != null) {
+ filePickerCamMessage = "file:" + imageVideoFile.absolutePath
+
+ val photoUri = FileProvider.getUriForFile(
+ this,
+ "$packageName.awesome_web_view.file_provider",
+ imageVideoFile
+ )
+
+ takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri)
+ } else {
+ takePictureIntent = null
+ }
+ }
+ return takePictureIntent
+ }
+
+ override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
+ super.onActivityResult(requestCode, resultCode, intent)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+// getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+// getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimary));
+ var results: Array? = null
+ if (resultCode == RESULT_OK) {
+ if (requestCode == FILE_PICKER_REQ_CODE) {
+ if (null == filePickerFilePath) {
+ return
+ }
+ if (intent == null || intent.dataString == null) {
+ if (filePickerCamMessage != null) {
+ results = arrayOf(Uri.parse(filePickerCamMessage))
+ }
+ } else {
+ val dataString = intent.dataString
+ if (dataString != null) {
+ results = arrayOf(Uri.parse(dataString))
+ }
+ }
+ }
+ }
+ filePickerFilePath!!.onReceiveValue(results)
+ filePickerFilePath = null
+ } else {
+ if (requestCode == FILE_PICKER_REQ_CODE) {
+ if (null == filePickerFileMessage) return
+ val result = if (intent == null || resultCode != RESULT_OK) null else intent.data
+ filePickerFileMessage!!.onReceiveValue(result)
+ filePickerFileMessage = null
+ }
+ }
+ }
+
+ //Creating image or video file for upload
+ @Throws(IOException::class)
+ protected fun createImageOrVideo(isVideo: Boolean): File {
+ @SuppressLint("SimpleDateFormat") val file_name = SimpleDateFormat("yyyy_mm_ss").format(
+ Date()
+ )
+ val new_name = "file_" + file_name + "_"
+ val sd_directory =
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ return File.createTempFile(new_name, if (isVideo) ".mp4" else ".jpg", sd_directory)
+ }
+
+ inner class MyWebViewClient : WebViewClient() {
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
+ override fun shouldInterceptRequest(
+ view: WebView,
+ request: WebResourceRequest
+ ): WebResourceResponse? {
+ LogUtil.e("shouldInterceptRequest request >>> ${request.url.toString()}")
+ return super.shouldInterceptRequest(view, request)
+ }
+
+ override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? {
+ LogUtil.e("shouldInterceptRequest String >>> $url")
+ return super.shouldInterceptRequest(view, url)
+ }
+
+ override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
+ BroadCastManager.onPageStarted(this@AwesomeWebViewActivity, key, url)
+ if (!url.contains("docs.google.com") && url.endsWith(".pdf")) {
+ webView!!.loadUrl("http://docs.google.com/gview?embedded=true&url=$url")
+ }
+ }
+
+ override fun onPageFinished(view: WebView, url: String) {
+ BroadCastManager.onPageFinished(this@AwesomeWebViewActivity, key, url)
+
+ if (updateTitleFromHtml) title!!.text = view.title
+ urlTv!!.text = UrlParser.getHost(url)
+ requestCenterLayout()
+
+ if (view.canGoBack() || view.canGoForward()) {
+ back!!.visibility = if (showIconBack) View.VISIBLE else View.GONE
+ forward!!.visibility = if (showIconForward) View.VISIBLE else View.GONE
+ back!!.isEnabled =
+ !disableIconBack && (if (rtl) view.canGoForward() else view.canGoBack())
+ forward!!.isEnabled =
+ !disableIconForward && (if (rtl) view.canGoBack() else view.canGoForward())
+ } else {
+ back!!.visibility = View.GONE
+ forward!!.visibility = View.GONE
+ }
+
+ if (injectJavaScript != null) {
+ if (injectJavaScriptMainPage!! && url != this@AwesomeWebViewActivity.url) {
+ return
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ webView!!.evaluateJavascript(injectJavaScript!!, null)
+ } else {
+ webView!!.loadUrl(injectJavaScript!!)
+ }
+ }
+ }
+
+ override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
+ handler.sendEmptyMessage(MSG_CLICK_ON_URL)
+
+ if (url.endsWith(".mp4")) {
+ val intent = Intent(Intent.ACTION_VIEW)
+ intent.setDataAndType(Uri.parse(url), "video/*")
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ view.context.startActivity(intent)
+ // If we return true, onPageStarted, onPageFinished won't be called.
+ return true
+ } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url
+ .startsWith("mms:") || url.startsWith("mmsto:")
+ ) {
+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ view.context.startActivity(intent)
+ return true // If we return true, onPageStarted, onPageFinished won't be called.
+ } else if (url.startsWith("mailto:")) {
+ val mt = MailTo.parse(url)
+
+ val emailIntent = Intent(Intent.ACTION_SEND)
+
+ emailIntent.setType("text/html")
+ emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mt.to))
+ emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.subject)
+ emailIntent.putExtra(Intent.EXTRA_CC, mt.cc)
+ emailIntent.putExtra(Intent.EXTRA_TEXT, mt.body)
+
+ startActivity(emailIntent)
+
+ return true
+ } else if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {
+ if (extraHeaders == null || extraHeadersMainPage!! && url != this@AwesomeWebViewActivity.url) {
+ return super.shouldOverrideUrlLoading(view, url)
+ } else {
+ view.loadUrl(url, extraHeaders!!)
+ return true
+ }
+ } else {
+ if (webViewAppJumpEnabled!!) {
+ try {
+ val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ view.context.startActivity(intent)
+ return true // If we return true, onPageStarted, onPageFinished won't be called.
+ } catch (exception: Exception) {
+ exception.printStackTrace()
+ return true
+ }
+ } else {
+ return super.shouldOverrideUrlLoading(view, url)
+ }
+ }
+ }
+
+ override fun onLoadResource(view: WebView, url: String) {
+ BroadCastManager.onLoadResource(this@AwesomeWebViewActivity, key, url)
+ }
+
+ override fun onPageCommitVisible(view: WebView, url: String) {
+ BroadCastManager.onPageCommitVisible(this@AwesomeWebViewActivity, key, url)
+ }
+ }
+
+ protected fun parsePermission(resource: Array): Array {
+ val permissions: MutableList = ArrayList()
+ for (res in resource) {
+ if (res == PermissionRequest.RESOURCE_AUDIO_CAPTURE) {
+ permissions.add(Manifest.permission.RECORD_AUDIO)
+ }
+ if (res == PermissionRequest.RESOURCE_VIDEO_CAPTURE) {
+ permissions.add(Manifest.permission.CAMERA)
+ }
+ }
+
+ val result = arrayOfNulls(permissions.size)
+ for (i in permissions.indices) {
+ result[i] = permissions[i]
+ }
+ return result
+ }
+
+ companion object {
+ protected const val FILE_PICKER_REQ_CODE: Int = 1
+ }
+}
\ No newline at end of file
diff --git a/library/src/main/java/com/wuadam/awesomewebview/enums/Position.java b/library/src/main/java/kr/lunaticbum/awesomewebview/enums/Position.java
similarity index 78%
rename from library/src/main/java/com/wuadam/awesomewebview/enums/Position.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/enums/Position.java
index 62ad266..985dab5 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/enums/Position.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/enums/Position.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.enums;
+package kr.lunaticbum.awesomewebview.enums;
/**
* Created by Leonardo on 11/14/15.
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/Base64ImgHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Base64ImgHelper.java
similarity index 92%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/Base64ImgHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Base64ImgHelper.java
index 76af518..a19a2e2 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/Base64ImgHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Base64ImgHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import android.text.TextUtils;
import android.util.Base64;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/BitmapHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/BitmapHelper.java
similarity index 98%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/BitmapHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/BitmapHelper.java
index c1ad26c..3b66cf0 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/BitmapHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/BitmapHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import android.content.Context;
import android.graphics.Bitmap;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/ColorHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/ColorHelper.java
similarity index 90%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/ColorHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/ColorHelper.java
index 47331b3..9818ba4 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/ColorHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/ColorHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import android.graphics.Color;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/DownPicUtil.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/DownPicUtil.java
similarity index 99%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/DownPicUtil.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/DownPicUtil.java
index b2cee87..d9bdfb9 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/DownPicUtil.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/DownPicUtil.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
/**
* Created by wuzongheng on 2018/2/18.
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/FileProvider4WebView.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FileProvider4WebView.java
similarity index 76%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/FileProvider4WebView.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FileProvider4WebView.java
index adba271..dec1a2f 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/FileProvider4WebView.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FileProvider4WebView.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import androidx.annotation.Keep;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/FormatHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FormatHelper.java
similarity index 98%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/FormatHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FormatHelper.java
index b282ad3..58d166a 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/FormatHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/FormatHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import java.io.BufferedInputStream;
import java.io.File;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/Md5Helper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Md5Helper.java
similarity index 97%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/Md5Helper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Md5Helper.java
index 924b0ac..419f468 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/Md5Helper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/Md5Helper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import java.io.File;
import java.io.FileInputStream;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/PermissionHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/PermissionHelper.java
similarity index 98%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/PermissionHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/PermissionHelper.java
index 19ad39f..020b78f 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/PermissionHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/PermissionHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import android.content.Context;
import android.content.pm.PackageManager;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/TypefaceHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/TypefaceHelper.java
similarity index 97%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/TypefaceHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/TypefaceHelper.java
index 7d33cec..2638f89 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/TypefaceHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/TypefaceHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import android.content.Context;
import android.graphics.Typeface;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/helpers/UrlParser.java b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/UrlParser.java
similarity index 89%
rename from library/src/main/java/com/wuadam/awesomewebview/helpers/UrlParser.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/helpers/UrlParser.java
index 34e3396..680da32 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/helpers/UrlParser.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/helpers/UrlParser.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.helpers;
+package kr.lunaticbum.awesomewebview.helpers;
import java.net.MalformedURLException;
import java.net.URL;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/BaseJsInterface.java b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/BaseJsInterface.java
similarity index 87%
rename from library/src/main/java/com/wuadam/awesomewebview/jsInterface/BaseJsInterface.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/BaseJsInterface.java
index b3c2b2f..7ac60ad 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/BaseJsInterface.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/BaseJsInterface.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.jsInterface;
+package kr.lunaticbum.awesomewebview.jsInterface;
import android.webkit.JavascriptInterface;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/CommonJsHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/CommonJsHelper.java
similarity index 97%
rename from library/src/main/java/com/wuadam/awesomewebview/jsInterface/CommonJsHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/CommonJsHelper.java
index 7c276c5..311c71a 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/CommonJsHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/CommonJsHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.jsInterface;
+package kr.lunaticbum.awesomewebview.jsInterface;
import android.text.TextUtils;
import android.util.Pair;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/VideoJsHelper.java b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/VideoJsHelper.java
similarity index 94%
rename from library/src/main/java/com/wuadam/awesomewebview/jsInterface/VideoJsHelper.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/VideoJsHelper.java
index 77cb4b7..4bf33f4 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/jsInterface/VideoJsHelper.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/jsInterface/VideoJsHelper.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.jsInterface;
+package kr.lunaticbum.awesomewebview.jsInterface;
import android.annotation.SuppressLint;
import android.os.Handler;
@@ -7,7 +7,7 @@ import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
-import com.wuadam.awesomewebview.views.VideoEnabledWebChromeClient;
+import kr.lunaticbum.awesomewebview.views.VideoEnabledWebChromeClient;
public class VideoJsHelper {
private VideoEnabledWebChromeClient videoEnabledWebChromeClient;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/listeners/BroadCastManager.java b/library/src/main/java/kr/lunaticbum/awesomewebview/listeners/BroadCastManager.java
similarity index 99%
rename from library/src/main/java/com/wuadam/awesomewebview/listeners/BroadCastManager.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/listeners/BroadCastManager.java
index 8c61cd8..baee0a7 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/listeners/BroadCastManager.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/listeners/BroadCastManager.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.listeners;
+package kr.lunaticbum.awesomewebview.listeners;
import android.content.BroadcastReceiver;
import android.content.Context;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/listeners/WebViewListener.java b/library/src/main/java/kr/lunaticbum/awesomewebview/listeners/WebViewListener.java
similarity index 94%
rename from library/src/main/java/com/wuadam/awesomewebview/listeners/WebViewListener.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/listeners/WebViewListener.java
index 292997a..4ac0797 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/listeners/WebViewListener.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/listeners/WebViewListener.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.listeners;
+package kr.lunaticbum.awesomewebview.listeners;
/**
* Created by TheFinestArtist on 1/26/16.
diff --git a/library/src/main/java/com/wuadam/awesomewebview/objects/CustomMenu.java b/library/src/main/java/kr/lunaticbum/awesomewebview/objects/CustomMenu.java
similarity index 90%
rename from library/src/main/java/com/wuadam/awesomewebview/objects/CustomMenu.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/objects/CustomMenu.java
index f44c5bc..233d40a 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/objects/CustomMenu.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/objects/CustomMenu.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.objects;
+package kr.lunaticbum.awesomewebview.objects;
import androidx.annotation.StringRes;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/views/ShadowLayout.java b/library/src/main/java/kr/lunaticbum/awesomewebview/views/ShadowLayout.java
similarity index 98%
rename from library/src/main/java/com/wuadam/awesomewebview/views/ShadowLayout.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/views/ShadowLayout.java
index 334a950..5fdd1c8 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/views/ShadowLayout.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/views/ShadowLayout.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.views;
+package kr.lunaticbum.awesomewebview.views;
import android.content.Context;
import android.content.res.TypedArray;
@@ -13,7 +13,7 @@ import androidx.core.content.ContextCompat;
import android.util.AttributeSet;
import android.widget.FrameLayout;
-import com.wuadam.awesomewebview.R;
+import kr.lunaticbum.awesomewebview.R;
/**
diff --git a/library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebChromeClient.java b/library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebChromeClient.java
similarity index 99%
rename from library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebChromeClient.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebChromeClient.java
index c466774..0681fe0 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebChromeClient.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebChromeClient.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.views;
+package kr.lunaticbum.awesomewebview.views;
import android.media.MediaPlayer;
import android.view.SurfaceView;
diff --git a/library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebView.java b/library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebView.java
similarity index 96%
rename from library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebView.java
rename to library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebView.java
index 63f4b66..eb3e4ff 100644
--- a/library/src/main/java/com/wuadam/awesomewebview/views/VideoEnabledWebView.java
+++ b/library/src/main/java/kr/lunaticbum/awesomewebview/views/VideoEnabledWebView.java
@@ -1,4 +1,4 @@
-package com.wuadam.awesomewebview.views;
+package kr.lunaticbum.awesomewebview.views;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -6,7 +6,7 @@ import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
-import com.wuadam.awesomewebview.jsInterface.VideoJsHelper;
+import kr.lunaticbum.awesomewebview.jsInterface.VideoJsHelper;
import java.util.Map;
diff --git a/library/src/main/res/layout/awesome_web_view.xml b/library/src/main/res/layout/awesome_web_view.xml
index 026f8c5..472710f 100644
--- a/library/src/main/res/layout/awesome_web_view.xml
+++ b/library/src/main/res/layout/awesome_web_view.xml
@@ -1,75 +1,81 @@
-
+
+
-
+
+ android:background="@color/finestWhite">
-
+
-
+ app:elevation="0dp">
-
-
-
+
-
+
+
+
-
+
-
+
-
-
+
-
-
+
+
-
+
+
-
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/layout/menus.xml b/library/src/main/res/layout/menus.xml
index 3cbadf8..89c8c90 100644
--- a/library/src/main/res/layout/menus.xml
+++ b/library/src/main/res/layout/menus.xml
@@ -10,7 +10,7 @@
android:orientation="vertical"
android:visibility="gone">
-
-
+
\ No newline at end of file
diff --git a/utils/build.gradle b/utils/build.gradle
deleted file mode 100644
index f9da1dc..0000000
--- a/utils/build.gradle
+++ /dev/null
@@ -1,46 +0,0 @@
-apply plugin: 'com.android.library'
-//apply plugin: 'com.novoda.bintray-release'
-
-
-android {
- namespace "com.thefinestartist.helpers"
- compileSdkVersion 34
-// buildToolsVersion '23.0.2'
-
- compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
-
- }
-
- lintOptions {
- abortOnError false
- }
-
- defaultConfig {
- minSdkVersion 7
- targetSdkVersion 33
- versionCode 1
- versionName '0.9.5'
- vectorDrawables.useSupportLibrary = true
- }
-}
-
-dependencies {
-
-// compile "com.thefinestartist:annotations:${rootProject.ext.versionName}"
- implementation "com.android.support:appcompat-v7:28.0.0"
- implementation "com.android.support:support-annotations:28.0.0"
- implementation 'androidx.annotation:annotation-jvm:1.9.1'
-// implementation project(':annotations')
-// testCompile 'junit:junit:4.12'
-}
-
-//publish {
-// userOrg = 'thefinestartist'
-// groupId = 'com.thefinestartist'
-// artifactId = 'utils'
-// publishVersion = rootProject.ext.versionName
-// desc = 'Context free and basic utils to build Android project conveniently.'
-// website = 'https://github.com/TheFinestArtist/AndroidBaseUtils'
-//}
diff --git a/utils/build.gradle.kts b/utils/build.gradle.kts
new file mode 100644
index 0000000..9f7fdfe
--- /dev/null
+++ b/utils/build.gradle.kts
@@ -0,0 +1,34 @@
+plugins {
+ id ("com.android.library")
+ id ("kotlin-android")
+}
+
+android {
+ namespace = "kr.lunaticbum.helpers"
+ compileSdk = 34
+ defaultConfig {
+ minSdk = 26
+ targetSdk = 34
+ }
+
+ buildFeatures {
+ viewBinding = true
+ dataBinding = true
+ }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+dependencies {
+ implementation ("com.android.support:appcompat-v7:28.0.0")
+ implementation ("com.android.support:support-annotations:28.0.0")
+ implementation ("androidx.annotation:annotation-jvm:1.9.1")
+ implementation ("androidx.core:core-ktx:1.13.1")
+}
\ No newline at end of file
diff --git a/utils/proguard-rules.pro b/utils/proguard-rules.pro
new file mode 100644
index 0000000..1a14e94
--- /dev/null
+++ b/utils/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /Users/TheFinestArtist/Library/Android/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/utils/src/androidTest/java/com/thefinestartist/utils/etc/PreferencesUtilTest.java b/utils/src/androidTest/java/com/thefinestartist/utils/etc/PreferencesUtilTest.java
index 9cd9921..959a050 100755
--- a/utils/src/androidTest/java/com/thefinestartist/utils/etc/PreferencesUtilTest.java
+++ b/utils/src/androidTest/java/com/thefinestartist/utils/etc/PreferencesUtilTest.java
@@ -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;
diff --git a/utils/src/main/AndroidManifest.xml b/utils/src/main/AndroidManifest.xml
index 5618ce2..b902be9 100644
--- a/utils/src/main/AndroidManifest.xml
+++ b/utils/src/main/AndroidManifest.xml
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/utils/src/main/java/android/print/PDFPrint.java b/utils/src/main/java/android/print/PDFPrint.java
new file mode 100644
index 0000000..f63e817
--- /dev/null
+++ b/utils/src/main/java/android/print/PDFPrint.java
@@ -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);
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/Base.java b/utils/src/main/java/com/thefinestartist/Base.java
deleted file mode 100644
index f897b78..0000000
--- a/utils/src/main/java/com/thefinestartist/Base.java
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/builders/ActivityBuilder.java b/utils/src/main/java/com/thefinestartist/builders/ActivityBuilder.java
deleted file mode 100644
index 5aa9817..0000000
--- a/utils/src/main/java/com/thefinestartist/builders/ActivityBuilder.java
+++ /dev/null
@@ -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 ActivityBuilder(@NonNull Class clazz) {
- intent = new Intent(Base.getContext(), clazz);
- }
-
- public 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 ActivityBuilder set(@NonNull String key, ArrayList 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);
- }
-}
diff --git a/utils/src/main/java/com/thefinestartist/converters/UnitConverter.java b/utils/src/main/java/com/thefinestartist/converters/UnitConverter.java
deleted file mode 100644
index a662034..0000000
--- a/utils/src/main/java/com/thefinestartist/converters/UnitConverter.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/ContextUtil.java b/utils/src/main/java/com/thefinestartist/utils/content/ContextUtil.java
deleted file mode 100644
index 7069e2e..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/content/ContextUtil.java
+++ /dev/null
@@ -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 getSystemService(Class 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);
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/Res.java b/utils/src/main/java/com/thefinestartist/utils/content/Res.java
deleted file mode 100644
index a4492cb..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/content/Res.java
+++ /dev/null
@@ -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 {
-}
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/ResourcesUtil.java b/utils/src/main/java/com/thefinestartist/utils/content/ResourcesUtil.java
deleted file mode 100644
index de61235..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/content/ResourcesUtil.java
+++ /dev/null
@@ -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;
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/ThemeUtil.java b/utils/src/main/java/com/thefinestartist/utils/content/ThemeUtil.java
deleted file mode 100644
index c239301..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/content/ThemeUtil.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/TypedValueUtil.java b/utils/src/main/java/com/thefinestartist/utils/content/TypedValueUtil.java
deleted file mode 100644
index 1a22773..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/content/TypedValueUtil.java
+++ /dev/null
@@ -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());
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/PackageUtil.java b/utils/src/main/java/com/thefinestartist/utils/etc/PackageUtil.java
deleted file mode 100644
index 7ff8539..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/etc/PackageUtil.java
+++ /dev/null
@@ -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);
- }
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/TypefaceUtil.java b/utils/src/main/java/com/thefinestartist/utils/etc/TypefaceUtil.java
deleted file mode 100644
index 32e600f..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/etc/TypefaceUtil.java
+++ /dev/null
@@ -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 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);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/L.java b/utils/src/main/java/com/thefinestartist/utils/log/L.java
deleted file mode 100644
index 709edcd..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/log/L.java
+++ /dev/null
@@ -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 {
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/LogHelper.java b/utils/src/main/java/com/thefinestartist/utils/log/LogHelper.java
deleted file mode 100644
index 1db79eb..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/log/LogHelper.java
+++ /dev/null
@@ -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());
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/LogUtil.java b/utils/src/main/java/com/thefinestartist/utils/log/LogUtil.java
deleted file mode 100644
index 5dfcd90..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/log/LogUtil.java
+++ /dev/null
@@ -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);
- }
-}
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/Settings.java b/utils/src/main/java/com/thefinestartist/utils/log/Settings.java
deleted file mode 100644
index ca68a98..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/log/Settings.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/utils/src/main/java/com/thefinestartist/utils/preferences/PreferencesUtil.java b/utils/src/main/java/com/thefinestartist/utils/preferences/PreferencesUtil.java
deleted file mode 100755
index ee68059..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/preferences/PreferencesUtil.java
+++ /dev/null
@@ -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 get(String key, Set defValue) {
- return get(defaultName, key, defValue);
- }
-
- @TargetApi(Build.VERSION_CODES.FROYO)
- public static 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 get(String name, String key, Set defValue) {
- return getPreferences(name).getStringSet(key, defValue);
- }
-
- @TargetApi(Build.VERSION_CODES.FROYO)
- public static 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 value) {
- put(defaultName, key, value);
- }
-
- @TargetApi(Build.VERSION_CODES.FROYO)
- public static 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 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 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();
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/service/ClipboardManagerUtil.java b/utils/src/main/java/com/thefinestartist/utils/service/ClipboardManagerUtil.java
deleted file mode 100644
index 4c3fff3..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/service/ClipboardManagerUtil.java
+++ /dev/null
@@ -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();
- }
- }
-}
diff --git a/utils/src/main/java/com/thefinestartist/utils/service/ServiceUtil.java b/utils/src/main/java/com/thefinestartist/utils/service/ServiceUtil.java
deleted file mode 100644
index 5557e21..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/service/ServiceUtil.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/service/VibratorUtil.java b/utils/src/main/java/com/thefinestartist/utils/service/VibratorUtil.java
deleted file mode 100755
index e24dbca..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/service/VibratorUtil.java
+++ /dev/null
@@ -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();
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/service/WindowManagerUtil.java b/utils/src/main/java/com/thefinestartist/utils/service/WindowManagerUtil.java
deleted file mode 100644
index dad44b8..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/service/WindowManagerUtil.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/ui/DisplayUtil.java b/utils/src/main/java/com/thefinestartist/utils/ui/DisplayUtil.java
deleted file mode 100644
index ddc38f4..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/ui/DisplayUtil.java
+++ /dev/null
@@ -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;
- }
-}
diff --git a/utils/src/main/java/com/thefinestartist/utils/ui/KeyboardUtil.java b/utils/src/main/java/com/thefinestartist/utils/ui/KeyboardUtil.java
deleted file mode 100644
index 9ae42cc..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/ui/KeyboardUtil.java
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/ui/ViewUtil.java b/utils/src/main/java/com/thefinestartist/utils/ui/ViewUtil.java
deleted file mode 100644
index 3847279..0000000
--- a/utils/src/main/java/com/thefinestartist/utils/ui/ViewUtil.java
+++ /dev/null
@@ -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));
- }
- }
-}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/Base.java b/utils/src/main/java/kr/lunaticbum/Base.java
new file mode 100644
index 0000000..3b44b6c
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/Base.java
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/Base.kt b/utils/src/main/java/kr/lunaticbum/Base.kt
new file mode 100644
index 0000000..4765da8
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/Base.kt
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/annotations/Extra.java b/utils/src/main/java/kr/lunaticbum/annotations/Extra.java
similarity index 91%
rename from utils/src/main/java/com/thefinestartist/annotations/Extra.java
rename to utils/src/main/java/kr/lunaticbum/annotations/Extra.java
index e7a510a..103efb4 100644
--- a/utils/src/main/java/com/thefinestartist/annotations/Extra.java
+++ b/utils/src/main/java/kr/lunaticbum/annotations/Extra.java
@@ -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;
diff --git a/utils/src/main/java/com/thefinestartist/binders/ExtrasBinder.java b/utils/src/main/java/kr/lunaticbum/binders/ExtrasBinder.java
similarity index 97%
rename from utils/src/main/java/com/thefinestartist/binders/ExtrasBinder.java
rename to utils/src/main/java/kr/lunaticbum/binders/ExtrasBinder.java
index 0ba8d77..3a5516e 100644
--- a/utils/src/main/java/com/thefinestartist/binders/ExtrasBinder.java
+++ b/utils/src/main/java/kr/lunaticbum/binders/ExtrasBinder.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.binders;
+package kr.lunaticbum.binders;
import android.app.Activity;
import android.content.Intent;
diff --git a/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.java b/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.java
new file mode 100644
index 0000000..e62db2a
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.java
@@ -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 ActivityBuilder(@NonNull Class clazz) {
+// intent = new Intent(Base.getContext(), clazz);
+// }
+//
+// public 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 ActivityBuilder set(@NonNull String key, ArrayList 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);
+// }
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.kt b/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.kt
new file mode 100644
index 0000000..cdada1c
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/builders/ActivityBuilder.kt
@@ -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) {
+ val intent: Intent =
+ Intent(getContext(), clazz)
+
+ fun 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?): ActivityBuilder {
+ intent.putExtra(key, value)
+ return this
+ }
+
+ fun set(key: String, value: ArrayList?): 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)
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/builders/BundleBuilder.java b/utils/src/main/java/kr/lunaticbum/builders/BundleBuilder.java
similarity index 94%
rename from utils/src/main/java/com/thefinestartist/builders/BundleBuilder.java
rename to utils/src/main/java/kr/lunaticbum/builders/BundleBuilder.java
index fab1c70..1b89e35 100644
--- a/utils/src/main/java/com/thefinestartist/builders/BundleBuilder.java
+++ b/utils/src/main/java/kr/lunaticbum/builders/BundleBuilder.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.builders;
+package kr.lunaticbum.builders;
import android.os.Bundle;
import android.os.Parcelable;
diff --git a/utils/src/main/java/com/thefinestartist/converters/Unit.java b/utils/src/main/java/kr/lunaticbum/converters/Unit.java
similarity index 78%
rename from utils/src/main/java/com/thefinestartist/converters/Unit.java
rename to utils/src/main/java/kr/lunaticbum/converters/Unit.java
index 9a1e3d6..2b6dbb3 100644
--- a/utils/src/main/java/com/thefinestartist/converters/Unit.java
+++ b/utils/src/main/java/kr/lunaticbum/converters/Unit.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.converters;
+package kr.lunaticbum.converters;
/**
* Unit is abbreviation class of {@link UnitConverter}.
diff --git a/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.java b/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.java
new file mode 100644
index 0000000..71c282a
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.java
@@ -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);
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.kt b/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.kt
new file mode 100644
index 0000000..295bbbb
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/converters/UnitConverter.kt
@@ -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()
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/enums/LogLevel.java b/utils/src/main/java/kr/lunaticbum/enums/LogLevel.java
similarity index 71%
rename from utils/src/main/java/com/thefinestartist/enums/LogLevel.java
rename to utils/src/main/java/kr/lunaticbum/enums/LogLevel.java
index 1482c54..87e3e55 100644
--- a/utils/src/main/java/com/thefinestartist/enums/LogLevel.java
+++ b/utils/src/main/java/kr/lunaticbum/enums/LogLevel.java
@@ -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}.
diff --git a/utils/src/main/java/com/thefinestartist/enums/Rotation.java b/utils/src/main/java/kr/lunaticbum/enums/Rotation.java
similarity index 85%
rename from utils/src/main/java/com/thefinestartist/enums/Rotation.java
rename to utils/src/main/java/kr/lunaticbum/enums/Rotation.java
index fbed605..46c2dbe 100644
--- a/utils/src/main/java/com/thefinestartist/enums/Rotation.java
+++ b/utils/src/main/java/kr/lunaticbum/enums/Rotation.java
@@ -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}.
diff --git a/utils/src/main/java/com/thefinestartist/listeners/KeyboardStateListener.java b/utils/src/main/java/kr/lunaticbum/listeners/KeyboardStateListener.java
similarity index 71%
rename from utils/src/main/java/com/thefinestartist/listeners/KeyboardStateListener.java
rename to utils/src/main/java/kr/lunaticbum/listeners/KeyboardStateListener.java
index bc0cc69..f0596b6 100644
--- a/utils/src/main/java/com/thefinestartist/listeners/KeyboardStateListener.java
+++ b/utils/src/main/java/kr/lunaticbum/listeners/KeyboardStateListener.java
@@ -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}.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.java b/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.java
new file mode 100644
index 0000000..7c99a2c
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.java
@@ -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 getSystemService(Class 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);
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.kt
new file mode 100644
index 0000000..d149a41
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ContextUtil.kt
@@ -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 {
+ 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 {
+ 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
+ get() = ContextCompat.getExternalCacheDirs(getContext())
+
+ @TargetApi(8)
+ fun getExternalFilesDir(type: String?): File? {
+ return getContext().getExternalFilesDir(type)
+ }
+
+ fun getExternalFilesDirs(type: String?): Array {
+ return ContextCompat.getExternalFilesDirs(getContext(), type)
+ }
+
+ @get:TargetApi(21)
+ val externalMediaDirs: Array
+ 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
+ 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 getSystemService(serviceClass: Class): 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, options: Bundle?): Boolean {
+ for (intent in intents) intent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ return ContextCompat.startActivities(getContext(), intents, options)
+ }
+
+ fun startActivities(intents: Array): 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)
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/content/Ctx.java b/utils/src/main/java/kr/lunaticbum/utils/content/Ctx.java
similarity index 76%
rename from utils/src/main/java/com/thefinestartist/utils/content/Ctx.java
rename to utils/src/main/java/kr/lunaticbum/utils/content/Ctx.java
index 5db6c95..b6e0ada 100644
--- a/utils/src/main/java/com/thefinestartist/utils/content/Ctx.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/Ctx.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.content;
+package kr.lunaticbum.utils.content;
/**
* Ctx is abbreviation class of {@link ContextUtil}.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/Res.java b/utils/src/main/java/kr/lunaticbum/utils/content/Res.java
new file mode 100644
index 0000000..ada1061
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/Res.java
@@ -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 {
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/Res.kt b/utils/src/main/java/kr/lunaticbum/utils/content/Res.kt
new file mode 100644
index 0000000..c0f92ca
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/Res.kt
@@ -0,0 +1,8 @@
+package kr.lunaticbum.utils.content
+
+/**
+ * Res is abbreviation class of [ResourcesUtil].
+ *
+ * @author Leonardo Taehwan Kim
+ */
+//class Res : ResourcesUtil()
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.java b/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.java
new file mode 100644
index 0000000..05d991b
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.java
@@ -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;
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.kt
new file mode 100644
index 0000000..1d7ca34
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ResourcesUtil.kt
@@ -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 {
+ 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 {
+ 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
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.java b/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.java
new file mode 100644
index 0000000..0d5f0f9
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.java
@@ -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);
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.kt
new file mode 100644
index 0000000..64d3596
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/ThemeUtil.kt
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.java b/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.java
new file mode 100644
index 0000000..84f0774
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.java
@@ -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());
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.kt
new file mode 100644
index 0000000..303ea49
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/content/TypedValueUtil.kt
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/APILevel.java b/utils/src/main/java/kr/lunaticbum/utils/etc/APILevel.java
similarity index 99%
rename from utils/src/main/java/com/thefinestartist/utils/etc/APILevel.java
rename to utils/src/main/java/kr/lunaticbum/utils/etc/APILevel.java
index 0c872fb..7b3010d 100644
--- a/utils/src/main/java/com/thefinestartist/utils/etc/APILevel.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/APILevel.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.etc;
+package kr.lunaticbum.utils.etc;
import android.os.Build;
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/IntArrayUtil.java b/utils/src/main/java/kr/lunaticbum/utils/etc/IntArrayUtil.java
similarity index 94%
rename from utils/src/main/java/com/thefinestartist/utils/etc/IntArrayUtil.java
rename to utils/src/main/java/kr/lunaticbum/utils/etc/IntArrayUtil.java
index 3a5feff..45285d9 100755
--- a/utils/src/main/java/com/thefinestartist/utils/etc/IntArrayUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/IntArrayUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.etc;
+package kr.lunaticbum.utils.etc;
/**
* IntArrayUtil helps to manage IntArray conveniently.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.java b/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.java
new file mode 100644
index 0000000..50c0d5d
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.java
@@ -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);
+// }
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.kt
new file mode 100644
index 0000000..cb4f1de
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/PackageUtil.kt
@@ -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)
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/SparseArrayUtil.java b/utils/src/main/java/kr/lunaticbum/utils/etc/SparseArrayUtil.java
similarity index 93%
rename from utils/src/main/java/com/thefinestartist/utils/etc/SparseArrayUtil.java
rename to utils/src/main/java/kr/lunaticbum/utils/etc/SparseArrayUtil.java
index 66468a6..93ab640 100644
--- a/utils/src/main/java/com/thefinestartist/utils/etc/SparseArrayUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/SparseArrayUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.etc;
+package kr.lunaticbum.utils.etc;
import android.util.SparseArray;
diff --git a/utils/src/main/java/com/thefinestartist/utils/etc/ThreadUtil.java b/utils/src/main/java/kr/lunaticbum/utils/etc/ThreadUtil.java
similarity index 86%
rename from utils/src/main/java/com/thefinestartist/utils/etc/ThreadUtil.java
rename to utils/src/main/java/kr/lunaticbum/utils/etc/ThreadUtil.java
index 6bce5ae..b7b4512 100644
--- a/utils/src/main/java/com/thefinestartist/utils/etc/ThreadUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/ThreadUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.etc;
+package kr.lunaticbum.utils.etc;
import android.os.Looper;
diff --git a/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.java b/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.java
new file mode 100644
index 0000000..121f747
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.java
@@ -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 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);
+// }
+// }
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.kt
new file mode 100644
index 0000000..92152ab
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/etc/TypefaceUtil.kt
@@ -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()
+
+ 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
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/AndroidLogPrinter.java b/utils/src/main/java/kr/lunaticbum/utils/log/AndroidLogPrinter.java
similarity index 79%
rename from utils/src/main/java/com/thefinestartist/utils/log/AndroidLogPrinter.java
rename to utils/src/main/java/kr/lunaticbum/utils/log/AndroidLogPrinter.java
index 1725169..0e983a5 100644
--- a/utils/src/main/java/com/thefinestartist/utils/log/AndroidLogPrinter.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/AndroidLogPrinter.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.log;
+package kr.lunaticbum.utils.log;
/**
* AndroidLogPrinter log message via Android system.
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/FileLogPrinter.java b/utils/src/main/java/kr/lunaticbum/utils/log/FileLogPrinter.java
similarity index 95%
rename from utils/src/main/java/com/thefinestartist/utils/log/FileLogPrinter.java
rename to utils/src/main/java/kr/lunaticbum/utils/log/FileLogPrinter.java
index 9c6b194..769c613 100644
--- a/utils/src/main/java/com/thefinestartist/utils/log/FileLogPrinter.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/FileLogPrinter.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.log;
+package kr.lunaticbum.utils.log;
/**
* FileLogPrinter log message via file system.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/L.java b/utils/src/main/java/kr/lunaticbum/utils/log/L.java
new file mode 100644
index 0000000..40fcec5
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/L.java
@@ -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 {
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/L.kt b/utils/src/main/java/kr/lunaticbum/utils/log/L.kt
new file mode 100644
index 0000000..517f88e
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/L.kt
@@ -0,0 +1,8 @@
+package kr.lunaticbum.utils.log
+
+/**
+ * L is abbreviation class of [LogUtil].
+ *
+ * @author Leonardo Taehwan Kim
+ */
+//class L : LogUtil()
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.java b/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.java
new file mode 100644
index 0000000..a9ada6c
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.java
@@ -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());
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.kt b/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.kt
new file mode 100644
index 0000000..c4fd82a
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/LogHelper.kt
@@ -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()) (message as Array).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 =
+ "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/log/LogPrinter.java b/utils/src/main/java/kr/lunaticbum/utils/log/LogPrinter.java
similarity index 89%
rename from utils/src/main/java/com/thefinestartist/utils/log/LogPrinter.java
rename to utils/src/main/java/kr/lunaticbum/utils/log/LogPrinter.java
index 7245ca5..cebd186 100644
--- a/utils/src/main/java/com/thefinestartist/utils/log/LogPrinter.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/LogPrinter.java
@@ -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}.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.java b/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.java
new file mode 100644
index 0000000..c9bcce4
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.java
@@ -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);
+// }
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.kt
new file mode 100644
index 0000000..e061d0f
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/LogUtil.kt
@@ -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!!)
+ }
+// }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/Settings.java b/utils/src/main/java/kr/lunaticbum/utils/log/Settings.java
new file mode 100644
index 0000000..b03491d
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/Settings.java
@@ -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;
+// }
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/utils/log/Settings.kt b/utils/src/main/java/kr/lunaticbum/utils/log/Settings.kt
new file mode 100644
index 0000000..796c906
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/log/Settings.kt
@@ -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
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/preferences/Pref.java b/utils/src/main/java/kr/lunaticbum/utils/preferences/Pref.java
similarity index 75%
rename from utils/src/main/java/com/thefinestartist/utils/preferences/Pref.java
rename to utils/src/main/java/kr/lunaticbum/utils/preferences/Pref.java
index fd661c6..487dae7 100644
--- a/utils/src/main/java/com/thefinestartist/utils/preferences/Pref.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/preferences/Pref.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.preferences;
+package kr.lunaticbum.utils.preferences;
/**
* Pref is abbreviation class of {@link PreferencesUtil}.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.java b/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.java
new file mode 100755
index 0000000..981cfdd
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.java
@@ -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 get(String key, Set defValue) {
+// return get(defaultName, key, defValue);
+// }
+//
+// @TargetApi(Build.VERSION_CODES.FROYO)
+// public static 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 get(String name, String key, Set defValue) {
+// return getPreferences(name).getStringSet(key, defValue);
+// }
+//
+// @TargetApi(Build.VERSION_CODES.FROYO)
+// public static 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 value) {
+// put(defaultName, key, value);
+// }
+//
+// @TargetApi(Build.VERSION_CODES.FROYO)
+// public static 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 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 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();
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.kt
new file mode 100644
index 0000000..80a465f
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/preferences/PreferencesUtil.kt
@@ -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?): Set? {
+ return get(defaultName, key, defValue)
+ }
+
+ @TargetApi(Build.VERSION_CODES.FROYO)
+ fun 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?): Set? {
+ return getPreferences(name).getStringSet(key, defValue)
+ }
+
+ @TargetApi(Build.VERSION_CODES.FROYO)
+ fun 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?) {
+ put(defaultName, key, value)
+ }
+
+ @TargetApi(Build.VERSION_CODES.FROYO)
+ fun 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?) {
+ 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 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()
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.java b/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.java
new file mode 100644
index 0000000..12145bf
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.java
@@ -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();
+// }
+// }
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.kt
new file mode 100644
index 0000000..ef14af1
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/ClipboardManagerUtil.kt
@@ -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
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.java b/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.java
new file mode 100644
index 0000000..b6225a8
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.java
@@ -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);
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.kt
new file mode 100644
index 0000000..f2b3042
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/ServiceUtil.kt
@@ -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
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.java b/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.java
new file mode 100755
index 0000000..bc5ecee
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.java
@@ -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();
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.kt
new file mode 100644
index 0000000..f332c30
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/VibratorUtil.kt
@@ -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()
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.java b/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.java
new file mode 100644
index 0000000..bc9e99e
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.java
@@ -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);
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.kt
new file mode 100644
index 0000000..255ddca
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/service/WindowManagerUtil.kt
@@ -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)
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.java b/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.java
new file mode 100644
index 0000000..3db246b
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.java
@@ -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;
+// }
+//}
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.kt
new file mode 100644
index 0000000..0f87930
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/DisplayUtil.kt
@@ -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
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/utils/ui/Keyboard.java b/utils/src/main/java/kr/lunaticbum/utils/ui/Keyboard.java
similarity index 79%
rename from utils/src/main/java/com/thefinestartist/utils/ui/Keyboard.java
rename to utils/src/main/java/kr/lunaticbum/utils/ui/Keyboard.java
index ff224cc..90983bc 100644
--- a/utils/src/main/java/com/thefinestartist/utils/ui/Keyboard.java
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/Keyboard.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.utils.ui;
+package kr.lunaticbum.utils.ui;
/**
* Keyboard is abbreviation class of {@link KeyboardUtil}.
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.java b/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.java
new file mode 100644
index 0000000..76c12c0
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.java
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.kt
new file mode 100644
index 0000000..b3a6be4
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/KeyboardUtil.kt
@@ -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
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.java b/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.java
new file mode 100644
index 0000000..0c1d1cf
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.java
@@ -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));
+// }
+// }
+//}
\ No newline at end of file
diff --git a/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.kt b/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.kt
new file mode 100644
index 0000000..89ec832
--- /dev/null
+++ b/utils/src/main/java/kr/lunaticbum/utils/ui/ViewUtil.kt
@@ -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))
+ }
+ }
+}
\ No newline at end of file
diff --git a/utils/src/main/java/com/thefinestartist/wip/AgeUtil.java b/utils/src/main/java/kr/lunaticbum/wip/AgeUtil.java
similarity index 96%
rename from utils/src/main/java/com/thefinestartist/wip/AgeUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/AgeUtil.java
index 0856f9f..a97fa50 100755
--- a/utils/src/main/java/com/thefinestartist/wip/AgeUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/AgeUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist
diff --git a/utils/src/main/java/com/thefinestartist/wip/AudioManagerUtil.java b/utils/src/main/java/kr/lunaticbum/wip/AudioManagerUtil.java
similarity index 98%
rename from utils/src/main/java/com/thefinestartist/wip/AudioManagerUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/AudioManagerUtil.java
index 73c04d4..386d6b3 100644
--- a/utils/src/main/java/com/thefinestartist/wip/AudioManagerUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/AudioManagerUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/18/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/AwakeUtil.java b/utils/src/main/java/kr/lunaticbum/wip/AwakeUtil.java
similarity index 98%
rename from utils/src/main/java/com/thefinestartist/wip/AwakeUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/AwakeUtil.java
index dc78dbb..523b38b 100644
--- a/utils/src/main/java/com/thefinestartist/wip/AwakeUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/AwakeUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/10/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/BitmapUtil.java b/utils/src/main/java/kr/lunaticbum/wip/BitmapUtil.java
similarity index 99%
rename from utils/src/main/java/com/thefinestartist/wip/BitmapUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/BitmapUtil.java
index 985003e..f4d577f 100644
--- a/utils/src/main/java/com/thefinestartist/wip/BitmapUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/BitmapUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/9/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/DateUtil.java b/utils/src/main/java/kr/lunaticbum/wip/DateUtil.java
similarity index 98%
rename from utils/src/main/java/com/thefinestartist/wip/DateUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/DateUtil.java
index 6c237bb..1bd8c59 100644
--- a/utils/src/main/java/com/thefinestartist/wip/DateUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/DateUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 1/26/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/EmailUtil.java b/utils/src/main/java/kr/lunaticbum/wip/EmailUtil.java
similarity index 95%
rename from utils/src/main/java/com/thefinestartist/wip/EmailUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/EmailUtil.java
index bc36b3c..eb9fccd 100755
--- a/utils/src/main/java/com/thefinestartist/wip/EmailUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/EmailUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist
diff --git a/utils/src/main/java/com/thefinestartist/wip/FileUtil.java b/utils/src/main/java/kr/lunaticbum/wip/FileUtil.java
similarity index 94%
rename from utils/src/main/java/com/thefinestartist/wip/FileUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/FileUtil.java
index 7b369bb..ca3ddfa 100644
--- a/utils/src/main/java/com/thefinestartist/wip/FileUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/FileUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/10/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/LanguageDetector.java b/utils/src/main/java/kr/lunaticbum/wip/LanguageDetector.java
similarity index 98%
rename from utils/src/main/java/com/thefinestartist/wip/LanguageDetector.java
rename to utils/src/main/java/kr/lunaticbum/wip/LanguageDetector.java
index c68ee6e..651f74c 100644
--- a/utils/src/main/java/com/thefinestartist/wip/LanguageDetector.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/LanguageDetector.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2014. 9. 2..
diff --git a/utils/src/main/java/com/thefinestartist/wip/NetworkUtil.java b/utils/src/main/java/kr/lunaticbum/wip/NetworkUtil.java
similarity index 99%
rename from utils/src/main/java/com/thefinestartist/wip/NetworkUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/NetworkUtil.java
index 5f72f5f..6b35371 100644
--- a/utils/src/main/java/com/thefinestartist/wip/NetworkUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/NetworkUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/21/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/PhotoUtil.java b/utils/src/main/java/kr/lunaticbum/wip/PhotoUtil.java
similarity index 99%
rename from utils/src/main/java/com/thefinestartist/wip/PhotoUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/PhotoUtil.java
index 2a47b3d..eebdfb6 100755
--- a/utils/src/main/java/com/thefinestartist/wip/PhotoUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/PhotoUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist
diff --git a/utils/src/main/java/com/thefinestartist/wip/RippleUtil.java b/utils/src/main/java/kr/lunaticbum/wip/RippleUtil.java
similarity index 93%
rename from utils/src/main/java/com/thefinestartist/wip/RippleUtil.java
rename to utils/src/main/java/kr/lunaticbum/wip/RippleUtil.java
index 02669da..9942dcb 100644
--- a/utils/src/main/java/com/thefinestartist/wip/RippleUtil.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/RippleUtil.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/21/16.
diff --git a/utils/src/main/java/com/thefinestartist/wip/Validator.java b/utils/src/main/java/kr/lunaticbum/wip/Validator.java
similarity index 98%
rename from utils/src/main/java/com/thefinestartist/wip/Validator.java
rename to utils/src/main/java/kr/lunaticbum/wip/Validator.java
index 428c405..4021f1f 100644
--- a/utils/src/main/java/com/thefinestartist/wip/Validator.java
+++ b/utils/src/main/java/kr/lunaticbum/wip/Validator.java
@@ -1,4 +1,4 @@
-package com.thefinestartist.wip;
+package kr.lunaticbum.wip;
/**
* Created by TheFinestArtist on 2/18/16.