Skip to content

Commit

Permalink
Update AutoSizeUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
JessYanCoding authored Aug 9, 2019
1 parent 972374d commit 45fd66f
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,26 @@ public static int in2px(Context context, float value) {
public static int mm2px(Context context, float value) {
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

private static Application getApplicationByReflect() {
try {
@SuppressLint("PrivateApi")
Class<?> activityThread = Class.forName("android.app.ActivityThread");
Object thread = activityThread.getMethod("currentActivityThread").invoke(null);
Object app = activityThread.getMethod("getApplication").invoke(thread);
if (app == null) {
throw new NullPointerException("you should init first");
}
return (Application) app;
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
throw new NullPointerException("you should init first");
}
}

0 comments on commit 45fd66f

Please sign in to comment.