Java Code Examples for android.widget.CompoundButton#OnCheckedChangeListener

The following examples show how to use android.widget.CompoundButton#OnCheckedChangeListener . 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: PreventFragment.java    From prevent with Do What The F*ck You Want To Public License 6 votes vote down vote up
public Adapter(PreventActivity activity) {
    super(activity, R.layout.item);
    mActivity = activity;
    mPm = mActivity.getPackageManager();
    inflater = LayoutInflater.from(activity);
    mListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ViewHolder holder = (ViewHolder) buttonView.getTag();
            Set<String> selections = mActivity.getSelection();
            if (isChecked) {
                selections.add(holder.packageName);
            } else {
                selections.remove(holder.packageName);
            }
            mActivity.checkSelection();
        }
    };
}
 
Example 2
Source File: FindReplace.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
protected void assignBooleanSwitch(final APDE context, final String key, final boolean defaultValue, final SwitchCompat switchCompat, final MutableBoolean value, final CompoundButton.OnCheckedChangeListener listener) {
	boolean savedValue = getPreferences(context).getBoolean(key, defaultValue);
	value.set(savedValue);
	switchCompat.setChecked(savedValue);
	
	switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			value.set(isChecked);
			
			getPreferences(context).edit().putBoolean(key, value.get()).commit();
			
			if (listener != null) {
				listener.onCheckedChanged(buttonView, isChecked);
			}
		}
	});
}
 
Example 3
Source File: MainActivity.java    From MockSMS with Apache License 2.0 6 votes vote down vote up
private Switch.OnCheckedChangeListener listener(final int roll) {
    return new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (roll == ROLL.READ.ordinal()) {
                Extra.getInstance(getBaseContext()).setRead(isChecked);
            } else if (roll == ROLL.SEEN.ordinal()) {
                Extra.getInstance(getBaseContext()).setSeen(isChecked);
            } else if (roll == ROLL.DELIVERED.ordinal()) {
                Extra.getInstance(getBaseContext()).setDelivered(isChecked);
            } else if (roll == ROLL.SLOT.ordinal()) {
                Extra.getInstance(getBaseContext()).setSLOT_ENABLED(isChecked);
            } else if (roll == ROLL.IMSI.ordinal()) {
                Extra.getInstance(getBaseContext()).setIMSI_ENABLED(isChecked);
            } else if (roll == ROLL.REPLY_PATH.ordinal()) {
                Extra.getInstance(getBaseContext()).setREPLY_PATH_PRESENT(isChecked);
            } else if (roll == ROLL.SERVICE_CENTER.ordinal()) {
                Extra.getInstance(getBaseContext()).setServiceCenterBool(isChecked);
            } else if (roll == ROLL.TIME_DIFFERENCE.ordinal()) {
                Extra.getInstance(getBaseContext()).setTimeDifferenceBool(isChecked);
            } else if (roll == ROLL.STATUS.ordinal()) {
                Extra.getInstance(getBaseContext()).setSmsStatusBool(isChecked);
            }
        }
    };
}
 
Example 4
Source File: Card.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
public Card(String title, String desc, String color, String prop, ActionBarActivity fa, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
    this.title = title;
    this.desc = desc;
    this.color = color;
    this.fa = fa;
    this.prop = prop;
    this.onCheckedChangeListener = onCheckedChangeListener;
}
 
Example 5
Source File: SettingsActivity.java    From android-AutofillFramework with Apache License 2.0 5 votes vote down vote up
private void setupSettingsSwitch(int containerId, int labelId, int switchId, boolean checked,
        CompoundButton.OnCheckedChangeListener checkedChangeListener) {
    ViewGroup container = findViewById(containerId);
    String switchLabel = ((TextView) container.findViewById(labelId)).getText().toString();
    final Switch switchView = container.findViewById(switchId);
    switchView.setContentDescription(switchLabel);
    switchView.setChecked(checked);
    container.setOnClickListener((view) -> switchView.performClick());
    switchView.setOnCheckedChangeListener(checkedChangeListener);
}
 
Example 6
Source File: Card.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
public Card(String title, String desc, String prop, ActionBarActivity fa, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
    this.title = title;
    this.desc = desc;
    this.fa = fa;
    this.prop = prop;
    this.onCheckedChangeListener = onCheckedChangeListener;
}
 
