package org.blitzortung.android.app.controller;

import android.view.View;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ButtonColumnHandler<V extends View> {

    private List<V> elements;

    private final RelativeLayout parentLayout;

    public ButtonColumnHandler(RelativeLayout parentLayout) {
        this.parentLayout = parentLayout;

        elements = new ArrayList<V>();
    }

    public void addElement(V element) {
        elements.add(element);
    }

    public void addAllElements(Collection<V> elements) {
        this.elements.addAll(elements);
    }

    public void disableButtonColumn() {
        enableButtonElements(false);
    }

    public void enableButtonColumn() {
        enableButtonElements(true);
    }

    private void enableButtonElements(boolean enabled) {
        for (V element : elements) {
            element.setEnabled(enabled);
        }
    }

    public void updateButtonColumn() {
        int previousIndex = -1;
        for (int currentIndex = 0; currentIndex < elements.size(); currentIndex++) {
            V element = elements.get(currentIndex);
            if (element.getVisibility() == View.VISIBLE) {
                //RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) element.getLayoutParams();
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                lp.width = 70;
                lp.height = 70;
                lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1);
                if (previousIndex < 0) {
                    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
                } else {
                    lp.addRule(RelativeLayout.BELOW, elements.get(previousIndex).getId());
                }
                element.setLayoutParams(lp);
                previousIndex = currentIndex;
            }
        }
    }
}

@@ -42,16 +42,52 @@
 oller;%0A%0A
+import android.util.DisplayMetrics;%0A
 import a
@@ -1277,116 +1277,8 @@
 ) %7B%0A
-                //RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) element.getLayoutParams();%0A
     
@@ -1491,18 +1491,42 @@
 width = 
-70
+(int)pxFromSp(element, 55)
 ;%0A      
@@ -1551,10 +1551,34 @@
 t = 
-70
+(int)pxFromSp(element, 55)
 ;%0A  
@@ -2004,11 +2004,221 @@
  %7D%0A    %7D
+%0A%0A    private float pxFromSp(V element, float sp) %7B%0A        final DisplayMetrics displayMetrics = element.getContext().getResources().getDisplayMetrics();%0A        return sp * displayMetrics.scaledDensity;%0A    %7D
 %0A%7D%0A

scale button column