PageRenderTime 228ms CodeModel.GetById 61ms app.highlight 80ms RepoModel.GetById 81ms app.codeStats 0ms

/TheElements/src/sand/falling/opengl/Control.java

http://thelements.googlecode.com/
Java | 74 lines | 53 code | 9 blank | 12 comment | 0 complexity | b2814dc89c530ce6d5faa284fa824210 MD5 | raw file
 1package sand.falling.opengl;
 2
 3import android.content.Context;
 4import android.util.AttributeSet;
 5import android.view.View;
 6import android.widget.ImageButton;
 7import android.widget.LinearLayout;
 8import android.widget.SeekBar;
 9
10public class Control extends LinearLayout
11{
12	//The instance of the current activity is stored here and modified through setActvity (call from DemoActivity)
13	private MainActivity activity;
14	
15	//Two objects in the control area
16	private ImageButton control_button;
17	private SeekBar brush_size_slider;
18	
19	final CharSequence[] elementslist = {"Sand", "Water", "Plant", "Wall", "Fire", "Ice", "Generator", "Oil", "Magma", "Stone", "C4"};
20	
21	//Constructor
22	public Control(Context context, AttributeSet attrs)
23	{ 
24		super(context, attrs);
25	}
26
27	//Sets the current instance of the activity
28	public void setActivity(MainActivity act)
29	{
30		activity = act;
31	}
32
33	//Called once the the xml is finished inflating	
34	@Override
35	protected void onFinishInflate()
36	{
37		//Define the ImageButton and SeekBar set before using the res ids
38		control_button = (ImageButton) findViewById(R.id.element_picker_button);
39		brush_size_slider = (SeekBar) findViewById(R.id.brush_size_slider);
40
41		//Set a click listener for the button which should pop up element picker dialog when clicked
42		control_button.setOnClickListener
43			(
44					new OnClickListener()
45					{
46						public void onClick(View v)
47						{
48							activity.showDialog(2); //Run the element picker dialog
49						}
50					}
51			);
52		//Set a palette image for the button
53		control_button.setImageResource(R.drawable.palette);
54
55		//Set a change listener for the seekbar
56		brush_size_slider.setOnSeekBarChangeListener
57			(
58					new SeekBar.OnSeekBarChangeListener()
59					{
60						public void onProgressChanged(SeekBar seekbar, int progress, boolean fromTouch)
61						{
62							//When it is dragged, set the brush size to 32 * the fraction of the bar dragged
63							int p = 32 * progress/seekbar.getMax();
64							MainActivity.setBrushSize(p);
65						}
66						//These aren't needed for now
67						public void onStartTrackingTouch(SeekBar seekbar) {}
68						public void onStopTrackingTouch(SeekBar seekbar) {}
69					}
70			);
71		//Start off the progress bar at a brush size of 4
72		brush_size_slider.setProgress((int)4*brush_size_slider.getMax()/32);
73	}
74}