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

The following examples show how to use android.widget.CompoundButton#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: AllegroUtils.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取 CompoundButton text
 *
 * @param view view
 * @return CompoundButton 显示的内容
 */
private static String getCompoundButtonText(View view) {
    try {
        CompoundButton switchButton = (CompoundButton) view;
        Method method;
        if (switchButton.isChecked()) {
            method = view.getClass().getMethod("getTextOn");
        } else {
            method = view.getClass().getMethod("getTextOff");
        }
        return (String) method.invoke(view);
    } catch (Throwable ignore) {
        ExceptionUtil.exceptionThrow(ignore);
        return "UNKNOWN";
    }
}
 
Example 2
Source File: RadioButtonGroupHelper.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
/**
 * {@link CompoundButton.OnCheckedChangeListener}
 */
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked && !mTag) {
        mTag = true;
        for (CompoundButton view : mViewSet) {
            if (view != buttonView && view.isChecked()) {
                // 这个 API 会触发监听事件
                view.setChecked(false);
            }
        }
        if (mListener != null) {
            mListener.onCheckedChanged((RadioButton) buttonView, buttonView.getId());
        }
        mTag = false;
    }
}
 
Example 3
Source File: ToggleGroup.java    From ToggleButtons with MIT License 6 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof CompoundButton) {
        final CompoundButton button = (CompoundButton) child;
        if (button.isChecked()) {
            mProtectFromCheckedChange = true;
         int currentCheck = getExclusiveCheckedId();
            if (mExclusive && currentCheck != View.NO_ID) {
                setCheckedStateForView(currentCheck, false);
            }
            mProtectFromCheckedChange = false;
            addCheckedId(button.getId());
        }
    }

    super.addView(child, index, params);
}
 
Example 4
Source File: ToggleGroup.java    From ToggleButtons with MIT License 6 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof CompoundButton) {
        final CompoundButton button = (CompoundButton) child;
        if (button.isChecked()) {
            mProtectFromCheckedChange = true;
         int currentCheck = getExclusiveCheckedId();
            if (mExclusive && currentCheck != View.NO_ID) {
                setCheckedStateForView(currentCheck, false);
            }
            mProtectFromCheckedChange = false;
            addCheckedId(button.getId());
        }
    }

    super.addView(child, index, params);
}
 
Example 5
Source File: EditShareFragment.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sync value of "can edit" {@link Switch} according to a change in one of its subordinate checkboxes.
 *
 * If all the subordinates are disabled, "can edit" has to be disabled.
 *
 * If any subordinate is enabled, "can edit" has to be enabled.
 *
 * @param subordinateCheckBoxView   Subordinate {@link CheckBox} that was changed.
 * @param isChecked                 'true' iif subordinateCheckBoxView was checked.
 */
private void syncCanEditSwitch(View subordinateCheckBoxView, boolean isChecked) {
    CompoundButton canEditCompound = (CompoundButton) getView().findViewById(R.id.canEditSwitch);
    if (isChecked) {
        if (!canEditCompound.isChecked()) {
            toggleDisablingListener(canEditCompound);
        }
    } else {
        boolean allDisabled = true;
        for (int i=0; allDisabled && i<sSubordinateCheckBoxIds.length; i++) {
            allDisabled &=
                    sSubordinateCheckBoxIds[i] == subordinateCheckBoxView.getId() ||
                            !((CheckBox) getView().findViewById(sSubordinateCheckBoxIds[i])).isChecked()
            ;
        }
        if (canEditCompound.isChecked() && allDisabled) {
            toggleDisablingListener(canEditCompound);
            for (int i=0; i<sSubordinateCheckBoxIds.length; i++) {
                getView().findViewById(sSubordinateCheckBoxIds[i]).setVisibility(View.GONE);
            }
        }
    }
}
 
Example 6
Source File: BooleanSettingsObject.java    From EasySettings with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param compoundButton changes the text of the given {@link CompoundButton}
 *                       according if it's "on" or "off"
 */
public void setTextAccordingToState(CompoundButton compoundButton)
{
	if(compoundButton.isChecked())
	{
		compoundButton.setText(onText);
	}

	else if(compoundButton.isChecked() == false)
	{
		compoundButton.setText(offText);
	}
}
 
Example 7
Source File: RecurrencePickerDialog.java    From Android-RecurrencePicker with Apache License 2.0 5 votes vote down vote up
private void updateDoneButtonState() {
    if (mModel.recurrenceState == RecurrenceModel.STATE_NO_RECURRENCE) {
        mDone.setEnabled(true);
        return;
    }

    if (mInterval.getText().toString().length() == 0) {
        mDone.setEnabled(false);
        return;
    }

    if (mEndCount.getVisibility() == View.VISIBLE &&
            mEndCount.getText().toString().length() == 0) {
        mDone.setEnabled(false);
        return;
    }

    if (mModel.freq == RecurrenceModel.FREQ_WEEKLY) {
        for (CompoundButton b : mWeekByDayButtons) {
            if (b.isChecked()) {
                mDone.setEnabled(true);
                return;
            }
        }
        mDone.setEnabled(false);
        return;
    }

    mDone.setEnabled(true);
}
 
