package com.sometrik.framework;

import com.sometrik.framework.NativeCommand.Selector;

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

public class FWActionSheet extends PopupMenu implements NativeCommandHandler {

  private FrameWork frame;
  private int id;
  private boolean hasEntries = false;
  
  public FWActionSheet(FrameWork frame, View anchor, int id) {
    super(frame, anchor);
    this.id = id;
   
    // Add dummy entry, or the menu will not have any width
    getMenu().add("No menu entries");
    show();
  }

  @Override
  public void onScreenOrientationChange(boolean isLandscape) { }

  @Override
  public void addChild(View view) { }

  @Override
  public void addOption(int optionId, String text) {
    if (!hasEntries) {
      getMenu().clear();
      hasEntries = true;      
    }
    System.out.println("ActionSheet adding option " + optionId + " " + text);
    getMenu().add(Menu.NONE, optionId, Menu.NONE, text);
  }

  @Override
  public void addColumn(String text, int columnType) { }

  @Override
  public void addData(String text, int row, int column, int sheet) { }

  @Override
  public void setValue(String v) { }

  @Override
  public void setBitmap(Bitmap bitmap) { }

  @Override
  public void addImageUrl(String url, int width, int height) { }

  @Override
  public void setValue(int v) { }

  @Override
  public void reshape(int value, int size) { }

  @Override
  public void reshape(int size) { }

  @Override
  public void setViewVisibility(boolean visible) { }

  @Override
  public void setStyle(Selector selector, String key, String value) { }

  @Override
  public void setError(boolean hasError, String errorText) { }

  @Override
  public void clear() { }

  @Override
  public void flush() { }

  @Override
  public void deinitialize() {
    dismiss();
  }

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

}

@@ -139,16 +139,46 @@
 w.Menu;%0A
+import android.view.MenuItem;%0A
 import a
@@ -311,36 +311,8 @@
 er %7B
-%0A%0A  private FrameWork frame;
 %0A  p
@@ -390,16 +390,22 @@
 onSheet(
+final 
 FrameWor
@@ -425,16 +425,22 @@
  anchor,
+ final
  int id)
@@ -489,16 +489,423 @@
  id;%0A   
+    %0A    this.setOnDismissListener(new OnDismissListener() %7B%0A      @Override%0A      public void onDismiss(PopupMenu arg0) %7B%0A%09frame.intChangedEvent(id, 0, 0);     %09  %0A      %7D%0A    %7D);%0A    %0A    this.setOnMenuItemClickListener(new OnMenuItemClickListener() %7B%0A      @Override%0A      public boolean onMenuItemClick(MenuItem item) %7B%0A%09frame.intChangedEvent(id, item.getItemId(), 0);%0A%09return true;%0A      %7D%0A    %7D);%0A    
 %0A    // 
@@ -1295,86 +1295,8 @@
   %7D%0A
-    System.out.println(%22ActionSheet adding option %22 + optionId + %22 %22 + text);%0A
     

add listeners. Fixes #411