// This method is called when we click on a togle button
  // This method will write the value to the database
  private void changeToggleButton(int togleID) {
    try { // track we come here
      ActivityGroupSettings.group.parent.trackEvent(
          TrackingValues.eventCategorySettings,
          TrackingValues.eventCategorySettingsChangeFoodCompositionVisible);
    } catch (NullPointerException e) {
    }

    if (defaultValue != togleID) {
      updateToggleButton(togleID);
    } else {
      Toast.makeText(
              this, getResources().getString(R.string.standard_cant_be_hidden), Toast.LENGTH_SHORT)
          .show();

      // set toglebutton back to on
      switch (defaultValue) {
        case 1:
          tgCarb.toggle();
          break;
        case 2:
          tgProt.toggle();
          break;
        case 3:
          tgFat.toggle();
          break;
        case 4:
          tgKcal.toggle();
          break;
      }
    }
  }
Beispiel #2
0
 private void startSamplingService() {
   Session.setCurrentSamplingMode(selectedMode);
   boolean success = samplingService.startSampling();
   if (success) {
     Session.resetSummary();
     Session.setSamplingStartTime(System.currentTimeMillis());
     clearSummaryTable();
     rg.setEnabled(false);
   } else {
     startStop.toggle();
   }
 }
Beispiel #3
0
 public void onClick(View v) {
   ((ToggleButton) v).toggle();
   Channel channel = getItem((Integer) v.getTag());
   String boolglobalsend = channel.send ? "0" : "1";
   netutil.newapicommand(
       (ResultsListener) localservice,
       context,
       "om_device_channel_active:"
           + localservice.settings.getString("device", "")
           + ","
           + channel.u
           + ","
           + boolglobalsend);
 }
Beispiel #4
0
 public void checkBT() {
   if (mBluetoothAdapter != null) {
     if (!mBluetoothAdapter.isEnabled()) {
       enableBT.setText(R.string.enable_bt);
       bluetoothImage.setBackground(getResources().getDrawable((R.drawable.btooth_off)));
       pairedDevicesTg.setEnabled(false);
       discoverBT.setEnabled(false);
       if (pairedDevicesTg.isChecked()) pairedDevicesTg.toggle();
       discoveredDevicesArList.clear();
       tmpBtChecker.clear();
       adapterForDiscoveredDevices.notifyDataSetChanged();
     } else {
       enableBT.setText(R.string.disable_bt);
       bluetoothImage.setBackground(getResources().getDrawable((R.drawable.btooth_on)));
       pairedDevicesTg.setEnabled(true);
       discoverBT.setEnabled(true);
     }
   } else {
     enableBT.setText(R.string.no_bt_found_button);
     bluetoothImage.setBackground(getResources().getDrawable((R.drawable.btooth_not_found)));
     pairedDevicesTg.setEnabled(false);
   }
 }
  // Override onCreate so that the code will run when the activity is started.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // Call to the super class.
    super.onCreate(savedInstanceState);

    // Remove title and notification bars to give it an android feel.
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Set the content layout to the inactivity_screen XML file.
    setContentView(R.layout.inactivity_screen);

    // Set the declared objects to match the objects in the XML file.
    statusButton = (ToggleButton) findViewById(R.id.toggleButton1);
    timePref = (TextView) findViewById(R.id.textView3);

    backButton = (ImageButton) findViewById(R.id.back_button);
    homeButton = (ImageButton) findViewById(R.id.home_button);
    settingsButton = (ImageButton) findViewById(R.id.settings_button);

    infoButton = (ImageView) findViewById(R.id.imageView4);

    // Set a listener for the information button
    infoButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            // Use a layout inflater to open a pop-up window with the informational text.
            LayoutInflater layoutInflater =
                (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = layoutInflater.inflate(R.layout.info_popup, null);
            final PopupWindow popupWindow =
                new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

            infoText = (TextView) popupWindow.getContentView().findViewById(R.id.info_text);
            infoText.setText(
                "This is the inactivity alerts screen."
                    + "\n"
                    + "\n"
                    + "To enable/disable the service use the toggle button."
                    + "\n"
                    + "\n"
                    + "The current inactivity time measure is shown, to change this navigate to the iCare settings."
                    + "\n"
                    + "\n"
                    + "Press dismiss to close this message.");

            // create a dismiss button to close the pop-up window.
            Button dismiss = (Button) popupView.findViewById(R.id.dismiss_button);
            dismiss.setOnClickListener(
                new Button.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    popupWindow.dismiss();
                  }
                });

            // Put the pop-up window in the centre of the screen
            popupWindow.showAtLocation(infoButton, Gravity.CENTER, 0, 0);
          }
        });

    // Set a listener for the home button which starts the HomeScreen class
    homeButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(InactivityScreen.this, HomeScreen.class);
            startActivity(i);
          }
        });

    // Set a listener for the back button which starts the CalenderScreen class
    backButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(InactivityScreen.this, CalenderScreen.class);
            startActivity(i);
          }
        });

    // Set a listener for the settings button which starts the Settings class
    settingsButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Intent i = new Intent(InactivityScreen.this, Settings.class);
            startActivity(i);
          }
        });

    // Get preference value from sharedPreferences to show the current time measurement
    prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    time = prefs.getString("inactivity_length", "No Value Entered");
    timePref.setText(time + " minutes");

    // Get the current status from shared preferences
    checkPref = prefs.getBoolean("inactivity_pref", true);

    // If the status in preferences is "on" change the toggle button.
    if (checkPref == true) {
      statusButton.toggle();
    }

    // Set an actionListener for the ToggleButton
    statusButton.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View arg0) {
            // If the toggle button is pressed save the change to the shared preferences.
            SharedPreferences.Editor editor = prefs.edit();
            boolean checked = statusButton.isChecked();
            editor.putBoolean("inactivity_pref", checked);
            editor.commit();
          }
        });
  };