沉浸式模式的相关说明再现每一个器件进入此模式时 [英] Immersive mode instructions reappear every time the device enters this mode

查看:617
本文介绍了沉浸式模式的相关说明再现每一个器件进入此模式时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用了全新的沉浸式模式,通过调用(在的onCreate ):

getWindow()getDecorView()setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

这个伟大的工程,但如何做弹出(从顶部向下滑动退出全屏)会在每次活动启动(如果手机而活动是显示被锁定)时,即使虽然用户确认弹出。据我了解,在弹出的是由系统自动产生的,所以有什么我可以做些什么来改变这种状况,是否正确?

这个问题是可重复的,如下所示:

  1. 在启动身临其境的活动[没有弹出窗口,只在第一个启动(正确)]
  2. preSS电源按钮以关闭屏幕,同时该活动展示
  3. preSS一次电源按钮在屏幕上切换
  4. 关闭调用结束活动()如从一个按钮或菜单选项
  5. 在再次启动活动 - 弹出再次出现

在弹出没有再出现,如果该活动启动,关闭,并重新启动没有击中的电源按钮之间。此外,它只是重新出现,如果活动是最顶端,而电源按钮是pressed。

解决方法:的的活动需要通过调用完成()(例如,从一个按钮或菜单选项)关闭。它工作正常,如果活动是由背键关闭。

我已上载这里一个示例应用程序:<一href="https://github.com/niko001/com.greatbytes.immersivebug/tree/master/Test5">https://github.com/niko001/com.greatbytes.immersivebug/tree/master/Test5

修改:现在有一个 Xposed模块禁用应急模式,所以我想我不是一个人在看到这是一个烦恼;)

解决方案

真有趣的问题!感谢您的明确指​​示,再现问题是不是一个问题。

好了,通源挖了差不多30分钟,并说以后他们为什么要这样做呢?一堆的时候,我想,我终于得到它。我会尽力解释尽我所能,但这只是我的跨pretation,可能不是正确的:

有人在机器人的实现的是,沉浸式模式将派人进入恐慌状态:如何退出? (_sorry,我不知道还有什么恐慌将是约_)

在恐慌这种状态下,用户会转向的电源按钮

....>电源按钮 - >用户打开屏幕关闭(在 X 毫秒,因为EPOCH)

....>祈祷导航栏回来

....>电源按钮 - >用户打开屏幕上(在毫秒,因为EPOCH)

现在,持续时间Ÿ - X 具有重要的意义。我们将稍后讨论这个问题,但首先,让我们来看看如何恐慌定义:

恐慌发生在祈祷导航栏伤愈复出持续时间不超过5秒。此值召开方式:

  mPanicThresholdMs = context.getResources()
                 .getInteger(R.integer.config_immersive_mode_confirmation_panic);

&LT;! - 阈值(毫秒)下屏幕关闭/屏幕上会被视为
     的身临其境的方式确认提示复位.--&GT;
&LT;整数NAME =config_immersive_mode_confirmation_panic&GT; 5000&LT; /整数GT;
 

嗯,好吧。所以,它并不重要,如果有已经确认一旦用户,该提示会回来如果上述准则得到满足。 - 甚至在第100发射

和这里的地方的动作发生:

 公共无效onPowerKeyDown(布尔isScreenOn,很长一段时间,布尔inImmersiveMode){
    如果(mPanicPackage =空&安培;&安培; isScreenOn&安培;及(时间 -  mPanicTime&所述;!mPanicThresholdMs)){
        //打开屏幕的背面上内恐慌门槛
        unconfirmPackage(mPanicPackage);
    }
    如果(isScreenOn&安培;&安培; inImmersiveMode){
        //转动屏幕关闭,请记住,如果我们在身临其境的模式
        mPanicTime =时间;
        mPanicPackage = mLastPackage;
    } 其他 {
        mPanicTime = 0;
        mPanicPackage = NULL;
    }
}
 

  

(时间 - mPanicTime&LT; mPanicThresholdMs)==>(Y - X)&LT; 5000

unconfirmPackage(mPanicPackage) mPanicPackage (你的)从下 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS 。

不用说,我觉得这个奇怪......与错。即使用户是在恐慌,并采取了电源按钮的路线,他/她将看不到有帮助的提醒,直到下次启动。那么,有什么意义呢?

或可能是我错了恐慌的定义。

  

所以有什么我可以做些什么来改变这种状况,是否正确?

