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
Post a Comment