Java Code Examples for android.widget.Switch#isChecked()

The following examples show how to use android.widget.Switch#isChecked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormBindings.java    From SimpleFTP with MIT License 6 votes vote down vote up
/**
 * Binding method for Switch
 * @param view The Switch widget.
 * @param observable The field value.
 */
@BindingAdapter("binding")
public static void bindSwitch(Switch view, final FieldViewModel<Boolean> observable) {
    if (view.getTag() == null) {
        view.setTag(true);
        view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                observable.set(isChecked);
            }
        });
    }

    boolean newValue = observable.get() == null ? false : observable.get().booleanValue();
    if (view.isChecked() != newValue) {
        view.setChecked(newValue);
    }

    String newError = observable.getError();
    if (view.getError() != newError) {
        view.setError(newError);
    }
}
 
Example 2
Source File: main_activity.java    From telegram-sms with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void set_privacy_mode_checkbox(TextView chat_id, Switch chat_command, Switch privacy_mode_switch) {
    if (!chat_command.isChecked()) {
        privacy_mode_switch.setVisibility(View.GONE);
        privacy_mode_switch.setChecked(false);
        return;
    }
    if (public_func.parse_long(chat_id.getText().toString()) < 0) {
        privacy_mode_switch.setVisibility(View.VISIBLE);
    } else {
        privacy_mode_switch.setVisibility(View.GONE);
        privacy_mode_switch.setChecked(false);
    }
}
 
Example 3
Source File: SettingsFragment.java    From haven with GNU General Public License v3.0 5 votes vote down vote up
public void checkCallToVerify (View v) {
    Switch callSwitch = v.findViewById(R.id.signalCallSwitch);
    if (callSwitch != null && callSwitch.isChecked()) {
        preferences.setVoiceVerification(true);
    } else {
        preferences.setVoiceVerification(false);
    }
}
 
Example 4
Source File: MainActivity.java    From XMouse with MIT License 5 votes vote down vote up
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
	if(sensorEvent.sensor.getType()==Sensor.TYPE_GYROSCOPE)
	{
		float gyroscopeX=sensorEvent.values[1];
		float gyroscopeY=sensorEvent.values[0];
		float gyroscopeZ=sensorEvent.values[2];

		String cmd;

		Switch mouseSwitch=findViewById(R.id.mouseSwitch);
		if (mouseSwitch.isChecked()) {
			if (Math.abs(gyroscopeX) >= 2 || Math.abs(gyroscopeY) >= 2) {
				if (gyroscopeX < 0 || gyroscopeY < 0) {
					cmd = "xdotool mousemove_relative -- " + (gyroscopeX) * 5 + " " + (gyroscopeY) * 5;
				} else {

					cmd = "xdotool mousemove_relative " + (gyroscopeX) * 5 + " " + (gyroscopeY) * 5;
				}
				conn.executeShellCommand(cmd);
			}
			if (gyroscopeZ >= 3) {
				cmd = "xdotool click 4";
				conn.executeShellCommand(cmd);
			} else if (gyroscopeZ <= -3) {
				cmd = "xdotool click 5";
				conn.executeShellCommand(cmd);
			}
		}
	}
}
 
Example 5
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 4 votes vote down vote up
private void sendIdeaFromDialog() {
    Switch doLater = (Switch) mNewIdeaDialog.findViewById(R.id.doLater);

    String text = mIdeaField.getText().toString();
    if (!text.equals("")) {

        boolean later = doLater.isChecked();

        if (mRadioGroup.getCheckedRadioButtonId() != -1) {
            View radioButton = mRadioGroup.findViewById(mRadioGroup.getCheckedRadioButtonId());
            RadioButton btn = (RadioButton) mRadioGroup.getChildAt(mRadioGroup.indexOfChild(radioButton));
            String selection = (String) btn.getText();

            String note = mNoteField.getText().toString();
            int priority = Integer.parseInt(selection);

            mDbHelper.newEntry(text, note, priority, later); //add the idea to the actual database
            displayIdeasCount();

            DatabaseHelper.notifyAllLists();
            mDbHelper.sortByAscPriority();

        }

        mNewIdeaDialog.dismiss();

        if (mTinyDB.getBoolean(getString(R.string.handle_idea_pref))) {
            //move tab where idea was created
            int index = 0;
            if (later) index = 1;

            tabLayout.setScrollPosition(index, 0f, true);
            mViewPager.setCurrentItem(index);

            //start the handle idea guide
            handleIdeaGuide();
        }

    } else {
        mIdeaError.setVisibility(View.VISIBLE);
    }
}
 
Example 6
Source File: SwitchSkillViewFragment.java    From Easer with GNU General Public License v3.0 4 votes vote down vote up
private static boolean fromSwitch(@NonNull Switch sw) {
    return sw.isChecked();
}