正确的。为了解决这个问题,你就必须添加你的包名由 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS 持有价值。但是,写一个安全的环境,你的应用程序需要 WRITE_SECURE_SETTINGS 权限 - 而不是通过第三方应用

链接:

<一个href="https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/policy/src/com/android/internal/policy/impl/ImmersiveModeConfirmation.java">ImmersiveModeConfirmation (管理显示辅助类/隐藏确认提示)

My app uses the new "immersive mode" by calling (in onCreate):

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

This works great, but the "how-to" popup ("Swipe down from the top to exit full screen") appears every time the Activity is launched (if the phone is being locked while the activity was showing), even though the user has acknowledged the popup. As far as I understand, the popup is automatically generated by the system, so there's nothing I can do to change this situation, correct?

This issue is reproducible as follows:

  1. Launch immersive Activity [no popup appears, only on the very first launch (correctly)]
  2. Press the power button to switch off screen while the activity is showing
  3. Press power button again to switch on screen
  4. Close Activity by calling finish() e.g. from a button or menu option
  5. Launch Activity again - popup reappears

The popup does NOT reappear if the activity is launched, closed, and relaunched without hitting the power-button in between. Also, it ONLY reappears if the activity was topmost while the power button was pressed.

Correction: The Activity needs to be closed by calling "finish()" (e.g. from a button or a menu option). It works correctly if the Activity is closed by the back-key.

I've uploaded a sample app here: https://github.com/niko001/com.greatbytes.immersivebug/tree/master/Test5

EDIT: There's now an Xposed module to disable the "panic mode", so I guess I'm not alone in seeing this is an annoyance ;)

解决方案

Really interesting question! Thanks to your clear instructions, reproducing the issue wasn't a problem.

Alright, after digging through the source for almost 30-minutes and saying why would they do this? a bunch of times, I think I finally get it. I'll try to explain the best I can, but this is only my interpretation, and may not be correct:

Someone at android realized that the Immersive Mode will send people into a state of panic: how do i exit? (_sorry, I don't know what else the panic would be about_).

In this state of panic, the user will turn to the POWER BUTTON

.... > Power button --> User turns screen off (at x milliseconds since EPOCH)

.... > Praying that the navigation bar comes back

.... > Power button --> User turns screen on (at y milliseconds since EPOCH)

Now, the duration y - x is of significance. We'll discuss it a bit later, but first, let's look at how panic is defined:

panic happens when Praying the navigation bar comes back lasts less than 5 seconds. This value is held by:

mPanicThresholdMs = context.getResources()
                 .getInteger(R.integer.config_immersive_mode_confirmation_panic);

<!-- Threshold (in ms) under which a screen off / screen on will be considered 
     a reset of the immersive mode confirmation prompt.-->
<integer name="config_immersive_mode_confirmation_panic">5000</integer>

Ah, okay. So, it doesn't matter if the user has already acknowledged once, the prompt will be back if the above-mentioned criterion is met - even on the 100th launch.

And here's where the action happens:

public void onPowerKeyDown(boolean isScreenOn, long time, boolean inImmersiveMode) {
    if (mPanicPackage != null && !isScreenOn && (time - mPanicTime < mPanicThresholdMs)) {
        // turning the screen back on within the panic threshold
        unconfirmPackage(mPanicPackage);
    }
    if (isScreenOn && inImmersiveMode) {
        // turning the screen off, remember if we were in immersive mode
        mPanicTime = time;
        mPanicPackage = mLastPackage;
    } else {
        mPanicTime = 0;
        mPanicPackage = null;
    }
}

(time - mPanicTime < mPanicThresholdMs) ==> ( y - x ) < 5000

unconfirmPackage(mPanicPackage) removes mPanicPackage (yours) from the list of packages stored under Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS.

Needless to say, I find this strange... and wrong. Even if the user is in panic, and takes the power button route, s/he won't see the helpful reminder until next launch. So, what's the point?

Or may be, I am wrong about the definition of panic.

so there's nothing I can do to change this situation, correct?

Correct. To fix this, you would have to add your package-name to value held by Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS. But, to write to a secure setting, your app requires WRITE_SECURE_SETTINGS permission - not for use by third-party applications.

Links:

ImmersiveModeConfirmation (helper class that manages showing/hiding of confirmation prompt)

这篇关于沉浸式模式的相关说明再现每一个器件进入此模式时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