15

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 ok When 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 :(

zoki
  • 535
  • 1
  • 3
  • 17
  • How did you prepare a video screen like above. can you guide me to build a media controller like above. – madan V Nov 08 '13 at 18:43
  • As I said above it's a custom VideoView and MediaController. Then I have one FrameLayout which is transparent and fullscreen and contains two other views, top and bottom which have fixed size and are positioned top (layout_gravity=top) and bottom. Nothing special :) – zoki Nov 10 '13 at 12:32
  • can you post your source code. it will be very helpful to me. – madan V Nov 11 '13 at 05:00
  • 1
    Bottom controls: http://pastie.org/private/t2p0xkppk34ipl3in4888q – zoki Nov 11 '13 at 09:46
  • how did you manage the toggle screen. – madan V Dec 11 '13 at 12:17
  • what do you mean with toggle screen? – zoki Dec 22 '13 at 22:19
  • i am using a toggle button to switch b/w small screen and big screen. to do that i need to change the layout file while changing the layout i am suspending the video and resuming so it is taking some time to resume how can i over come that. i want to do it similar to you-tube how can i do that. – madan V Dec 23 '13 at 08:16
  • I don't have that. Probably you will have to do everything manually from code with hiding and showing items, which are all in one layout. Don't have any other idea how this could be done. – zoki Dec 23 '13 at 14:15
  • Thanks for reply, if you know anything related to this let me know. – madan V Dec 24 '13 at 05:16
  • @zoki: could you please teach me how to extend MediaController? I tried but failed a couple of times. – Behnam Mar 11 '14 at 11:25
  • You can't extend it ... ok, you can but it won't help you much. You should copy MediaController source code from grepcode. But because MediaController is private in VideoView you will have to copy also VideoView source code. And then in your local VideoView just change import to your local MediaController. – zoki Mar 11 '14 at 13:13
  • I had a related issue also - but I was using a scrollview as the root container instead, so doing mediaController.setAnchorView(scrollView); worked – Kevin Lee Jan 30 '16 at 16:14

5 Answers5

5

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.

Community
  • 1
  • 1
Barış Çırıka
  • 1,570
  • 1
  • 15
  • 24
  • With this methods I get size with navigation bar (1184x720). To get real size (1280x720) I need to invoke rawWidth (in Samyboy89 post). But if I set controls widht to display width it's ok then for navigation bars which are on right side. But if they are on bottom (tablets) then they are hidden behind :( Mediacontroller should be somehow aware of navigation bar, but I don't know know how to solve this :( – zoki Nov 15 '12 at 07:54
  • 3
    I investigated this a little more. android:fitsSystemWindows works only if activity is not fullscreen; and here I had a problem. In this case the only solution was to set programmaticaly width and height and set gravity top|left (like you said). Sorry that I can't give you points any more :( – zoki Nov 29 '12 at 20:36
4

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);
sweggersen
  • 2,342
  • 1
  • 22
  • 27
  • Thanks, I have this already. With first I hide a navigation bar (ok, a little different - http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)) and with second I resize video to match fullscreen. But I have a problem where controls also match fullscreen, but they shouldn't go that wide (should respect navigation bar). On tablet it's also a problem where they go too low, and are overlayed with navigation bar. I thinks that fitsSystemWindows should somehow solve that, but I don't know how :( – zoki Nov 15 '12 at 07:43
1

Use bringToFront() for the views to be at the top

Kavin Varnan
  • 1,989
  • 18
  • 23
  • It doesn't help:( I have updated first post with pictures to see better what's wrong. – zoki Nov 06 '12 at 07:40
1

Since VideoViews are SurfaceViews, they do not have the same behavior as a normal View. You need to ensure that it remains in the background by specifying:

videoview.setZOrderMediaOverlay(false);
Phil
  • 35,852
  • 23
  • 123
  • 164
  • I have tried this also, but it didn't help ... maybe I did something wrong. If I'm correct this is for z-ordering surafce views. I have only one (VideoView) and I think it's not a problem with z-order, but with size of controls (check comment @Samyboy89). – zoki Nov 15 '12 at 07:50
1

add android:fitsSystemWindows="false" inside your framelayout that contain the surfaceview.

and this code inside your activity

your_framelayout_here.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Sujith S Manjavana
  • 1,417
  • 6
  • 33
  • 60