/**
 * This file was auto-generated by the Titanium Module SDK helper for Android
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */
package com.alcoapps.actionbarextras;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;

import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.common.Log;

import android.app.Activity;
import android.app.ActionBar;
import android.view.ViewConfiguration;


@Kroll.module(name="Actionbarextras", id="com.alcoapps.actionbarextras")
public class ActionbarextrasModule extends KrollModule
{

	// Standard Debugging variables
	private static final String TAG = "ActionbarextrasModule";

	// You can define constants with @Kroll.constant, for example:
	// @Kroll.constant public static final String EXTERNAL_NAME = value;
	
	public ActionbarextrasModule()
	{
		super();
	}

	@Kroll.onAppCreate
	public static void onAppCreate(TiApplication app)
	{
		Log.d(TAG, "inside onAppCreate");
		// put module init code that needs to run when the application is created
		
		// hack taken from: http://stackoverflow.com/questions/9286822/how-to-force-use-of-overflow-menu-on-devices-with-menu-button
		try {
	        ViewConfiguration config = ViewConfiguration.get(app);
	        java.lang.reflect.Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
	        if(menuKeyField != null) {
	            menuKeyField.setAccessible(true);
	            menuKeyField.setBoolean(config, false);
	        }
	    } catch (Exception ex) {
	        // Ignore
	    }
	}

	// Methods
    @Kroll.method
    public void setExtras(KrollDict args)
    {
            Log.d(TAG, "called the setextras method");
            
            // declare stuff
            TiApplication appContext = TiApplication.getInstance();
            Activity activity = appContext.getCurrentActivity();
            ActionBar actionBar = activity.getActionBar();
            
            if (!TiApplication.isUIThread()) {
				
                if (args.containsKey("title")){
                    actionBar.setTitle((String) args.get("title"));
                }
                
                if (args.containsKey("subtitle")){
                    actionBar.setSubtitle((String) args.get("subtitle"));
                }
            }
    }
}


@@ -675,16 +675,95 @@
 ation;%0A%0A
+import android.graphics.Color;%0Aimport android.graphics.drawable.ColorDrawable;%0A
 %0A@Kroll.
@@ -2593,32 +2593,254 @@
               %7D%0A
+                %0A                if (args.containsKey(%22backgroundColor%22)) %7B%0A                    actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor((String) args.get(%22backgroundColor%22))));%0A                %7D%0A
             %7D%0A  

Add backgroundColor option to ActionBar