admin
2020-07-14 7af22bf20c862c8ab2270cfeef8f3530f174ac9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.wpc.library.videocomponents;
 
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.os.Build;
import android.os.Handler;
import android.view.View;
 
public abstract class NavHiderCompat {
    
    public static NavHiderCompat getInstance(View view) {
        NavHiderCompat navHider;
        final int version = Build.VERSION.SDK_INT;
        if (version >= Build.VERSION_CODES.HONEYCOMB) {
            navHider = new NavHiderCompatHC(view);
        } else {
            navHider = null;
        }
        return navHider;
    }
    
    abstract public void setNavVisibility(boolean visible);
    
    @SuppressLint("NewApi")
    static class NavHiderCompatHC extends NavHiderCompat implements
            View.OnSystemUiVisibilityChangeListener, ActionBar.OnMenuVisibilityListener {
 
        private int mLastSystemUiVis;
        
        private View mView;
        
        public NavHiderCompatHC(View view) {
            super();
            mView = view;
            mView.setOnSystemUiVisibilityChangeListener(this);
        }
 
        @Override
        public void onMenuVisibilityChanged(boolean isVisible) {
            setNavVisibility(true);
        }
 
        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            // Detect when we go out of nav-hidden mode, to clear our state
            // back to having the full UI chrome up.  Only do this when
            // the state is changing and nav is no longer hidden.
            int diff = mLastSystemUiVis ^ visibility;
            mLastSystemUiVis = visibility;
            if ((diff & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
                    && (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                setNavVisibility(true);
            }
        }
        
        @Override
        public void setNavVisibility(boolean visible) {
            int newVis = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            if (!visible) {
                newVis |= View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            }
 
            // If we are now visible, schedule a timer for us to go invisible.
            if (visible) {
                Handler h = mView.getHandler();
                if (h != null) {
//                    h.removeCallbacks(mNavHider);
//                    if (!mMenusOpen && !mPaused) {
//                        // If the menus are open or play is paused, we will not auto-hide.
//                        h.postDelayed(mNavHider, 3000);
//                    }
                }
            }
 
            // Set the new desired visibility.
            mView.setSystemUiVisibility(newVis);
//            mNavVisible = visible;
        }
    }
}