package com.sometrik.framework;

import android.util.DisplayMetrics;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class NavigationBar extends FrameLayout implements NativeCommandHandler {
  
  FrameWork frame;
  LinearLayout baseLayout;
  LinearLayout.LayoutParams childParams;
  int displayScale = 1;
  
  public NavigationBar(FrameWork frame) {
    super(frame);
    this.frame = frame;
    this.setBackground(frame.getResources().getDrawable(android.R.drawable.dialog_holo_light_frame));
    baseLayout = new LinearLayout(frame);
    baseLayout.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    baseLayout.setLayoutParams(params);
    setLayoutParams(params);
    DisplayMetrics metrics = frame.setupDisplayMetrics();
    displayScale = (int) metrics.scaledDensity;
    childParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 60 * displayScale);
    childParams.weight = 1;
    
    
    addView(baseLayout);
  }

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

  @Override
  public void addChild(View view) {
    System.out.println("addChild on NavigationBar " + view.getId());
    final int buttonId = view.getId();
    view.setLayoutParams(childParams);
    view.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
	System.out.println("Navigation OnClick: " + buttonId);
	frame.intChangedEvent(System.currentTimeMillis() / 1000.0, getId(), 1, buttonId);
      }
    });
    baseLayout.addView(view);
  }

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

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

  @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 setValue(int v) {
    // TODO Auto-generated method stub
    
  }

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

  @Override
  public void setViewEnabled(Boolean enabled) {
    // TODO Auto-generated method stub
    
  }

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

  @Override
  public void setStyle(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 int getElementId() {
    return getId();
  }

  @Override
  public void setImage(byte[] bytes) {
    // TODO Auto-generated method stub
    
  }

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

}

@@ -26,16 +26,47 @@
 ework;%0A%0A
+import android.graphics.Color;%0A
 import a
@@ -93,16 +93,16 @@
 etrics;%0A
-
 import a
@@ -189,16 +189,65 @@
 rLayout;
+%0Aimport android.widget.LinearLayout.LayoutParams;
 %0A%0Apublic
@@ -522,16 +522,18 @@
  frame;%0A
+//
     this
@@ -622,24 +622,77 @@
 ht_frame));%0A
+    setBackgroundColor(Color.parseColor(%22#ffffff%22));%0A
     baseLayo
@@ -2820,47 +2820,1131 @@
     
-// TODO Auto-generated method stub%0A    
+if (key.equals(%22width%22)) %7B%0A      LinearLayout.LayoutParams params = (android.widget.LinearLayout.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 = (android.widget.LinearLayout.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
 %0A  %7D

Add style options to NavigationBar