Java Code Examples for android.widget.CompoundButton#setChecked()

The following examples show how to use android.widget.CompoundButton#setChecked() . 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: AwooEndpointFragment.java    From United4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton button, boolean b) {
    // if we're being *UNchecked*, we don't care about it.
    if (!b) return;
    // uncheck all the other buttons
    for (CompoundButton other : buttons) {
        if (!other.equals(button)) other.setChecked(false);
    }
    // awoo_endpoint will be set to the text of the button
    String text = String.valueOf(button.getText());
    if (getView() == null) return;
    // if it's the other button, show the other box and populate it with the awoo endpoint.
    // no need to save the awoo_endpoint property, that's done in the ontextchanged listener
    if ("Other".equals(text)) {
        getView().findViewById(R.id.other_box).setVisibility(View.VISIBLE);
        ((TextView) getView().findViewById(R.id.other_box)).setText(P.get("awoo_endpoint"), TextView.BufferType.EDITABLE);
    } else {
        // if it's not the other button, hide the other box and update the property
        getView().findViewById(R.id.other_box).setVisibility(View.GONE);
        P.set("awoo_endpoint", text);
    }
}
 
Example 2
Source File: SettingFragment.java    From WifiChat with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // TODO Auto-generated method stub
    switch (buttonView.getId()) {
        case R.id.checkbox_sound:
            buttonView.setChecked(isChecked);
            BaseApplication.setSoundFlag(!isChecked);
            break;

        case R.id.checkbox_vibration:
            buttonView.setChecked(isChecked);
            BaseApplication.setVibrateFlag(isChecked);
            break;

        default:
            break;
    }
}
 
Example 3
Source File: ListMenuItemView.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
public void setChecked(boolean checked) {
    CompoundButton compoundButton;

    if (mItemData.isExclusiveCheckable()) {
        if (mRadioButton == null) {
            insertRadioButton();
        }
        compoundButton = mRadioButton;
    } else {
        if (mCheckBox == null) {
            insertCheckBox();
        }
        compoundButton = mCheckBox;
    }

    compoundButton.setChecked(checked);
}
 
Example 4
Source File: ExtendChatViewAdapter.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    try {
        IMMessage message = (IMMessage) buttonView.getTag();
        if(isChecked)
        {
            sharingMsg.put(message.getId(),message);
        }
        else {
            sharingMsg.remove(message.getId());
        }
    }catch (Exception ex)
    {
        buttonView.setOnCheckedChangeListener(null);
        buttonView.setChecked(!isChecked);
        buttonView.setOnCheckedChangeListener(this);
    }
}
 
Example 5
Source File: SwitchDrawerItem.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isEnabled()) {
        checked = isChecked;
        if (getOnCheckedChangeListener() != null) {
            getOnCheckedChangeListener().onCheckedChanged(SwitchDrawerItem.this, buttonView, isChecked);
        }
    } else {
        buttonView.setOnCheckedChangeListener(null);
        buttonView.setChecked(!isChecked);
        buttonView.setOnCheckedChangeListener(checkedChangeListener);
    }
}
 
Example 6
Source File: MainActivity.java    From TextCounter with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    setChecking();
    compoundButton.setChecked(true);

    switch (compoundButton.getId()){
        case R.id.radioButton1:
            builder.setType(TextCounter.BYTE);
            seekBar1.setEnabled(false);
            type = TextCounter.BYTE;
            break;
        case R.id.radioButton2:
            builder.setType(TextCounter.SHORT);
            seekBar1.setEnabled(false);
            type = TextCounter.SHORT;
            break;
        case R.id.radioButton3:
            builder.setType(TextCounter.INT);
            seekBar1.setEnabled(false);
            type = TextCounter.INT;
            break;
        case R.id.radioButton4:
            builder.setType(TextCounter.FLOAT);
            seekBar1.setEnabled(true);
            type = TextCounter.FLOAT;
            break;
        case R.id.radioButton5:
            builder.setType(TextCounter.LONG);
            seekBar1.setEnabled(false);
            type = TextCounter.LONG;
            break;
        case R.id.radioButton6:
            builder.setType(TextCounter.DOUBLE);
            seekBar1.setEnabled(true);
            type = TextCounter.DOUBLE;
            break;
        default:
            return;
    }
}
 
