forked from kymjs/Common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
张涛
committed
Oct 12, 2016
1 parent
cc892fc
commit 0e7e13b
Showing
6 changed files
with
217 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.kymjs.common; | ||
|
||
import android.app.Application; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Created by ZhangTao on 10/12/16. | ||
*/ | ||
public class App { | ||
|
||
public static final Application INSTANCE; | ||
|
||
static { | ||
Application app = null; | ||
try { | ||
app = (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null); | ||
if (app == null) | ||
throw new IllegalStateException("Static initialization of Applications must be on main thread."); | ||
} catch (final Exception e) { | ||
LogUtils.e("Failed to get current application from AppGlobals." + e.getMessage()); | ||
try { | ||
app = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); | ||
} catch (final Exception ex) { | ||
LogUtils.e("Failed to get current application from ActivityThread." + e.getMessage()); | ||
} | ||
} finally { | ||
INSTANCE = app; | ||
} | ||
} | ||
|
||
public static void toast(String msg) { | ||
Toast.makeText(INSTANCE, msg, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
public static void toast(int msgId) { | ||
Toast.makeText(INSTANCE, msgId, Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
public static void longToast(String msg) { | ||
Toast.makeText(INSTANCE, msg, Toast.LENGTH_LONG).show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
Common/common/src/main/java/com/kymjs/common/LogUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.kymjs.common; | ||
|
||
// | ||
// Source code recreated from a .class file by IntelliJ IDEA | ||
// (powered by Fernflower decompiler) | ||
// | ||
|
||
import android.util.Log; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by ZhangTao on 10/12/16. | ||
*/ | ||
public class LogUtils { | ||
public static boolean mLogEnable = true; | ||
private static String mClassname = LogUtils.class.getName(); | ||
private static ArrayList<String> mMethods = new ArrayList<>(); | ||
|
||
public static void setEnable(boolean logEnable) { | ||
mLogEnable = logEnable; | ||
} | ||
|
||
public static void d(String tag, String msg) { | ||
if (mLogEnable) { | ||
Log.d(tag, getMsgWithLineNumber(msg)); | ||
} | ||
|
||
} | ||
|
||
public static void e(String tag, String msg) { | ||
if (mLogEnable) { | ||
Log.e(tag, getMsgWithLineNumber(msg)); | ||
} | ||
|
||
} | ||
|
||
public static void i(String tag, String msg) { | ||
if (mLogEnable) { | ||
Log.i(tag, getMsgWithLineNumber(msg)); | ||
} | ||
|
||
} | ||
|
||
public static void w(String tag, String msg) { | ||
if (mLogEnable) { | ||
Log.w(tag, getMsgWithLineNumber(msg)); | ||
} | ||
|
||
} | ||
|
||
public static void v(String tag, String msg) { | ||
if (mLogEnable) { | ||
Log.v(tag, getMsgWithLineNumber(msg)); | ||
} | ||
|
||
} | ||
|
||
public static void d(String msg) { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(msg); | ||
Log.d(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static void e(String msg) { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(msg); | ||
Log.e(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static void i(String msg) { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(msg); | ||
Log.i(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static void i() { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(""); | ||
Log.i(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static void w(String msg) { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(msg); | ||
Log.w(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static void v(String msg) { | ||
if (mLogEnable) { | ||
String[] content = getMsgAndTagWithLineNumber(msg); | ||
Log.v(content[0], content[1]); | ||
} | ||
|
||
} | ||
|
||
public static String getMsgWithLineNumber(String msg) { | ||
try { | ||
StackTraceElement[] e = (new Throwable()).getStackTrace(); | ||
int var2 = e.length; | ||
|
||
for (StackTraceElement st : e) { | ||
if (!mClassname.equals(st.getClassName()) && !mMethods.contains(st.getMethodName())) { | ||
int b = st.getClassName().lastIndexOf(".") + 1; | ||
String TAG = st.getClassName().substring(b); | ||
return TAG + "->" + st.getMethodName() + "():" + st.getLineNumber() + "->" + msg; | ||
} | ||
} | ||
} catch (Exception var8) { | ||
} | ||
|
||
return msg; | ||
} | ||
|
||
public static String[] getMsgAndTagWithLineNumber(String msg) { | ||
try { | ||
StackTraceElement[] e = (new Throwable()).getStackTrace(); | ||
int var2 = e.length; | ||
|
||
for (StackTraceElement st : e) { | ||
if (!mClassname.equals(st.getClassName()) && !mMethods.contains(st.getMethodName())) { | ||
int b = st.getClassName().lastIndexOf(".") + 1; | ||
String TAG = st.getClassName().substring(b); | ||
String message = st.getMethodName() + "():" + st.getLineNumber() + "->" + msg; | ||
return new String[]{TAG, message}; | ||
} | ||
} | ||
} catch (Exception var9) { | ||
} | ||
|
||
return new String[]{"universal tag", msg}; | ||
} | ||
|
||
static { | ||
Method[] ms = LogUtils.class.getDeclaredMethods(); | ||
for (Method m : ms) { | ||
mMethods.add(m.getName()); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ DEVELOPER_NAME=ZhangTao | |
DEVELOPER_EMAIL=[email protected] | ||
|
||
COMMON_MODULE_NAME=common | ||
COMMON_MODULE_VERSION=1.0.2 | ||
COMMON_MODULE_VERSION=1.0.4 | ||
|
||
KOTLIN_COMMON_MODULE_NAME=kotlin-common | ||
KOTLIN_COMMON_MODULE_VERSION=1.0.0 |