package io.kickflip.sdk.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public abstract class ImmersiveActivity extends Activity {
    public static final String TAG = "ImmersiveActivity";
    private boolean mUseImmersiveMode = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideSystemUi();
    }

    /**
     * If true, use Android's Immersive Mode. If false
     * use the "Lean Back" experience.
     * @see <a href="https://developer.android.com/design/patterns/fullscreen.html">Android Full Screen docs</a>
     * @param useIt
     */
    public void setUseImmersiveMode(boolean useIt) {
        mUseImmersiveMode = useIt;
    }

    private void hideSystemUi() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        if (!isKitKat() || !mUseImmersiveMode) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (isKitKat() && hasFocus && mUseImmersiveMode) {
            getWindow().getDecorView().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
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            );
        }
    }

    private boolean isKitKat() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    }
}

@@ -514,16 +514,150 @@
 State);%0A
+        requestWindowFeature(Window.FEATURE_NO_TITLE);%0A    %7D%0A%0A    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A
         
@@ -668,24 +668,24 @@
 SystemUi();%0A
-
     %7D%0A%0A    /
@@ -1055,63 +1055,8 @@
 ) %7B%0A
-        requestWindowFeature(Window.FEATURE_NO_TITLE);%0A
     
@@ -1242,16 +1242,92 @@
 CREEN);%0A
+        %7D else if (mUseImmersiveMode) %7B%0A            setKitKatWindowFlags();%0A
         
@@ -1550,32 +1550,166 @@
 siveMode) %7B%0A    
+        setKitKatWindowFlags();%0A        %7D%0A    %7D%0A%0A    @TargetApi(Build.VERSION_CODES.KITKAT)%0A    private void setKitKatWindowFlags() %7B%0A
         getWindo
@@ -1750,20 +1750,16 @@
 bility(%0A
-    
         
@@ -2147,24 +2147,10 @@
     
-    );%0A        %7D
+);
 %0A   

fix immersiveMode