Example 7
Source File: RequestPermissionActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void disableToggleIfGranted(String permission, CompoundButton toggleButton, ViewGroup wrapLayout) {
    if (isGranted(permission)) {
        toggleButton.setChecked(true);
        toggleButton.setEnabled(false);
        wrapLayout.setBackgroundResource(0);
    } else if (permission.equals(requestedPermission)) {
        wrapLayout.setBackgroundResource(R.drawable.highlight_border);
    }
}
 
Example 8
Source File: RealSwitch.java    From RealSwitch with MIT License 5 votes vote down vote up
protected void updateButton(CompoundButton cb, KrollDict d) {
	if (d.containsKey(TiC.PROPERTY_TITLE_OFF)) {
		((Switch) cb).setTextOff(TiConvert.toString(d,
				TiC.PROPERTY_TITLE_OFF));
	}
	if (d.containsKey(TiC.PROPERTY_TITLE_ON)) {
		((Switch) cb).setTextOn(TiConvert.toString(d,
				TiC.PROPERTY_TITLE_ON));
	}
	if (d.containsKey(TiC.PROPERTY_VALUE)) {
		cb.setChecked(TiConvert.toBoolean(d, TiC.PROPERTY_VALUE));
	}
	if (d.containsKey(TiC.PROPERTY_COLOR)) {
		cb.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR));
	}
	if (d.containsKey(TiC.PROPERTY_FONT)) {
		TiUIHelper.styleText(cb, d.getKrollDict(TiC.PROPERTY_FONT));
	}
	if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN)) {
		String textAlign = d.getString(TiC.PROPERTY_TEXT_ALIGN);
		TiUIHelper.setAlignment(cb, textAlign, null);
	}
	if (d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) {
		String verticalAlign = d.getString(TiC.PROPERTY_VERTICAL_ALIGN);
		TiUIHelper.setAlignment(cb, null, verticalAlign);
	}
	cb.invalidate();
}
 
Example 9
Source File: SecondarySwitchDrawerItem.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isEnabled()) {
        checked = isChecked;
        if (getOnCheckedChangeListener() != null) {
            getOnCheckedChangeListener().onCheckedChanged(SecondarySwitchDrawerItem.this, buttonView, isChecked);
        }
    } else {
        buttonView.setOnCheckedChangeListener(null);
        buttonView.setChecked(!isChecked);
        buttonView.setOnCheckedChangeListener(checkedChangeListener);
    }
}
 
Example 10
Source File: SwitchPreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (!callChangeListener(isChecked)) {
        // Listener didn't like it, change it back.
        // CompoundButton will make sure we don't recurse.
        buttonView.setChecked(!isChecked);
        return;
    }

    SwitchPreference.this.setChecked(isChecked);
}
 
Example 11
Source File: RadioButtonGroupHelper.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 取消选中
 */
public void clearCheck() {
    for (CompoundButton view : mViewSet) {
        if (view.isChecked()) {
            view.setChecked(false);
        }
    }
}
 
Example 12
Source File: InstallFromListActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void setUpToggle() {
    FrameLayout toggleContainer = findViewById(R.id.toggle_button_container);
    CompoundButton userTypeToggler;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        Switch switchButton = new Switch(this);
        switchButton.setTextOff(Localization.get("toggle.web.user.mode"));
        switchButton.setTextOn(Localization.get("toggle.mobile.user.mode"));
        userTypeToggler = switchButton;
    } else {
        ToggleButton toggleButton = new ToggleButton(this);
        toggleButton.setTextOff(Localization.get("toggle.web.user.mode"));
        toggleButton.setTextOn(Localization.get("toggle.mobile.user.mode"));
        userTypeToggler = toggleButton;
    }

    // Important for this call to come first; we don't want the listener to be invoked on the
    // first auto-setting, just on user-triggered ones
    userTypeToggler.setChecked(inMobileUserAuthMode);
    userTypeToggler.setOnCheckedChangeListener((buttonView, isChecked) -> {
        inMobileUserAuthMode = isChecked;
        errorMessage = null;
        errorMessageBox.setVisibility(View.INVISIBLE);
        ((EditText)findViewById(R.id.edit_password)).setText("");
        setProperAuthView();
    });

    toggleContainer.addView(userTypeToggler);
}
 
