package com.githang.statusbar;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;


/**
 * 兼容KITKAT版本
 *
 * @author 黄浩杭 (huanghaohang@parkingwang.com)
 * @version 2016-06-20
 * @since 2016-06-20
 */

class StatusBarKitkatImpl implements IStatusBar {
    @TargetApi(Build.VERSION_CODES.KITKAT)
    public void setStatusBarColor(Window window, int color, boolean lightStatusBar) {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
        View statusBarView = new View(window.getContext());
        int statusBarHeight = getStatusBarHeight(window.getContext());
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, statusBarHeight);
        params.gravity = Gravity.TOP;
        statusBarView.setLayoutParams(params);
        statusBarView.setBackgroundColor(color);
        decorViewGroup.addView(statusBarView);
        StatusBarCompat.setFitsSystemWindows(window, true);

        StatusBarCompatFlavorRom.setLightStatusBar(window, lightStatusBar);
    }

    private static int getStatusBarHeight(Context context) {
        int statusBarHeight = 0;
        Resources res = context.getResources();
        int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = res.getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }
}

@@ -157,16 +157,41 @@
 .Build;%0A
+import android.util.Log;%0A
 import a
@@ -534,16 +534,90 @@
 usBar %7B%0A
+    private static final String STATUS_BAR_VIEW_TAG = %22ghStatusBarView%22;%0A%0A
     @Tar
@@ -918,39 +918,216 @@
 w = 
-new View(window.getContext());%0A
+decorViewGroup.findViewWithTag(STATUS_BAR_VIEW_TAG);%0A        if (statusBarView == null) %7B%0A            statusBarView = new View(window.getContext());%0A            statusBarView.setTag(STATUS_BAR_VIEW_TAG);%0A    
     
@@ -1185,32 +1185,36 @@
 .getContext());%0A
+    
         FrameLay
@@ -1333,16 +1333,20 @@
         
+   
+ 
 params.g
@@ -1367,16 +1367,20 @@
 ty.TOP;%0A
+    
         
@@ -1426,53 +1426,8 @@
     
-    statusBarView.setBackgroundColor(color);%0A
     
@@ -1469,16 +1469,75 @@
 rView);%0A
+        %7D%0A        statusBarView.setBackgroundColor(color);%0A
         
@@ -1588,17 +1588,16 @@
  true);%0A
-%0A
         

Fix #3, statusBarView will be recreate when reset status bar color