|
|
@@ -3,6 +3,7 @@ package com.mgtech.base_library.base;
|
|
|
import android.content.Context;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.content.res.Configuration;
|
|
|
+import android.content.res.TypedArray;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
@@ -19,6 +20,8 @@ import com.mgtech.base_library.language.LanguageUtil;
|
|
|
import com.mgtech.base_library.util.SharePrefUtil;
|
|
|
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
+
|
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.Unbinder;
|
|
|
|
|
|
@@ -68,16 +71,17 @@ public abstract class BaseActivity extends RxAppCompatActivity{
|
|
|
|
|
|
ARouter.getInstance().inject(this);
|
|
|
|
|
|
- initData();
|
|
|
|
|
|
- initView();
|
|
|
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
|
|
|
if (fullScreen){
|
|
|
setStatusBarBgColor();
|
|
|
setStatusBarTextColor(getStatusBarColor());
|
|
|
}
|
|
|
|
|
|
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
|
+ initData();
|
|
|
+
|
|
|
+ initView();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -86,6 +90,12 @@ public abstract class BaseActivity extends RxAppCompatActivity{
|
|
|
super.onDestroy();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void setRequestedOrientation(int requestedOrientation) {
|
|
|
+ if (isTranslucentOrFloating())
|
|
|
+ return;
|
|
|
+ super.setRequestedOrientation(requestedOrientation);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void attachBaseContext(Context newBase) {
|
|
|
@@ -164,4 +174,21 @@ public abstract class BaseActivity extends RxAppCompatActivity{
|
|
|
protected void setStatusBarColor(@ColorInt int statusBarColor) {
|
|
|
this.statusBarColor = statusBarColor;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private boolean isTranslucentOrFloating() {
|
|
|
+ boolean isTranslucentOrFloating = false;
|
|
|
+ try {
|
|
|
+ int[] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
|
|
|
+ final TypedArray ta = obtainStyledAttributes(styleableRes);
|
|
|
+ Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
|
|
|
+ m.setAccessible(true);
|
|
|
+ isTranslucentOrFloating = (boolean) m.invoke(null, ta);
|
|
|
+ m.setAccessible(false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return isTranslucentOrFloating;
|
|
|
+ }
|
|
|
}
|