/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2012 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 ti.modules.titanium.ui.widget.tabgroup;

import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.titanium.TiC;

import ti.modules.titanium.ui.TabProxy;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TiUIActionBarTab extends TiUIAbstractTab {

	public static class TabFragment extends Fragment {
		private View contentView;

		public void setContentView(View view) {
			contentView = view;
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
			return contentView;
		}
	}

	ActionBar.Tab tab;

	/**
	 * The fragment that will provide the content view of the tab.
	 * This fragment will be attached when the tab is selected and
	 * detached when it is later unselected. This reference will be
	 * initialized when the tab is first selected.
	 */
	TabFragment fragment;

	public TiUIActionBarTab(TabProxy proxy, ActionBar.Tab tab) {
		super(proxy);
		this.tab = tab;

		proxy.setModelListener(this);

		// Provide a reference to this instance by placing
		// a reference inside the "tag" slot that ActionBar.Tab provides.
		tab.setTag(this);

		Object title = proxy.getProperty(TiC.PROPERTY_TITLE);
		if (title != null) {
			tab.setText(title.toString());
		}
	}

	@Override
	public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) {
		if (key.equals(TiC.PROPERTY_TITLE)) {
			tab.setText(newValue.toString());
		}
	}

	/**
	 * Initialize this tab's fragment. Called by the tab group
	 * when the tab is first selected to create the fragment which
	 * will display the tab's content view.
	 */
	void initializeFragment() {
		fragment = new TabFragment();
		fragment.setContentView(getContentView());
	}

}

@@ -345,20 +345,112 @@
 tor.
-titanium.TiC
+kroll.common.Log;%0Aimport org.appcelerator.titanium.TiC;%0Aimport org.appcelerator.titanium.util.TiUIHelper
 ;%0A%0Ai
@@ -547,16 +547,59 @@
 agment;%0A
+import android.graphics.drawable.Drawable;%0A
 import a
@@ -767,16 +767,71 @@
 tTab %7B%0A%0A
+%09private static final String TAG = %22TiUIActionBarTab%22;%0A
 %09public 
@@ -1799,24 +1799,171 @@
 ing());%0A%09%09%7D%0A
+%09%09Object url = proxy.getProperty(TiC.PROPERTY_ICON);%0A%09%09if (url != null) %7B%0A%09%09%09Drawable icon = getDrawableFromUrl(url);%0A%09%09%09tab.setIcon(icon);%0A%09%09%7D%0A%09%09%0A
 %09%7D%0A%0A%09@Overri
@@ -2142,18 +2142,412 @@
 );%0A%09%09%7D%0A%09
-%7D%0A
+%09if (key.equals(TiC.PROPERTY_ICON)) %7B%0A%09%09%09Drawable icon = null;%0A%09%09%09if (newValue != null)%7B%0A%09%09%09%09icon = getDrawableFromUrl(newValue);%0A%09%09%09%7D%0A%09%09%09tab.setIcon(icon);%0A%09%09%7D%0A%09%7D%0A%0A%09private Drawable getDrawableFromUrl(Object url)%0A%09%7B%0A%09%09try %7B%0A%09%09%09return TiUIHelper.getResourceDrawable(url);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09Log.w(TAG, %22Could not load drawable %22+e.getMessage(), Log.DEBUG_MODE);%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%09
 %0A%09/**%0A%09 

Add support for ActionBarTab setIcon