Ejemplo n.º 1
0
 // custom button
 // button with two states
 // if button is checked, starts a service..
 // this is used to list available devices when button is clicked. ie; displays username
 @Override
 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   switch (buttonView.getId()) {
     case R.id.switch_service:
       if (isChecked) {
         startService(new Intent(getApplicationContext(), LongRunningService.class));
         layoutMainTwo.setVisibility(View.VISIBLE);
         AppGlobals.setService(true);
         showUsername.setTextColor(Color.parseColor("#4CAF50"));
         ServiceHelpers.discover(MainActivity.this, peerList);
       } else {
         stopService(new Intent(getApplicationContext(), LongRunningService.class));
         layoutMainTwo.setVisibility(View.GONE);
         AppGlobals.setService(false);
         showUsername.setTextColor(Color.parseColor("#F44336"));
         ServiceHelpers.stopDiscover();
       }
       invalidateOptionsMenu();
   }
 }