Example usage for android.widget CompoundButton setOnCheckedChangeListener

List of usage examples for android.widget CompoundButton setOnCheckedChangeListener

Introduction

In this page you can find the example usage for android.widget CompoundButton setOnCheckedChangeListener.

Prototype

public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener) 

Source Link

Document

Register a callback to be invoked when the checked state of this button changes.

Usage

From source file:it.cosenonjaviste.twowaydatabinding.DataBindingConverters.java

@BindingAdapter({ "app:binding" })
public static void bindCompoundButton(CompoundButton view, final ObservableBoolean observableBoolean) {
    if (observableBoolean != null) {
        if (view.getTag(R.id.bound_observable) != observableBoolean) {
            view.setTag(R.id.bound_observable, observableBoolean);
            view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override/* www . j av  a  2 s. c  o  m*/
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    observableBoolean.set(isChecked);
                }
            });
        }
        boolean newValue = observableBoolean.get();
        if (view.isChecked() != newValue) {
            view.setChecked(newValue);
        }
    }
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.contents.AudioEffectSettingsBaseFragment.java

@Override
protected void onUpdateActionBarAndOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onUpdateActionBarAndOptionsMenu(menu, inflater);

    // inflate menu for audio effect settings
    inflater.inflate(R.menu.audio_effect_settings, menu);

    // set up effect On/Off switch
    MenuItem menuSwitchItem = menu.findItem(R.id.menu_item_action_bar_switch);
    CompoundButton effectOnOffSwitch = (CompoundButton) MenuItemCompat.getActionView(menuSwitchItem);

    effectOnOffSwitch.setChecked(onGetActionBarSwitchCheckedState());
    effectOnOffSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/* w  w  w.j  ava 2s.c  om*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            onActionBarSwitchCheckedChanged(buttonView, isChecked);
        }
    });

    ActionBar actionBar = getActionBar();

    actionBar.setTitle(onGetActionBarTitleText());
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_wa_filtering.CustomFilteringWrapperAdapterExampleActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_wa_on_off_toggle, menu);

    // setting up the filtering on/off switch
    MenuItem menuSwitchItem = menu.findItem(R.id.menu_switch_on_off);
    CompoundButton actionView = MenuItemCompat.getActionView(menuSwitchItem).findViewById(R.id.switch_view);

    actionView.setChecked(mFilteringAdapter.isFilteringEnabled());

    actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//ww w  .  ja v  a 2 s. co  m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mFilteringAdapter.setFilteringEnabled(!mFilteringAdapter.isFilteringEnabled());
        }
    });

    return true;
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_wa_insertion.CustomInsertionWrapperAdapterExampleActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_wa_on_off_toggle, menu);

    // setting up the insertion on/off switch
    MenuItem menuSwitchItem = menu.findItem(R.id.menu_switch_on_off);
    CompoundButton actionView = MenuItemCompat.getActionView(menuSwitchItem).findViewById(R.id.switch_view);

    actionView.setChecked(mInsertionAdapter.isInsertionEnabled());

    actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/* ww w.  java  2s.  co  m*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mInsertionAdapter.setInsertionEnabled(!mInsertionAdapter.isInsertionEnabled());
        }
    });

    return true;
}

From source file:rikka.materialpreference.SwitchPreference.java

private void syncSwitchView(final View view) {
    if (view instanceof CompoundButton) {
        CompoundButton switchView = (CompoundButton) view;
        switchView.setOnCheckedChangeListener(null);

        if (!mSetInPost) {
            switchView.setChecked(mChecked);
        } else {//from  w  ww.jav a2s .  c  o m
            view.post(new Runnable() {
                @Override
                public void run() {
                    ((CompoundButton) view).setChecked(mChecked);
                    mSetInPost = false;
                }
            });
        }

        if (view instanceof Switch) {
            ((Switch) switchView).setTextOn(mSwitchOn);
            ((Switch) switchView).setTextOff(mSwitchOff);
        } else if (view instanceof SwitchCompat) {
            ((SwitchCompat) switchView).setTextOn(mSwitchOn);
            ((SwitchCompat) switchView).setTextOff(mSwitchOff);
        }

        switchView.setOnCheckedChangeListener(mListener);
    }
}

From source file:com.matthewmitchell.wakeifyplus.database.AlarmCursorAdapter.java

@Override
public void bindView(View v, Context context, Cursor c) {

    final String name = c.getString(c.getColumnIndex("name"));
    final long time = c.getLong(c.getColumnIndex("time"));

    TextView time_text = (TextView) v.findViewById(R.id.time);
    if (time_text != null) {
        time_text.setText(date_format.format(new Date(time)));
    }/*from  w  w  w .j av  a  2 s  .  co m*/

    TextView name_text = (TextView) v.findViewById(R.id.name);
    if (name_text != null) {
        name_text.setText(name);
    }

    // Do on/off button alarm code

    CompoundButton onOff = (CompoundButton) v.findViewById(R.id.alarm_switch);
    // Make sure the change listener is not set for setting value from database.
    onOff.setOnCheckedChangeListener(null);
    onOff.setChecked(c.getInt(c.getColumnIndex("onOff")) == 1);
    final Context contextl = context;
    final long id = c.getInt(c.getColumnIndex("_id"));
    onOff.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            AlarmDatabase database = new AlarmDatabase(contextl);
            SQLiteDatabase write = database.getWritableDatabase();
            ContentValues values = new ContentValues(1);
            if (isChecked) {
                // Alarm has been turned on
                values.put("onOff", 1);
                // Add system alarm
                AlarmReceiver.scheduleAlarm(contextl, id, false);
            } else {
                // Alarm has been switched off
                values.put("onOff", 0);
                AlarmReceiver.removeAlarm(contextl, id);
            }
            write.update(AlarmDatabase.ALARMS_TABLE, values, "_id = " + id, null);
            write.close();
            database.close();
            // Reload cursor
            main.getSupportLoaderManager().restartLoader(0, null, main);
        }

    });
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_d_grid.DraggableGridExampleFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_drag_grid, menu);

    // setting up the item move mode selection switch
    MenuItem menuSwitchItem = menu.findItem(R.id.menu_switch_swap_mode);
    CompoundButton actionView = (CompoundButton) MenuItemCompat.getActionView(menuSwitchItem)
            .findViewById(R.id.switch_view);

    actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*from  w  ww  .j  a  v a 2  s  .  c om*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateItemMoveMode(isChecked);
        }
    });
}