Example 7
Source File: TimerSkillViewFragment.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.skill_event__timer, container, false);

    group_short = view.findViewById(R.id.group_short);
    group_long = view.findViewById(R.id.group_long);

    radioButton_short = view.findViewById(R.id.radioButton_short);
    radioButton_long = view.findViewById(R.id.radioButton_long);
    CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (buttonView == radioButton_short) {
                radioButton_long.setChecked(!isChecked);
                group_short.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            } else if (buttonView == radioButton_long) {
                radioButton_short.setChecked(!isChecked);
                group_long.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            } else {
                throw new IllegalStateException("This OnCheckedChangeListener shouldn't be used elsewhere.");
            }
        }
    };
    radioButton_short.setOnCheckedChangeListener(onCheckedChangeListener);
    radioButton_long.setOnCheckedChangeListener(onCheckedChangeListener);
    radioButton_long.setChecked(true);
    radioButton_short.setChecked(true);

    editText_second = view.findViewById(R.id.editText_second);

    editText_minute = view.findViewById(R.id.editText_minute);
    radioButton_exact = view.findViewById(R.id.radioButton_exact);
    radioButton_inexact = view.findViewById(R.id.radioButton_inexact);
    radioButton_repeat = view.findViewById(R.id.radioButton_repeat);
    radioButton_one_time = view.findViewById(R.id.radioButton_one_time);
    return view;
}
 
Example 8
Source File: SwitcherFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
public static SwitcherFragment newInstance(String title, String summary, boolean checked,
                                           CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
    Bundle args = new Bundle();
    args.putString(INTENT_TITLE, title);
    args.putString(INTENT_SUMMARY, summary);
    args.putBoolean(INTENT_CHECKED, checked);
    SwitcherFragment fragment = new SwitcherFragment();
    fragment.setArguments(args);
    fragment.mOnCheckedChangeListener = onCheckedChangeListener;
    return fragment;
}
 
Example 9
Source File: EnhancedToggleButton.java    From RxAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
@Override
public void setOnCheckedChangeListener(
        CompoundButton.OnCheckedChangeListener listener){
    if(this.mListener == null) {this.mListener = listener;}
    super.setOnCheckedChangeListener(listener);
}
 
Example 10
Source File: ItemViewHelper.java    From JianshuApp with GNU General Public License v3.0 4 votes vote down vote up
public ItemViewHelper setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) {
    CompoundButton view = this.getView(viewId);
    view.setOnCheckedChangeListener(listener);
    return this;
}
 
Example 11
Source File: CustomNotificationsDialogFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void initializeViews(@NonNull View view) {
  customNotificationsSwitch = view.findViewById(R.id.custom_notifications_enable_switch);
  soundLabel                = view.findViewById(R.id.custom_notifications_sound_label);
  soundSelector             = view.findViewById(R.id.custom_notifications_sound_selection);
  vibrateLabel              = view.findViewById(R.id.custom_notifications_vibrate_label);
  vibrateSwitch             = view.findViewById(R.id.custom_notifications_vibrate_switch);

  Toolbar toolbar = view.findViewById(R.id.custom_notifications_toolbar);

  toolbar.setNavigationOnClickListener(v -> dismissAllowingStateLoss());

  CompoundButton.OnCheckedChangeListener onCustomNotificationsSwitchCheckChangedListener = (buttonView, isChecked) -> {
    viewModel.setHasCustomNotifications(isChecked);
  };

  viewModel.isInitialLoadComplete().observe(getViewLifecycleOwner(), customNotificationsSwitch::setEnabled);

  viewModel.hasCustomNotifications().observe(getViewLifecycleOwner(), hasCustomNotifications -> {
    if (customNotificationsSwitch.isChecked() != hasCustomNotifications) {
      customNotificationsSwitch.setOnCheckedChangeListener(null);
      customNotificationsSwitch.setChecked(hasCustomNotifications);
    }

    customNotificationsSwitch.setOnCheckedChangeListener(onCustomNotificationsSwitchCheckChangedListener);

    soundLabel.setEnabled(hasCustomNotifications);
    vibrateLabel.setEnabled(hasCustomNotifications);
    soundSelector.setVisibility(hasCustomNotifications ? View.VISIBLE : View.GONE);
    vibrateSwitch.setVisibility(hasCustomNotifications ? View.VISIBLE : View.GONE);
  });

  if (!NotificationChannels.supported()) {
    customNotificationsSwitch.setVisibility(View.GONE);
    view.findViewById(R.id.custom_notifications_enable_label).setVisibility(View.GONE);
  }

  CompoundButton.OnCheckedChangeListener onVibrateSwitchCheckChangedListener = (buttonView, isChecked) -> {
    viewModel.setMessageVibrate(isChecked ? RecipientDatabase.VibrateState.ENABLED : RecipientDatabase.VibrateState.DISABLED);
  };

  viewModel.getVibrateState().observe(getViewLifecycleOwner(), vibrateState -> {
    boolean vibrateEnabled = vibrateState != RecipientDatabase.VibrateState.DISABLED;

    if (vibrateSwitch.isChecked() != vibrateEnabled) {
      vibrateSwitch.setOnCheckedChangeListener(null);
      vibrateSwitch.setChecked(vibrateEnabled);
    }

    vibrateSwitch.setOnCheckedChangeListener(onVibrateSwitchCheckChangedListener);
  });

  viewModel.getNotificationSound().observe(getViewLifecycleOwner(), sound -> {
    soundSelector.setText(getRingtoneSummary(requireContext(), sound));
    soundSelector.setTag(sound);
  });

  soundSelector.setOnClickListener(v -> launchSoundSelector(viewModel.getNotificationSound().getValue()));
}
 
