Java Code Examples for android.widget.CompoundButton#setOnCheckedChangeListener()
The following examples show how to use
android.widget.CompoundButton#setOnCheckedChangeListener() .
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: ConfigurationActivity.java From Noyze with Apache License 2.0 | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // R.menu.configure_overflow getMenuInflater().inflate(R.menu.toggle_switch, menu); // Get the action view used in your switch item final MenuItem toggle = menu.findItem(R.id.action_switch); if (null != toggle) { switchView = (CompoundButton) toggle.getActionView().findViewById(R.id.switch_view); if (null != switchView) { switchView.setChecked(VolumeAccessibilityService.isEnabled(this)); switchView.setOnCheckedChangeListener(this); } } return super.onCreateOptionsMenu(menu); }
Example 2
Source File: ShareFileFragment.java From Cirrus_depricated with GNU General Public License v2.0 | 6 votes |
/** * Called by R.id.shareViaLinkExpirationSwitch to set or clear the expiration date. * * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkExpirationSwitch * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { if (!isResumed()) { // very important, setCheched(...) is called automatically during // Fragment recreation on device rotations return; } if (isChecked) { ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment.newInstance(mFile, -1); dialog.show( getActivity().getSupportFragmentManager(), ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG ); } else { ((FileActivity) getActivity()).getFileOperationsHelper(). setExpirationDateToShareViaLink(mFile, -1); } // undo the toggle to grant the view will be correct if the dialog is cancelled switchView.setOnCheckedChangeListener(null); switchView.toggle(); switchView.setOnCheckedChangeListener(mOnExpirationDateInteractionListener); }
Example 3
Source File: CheckBoxBindingAdapterUtils.java From xDrip with GNU General Public License v3.0 | 6 votes |
@BindingAdapter(value = {"onCheckedChanged", "checkedAttrChanged"}, requireAll = false) public static void setListeners(CompoundButton view, final OnCheckedChangeListener listener, final InverseBindingListener attrChange) { if (attrChange == null) { view.setOnCheckedChangeListener(listener); } else { view.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (listener != null) { listener.onCheckedChanged(buttonView, isChecked); } attrChange.onChange(); } }); } }
Example 4
Source File: CheckBoxBindingAdapterUtils.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@BindingAdapter(value = {"onCheckedChanged", "checkedAttrChanged"}, requireAll = false) public static void setListeners(CompoundButton view, final OnCheckedChangeListener listener, final InverseBindingListener attrChange) { if (attrChange == null) { view.setOnCheckedChangeListener(listener); } else { view.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (listener != null) { listener.onCheckedChanged(buttonView, isChecked); } attrChange.onChange(); } }); } }
Example 5
Source File: ToggleDrawerItem.java From MaterialDrawer-Xamarin with Apache License 2.0 | 5 votes |
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isEnabled()) { checked = isChecked; if (getOnCheckedChangeListener() != null) { getOnCheckedChangeListener().onCheckedChanged(ToggleDrawerItem.this, buttonView, isChecked); } } else { buttonView.setOnCheckedChangeListener(null); buttonView.setChecked(!isChecked); buttonView.setOnCheckedChangeListener(checkedChangeListener); } }
Example 6
Source File: ManageAddonsActivity.java From MCPELauncher with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public boolean onCreateOptionsMenu(Menu menu) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getMenuInflater().inflate(R.menu.ab_master, menu); master = (CompoundButton) menu.findItem(R.id.ab_switch_container).getActionView() .findViewById(R.id.ab_switch); if (master != null) { master.setOnCheckedChangeListener(new android.widget.CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { findAddons(); } else { ((ArrayAdapter<?>) getListAdapter()).clear(); } SharedPreferences.Editor sh = Utils.getPrefs(0).edit(); sh.putBoolean("zz_load_native_addons", isChecked); sh.apply(); refreshABToggle(); } }); refreshABToggle(); } else { System.err.println("WTF?"); } return true; } else { return false; } }
Example 7
Source File: SwitchPreferenceEx.java From document-viewer with GNU General Public License v3.0 | 5 votes |
@Override protected void onBindView(final View view) { final Checkable cview = getCheckableView(view); if (cview instanceof CompoundButton) { final CompoundButton btn = (CompoundButton) cview; btn.setOnCheckedChangeListener(mListener); } super.onBindView(view); }
Example 8
Source File: ShareFileFragment.java From Cirrus_depricated with GNU General Public License v2.0 | 5 votes |
/** * Called by R.id.shareViaLinkSectionSwitch to create or delete a public link. * * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkSectionSwitch * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { if (!isResumed()) { // very important, setCheched(...) is called automatically during // Fragment recreation on device rotations return; } if (isChecked) { if (mCapabilities != null && mCapabilities.getFilesSharingPublicPasswordEnforced().isTrue()) { // password enforced by server, request to the user before trying to create ((FileActivity) getActivity()).getFileOperationsHelper(). requestPasswordForShareViaLink(mFile, true); } else { // create without password if not enforced by server or we don't know if enforced; ((FileActivity) getActivity()).getFileOperationsHelper(). shareFileViaLink(mFile, null); // FileActivtiy#onCreateShareViaLinkOperationFinish still handles the guess of enforcement // for server in versions previous to OwnCloudVersion#MINIMUM_VERSION_CAPABILITIES_API } } else { ((FileActivity) getActivity()).getFileOperationsHelper(). unshareFileViaLink(mFile); } // undo the toggle to grant the view will be correct if any intermediate dialog is cancelled or // the create/delete operation fails switchView.setOnCheckedChangeListener(null); switchView.toggle(); switchView.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); }
Example 9
Source File: RepoAdapter.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
private void setupView(Cursor cursor, View view, CompoundButton switchView) { final Repo repo = new Repo(cursor); switchView.setChecked(repo.inuse); // Add this listener *after* setting the checked status, so we don't // invoke the listener while setting up the view... switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (enabledListener != null) { enabledListener.onSetEnabled(repo, isChecked); } } }); TextView nameView = (TextView) view.findViewById(R.id.repo_name); nameView.setText(repo.getName()); View unsignedView = view.findViewById(R.id.repo_unsigned); View unverifiedView = view.findViewById(R.id.repo_unverified); if (repo.isSigned()) { unsignedView.setVisibility(View.GONE); unverifiedView.setVisibility(View.GONE); } else if (repo.isSignedButUnverified()) { unsignedView.setVisibility(View.GONE); unverifiedView.setVisibility(View.VISIBLE); } else { unsignedView.setVisibility(View.VISIBLE); unverifiedView.setVisibility(View.GONE); } }
Example 10
Source File: jni_string.java From stynico with MIT License | 5 votes |
protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.jni_main); StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary)); ViewWindow.showView(this, ""); mCompoundButton = (CompoundButton) findViewById(R.id.sw_window); mCompoundButton.setOnCheckedChangeListener(this); if (getResources().getBoolean(R.bool.use_watching_service)) { startService(new Intent(this, WatchingService.class)); } }
Example 11
Source File: CompoundButtonCheckedProperty.java From bindroid with MIT License | 5 votes |
/** * 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 12
Source File: SwitchDrawerItem.java From MaterialDrawer-Xamarin with Apache License 2.0 | 5 votes |
@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 13
Source File: ToggleButtonGroup.java From ToggleButtonGroup with Apache License 2.0 | 4 votes |
private void setStateTracker(CompoundButton view) { if (mCompoundButtonStateTracker == null) { mCompoundButtonStateTracker = new CompoundButtonCheckedStateTracker(); } view.setOnCheckedChangeListener(mCompoundButtonStateTracker); }
Example 14
Source File: MartianViewHolder.java From RxJava2RetrofitDemo with Apache License 2.0 | 4 votes |
@Override public MartianViewHolder setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) { CompoundButton view = getView(viewId); view.setOnCheckedChangeListener(listener); return this; }
Example 15
Source File: BasisViewHelper.java From FastLib with Apache License 2.0 | 4 votes |
public T setOnCheckedChangeListener(int id, CompoundButton.OnCheckedChangeListener listener) { CompoundButton button = getContentView().findViewById(id); button.setOnCheckedChangeListener(listener); return back(); }
Example 16
Source File: BaseViewHolder.java From JD-Test with Apache License 2.0 | 2 votes |
/** * Sets the on checked change listener of the view. * * @param viewId The view id. * @param listener The checked change listener of compound button. * @return The BaseViewHolder for chaining. */ public BaseViewHolder setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) { CompoundButton view = getView(viewId); view.setOnCheckedChangeListener(listener); return this; }
Example 17
Source File: ViewFinder.java From FeedListViewDemo with MIT License | 2 votes |
/** * Register on checked change listener to child view with given id * * @param id * @param listener * @return view registered with listener */ public CompoundButton onCheck(final int id, final OnCheckedChangeListener listener) { CompoundButton checkable = find(id); checkable.setOnCheckedChangeListener(listener); return checkable; }
Example 18
Source File: BaseViewHolder.java From AndroidBase with Apache License 2.0 | 2 votes |
/** * Sets the on checked change listener of the view. * * @param viewId The view id. * @param listener The checked change listener of compound button. * @return The BaseViewHolder for chaining. */ public BaseViewHolder setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) { CompoundButton view = getView(viewId); view.setOnCheckedChangeListener(listener); return this; }
Example 19
Source File: BaseViewHolder.java From imsdk-android with MIT License | 2 votes |
/** * Sets the on checked change listener of the view. * * @param viewId The view id. * @param listener The checked change listener of compound button. * @return The BaseViewHolder for chaining. */ public BaseViewHolder setOnCheckedChangeListener(@IdRes int viewId, CompoundButton.OnCheckedChangeListener listener) { CompoundButton view = getView(viewId); view.setOnCheckedChangeListener(listener); return this; }
Example 20
Source File: BaseViewHolder.java From NIM_Android_UIKit with MIT License | 2 votes |
/** * Sets the on checked change listener of the view. * * @param viewId The view id. * @param listener The checked change listener of compound button. * @return The BaseViewHolder for chaining. */ public BaseViewHolder setOnCheckedChangeListener(int viewId, CompoundButton.OnCheckedChangeListener listener) { CompoundButton view = getView(viewId); view.setOnCheckedChangeListener(listener); return this; }