android.widget.CompoundButton#OnCheckedChangeListener ( )源码实例Demo

下面列出了android.widget.CompoundButton#OnCheckedChangeListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: APDE   文件: FindReplace.java
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);
			}
		}
	});
}
 
源代码2 项目: MockSMS   文件: MainActivity.java
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);
            }
        }
    };
}
 
源代码3 项目: prevent   文件: PreventFragment.java
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();
        }
    };
}
 
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;
}
 
源代码5 项目: Pimp_my_Z1   文件: Card.java
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;
}
 
源代码6 项目: Easer   文件: TimerSkillViewFragment.java
@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;
}
 
源代码7 项目: Pimp_my_Z1   文件: Card.java
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;
}
 
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);
}
 
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()));
}
 
源代码10 项目: FastLib   文件: BasisViewHelper.java
public T setOnCheckedChangeListener(int id, CompoundButton.OnCheckedChangeListener listener) {
    CompoundButton button = getContentView().findViewById(id);
    button.setOnCheckedChangeListener(listener);
    return back();
}
 
源代码11 项目: videocreator   文件: CommonHolder.java
/**
 * @param viewId
 * @param listener
 * @return
 */
public CommonHolder setCheckedChanged(int viewId, CompoundButton.OnCheckedChangeListener listener) {
    View view = getView(viewId);
    ((CheckBox) view).setOnCheckedChangeListener(listener);
    return this;
}
 
源代码12 项目: Pimp_my_Z1   文件: CardSwitchDisabled.java
public CardSwitchDisabled(String title, String desc, String color, String prop, ActionBarActivity fa, CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
    super(title, desc, color, prop, fa, onCheckedChangeListener);
}
 
源代码13 项目: RxAndroidBootstrap   文件: EnhancedToggleButton.java
@Override
public void setOnCheckedChangeListener(
        CompoundButton.OnCheckedChangeListener listener){
    if(this.mListener == null) {this.mListener = listener;}
    super.setOnCheckedChangeListener(listener);
}
 
源代码14 项目: JianshuApp   文件: ItemViewHelper.java
public ItemViewHelper setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) {
    CompoundButton view = this.getView(viewId);
    view.setOnCheckedChangeListener(listener);
    return this;
}
 
源代码15 项目: AndroidSmartHome   文件: SaklarAdapter.java
@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);

}
 
源代码16 项目: droidkaigi2016   文件: SettingSwitchRowView.java
public void init(boolean defaultValue, CompoundButton.OnCheckedChangeListener listener) {
    binding.settingSwitch.setChecked(defaultValue);
    onCheckedChangeListener = listener;
}
 
源代码17 项目: px-android   文件: LabeledSwitch.java
public void setOnCheckedChanged(final CompoundButton.OnCheckedChangeListener listener) {
    this.listener = listener;
}
 
源代码18 项目: TelePlus-Android   文件: ArchivedStickerSetCell.java
public void setOnCheckClick(CompoundButton.OnCheckedChangeListener listener) {
    checkBox.setOnCheckedChangeListener(onCheckedChangeListener = listener);
    checkBox.setOnClickListener(v -> {

    });
}
 
源代码19 项目: AcDisplay   文件: SwitchBarPermissible.java
/**
 * {@inheritDoc}
 */
@Override
public void setOnCheckedChangeListener(
        @Nullable CompoundButton.OnCheckedChangeListener listener) {
    mListener = listener;
}
 
源代码20 项目: AcDisplay   文件: ICheckable.java
void setOnCheckedChangeListener(@Nullable CompoundButton.OnCheckedChangeListener listener);