package com.sometrik.framework;

import java.util.ArrayList;

import android.app.ActionBar;
import android.view.MenuItem;
import android.view.View;

public class FWActionBar implements NativeCommandHandler {
  
  int id;
  ActionBar actionBar;
  ArrayList<ActionBarItem> itemList;
  

  public FWActionBar(FrameWork frame, String title, int id){
    actionBar = frame.getActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(title);
    actionBar.show();
    itemList = new ArrayList<ActionBarItem>();
    this.id = id;
  }
  
  public ArrayList<ActionBarItem> getItemList(){
    return itemList;
  }
  
  @Override
  public void onScreenOrientationChange(boolean isLandscape) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addChild(View view) {
    System.out.println("Command couldn't be handled by FWActionBar");
  }

  @Override
  public void addOption(int optionId, String text) {
    itemList.add(new ActionBarItem(optionId, text, "default"));
  }

  @Override
  public void addData(String text, int row, int column, int sheet) {
    System.out.println("Command couldn't be handled by FWActionBar");
  }

  @Override
  public void setValue(String v) {
    actionBar.setTitle(v);
  }

  @Override
  public void setValue(int v) {
    if (v == 0){
      actionBar.hide();
    } else if (v == 1){
      actionBar.show();
    }
  }

  @Override
  public void setViewEnabled(Boolean enabled) {
    if (!enabled){
      actionBar.hide();
    } else {
      actionBar.show();
    }
  }

  @Override
  public void setViewVisibility(boolean visible) {
    if (!visible){
      actionBar.hide();
    } else {
      actionBar.show();
    }
  }

  @Override
  public void setStyle(String key, String value) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setError(boolean hasError, String errorText) {
    System.out.println("Command couldn't be handled by FWActionBar");
  }

  @Override
  public int getElementId() {
    return id;
  }

  
  public class ActionBarItem {

    int id;
    String name;
    String pictureAsset;

    public ActionBarItem(int id, String name, String pictureAsset) {
      this.id = id;
      this.name = name;
      this.pictureAsset = pictureAsset;
    }
  }

  @Override
  public void clear() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void flush() {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addColumn(String text, int columnType) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void reshape(int value, int size) {
    // TODO Auto-generated method stub
    
  }
}

@@ -26,16 +26,72 @@
 ework;%0A%0A
+import java.io.IOException;%0Aimport java.io.InputStream;%0A
 import j
@@ -160,21 +160,154 @@
 oid.
-view.MenuItem
+graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0Aimport android.graphics.drawable.BitmapDrawable;%0Aimport android.graphics.drawable.Drawable
 ;%0Aim
@@ -463,16 +463,35 @@
 emList;%0A
+  FrameWork frame;%0A
   %0A%0A  pu
@@ -543,24 +543,48 @@
 e, int id)%7B%0A
+    this.frame = frame;%0A
     actionBa
@@ -1995,47 +1995,276 @@
     
-// TODO Auto-generated method stub
+if (key.equals(%22icon%22))%7B%0A      try %7B%0A%09InputStream stream = frame.getAssets().open(value);%0A%09Bitmap b = BitmapFactory.decodeStream(stream);%0A%09;%0A%09Drawable d = new BitmapDrawable(b);%0A%09actionBar.setIcon(d);%0A      %7D catch (IOException e) %7B%0A%09e.printStackTrace();%0A      %7D
 %0A    
+%7D
 %0A  %7D

Add icon style