android - Test for keepScreenOn attribute -


given have simple android activity following view code:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"              xmlns:tools="http://schemas.android.com/tools"              android:layout_width="match_parent"              android:layout_height="match_parent"              tools:ignore="mergerootframe"              android:keepscreenon="true">       <!-- more views -->  </framelayout> 

then:

how can test activity keep it's screen on , prevents tablet sleep?

sidenote:

if set flag_keep_screen_on flag in activity (oncreate) this:

@override protected void oncreate(final bundle savedinstancestate) {     super.oncreate(savedinstancestate);      getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on); } 

then can read via robolectric this:

public static int getwindowflags(final activity activity) throws exception {     class clazz = class.forname(window.class.getname());     method m = clazz.getmethod("getforcedwindowflags");      m.setaccessible(true);      return (int) m.invoke(activity.getwindow()); } 

however, flag not being set when single view within view hierarchy defines flag.

do need iterate views, find view defines this?

i searched robolectric sources flag , didn't find anything. i've created issue it.

you found workaround - set programmatically in case can test it. , can test without reflection:

assertthat( shadowwindow.getflag( windowmanager.layoutparams.flag_keep_screen_on ), is( true ) ); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -