package net.unbuensitio.statusbar.color.emui;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.apache.cordova.CordovaArgs;
import org.json.JSONException;

import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.graphics.Color;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager;

public class StatusbarTransparent extends CordovaPlugin {

	@Override
	public boolean execute(String action, final CordovaArgs args, CallbackContext callback) throws JSONException {
		// grab the correct methods
		if(action.equalsIgnoreCase("enable")) {
			if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
				cordova.getActivity().runOnUiThread( new Runnable() {
					public void run() {
						//cordova.getActivity().getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
						/*int color = Color.parseColor(preferences.getString("StatusBarBackgroundColor", "#4CAF50"));
						Window window = cordova.getActivity().getWindow();
						window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
						window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
						window.setStatusBarColor(color);*/
						Window window = cordova.getActivity().getWindow();
						window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
						window.setStatusBarColor(Color.parseColor("#0093DE"));
					}
				});
				callback.success();
			} else {
				callback.error("not supported");
			}
			return true;
		} else if(action.equalsIgnoreCase("color")) {
			if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
				cordova.getActivity().runOnUiThread( new Runnable() {
					public void run() {
						Window window = cordova.getActivity().getWindow();
						window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
						window.setStatusBarColor(Color.parseColor(args.getString(0)));
					}
				});
				callback.success();
			} else {
				callback.error("not supported");
			}
			return true;
		} else if(action.equalsIgnoreCase("disable")) {
			if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
				cordova.getActivity().runOnUiThread( new Runnable() {
					public void run() {
						cordova.getActivity().getWindow().clearFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
					}
				});
				callback.success();
			} else {
				callback.error("not supported");
			}
			return true;
		} else {
			callback.error("Unknown Action: " + action);
			return false;
		}
	}
}

@@ -531,16 +531,22 @@
 execute(
+final 
 String a
@@ -575,16 +575,22 @@
 gs args,
+ final
  Callbac
@@ -1649,57 +1649,8 @@
 ) %7B%0A
-%09%09%09if(VERSION.SDK_INT %3E= VERSION_CODES.KITKAT) %7B%0A
 %09%09%09%09
@@ -1695,32 +1695,47 @@
 ew Runnable() %7B%0A
+%09%09%09%09%09@Override%0A
 %09%09%09%09%09public void
@@ -1739,24 +1739,39 @@
 oid run() %7B%0A
+%09%09%09%09%09    try %7B%0A
 %09%09%09%09%09%09Window
@@ -1978,95 +1978,162 @@
 %09%09%09%09
-%7D%0A%09%09%09%09%7D);%0A%09%09%09%09callback.success();%0A%09%09%09%7D else %7B%0A%09%09%09%09callback.error(%22not supported%22);%0A%09%09%09%7D
+    %7D catch (JSONException ignore) %7B%0A%09%09%09%09%09%09LOG.e(TAG, %22Invalid hexString argument, use f.i. '#777777'%22);%0A%09%09%09%09%09    %7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D);%0A%09%09%09%09callback.success();
 %0A%09%09%09

Update StatusbarTransparent.java