package com.sometrik.framework;

import com.sometrik.framework.NativeCommand.Selector;

import android.graphics.Bitmap;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.PopupMenu;

public class FWActionSheet extends PopupMenu implements NativeCommandHandler {

  private FrameWork frame;
  private MenuInflater inflater;
  private Menu menu;
  private int id;
  
  public FWActionSheet(FrameWork frame, View anchor, int id) {
    super(frame, anchor);
    this.id = id;
    inflater = new MenuInflater(frame);
    menu = getMenu();
  }

  @Override
  public void onScreenOrientationChange(boolean isLandscape) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addChild(View view) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addOption(int optionId, String text) {
    menu.add(Menu.NONE, optionId, Menu.NONE, text);
  }

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

  @Override
  public void addData(String text, int row, int column, int sheet) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setValue(String v) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setBitmap(Bitmap bitmap) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void addImageUrl(String url, int width, int height) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void setValue(int v) {
    if (v > 0) {
      show();
    }
  }

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

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

  @Override
  public void setViewVisibility(boolean visible) {
    // TODO Auto-generated method stub
    
  }

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

  @Override
  public void setError(boolean hasError, String errorText) {
    // TODO Auto-generated method stub
    
  }

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

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

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

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

}

@@ -143,42 +143,8 @@
 nu;%0A
-import android.view.MenuInflater;%0A
 impo
@@ -320,68 +320,52 @@
 ate 
-MenuInflater inflater;%0A  private Menu menu;%0A  private int id
+int id;%0A  private boolean hasEntries = false
 ;%0A  
@@ -479,63 +479,115 @@
 %0A   
- inflater = new MenuInflater(frame);%0A    menu = getMenu
+%0A    // Add dummy entry, or the menu will not have any width%0A    getMenu().add(%22No menu entries%22);%0A    show
 ();%0A
@@ -669,54 +669,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -720,54 +720,8 @@
 w) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -789,20 +789,188 @@
 ) %7B%0A    
-m
+if (!hasEntries) %7B%0A      getMenu().clear();%0A      hasEntries = true;      %0A    %7D%0A    System.out.println(%22ActionSheet adding option %22 + optionId + %22 %22 + text);%0A    getM
 enu
+()
 .add(Men
@@ -1080,54 +1080,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1164,54 +1164,8 @@
 t) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1214,54 +1214,8 @@
 v) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1270,54 +1270,8 @@
 p) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1348,54 +1348,8 @@
 t) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1395,47 +1395,8 @@
 v) %7B
-%0A    if (v %3E 0) %7B%0A      show();%0A    %7D%0A 
  %7D%0A%0A
@@ -1455,54 +1455,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1504,54 +1504,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1570,54 +1570,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1655,54 +1655,8 @@
 e) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A 
  %7D%0A%0A
@@ -1731,224 +1731,86 @@
 t) %7B
-%0A    // TODO Auto-generated method stub%0A    %0A  %7D%0A%0A  @Override%0A  public void clear() %7B%0A    // TODO Auto-generated method stub%0A    %0A  %7D%0A%0A  @Override%0A  public void flush() %7B%0A    // TODO Auto-generated method stub%0A    %0A 
+ %7D%0A%0A  @Override%0A  public void clear() %7B %7D%0A%0A  @Override%0A  public void flush() %7B
  %7D%0A%0A
@@ -1860,47 +1860,18 @@
     
-// TODO Auto-generated method stub%0A    
+dismiss();
 %0A  %7D

make the ActionSheet work