public class MainActivity extends ActionBarActivity {
private static final String TAG = raspberrypiaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();}}
@Override
publicboolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true; }
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings)
{ returntrue; }
returnsuper.onOptionsItemSelected(item); }
publicstaticclass PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView; } }
public void switchLight(View view) {
switch (view.getId()) {
case R.id.light1:
if (((ToggleButton) view).isChecked()) ConnectionBT.MESSAGE = 1;
else ConnectionBT.MESSAGE = no1; // buzzer
break;
case R.id.light2:
if (((ToggleButton) view).isChecked()) ConnectionBT.MESSAGE = 2;
else ConnectionBT.MESSAGE = no2; // laser
break;
case R.id.light3:
if (((ToggleButton) view).isChecked()) ConnectionBT.MESSAGE = 3;
else ConnectionBT.MESSAGE = no3; // light
break;
case R.id.light4:
if (((ToggleButton) view).isChecked()) ConnectionBT.MESSAGE = 4;
else ConnectionBT.MESSAGE = no4; // light2
break;
default:
break; }
byte[] msg = ConnectionBT.MESSAGE.getBytes();
try {
ConnectionBT.mOutStream.write(msg);
} catch (IOException e) { }
}
}