Example 12
Source File: SaklarAdapter.java    From AndroidSmartHome with Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(final SaklarHolder holder, final int position) {

    final Saklar saklar = saklarList.get(position);

    // Saklar Switch Listenner
    CompoundButton.OnCheckedChangeListener toggleListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            AgnosthingsApi api = new AgnosthingsApi(context);

            realm.beginTransaction();
            if (isChecked) {
                saklar.setValue(1);
                holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_green);
            } else {
                saklar.setValue(0);
                holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_grey);
            }
            realm.commitTransaction();

            // Push updated data saklar
            api.pushDataSaklar();
        }
    };

    holder.saklarName.setText(saklar.getName());

    // Disable Listener sementara
    holder.saklarSwitch.setOnCheckedChangeListener(null);

    // Set Saklar dari Object / Database
    if (saklar.getValue() == 1) {
        holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_green);
        holder.saklarSwitch.setChecked(true);
    } else if (saklar.getValue() == 0) {
        holder.saklarIcon.setImageResource(R.drawable.ic_lightbulb_outline_grey);
        holder.saklarSwitch.setChecked(false);
    }

    holder.saklarSwitch.setOnCheckedChangeListener(toggleListener);

}
 
Example 13
Source File: SettingSwitchRowView.java    From droidkaigi2016 with Apache License 2.0 4 votes vote down vote up
public void init(boolean defaultValue, CompoundButton.OnCheckedChangeListener listener) {
    binding.settingSwitch.setChecked(defaultValue);
    onCheckedChangeListener = listener;
}
 
Example 14
Source File: LabeledSwitch.java    From px-android with MIT License 4 votes vote down vote up
public void setOnCheckedChanged(final CompoundButton.OnCheckedChangeListener listener) {
    this.listener = listener;
}
 
Example 15
Source File: CardSwitchDisabled.java    From Pimp_my_Z1 with GNU General Public License v2.0 4 votes vote down vote up
public CardSwitchDisabled(String title, String desc, String color, String prop, ActionBarActivity fa, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
    super(title, desc, color, prop, fa, onCheckedChangeListener);
}
 
Example 16
Source File: ArchivedStickerSetCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void setOnCheckClick(CompoundButton.OnCheckedChangeListener listener) {
    checkBox.setOnCheckedChangeListener(onCheckedChangeListener = listener);
    checkBox.setOnClickListener(v -> {

    });
}
 
Example 17
Source File: CommonHolder.java    From videocreator with Apache License 2.0 4 votes vote down vote up
/**
 * @param viewId
 * @param listener
 * @return
 */
public CommonHolder setCheckedChanged(int viewId, CompoundButton.OnCheckedChangeListener listener) {
    View view = getView(viewId);
    ((CheckBox) view).setOnCheckedChangeListener(listener);
    return this;
}
 
Example 18
Source File: SwitchBarPermissible.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setOnCheckedChangeListener(
        @Nullable CompoundButton.OnCheckedChangeListener listener) {
    mListener = listener;
}
 
Example 19
Source File: BasisViewHelper.java    From FastLib with Apache License 2.0 4 votes vote down vote up
public T setOnCheckedChangeListener(int id, CompoundButton.OnCheckedChangeListener listener) {
    CompoundButton button = getContentView().findViewById(id);
    button.setOnCheckedChangeListener(listener);
    return back();
}
 
Example 20
Source File: ICheckable.java    From AcDisplay with GNU General Public License v2.0 votes vote down vote up
void setOnCheckedChangeListener(@Nullable CompoundButton.OnCheckedChangeListener listener);