package com.sometrik.framework;

import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;

public class FWPopupView extends PopupWindow implements NativeCommandHandler {

  FrameWork frame;
  View parentView;
  int id;
  
  public FWPopupView(FrameWork frame, View parentView, int id){
    this.frame = frame;
    this.parentView = parentView;
    this.id = id;
  }

  @Override
  public void onScreenOrientationChange(boolean isLandscape) {
    
  }

  @Override
  public void addChild(View view) {
    System.out.println("setting new contentView for popupView");
    this.setContentView(view);
  }

  @Override
  public void addOption(int optionId, String text) {
    System.out.println("command couldn't be handled by popupView");
  }

  @Override
  public void addData(int rowNumber, int columnNumber, String text) {
    System.out.println("command couldn't be handled by popupView");
  }

  @Override
  public void setValue(String v) {
    System.out.println("command couldn't be handled by popupView");
  }

  @Override
  public void setValue(int v) {
    if (v == 1){
      showAtLocation(parentView, Gravity.CENTER, 0, 0);
    } else if (v <= 0){
      dismiss();
    }
  }

  @Override
  public void setViewEnabled(Boolean enabled) {
    if (enabled){
      showAtLocation(parentView, Gravity.CENTER, 0, 0);
    } else {
      dismiss();
    }
  }

  @Override
    public void setViewVisibility(boolean visible) {
    if (visible){
      showAtLocation(parentView, Gravity.CENTER, 0, 0);
    } else {
      dismiss();
    }
  }

  @Override
  public void setStyle(String key, String value) {
    System.out.println("command couldn't be handled by popupView");
  }

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

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

@@ -218,20 +218,19 @@
 rame;%0A  
-View
+int
  parentV
@@ -228,24 +228,26 @@
 t parentView
+Id
 ;%0A  int id;%0A
@@ -287,20 +287,19 @@
  frame, 
-View
+int
  parentV
@@ -301,16 +301,18 @@
 rentView
+Id
 , int id
@@ -357,16 +357,18 @@
 rentView
+Id
  = paren
@@ -372,16 +372,18 @@
 rentView
+Id
 ;%0A    th
@@ -1105,24 +1105,25 @@
 (v == 1)
+ 
 %7B%0A      
 showAtLo
@@ -1114,38 +1114,256 @@
 %7B%0A      
-showAtLocation(parentV
+System.out.println(%22Trying to show FWPopupView on parentViewId %22 + parentViewId);%0A      View view = (View)frame.views.get(parentViewId);%0A      if (view == null) %7B%0A%09System.out.println(%22view was null%22);%0A%09return;%0A      %7D%0A      showAtLocation(v
 iew, Gra
@@ -1404,16 +1404,17 @@
 (v %3C= 0)
+ 
 %7B%0A      
@@ -1526,32 +1526,54 @@
  showAtLocation(
+(View)frame.views.get(
 parentView, Grav
@@ -1558,32 +1558,35 @@
 s.get(parentView
+Id)
 , Gravity.CENTER
@@ -1739,16 +1739,38 @@
 ocation(
+(View)frame.views.get(
 parentVi
@@ -1771,16 +1771,19 @@
 rentView
+Id)
 , Gravit

Change parentView to use int and search