1 package com.faust; 2 3 import android.content.Context; 4 import android.graphics.Color; 5 import android.view.Gravity; 6 import android.view.ViewGroup; 7 import android.widget.CheckBox; 8 import android.widget.CompoundButton; 9 import android.widget.LinearLayout; 10 import android.widget.TextView; 11 12 class Checkbox{ 13 int id = 0; 14 String address = ""; 15 LinearLayout frame, localVerticalGroup; 16 CheckBox checkbox; 17 TextView textLabel; 18 19 /* 20 * The constructor. 21 * addr: the tree address of the parameter controlled by the slider 22 * currentParameterID: the current parameter id in the parameters tree 23 * width: width of the view in pxs 24 * backgroundColor: grey level of the background of the view (0-255) 25 * label: the parameter's name 26 */ Checkbox(Context c, String addr, int currentParameterID, int width, int height, int backgroundColor, String label)27 public Checkbox(Context c, String addr, int currentParameterID, 28 int width, int height, int backgroundColor, String label){ 29 id = currentParameterID; 30 address = addr; 31 32 checkbox = new CheckBox(c); 33 checkbox.setGravity(Gravity.CENTER); 34 //checkbox.setText(label); 35 checkbox.setButtonDrawable(null); 36 checkbox.setBackgroundResource(R.drawable.checkbox); 37 checkbox.setLayoutParams(new ViewGroup.LayoutParams( 38 height, height)); 39 40 textLabel = new TextView(c); 41 textLabel.setGravity(Gravity.CENTER); 42 textLabel.setText(label); 43 44 frame = new LinearLayout(c); 45 frame.setLayoutParams(new ViewGroup.LayoutParams( 46 width, ViewGroup.LayoutParams.WRAP_CONTENT)); 47 frame.setOrientation(LinearLayout.VERTICAL); 48 frame.setBackgroundColor(Color.rgb(backgroundColor, 49 backgroundColor, backgroundColor)); 50 frame.setPadding(2,2,2,2); 51 52 localVerticalGroup = new LinearLayout(c); 53 localVerticalGroup.setOrientation(LinearLayout.VERTICAL); 54 localVerticalGroup.setGravity(Gravity.CENTER); 55 localVerticalGroup.setBackgroundColor(Color.rgb(backgroundColor+15, 56 backgroundColor+15, backgroundColor+15)); 57 localVerticalGroup.setPadding(0,10,0,10); 58 59 localVerticalGroup.addView(checkbox); 60 localVerticalGroup.addView(textLabel); 61 frame.addView(localVerticalGroup); 62 } 63 setStatus(float value)64 public void setStatus(float value){ 65 if(value == 0.0f) checkbox.setChecked(false); 66 else if(value != 0.0f) checkbox.setChecked(true); 67 } 68 69 /* 70 * Add the checkbox to group 71 */ addTo(LinearLayout group)72 public void addTo(LinearLayout group){ 73 group.addView(frame); 74 } 75 76 /* 77 * Set the checkbox's listeners 78 */ linkTo(final ParametersInfo parametersInfo)79 public void linkTo(final ParametersInfo parametersInfo){ 80 checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 81 @Override 82 public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) { 83 if (isChecked) parametersInfo.values[id] = 1.f; 84 else parametersInfo.values[id] = 0.f; 85 FaustActivity.dspFaust.setParamValue(address, parametersInfo.values[id]); 86 } 87 }); 88 } 89 } 90