/*
 * Copyright (c) 2017 UniqueStudio
 *
 *
 * This file is part of ParsingPlayer.
 *
 * ParsingPlayer is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with ParsingPlayer; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

package com.hustunique.parsingplayer.player.android;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;

import com.hustunique.parsingplayer.R;
import com.hustunique.parsingplayer.player.view.ParsingVideoView;
import com.orhanobut.logger.Logger;

/**
 * Created by JianGuo on 2/15/17.
 * Activity supporting playing video in fullscreen
 */
public class VideoActivity extends AppCompatActivity implements View.OnSystemUiVisibilityChangeListener {
    private static final String TAG = "VideoActivity";
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 2000;

    /**
     * Some older devices needs a small delay between UI widget updates
     * and a change of the status and navigation bar.
     */
    private static final int UI_ANIMATION_DELAY = 300;
    private ParsingVideoView mVideoView;
    private View mDecorView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDecorView = getWindow().getDecorView();
        mDecorView.setOnSystemUiVisibilityChangeListener(this);
        hideSystemUI();
        setContentView(R.layout.activity_video);
        mVideoView = (ParsingVideoView) findViewById(R.id.fullscreen_content);
        mVideoView.setRestoreListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    // This snippet hides the system bars.
    private void hideSystemUI() {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        mDecorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                        | View.SYSTEM_UI_FLAG_IMMERSIVE);
    }

    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0){
            Handler handler = new Handler(getMainLooper());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    hideSystemUI();
                }
            },AUTO_HIDE_DELAY_MILLIS);
        }
    }
}

@@ -2642,184 +2642,8 @@
 ) %7B%0A
-        // Set the IMMERSIVE flag.%0A        // Set the content to appear under the system bars so that the content%0A        // doesn't resize when the system bars hide and show.%0A
     
@@ -2679,33 +2679,16 @@
 ibility(
-%0A                
 View.SYS
@@ -2703,164 +2703,21 @@
 LAG_
-LAYOUT_STABLE%0A                        %7C View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION%0A                        %7C View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN%0A         
+FULLSCREEN %7C%0A
     
@@ -2719,33 +2719,32 @@
 %0A               
-%7C
  View.SYSTEM_UI_
@@ -2768,99 +2768,9 @@
 ION 
-// hide nav bar%0A                        %7C View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
+%7C
 %0A   
@@ -2785,18 +2785,8 @@
     
-         %7C
  Vie
@@ -2959,16 +2959,17 @@
 N) == 0)
+ 
 %7B%0A      
@@ -3179,32 +3179,32 @@
               %7D%0A
-
             %7D,AU
@@ -3201,16 +3201,17 @@
       %7D,
+ 
 AUTO_HID

fix immersive mode in VideoActivity