SystemUtils类处理
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -32,7 +33,6 @@ import com.chwl.app.R;
|
||||
import com.chwl.app.ui.widget.magicindicator.buildins.UIUtil;
|
||||
import com.chwl.app.utils.BlurTransformation;
|
||||
import com.chwl.core.utils.LogUtils;
|
||||
import com.chwl.core.utils.SystemUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -438,7 +438,8 @@ public class ImageLoadUtils {
|
||||
|
||||
|
||||
public static void clearMemory(Context context) {
|
||||
if (SystemUtils.isMainThread()) {
|
||||
// if (SystemUtils.isMainThread()) {
|
||||
if (Looper.getMainLooper() == Looper.myLooper()) {
|
||||
Glide.get(context.getApplicationContext()).clearMemory();
|
||||
}
|
||||
}
|
||||
|
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.chwl.core.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.chwl.library.utils.config.BasicConfig;
|
||||
import com.chwl.library.utils.log.MLog;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author daixiang
|
||||
*
|
||||
*/
|
||||
public final class SystemUtils {
|
||||
|
||||
public static final String TAG = "SystemUtils";
|
||||
|
||||
public static boolean isMainThread() {
|
||||
|
||||
return Looper.getMainLooper() == Looper.myLooper();
|
||||
}
|
||||
|
||||
/**
|
||||
* MediaSessionLegacyHelper is a static singleton that is lazily instantiated and keeps a
|
||||
* reference to the context it's given the first time MediaSessionLegacyHelper.getHelper()
|
||||
* is called.
|
||||
* This leak was introduced in android-5.0.1_r1 and fixed in Android 5.1.0_r1 by calling
|
||||
* context.getApplicationContext().
|
||||
* Fix: https://github.com/android/platform_frameworks_base/commit/9b5257c9c99c4cb541d8e8e78fb04f008b1a9091
|
||||
*
|
||||
* Hack: to fix this, you could call MediaSessionLegacyHelper.getHelper() early in
|
||||
* Application.onCreate() and pass it the application context.
|
||||
* https://github.com/square/leakcanary/blob/master/leakcanary-android/src/main/java/com/squareup/leakcanary/AndroidExcludedRefs.java
|
||||
*/
|
||||
public static void fixMediaSessionLegacyHelper() {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT != 21) {
|
||||
MLog.info(TAG, "fixMediaSessionLegacyHelper api:" + Build.VERSION.SDK_INT);
|
||||
return;
|
||||
}
|
||||
Class cls = Class.forName("android.media.session.MediaSessionLegacyHelper");
|
||||
if (cls == null) {
|
||||
return;
|
||||
}
|
||||
Method method = cls.getMethod("getHelper", Context.class);
|
||||
method.invoke(null, BasicConfig.INSTANCE.getAppContext());
|
||||
MLog.info(TAG, "fixMediaSessionLegacyHelper done!");
|
||||
} catch (Throwable throwable) {
|
||||
MLog.error(TAG, "fixMediaSessionLegacyHelper error! " + throwable);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -63,7 +63,7 @@ import com.chwl.library.easyphoto.utils.media.MediaScannerConnectionUtils;
|
||||
import com.chwl.library.easyphoto.utils.permission.PermissionUtil;
|
||||
import com.chwl.library.easyphoto.utils.settings.SettingsUtils;
|
||||
import com.chwl.library.easyphoto.utils.string.StringUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.SystemUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.EPSystemUtils;
|
||||
import com.chwl.library.easyphoto.utils.uri.UriUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -163,7 +163,7 @@ public class EasyPhotosActivity extends AppCompatActivity implements AlbumItemsA
|
||||
statusColor = ContextCompat.getColor(this, R.color.colorPrimaryDark);
|
||||
}
|
||||
if (ColorUtils.isWhiteColor(statusColor)) {
|
||||
SystemUtils.getInstance().setStatusDark(this, true);
|
||||
EPSystemUtils.getInstance().setStatusDark(this, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ import com.chwl.library.easyphoto.ui.widget.PressedTextView;
|
||||
import com.chwl.library.easyphoto.models.album.AlbumModel;
|
||||
import com.chwl.library.easyphoto.models.album.entity.Photo;
|
||||
import com.chwl.library.easyphoto.utils.color.ColorUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.SystemUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.EPSystemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class PreviewActivity extends AppCompatActivity implements PreviewPhotosA
|
||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemUtils.getInstance().systemUiHide(PreviewActivity.this, decorView);
|
||||
EPSystemUtils.getInstance().systemUiHide(PreviewActivity.this, decorView);
|
||||
}
|
||||
};
|
||||
private RelativeLayout mBottomBar;
|
||||
@@ -99,7 +99,7 @@ public class PreviewActivity extends AppCompatActivity implements PreviewPhotosA
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
decorView = getWindow().getDecorView();
|
||||
SystemUtils.getInstance().systemUiInit(this, decorView);
|
||||
EPSystemUtils.getInstance().systemUiInit(this, decorView);
|
||||
|
||||
setContentView(R.layout.activity_preview_easy_photos);
|
||||
|
||||
@@ -189,7 +189,7 @@ public class PreviewActivity extends AppCompatActivity implements PreviewPhotosA
|
||||
|
||||
private void show() {
|
||||
// Show the system bar
|
||||
SystemUtils.getInstance().systemUiShow(this, decorView);
|
||||
EPSystemUtils.getInstance().systemUiShow(this, decorView);
|
||||
|
||||
mVisible = true;
|
||||
|
||||
@@ -224,12 +224,12 @@ public class PreviewActivity extends AppCompatActivity implements PreviewPhotosA
|
||||
setClick(R.id.iv_back, R.id.tv_edit, R.id.tv_selector);
|
||||
|
||||
mToolBar = (FrameLayout) findViewById(R.id.m_top_bar_layout);
|
||||
if (!SystemUtils.getInstance().hasNavigationBar(this)) {
|
||||
if (!EPSystemUtils.getInstance().hasNavigationBar(this)) {
|
||||
FrameLayout mRootView = (FrameLayout) findViewById(R.id.m_root_view);
|
||||
mRootView.setFitsSystemWindows(true);
|
||||
mToolBar.setPadding(0, SystemUtils.getInstance().getStatusBarHeight(this), 0, 0);
|
||||
mToolBar.setPadding(0, EPSystemUtils.getInstance().getStatusBarHeight(this), 0, 0);
|
||||
if (ColorUtils.isWhiteColor(statusColor)) {
|
||||
SystemUtils.getInstance().setStatusDark(this, true);
|
||||
EPSystemUtils.getInstance().setStatusDark(this, true);
|
||||
}
|
||||
}
|
||||
mBottomBar = (RelativeLayout) findViewById(R.id.m_bottom_bar);
|
||||
|
@@ -34,7 +34,7 @@ import com.chwl.library.easyphoto.models.album.AlbumModel;
|
||||
import com.chwl.library.easyphoto.models.album.entity.Photo;
|
||||
import com.chwl.library.easyphoto.ui.adapter.PuzzleSelectorPreviewAdapter;
|
||||
import com.chwl.library.easyphoto.utils.color.ColorUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.SystemUtils;
|
||||
import com.chwl.library.easyphoto.utils.system.EPSystemUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class PuzzleSelectorActivity extends AppCompatActivity implements View.On
|
||||
statusColor = ContextCompat.getColor(this, R.color.easy_photos_status_bar);
|
||||
}
|
||||
if (ColorUtils.isWhiteColor(statusColor)) {
|
||||
SystemUtils.getInstance().setStatusDark(this, true);
|
||||
EPSystemUtils.getInstance().setStatusDark(this, true);
|
||||
}
|
||||
}
|
||||
albumModel = AlbumModel.getInstance();
|
||||
|
@@ -20,14 +20,14 @@ import java.lang.reflect.Method;
|
||||
* Created by huan on 2017/11/13.
|
||||
*/
|
||||
|
||||
public class SystemUtils {
|
||||
private static SystemUtils instance = null;
|
||||
public class EPSystemUtils {
|
||||
private static EPSystemUtils instance = null;
|
||||
private Boolean hasNavigation = null;//是否有导航栏
|
||||
|
||||
/**
|
||||
* 私有构造方法
|
||||
*/
|
||||
private SystemUtils() {
|
||||
private EPSystemUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,11 +35,11 @@ public class SystemUtils {
|
||||
*
|
||||
* @return 单例
|
||||
*/
|
||||
public static SystemUtils getInstance() {
|
||||
public static EPSystemUtils getInstance() {
|
||||
if (null == instance) {
|
||||
synchronized (SystemUtils.class) {
|
||||
synchronized (EPSystemUtils.class) {
|
||||
if (null == instance) {
|
||||
instance = new SystemUtils();
|
||||
instance = new EPSystemUtils();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user