package com.sometrik.framework;

import java.util.ArrayList;

import com.sometrik.framework.NativeCommand.Selector;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class FWPicker extends Spinner implements NativeCommandHandler { 
  private FrameWork frame;
  private ArrayAdapter<String> adapter;
  private ArrayList<Integer> idList;

  public FWPicker(FrameWork frameWork) {
    super(frameWork);
    this.frame = frameWork;
    adapter = new ArrayAdapter<String>(frame, android.R.layout.simple_spinner_item);
    idList = new ArrayList<Integer>();
    
    setOnItemSelectedListener(new OnItemSelectedListener() {

      @Override
      public void onItemSelected(AdapterView<?> view, View arg1, int position, long itemId) {
	frame.sendNativeValueEvent(getId(), idList.get(position), 0);
      }

      @Override
      public void onNothingSelected(AdapterView<?> arg0) {
      }
    });
  }

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

  @Override
  public void addChild(View view) {
    System.out.println("Picker couldn't handle addChild");
    //TODO
  }

  @Override
  public void addOption(int optionId, String text) {
    idList.add(optionId);
    adapter.add(text);
    setAdapter(adapter);
  }

  @Override
  public void setValue(String v) {

  }

  @Override
  public void setValue(int v) {

  }

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

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

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

  @Override
  public void addData(String text, int row, int column, int sheet) {
    System.out.println("Picker couldn't handle command");
  }
  
  @Override
  public void setViewVisibility(boolean visibility) {
    if (visibility){
      this.setVisibility(VISIBLE);
    } else {
      this.setVisibility(INVISIBLE);
    }
  }

  @Override
  public void clear() {
    System.out.println("couldn't handle command");
  }

  @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
    
  }

  @Override
  public void setBitmap(Bitmap bitmap) { }

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

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

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

@@ -142,16 +142,49 @@
 Bitmap;%0A
+import android.text.InputFilter;%0A
 import a
@@ -480,16 +480,75 @@
  idList;
+%0A  ViewStyleManager normalStyle, activeStyle, currentStyle;
 %0A%0A  publ
@@ -761,16 +761,272 @@
 );%0A    %0A
+    final float scale = getContext().getResources().getDisplayMetrics().density;%0A    this.normalStyle = currentStyle = new ViewStyleManager(frame.bitmapCache, scale, true);%0A    this.activeStyle = new ViewStyleManager(frame.bitmapCache, scale, false);%0A    %0A
     setO
@@ -1875,16 +1875,189 @@
 value) %7B
+%0A    if (selector == Selector.NORMAL) %7B%0A      normalStyle.setStyle(key, value);%0A    %7D else if (selector == Selector.ACTIVE) %7B%0A      activeStyle.setStyle(key, value);%0A    %7D%0A 
  %7D%0A  %0A  
@@ -2095,16 +2095,47 @@
 yles() %7B
+%0A    currentStyle.apply(this); 
  %7D%0A%0A  @O

Make FWPicker stylable