From source file:com.doctoror.surprise.SurpriseActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFragmentTransactionsAllowed = true;
    setContentView(R.layout.activity_surprise);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mLocalBroadcastManager.registerReceiver(mServiceReceiver, mServiceReceiver.mIntentFilter);

    mAnimatorSurprise = (ViewAnimator) findViewById(R.id.animator_surprise);
    mAnimatorUpgrade = (ViewAnimator) findViewById(R.id.animator_upgrade);

    mPackageManager = getPackageManager();
    mReceiverComponent = new ComponentName(this, SurpriseReceiver.class);
    final CompoundButton surprise = (CompoundButton) findViewById(R.id.btn_surprise);
    surprise.setChecked(mPackageManager//from   w w  w .  ja v  a  2 s.  c o  m
            .getComponentEnabledSetting(mReceiverComponent) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    surprise.setOnCheckedChangeListener(this);

    findViewById(R.id.btn_surprise_to_su).setOnClickListener(this);
    findViewById(R.id.info_surprise).setOnClickListener(this);
    findViewById(R.id.info_upgrade).setOnClickListener(this);
}

From source file:com.cerema.cloud2.ui.fragment.EditShareFragment.java

/**
 * Binds or unbinds listener for user actions to enable or disable a permission on the edited share
 * to the views receiving the user events.
 *
 * @param editShareView     Root view in the fragment.
 * @param enable            When 'true', listener is bound to view; when 'false', it is unbound.
 */// ww w  .  j  av a2  s  .  c o  m
private void setPermissionsListening(View editShareView, boolean enable) {
    if (enable && mOnPrivilegeChangeListener == null) {
        mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
    }
    CompoundButton.OnCheckedChangeListener changeListener = enable ? mOnPrivilegeChangeListener : null;
    CompoundButton compound;

    compound = (CompoundButton) editShareView.findViewById(R.id.canShareSwitch);
    compound.setOnCheckedChangeListener(changeListener);

    compound = (CompoundButton) editShareView.findViewById(R.id.canEditSwitch);
    compound.setOnCheckedChangeListener(changeListener);

    if (mFile.isFolder()) {
        compound = (CompoundButton) editShareView.findViewById(R.id.canEditCreateCheckBox);
        compound.setOnCheckedChangeListener(changeListener);

        compound = (CompoundButton) editShareView.findViewById(R.id.canEditChangeCheckBox);
        compound.setOnCheckedChangeListener(changeListener);

        compound = (CompoundButton) editShareView.findViewById(R.id.canEditDeleteCheckBox);
        compound.setOnCheckedChangeListener(changeListener);
    }

}

From source file:com.owncloud.android.ui.fragment.EditShareFragment.java

/**
 * Binds or unbinds listener for user actions to enable or disable a permission on the edited share
 * to the views receiving the user events.
 *
 * @param editShareView     Root view in the fragment.
 * @param enable            When 'true', listener is bound to view; when 'false', it is unbound.
 *///from  www .  j av a  2 s .  c o m
private void setPermissionsListening(View editShareView, boolean enable) {
    if (enable && mOnPrivilegeChangeListener == null) {
        mOnPrivilegeChangeListener = new OnPrivilegeChangeListener();
    }
    CompoundButton.OnCheckedChangeListener changeListener = enable ? mOnPrivilegeChangeListener : null;
    CompoundButton compound;

    compound = editShareView.findViewById(R.id.canShareSwitch);
    compound.setOnCheckedChangeListener(changeListener);

    compound = editShareView.findViewById(R.id.canEditSwitch);
    compound.setOnCheckedChangeListener(changeListener);

    if (mFile.isFolder()) {
        compound = editShareView.findViewById(R.id.canEditCreateCheckBox);
        compound.setOnCheckedChangeListener(changeListener);

        compound = editShareView.findViewById(R.id.canEditChangeCheckBox);
        compound.setOnCheckedChangeListener(changeListener);

        compound = editShareView.findViewById(R.id.canEditDeleteCheckBox);
        compound.setOnCheckedChangeListener(changeListener);
    }

}