Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Jun 17, 2022
1 parent 00cba84 commit 8f78345
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public SmallVideoHelper(Context context, StandardGSYVideoPlayer player) {
* 处理全屏逻辑
*/
private void resolveToFull() {
systemUiVisibility = CommonUtil.getAppCompActivity(context).getWindow().getDecorView().getSystemUiVisibility();
systemUiVisibility = CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().getSystemUiVisibility();
CommonUtil.hideSupportActionBar(context, gsyVideoOptionBuilder.isHideActionBar(), gsyVideoOptionBuilder.isHideStatusBar());
if (gsyVideoOptionBuilder.isHideKey()) {
hideNavKey(context);
Expand Down Expand Up @@ -341,7 +341,7 @@ public void run() {
private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) {
listParent.getLocationOnScreen(listItemRect);
int statusBarH = getStatusBarHeight(context);
int actionBerH = getActionBarHeight(CommonUtil.getAppCompActivity(context));
int actionBerH = getActionBarHeight(CommonUtil.getActivityNestWrapper(context));
if (statusBar) {
listItemRect[1] = listItemRect[1] - statusBarH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void hideSupportActionBar(Context context, boolean actionBar, bool
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
CommonUtil.getAppCompActivity(context).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
CommonUtil.getActivityNestWrapper(context).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
Expand All @@ -157,46 +157,39 @@ public static void showSupportActionBar(Context context, boolean actionBar, bool
Activity activity = (Activity) context;
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
CommonUtil.getAppCompActivity(context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
CommonUtil.getActivityNestWrapper(context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
}

public static void hideNavKey(Context context) {
if (Build.VERSION.SDK_INT >= 29) {
// 设置屏幕始终在前面,不然点击鼠标,重新出现虚拟按键
CommonUtil.getAppCompActivity(context).getWindow().getDecorView().setSystemUiVisibility(
CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav
// bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);

} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// 设置屏幕始终在前面,不然点击鼠标,重新出现虚拟按键
CommonUtil.getAppCompActivity(context).getWindow().getDecorView().setSystemUiVisibility(
CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav
// bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
} else {
CommonUtil.getAppCompActivity(context).getWindow().getDecorView().setSystemUiVisibility(
CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav
);
}
}

public static void showNavKey(Context context, int systemUiVisibility) {
CommonUtil.getAppCompActivity(context).getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
}


/**
* Get AppCompatActivity from context
*
* @param context
* @return AppCompatActivity if it's not null
*/
public static AppCompatActivity getAppCompActivity(Context context) {
if (context == null) return null;
if (context instanceof AppCompatActivity) {
Expand All @@ -208,6 +201,17 @@ public static AppCompatActivity getAppCompActivity(Context context) {
}


/**
* Get Activity from context
*
* @param context
* @return AppCompatActivity if it's not null
*/
public static Activity getActivityNestWrapper(Context context) {
return getActivityContext(context);
}


/**
* dip转为PX
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void run() {
private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) {
mParent.getLocationOnScreen(mNormalItemRect);
int statusBarH = getStatusBarHeight(context);
int actionBerH = getActionBarHeight(CommonUtil.getAppCompActivity(context));
int actionBerH = getActionBarHeight(CommonUtil.getActivityNestWrapper(context));
if (statusBar) {
mNormalItemRect[1] = mNormalItemRect[1] - statusBarH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void resolveFullBtn() {
* 处理全屏逻辑
*/
private void resolveToFull() {
systemUiVisibility = CommonUtil.getAppCompActivity(context).getWindow().getDecorView().getSystemUiVisibility();
systemUiVisibility = CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().getSystemUiVisibility();
CommonUtil.hideSupportActionBar(context, hideActionBar, hideStatusBar);
if (hideKey) {
hideNavKey(context);
Expand Down Expand Up @@ -365,7 +365,7 @@ public void run() {
private void saveLocationStatus(Context context, boolean statusBar, boolean actionBar) {
listParent.getLocationOnScreen(listItemRect);
int statusBarH = getStatusBarHeight(context);
int actionBerH = getActionBarHeight(CommonUtil.getAppCompActivity(context));
int actionBerH = getActionBarHeight(CommonUtil.getActivityNestWrapper(context));
if (statusBar) {
listItemRect[1] = listItemRect[1] - statusBarH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ private void saveLocationStatus(Context context, boolean statusBar, boolean acti
getLocationOnScreen(mListItemRect);
if (context instanceof Activity) {
int statusBarH = getStatusBarHeight(context);
int actionBerH = getActionBarHeight(CommonUtil.getAppCompActivity(context));
boolean isTranslucent = ((WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS & CommonUtil.getAppCompActivity(context).getWindow().getAttributes().flags)
int actionBerH = getActionBarHeight(CommonUtil.getActivityNestWrapper(context));
boolean isTranslucent = ((WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS & CommonUtil.getActivityNestWrapper(context).getWindow().getAttributes().flags)
== WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Debuger.printfLog("*************isTranslucent*************** " + isTranslucent);
if (statusBar && !isTranslucent) {
Expand Down Expand Up @@ -631,7 +631,7 @@ public OrientationOption getOrientationOption() {
public GSYBaseVideoPlayer startWindowFullscreen(final Context context, final boolean actionBar, final boolean statusBar) {


mSystemUiVisibility = CommonUtil.getAppCompActivity(context).getWindow().getDecorView().getSystemUiVisibility();
mSystemUiVisibility = CommonUtil.getActivityNestWrapper(context).getWindow().getDecorView().getSystemUiVisibility();

hideSupportActionBar(context, actionBar, statusBar);

Expand Down

0 comments on commit 8f78345

Please sign in to comment.