Example 8
Source File: RecurrenceOptionCreator.java    From SublimePicker with Apache License 2.0 5 votes vote down vote up
private void updateDoneButtonState() {
    if (mModel.recurrenceState == RecurrenceModel.STATE_NO_RECURRENCE) {
        mButtonLayout.updateValidity(true);
        return;
    }

    if (mInterval.getText().toString().length() == 0) {
        mButtonLayout.updateValidity(false);
        return;
    }

    if (mEndCount.getVisibility() == View.VISIBLE &&
            mEndCount.getText().toString().length() == 0) {
        mButtonLayout.updateValidity(false);
        return;
    }

    if (mModel.freq == RecurrenceModel.FREQ_WEEKLY) {
        for (CompoundButton b : mWeekByDayButtons) {
            if (b.isChecked()) {
                mButtonLayout.updateValidity(true);
                return;
            }
        }
        mButtonLayout.updateValidity(false);
        return;
    }
    mButtonLayout.updateValidity(true);
}
 
Example 9
Source File: ToggleGroup.java    From ToggleButtons with MIT License 5 votes vote down vote up
/**
 * Determines where to position dividers between children. Note: this is an 'illegal' override
 * of a hidden method.
 *
 * @param childIndex Index of child to check for preceding divider
 * @return true if there should be a divider before the child at childIndex
 */
protected boolean hasDividerBeforeChildAt(int childIndex) {
    final CompoundButton child = (CompoundButton) getChildAt(childIndex);
    if (child == null)
        return false;
    if (child.getVisibility() == GONE)
        return false;
    final CompoundButton previous = getVisibleViewBeforeChildAt(childIndex);
    if (previous == null)
        return false;

    // If both are checked, add a divider
    return child.isChecked() && previous.isChecked();
}
 
Example 10
Source File: Option.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
public void setCompoundButton(CompoundButton cb) {
    if (mCompoundButton == cb) {
        return;
    }

    boolean checked = cb.isChecked();

    mCompoundButton.setOnCheckedChangeListener(null);
    mCompoundButton = cb;
    mCompoundButton.setOnCheckedChangeListener(this);
    setChecked(checked);
}
 
Example 11
Source File: ApplyAllDialogFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.sw_prayer)
void onPrayerChanged(CompoundButton v) {
    mPrayerEnabled = v.isChecked();
    mPrayerTextView.setEnabled(mPrayerEnabled);
    mNotificationCheckBox.setEnabled(mPrayerEnabled);
    mVibrateCheckBox.setEnabled(mPrayerEnabled);
    mReminderButton.setEnabled(mPrayerEnabled);
    mNotificationButton.setEnabled(mPrayerEnabled);
}
 
Example 12
Source File: DemoActivity.java    From MultiRowsRadioGroup with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    CompoundButton cb = (CompoundButton) group.findViewById(checkedId);
    if(cb!=null && cb.isChecked()){
        TextView titleTv = ((TextView)group.findViewById(android.R.id.title));
        if(titleTv!=null){
            titleTv.setText("selected:"+cb.getText());
        }
    }
}
 
Example 13
Source File: AopUtil.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 CompoundButton text
 *
 * @param view view
 * @return CompoundButton 显示的内容
 */
public static String getCompoundButtonText(View view) {
    try {
        CompoundButton switchButton = (CompoundButton) view;
        Method method;
        if (switchButton.isChecked()) {
            method = view.getClass().getMethod("getTextOn");
        } else {
            method = view.getClass().getMethod("getTextOff");
        }
        return (String) method.invoke(view);
    } catch (Exception ex) {
        return "UNKNOWN";
    }
}
 
Example 14
Source File: CompoundButtonCheckedProperty.java    From bindroid with MIT License 5 votes vote down vote up
/**
 * Constructs a CompoundButtonCheckedProperty for a {@link CompoundButton}.
 * 
 * @param button
 *          the button being bound.
 */
public CompoundButtonCheckedProperty(CompoundButton button) {
  final WeakReference<CompoundButton> weakButton = new WeakReference<CompoundButton>(button);
  button.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      CompoundButtonCheckedProperty.this.trackable.updateTrackers();
    }
  });
  this.getter = new Function<Boolean>() {
    @Override
    public Boolean evaluate() {
      CompoundButton button = weakButton.get();
      if (button != null) {
        CompoundButtonCheckedProperty.this.trackable.track();
        return CompoundButtonCheckedProperty.this.lastValue = button.isChecked();
      } else {
        return CompoundButtonCheckedProperty.this.lastValue;
      }
    }
  };
  this.setter = new Action<Boolean>() {
    @Override
    public void invoke(Boolean parameter) {
      CompoundButton button = weakButton.get();
      if (button != null) {
        button.setChecked(parameter);
        CompoundButtonCheckedProperty.this.lastValue = parameter;
      }
    }
  };
  this.propertyType = Boolean.TYPE;
}
 
Example 15
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 16
Source File: CheckBoxBindingAdapterUtils.java    From xDrip-plus 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);
    }
}
 
Example 17
Source File: ACompoundButton.java    From robotium-sandwich with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isChecked() {
	CompoundButton view = (CompoundButton) getAndWaitForView();
	return view.isChecked();
}
 
Example 18
Source File: WidgetAccess.java    From NextInputs-Android with Apache License 2.0 4 votes vote down vote up
public static boolean getBoolean(CompoundButton view) {
    return view.isChecked();
}
 
Example 19
Source File: WidgetAccess.java    From NextInputs-Android with Apache License 2.0 4 votes vote down vote up
public boolean getBoolean(int viewId) {
    CompoundButton button = findView(viewId);
    return button.isChecked();
}
 
Example 20
Source File: MainActivity.java    From WiFiAfterConnect with Apache License 2.0 4 votes vote down vote up
public void onWifiToggle(View v) {
	CompoundButton btn = (CompoundButton)v;
	wifiTools.setWifiEnabled(btn.isChecked());
	if (!btn.isChecked())
		setAuthenticateNowEnabled(false, R.string.auth_now_disabled_label);;
}