package org.azavea.otm.ui;

import org.azavea.otm.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

public class FilterDisplay extends Activity{
    final private int SIDE_MARGIN = 15;
    
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.filter_activity);
        
        LinearLayout list = (LinearLayout)findViewById(R.id.filter_list);
        addToggleFilter("Missing Tree", false, "filter_missing_tree", list);
        addToggleFilter("Missing Species", true, "filter_missing_tree", list);
    }
	
	private void addToggleFilter(String label, boolean value, String key, 
			LinearLayout list) {

		RelativeLayout container = new RelativeLayout(this);
		
		TextView text = new TextView(this);
		text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
		text.setText(label);
		
		ToggleButton toggle = new ToggleButton(this);
		toggle.setChecked(value);
		
		container.addView(text, getLabelLayout());
		container.addView(toggle, getControlLayout());
		list.addView(container);
	}
	
	private LayoutParams getLabelLayout() {
		RelativeLayout.LayoutParams params = 
				new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
						RelativeLayout.LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
		params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		params.setMargins(SIDE_MARGIN, 0, 0, 0);
		
		return params;
	}

	private LayoutParams getControlLayout() {
		RelativeLayout.LayoutParams params = 
				new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
						RelativeLayout.LayoutParams.WRAP_CONTENT);
		params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
		params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		params.setMargins(0, SIDE_MARGIN, 0, 0);
		
		return params;
	}
}

package org.azavea.otm.ui;

import java.util.HashMap;

import org.azavea.otm.R;
import org.azavea.otm.adapters.SpeciesAdapter;
import org.azavea.otm.data.Species;
import org.azavea.otm.filters.BooleanFilter;
import org.azavea.otm.filters.MapFilter;
import org.azavea.otm.filters.RangeFilter;
import org.json.JSONException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FilterDisplay extends Activity{
    
    private HashMap<String, MapFilter> filters = new HashMap<String, MapFilter>();
    
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.filter_activity);
        
        LinearLayout list = (LinearLayout)findViewById(R.id.filter_list);
        
        addToggleFilter(new BooleanFilter("filter_missing_tree", false, "Missing Tree"), list);
        addToggleFilter(new BooleanFilter("filter_missing_plot", false, "Missing Plot"), list);
        addToggleFilter(new BooleanFilter("filter_missing_thing", false, "Missing Thing"), list);
        addRangeFilter(new RangeFilter("filter_bip", "Diameter Z"), list);
        addRangeFilter(new RangeFilter("filter_bop", "Diameter X"), list);
        
    }
	
	public void onFinish(View view) {
		
	}
	
	public void onCancel(View view) {
		finish();
	}
	
	public void onClear(View view) {
		
	}
	
	private void addRangeFilter(RangeFilter filter, LinearLayout list) {
        LayoutInflater inflater = ((Activity)this).getLayoutInflater();
        View rangeControl = inflater.inflate(R.layout.filter_range_control, null);
        ((TextView)rangeControl.findViewById(R.id.filter_label)).setText(filter.label);
        rangeControl.setTag(filter);
        list.addView(rangeControl);
	}

	private void addToggleFilter(final BooleanFilter filter, LinearLayout list) {
        LayoutInflater inflater = ((Activity)this).getLayoutInflater();
        View toggle = inflater.inflate(R.layout.filter_toggle_control, null);
        ((TextView)toggle.findViewById(R.id.filter_label)).setText(filter.label);
        toggle.setTag(filter);
        list.addView(toggle);
	}
	
	private void addListFilter() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("Select a Species");
		 
		Species species[] = null;
		try {
			species = new Species[] {
				new Species(1, "Treeus Maximus", "Maximum Tree"),
				new Species(2, "Treeus Minimus", "Minimum Tree"),
				new Species(3, "Treeus Basicus", "Basic Tree"),
			 };
		} catch (JSONException e) {
			e.printStackTrace();
		}
		 
		 SpeciesAdapter adapter = new SpeciesAdapter(this, R.layout.species_list_row, species);
		 builder.setAdapter(adapter,  new  DialogInterface.OnClickListener() {
			 public void onClick(DialogInterface dialog, int pos) {
			     //selection processing code
			
			 }});
			 builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			     public void onClick(DialogInterface dialog, int whichButton) {
			
			     }
			 });
		 AlertDialog dialog=builder.create();
		 dialog.getListView(); 
		 dialog.show();
	}
}

Inflate filter layouts from resources