Example 13
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void tryCheckItem(CompoundButton button, int position) {
    AlbumFile albumFile = mAlbumFolders.get(mCurrentFolder).getAlbumFiles().get(position);
    if (button.isChecked()) {
        if (mCheckedList.size() >= mLimitCount) {
            int messageRes;
            switch (mFunction) {
                case Album.FUNCTION_CHOICE_IMAGE: {
                    messageRes = R.plurals.album_check_image_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_VIDEO: {
                    messageRes = R.plurals.album_check_video_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_ALBUM: {
                    messageRes = R.plurals.album_check_album_limit;
                    break;
                }
                default: {
                    throw new AssertionError("This should not be the case.");
                }
            }
            mView.toast(getResources().getQuantityString(messageRes, mLimitCount, mLimitCount));
            button.setChecked(false);
        } else {
            albumFile.setChecked(true);
            mCheckedList.add(albumFile);
            setCheckedCount();
        }
    } else {
        albumFile.setChecked(false);
        mCheckedList.remove(albumFile);
        setCheckedCount();
    }
}
 
Example 14
Source File: SwitchPreferenceEx.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
    if (!callChangeListener(isChecked)) {
        // Listener didn't like it, change it back.
        // CompoundButton will make sure we don't recurse.
        buttonView.setChecked(!isChecked);
        return;
    }

    SwitchPreferenceEx.this.setChecked(isChecked);
}
 
Example 15
Source File: ObservationFilterActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
	int filter = Integer.parseInt(buttonView.getTag().toString());
	((RadioButton) findViewById(android.R.id.content).findViewWithTag(timeFilter.toString())).setChecked(false);
	timeFilter = filter;
	buttonView.setChecked(true);
	showOrHideCustomWindow();
	setFilter();
}
 
Example 16
Source File: SwitchPreference.java    From NHentai-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {
	if (!callChangeListener(isChecked)) {
		buttonView.setChecked(!isChecked);
		return;
	}
	SwitchPreference.this.setChecked(isChecked);
}
 
Example 17
Source File: SwitchPreference.java    From MaterialPreferenceLibrary with Apache License 2.0 5 votes vote down vote up
@Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!callChangeListener(isChecked)) {
// Listener didn't like it, change it back.
// CompoundButton will make sure we don't recurse.
                buttonView.setChecked(!isChecked);
                return;
            }

            SwitchPreference.this.setChecked(isChecked);
        }
 
Example 18
Source File: ListMenuItemView.java    From zen4android with MIT License 4 votes vote down vote up
public void setCheckable(boolean checkable) {

        if (!checkable && mRadioButton == null && mCheckBox == null) {
            return;
        }

        if (mRadioButton == null) {
            insertRadioButton();
        }
        if (mCheckBox == null) {
            insertCheckBox();
        }

        // Depending on whether its exclusive check or not, the checkbox or
        // radio button will be the one in use (and the other will be otherCompoundButton)
        final CompoundButton compoundButton;
        final CompoundButton otherCompoundButton;

        if (mItemData.isExclusiveCheckable()) {
            compoundButton = mRadioButton;
            otherCompoundButton = mCheckBox;
        } else {
            compoundButton = mCheckBox;
            otherCompoundButton = mRadioButton;
        }

        if (checkable) {
            compoundButton.setChecked(mItemData.isChecked());

            final int newVisibility = checkable ? VISIBLE : GONE;
            if (compoundButton.getVisibility() != newVisibility) {
                compoundButton.setVisibility(newVisibility);
            }

            // Make sure the other compound button isn't visible
            if (otherCompoundButton.getVisibility() != GONE) {
                otherCompoundButton.setVisibility(GONE);
            }
        } else {
            mCheckBox.setVisibility(GONE);
            mRadioButton.setVisibility(GONE);
        }
    }
 
Example 19
Source File: RequestPermissionActivity.java    From financisto with GNU General Public License v2.0 4 votes vote down vote up
private void requestPermission(String permission, CompoundButton toggleButton) {
    toggleButton.setChecked(false);
    ActivityCompat.requestPermissions(this, new String[]{permission}, 0);
}
 
Example 20
Source File: CheckBoxBindingAdapterUtils.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@BindingAdapter(value = {"checked"})
public static void setChecked(CompoundButton view, boolean checked) {
    if (view.isChecked() != checked) {
        view.setChecked(checked);
    }
}