package com.sometrik.framework;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;

public class FWTextView extends TextView implements NativeCommandHandler {

  private FrameWork frame;
  
  public FWTextView(FrameWork frame) {
    super(frame);
    this.frame = frame;
//    Color color = new Color();
    this.setBackground(null);
    this.setBackgroundColor(Color.rgb(255, 255, 255));
  }

  @Override
  public void addChild(View view) {
    System.out.println("FWTextView couldn't handle command");
  }
  
  @Override
  public void addOption(int optionId, String text) {
    System.out.println("FWTextView couldn't handle command");
  }

  @Override
  public void setValue(String v) {
    setText(v);
  }

  @Override
  public void setValue(int v) {
    System.out.println("FWTextView couldn't handle command");
  }

  @Override
  public void setViewEnabled(Boolean enabled) {
    setEnabled(enabled);
  }

  @Override
  public void setStyle(String key, String value) {
    if (key.equals("font-size")) {
      if (value.equals("small")) {
	this.setTextSize(9);
      } else if (value.equals("medium")) {
	this.setTextSize(12);
      } else if (value.equals("large")) {
	this.setTextSize(15);
      }
    } else if (key.equals("padding-top")) {
      setPadding(getPaddingLeft(), Integer.parseInt(value), getPaddingRight(), getPaddingBottom());
    } else if (key.equals("padding-bottom")) {
      setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), Integer.parseInt(value));
    } else if (key.equals("padding-left")) {
      setPadding(Integer.parseInt(value), getPaddingTop(), getPaddingRight(), getPaddingBottom());
    } else if (key.equals("padding-right")) {
      setPadding(getPaddingLeft(), getPaddingTop(), Integer.parseInt(value), getPaddingBottom());
    }
  }

  @Override
  public void setError(boolean hasError, String errorText) {
    //TODO
    System.out.println("FWTextView couldn't handle command");
  }

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

  @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("FWTextView 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 setImage(byte[] bytes) {
    // TODO Auto-generated method stub
    
  }

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

@@ -171,24 +171,109 @@
 .widget.
-TextView
+LinearLayout;%0Aimport android.widget.TextView;%0Aimport android.widget.LinearLayout.LayoutParams
 ;%0A%0Apubli
@@ -1381,16 +1381,70 @@
 ze(15);%0A
+      %7D else %7B%0A%09setTextSize(Integer.parseInt(value));%0A
       %7D%0A
@@ -1917,24 +1917,24 @@
 -right%22)) %7B%0A
-
       setPad
@@ -2015,24 +2015,1494 @@
 gBottom());%0A
+    %7D  else if (key.equals(%22width%22)) %7B%0A      LinearLayout.LayoutParams params = (LayoutParams) getLayoutParams();%0A      if (value.equals(%22wrap-content%22)) %7B%0A%09params.width = LinearLayout.LayoutParams.WRAP_CONTENT;%0A      %7D else if (value.equals(%22match-parent%22)) %7B%0A%09params.width = LinearLayout.LayoutParams.MATCH_PARENT;%0A      %7D else %7B%0A%09final float scale = getContext().getResources().getDisplayMetrics().density;%0A%09int pixels = (int) (Integer.parseInt(value) * scale + 0.5f);%0A%09params.width = pixels;%0A      %7D%0A      setLayoutParams(params);%0A    %7D else if (key.equals(%22height%22)) %7B%0A      LinearLayout.LayoutParams params = (LayoutParams) getLayoutParams();%0A      if (value.equals(%22wrap-content%22)) %7B%0A%09params.height = LinearLayout.LayoutParams.WRAP_CONTENT;%0A      %7D else if (value.equals(%22match-parent%22)) %7B%0A%09params.height = LinearLayout.LayoutParams.MATCH_PARENT;%0A      %7D else %7B%0A%0A%09final float scale = getContext().getResources().getDisplayMetrics().density;%0A%09int pixels = (int) (Integer.parseInt(value) * scale + 0.5f);%0A%09params.height = pixels;%0A      %7D%0A      setLayoutParams(params);%0A    %7D else if (key.equals(%22typeface%22)) %7B%0A      if (value.equals(%22bold%22)) %7B%0A        setTypeface(null, Typeface.BOLD);%0A      %7D else if (value.equals(%22normal%22)) %7B%0A        setTypeface(null, Typeface.NORMAL);%0A      %7D else if (value.equals(%22italic%22)) %7B%0A        setTypeface(null, Typeface.ITALIC);%0A      %7D else if (value.equals(%22bold-italic%22)) %7B%0A        setTypeface(null, Typeface.BOLD_ITALIC);%0A      %7D%0A
     %7D%0A  %7D%0A%0A 

Add style options for FWTextView