Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fullscreen video player - mediacontroller behind navigation bar

I have a problem with mediacontroller which is hidden behind navigation bar (soft navigation keys on ICS). At first is OK (first picture), but when is navigation bar hidden for the first time, mediacontroller is resized to fit screen (correct), but is not resized back when navigation bar appears again (second picture). Also ad is moved behind (hidden for screenshot).

If I understand documentation correct fitsSystemWindows should be responsible for resizing. But it's not working.

How can I do that? Thanks for any help.

I'm testing this on Galaxy Nexus.

XML layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/playerLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="@color/black" >
<mynamespace.BKDVideoView
    android:id="@+id/videoview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"/>
<mynamespace.SubtitleTextView
    android:id="@+id/subtitleText"
    style="@style/SubtitleOverlayText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="30dp"
    android:gravity="center"
    android:visibility="gone"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true"/>
<FrameLayout
    android:id="@+id/adLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|right"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true"/>
<FrameLayout
    android:id="@+id/videoMediaControllerHolder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:animateLayoutChanges="true"/>

BKDVideoView is copy from GrepCode of VideoView with some customizations. I did the same for MediaController. In MediaController I'm calling hidding like that:

int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_STABLE;
    if (!visible)
    {
        newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }

    // mSystemUiHolder -> FrameLayout (playerLayout)
    mSystemUiHolder.setSystemUiVisibility(newVis);

When it's okWhen it's overlayed

Update: In case you have the same problem please check also comment in accepted answer. For views that needs to be fullscreen use sammyboy code. Thanks to both. Sorry, that I need too much time to figure this out and couldn't give you points :(

like image 773
zoki Avatar asked Nov 05 '12 17:11

zoki


2 Answers

this is systembar problem. Some devices fill_parent or match_parent entities has full screensizes and do not recognize systembar width and height. I suggest that: programmatically give an integer value to views. (calculate system bar width and height). and remove sb's width or height (landscape or portrait mode) from screensize and set this value to the views.

here the answer how to get screen dimensions etc.

like image 182
Barış Çırıka Avatar answered Oct 17 '22 13:10

Barış Çırıka


Look at this: http://bin-liu.blogspot.no/2012/03/how-to-hide-and-display-navigation-bar.html

public void onLayoutClicked(View v) {
    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}

.

Display display = getWindowManager().getDefaultDisplay();     
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
int rawWidth = (Integer) mGetRawW.invoke(display);
int rawHeight = (Integer) mGetRawH.invoke(display);
like image 28
sweggersen Avatar answered Oct 17 '22 14:10

sweggersen