List of usage examples for android.widget CompoundButton setChecked
@Override public void setChecked(boolean checked)
Changes the checked state of this button.
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/*from www . j av a2 s . co 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/*from w w w .j a va 2 s . 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/* w w w . j av a 2 s . c om*/ 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/*from w w w . j a v a 2s . com*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mInsertionAdapter.setInsertionEnabled(!mInsertionAdapter.isInsertionEnabled()); } }); return true; }
From source file:com.todoroo.astrid.ui.ImportanceControlSet.java
public void setImportance(Integer i) { for (CompoundButton b : buttons) { if (b.getTag() == i) { b.setChecked(true); b.setBackgroundResource(getResource(activity, R.attr.importance_background_selected)); } else {/* ww w . j a v a2s . c om*/ b.setChecked(false); b.setBackgroundResource(0); } } for (ImportanceChangedListener l : listeners) { l.importanceChanged(i); } }
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 .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:net.xisberto.work_schedule.PeriodListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.period_list_item, null); }/*from www .j a v a2 s .c o m*/ final Period period = (Period) getItem(position); ((TextView) convertView.findViewById(R.id.period_label)).setText(context.getString(period.getLabelId())); ((TextView) convertView.findViewById(R.id.period_time)) .setText(period.formatTime(DateFormat.is24HourFormat(context))); CompoundButton check_alarm = (CompoundButton) convertView.findViewById(R.id.check_alarm); if (show_checkboxes) { check_alarm.setChecked(period.enabled); check_alarm.setOnClickListener(new OnClickListener() { @Override public void onClick(View check_box) { boolean isChecked = ((CompoundButton) check_box).isChecked(); period.enabled = isChecked && (period.time.getTimeInMillis() > System.currentTimeMillis()); period.setAlarm(context, true); period.persist(context); ((CompoundButton) check_box).setChecked(period.enabled); } }); } else { check_alarm.setVisibility(View.GONE); LinearLayout layout_labels = (LinearLayout) convertView.findViewById(R.id.layout_labels); LayoutParams params = (LayoutParams) layout_labels.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); layout_labels.setLayoutParams(params); } return convertView; }
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))); }// w w w . j a v a 2 s .c om 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.android.deskclock.alarms.dataadapter.ExpandedAlarmViewHolder.java
private void bindDaysOfWeekButtons(Alarm alarm) { HashSet<Integer> setDays = alarm.daysOfWeek.getSetDays(); for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; i++) { final CompoundButton dayButton = dayButtons[i]; if (setDays.contains(mDayOrder[i])) { dayButton.setChecked(true); dayButton.setTextColor(UiDataModel.getUiDataModel().getWindowBackgroundColor()); } else {//from w w w .j a v a 2s . com dayButton.setChecked(false); dayButton.setTextColor(Color.WHITE); } } if (alarm.daysOfWeek.isRepeating()) { repeat.setChecked(true); repeatDays.setVisibility(View.VISIBLE); } else { repeat.setChecked(false); repeatDays.setVisibility(View.GONE); } }
From source file:com.anxpp.blog.fragment.SandboxFragment.java
private boolean restoreBooleanPrefState(Bundle savedInstanceState, int prefValue) { final boolean value = savedInstanceState.getBoolean(String.valueOf(prefValue)); final CompoundButton viewValue = (CompoundButton) viewRoot.findViewById(prefValue); viewValue.setChecked(value); return value; }