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:ru.valle.btc.MainActivity.java
private void showQRCodePopupForPrivateKey(final String label, final String address, final String[] data, final String[] dataTypes) { DisplayMetrics dm = getResources().getDisplayMetrics(); final int screenSize = Math.min(dm.widthPixels, dm.heightPixels); new AsyncTask<Void, Void, Bitmap[]>() { @Override//from w w w . ja v a2 s . c om protected Bitmap[] doInBackground(Void... params) { Bitmap[] result = new Bitmap[data.length]; for (int i = 0; i < data.length; i++) { if (data[i] != null) { QRCode qr = QRCode.getMinimumQRCode(data[i], ErrorCorrectLevel.M); result[i] = qr.createImage(screenSize / 2); } } return result; } @Override protected void onPostExecute(final Bitmap[] bitmap) { if (bitmap != null) { View view = getLayoutInflater().inflate(R.layout.private_key_qr, mainLayout, false); if (view != null) { final ToggleButton toggle1 = (ToggleButton) view.findViewById(R.id.toggle_1); final ToggleButton toggle2 = (ToggleButton) view.findViewById(R.id.toggle_2); final ToggleButton toggle3 = (ToggleButton) view.findViewById(R.id.toggle_3); final ImageView qrView = (ImageView) view.findViewById(R.id.qr_code_image); final TextView dataView = (TextView) view.findViewById(R.id.qr_code_data); if (data[0] == null) { toggle1.setVisibility(View.GONE); } else { toggle1.setTextOff(dataTypes[0]); toggle1.setTextOn(dataTypes[0]); toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle2.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[0]); dataView.setText(data[0]); } else if (!toggle2.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[1] == null) { toggle2.setVisibility(View.GONE); } else { toggle2.setTextOff(dataTypes[1]); toggle2.setTextOn(dataTypes[1]); toggle2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[1]); dataView.setText(data[1]); } else if (!toggle1.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] == null) { toggle3.setVisibility(View.GONE); } else { toggle3.setTextOff(dataTypes[2]); toggle3.setTextOn(dataTypes[2]); toggle3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle2.setChecked(false); qrView.setImageBitmap(bitmap[2]); dataView.setText(data[2]); } else if (!toggle1.isChecked() && !toggle2.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] != null) { toggle3.setChecked(true); } else if (data[0] != null) { toggle1.setChecked(true); } else { toggle2.setChecked(true); } AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(label); builder.setView(view); DialogInterface.OnClickListener shareClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, label); intent.putExtra(Intent.EXTRA_TEXT, data[selectedIndex]); startActivity( Intent.createChooser(intent, getString(R.string.share_chooser_title))); } }; if (systemSupportsPrint()) { builder.setPositiveButton(R.string.print, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Renderer.printWallet(MainActivity.this, label, SCHEME_BITCOIN + address, data[selectedIndex]); } }); builder.setNeutralButton(R.string.share, shareClickListener); } else { builder.setPositiveButton(R.string.share, shareClickListener); } builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } } } }.execute(); }
From source file:com.juick.android.MainActivity.java
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH) private void selectSourcesForCombined(final String prefix, final String[] codes) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); ScrollView v = new ScrollView(this); v.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ll.setOrientation(LinearLayout.VERTICAL); v.addView(ll);// w ww.ja v a 2 s . co m for (int i = 0; i < codes.length; i++) { final CompoundButton sw = VERSION.SDK_INT >= 14 ? new Switch(this) : new CheckBox(this); sw.setPadding(10, 10, 10, 10); sw.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); sw.setText(codes[i]); sw.setChecked(sp.getBoolean(prefix + codes[i], true)); ll.addView(sw); } new AlertDialog.Builder(MainActivity.this).setView(v).setCancelable(true) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { SharedPreferences.Editor e = sp.edit(); for (int i = 0; i < ll.getChildCount(); i++) { CompoundButton cb = (CompoundButton) ll.getChildAt(i); assert cb != null; e.putBoolean(prefix + codes[i], cb.isChecked()); } e.commit(); } }).create().show(); }
From source file:com.androidquery.AQuery.java
/** * Set checked state of a compound button. * * @param checked state//from ww w .j a v a 2 s . c o m * @return self */ public AQuery checked(boolean checked) { if (view instanceof CompoundButton) { CompoundButton cb = (CompoundButton) view; cb.setChecked(checked); } return self(); }
From source file:com.androidquery.AbstractAQuery.java
/** * Set checked state of a compound button. * * @param checked state// w ww.j a va 2 s .c o m * @return self */ public T checked(boolean checked) { if (view instanceof CompoundButton) { CompoundButton cb = (CompoundButton) view; cb.setChecked(checked); } return self(); }
From source file:uk.org.ngo.squeezer.dialog.AlarmSettingsDialog.java
@NonNull @Override//from www . j a va 2 s.c o m public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint({ "InflateParams" }) // OK, as view is passed to AlertDialog.Builder.setView() final View view = getActivity().getLayoutInflater().inflate(R.layout.alarm_settings_dialog, null); final TextView alarmVolumeHint = (TextView) view.findViewById(R.id.alarm_volume_hint); final TextView alarmSnoozeHint = (TextView) view.findViewById(R.id.alarm_snooze_hint); final TextView alarmTimeoutHint = (TextView) view.findViewById(R.id.alarm_timeout_hint); final TextView alarmFadeHint = (TextView) view.findViewById(R.id.alarm_fade_hint); final SeekBar alarmVolume = (SeekBar) view.findViewById(R.id.alarm_volume_seekbar); final SeekBar alarmSnooze = (SeekBar) view.findViewById(R.id.alarm_snooze_seekbar); final SeekBar alarmTimeout = (SeekBar) view.findViewById(R.id.alarm_timeout_seekbar); final CompoundButton alarmFadeToggle = (CompoundButton) view.findViewById(R.id.alarm_fade); alarmVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { alarmVolumeHint.setText(String.format("%d%%", progress)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmSnooze.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { alarmSnoozeHint.setText( getResources().getQuantityString(R.plurals.alarm_snooze_hint_text, progress, progress)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmTimeout.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (progress == 0) { alarmTimeoutHint.setText(R.string.alarm_timeout_hint_text_zero); } else { alarmTimeoutHint.setText(getResources().getQuantityString(R.plurals.alarm_timeout_hint_text, progress, progress)); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmFadeToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { alarmFadeHint.setText(isChecked ? R.string.alarm_fade_on_text : R.string.alarm_fade_off_text); } }); alarmVolume.setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_DEFAULT_VOLUME))); alarmSnooze .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_SNOOZE_SECONDS)) / 60); alarmTimeout .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_TIMEOUT_SECONDS)) / 60); alarmFadeToggle.setChecked("1".equals(mHostActivity.getPlayerPref(Player.Pref.ALARM_FADE_SECONDS))); Builder builder = new Builder(getActivity()); builder.setView(view); builder.setTitle(getResources().getString(R.string.alarms_settings_dialog_title, mHostActivity.getPlayer().getName())); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mHostActivity.onPositiveClick(alarmVolume.getProgress(), alarmSnooze.getProgress() * 60, alarmTimeout.getProgress() * 60, alarmFadeToggle.isChecked()); } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); }
From source file:org.odk.collect.android.widgets.SelectMultiWidget.java
@SuppressWarnings("unchecked") public SelectMultiWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt;//from w w w . j a v a2 s. com mCheckboxes = new ArrayList<CheckBox>(); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } setOrientation(LinearLayout.VERTICAL); String fieldElementReference = prompt.getFormElement().getBind().getReference().toString(); fieldName = getFieldID(fieldElementReference); if (fieldName.equalsIgnoreCase("typedirt")) { if (PropertiesUtils.getiAnswer32() == 1) { setVisibility(VISIBLE); } else setVisibility(INVISIBLE); PropertiesUtils.setLayoutQuestion321(this); } if (fieldName.equalsIgnoreCase("taste1")) { if (PropertiesUtils.getiAns33() == 0) { setVisibility(INVISIBLE); } else { if (PropertiesUtils.getiAns332() == 0) { setVisibility(INVISIBLE); } else setVisibility(VISIBLE); } PropertiesUtils.setLayoutQues333(this); } Vector<Selection> ve = new Vector<Selection>(); if (prompt.getAnswerValue() != null) { ve = (Vector<Selection>) prompt.getAnswerValue().getValue(); } // int row_index = 0 ; // int col_index = 0 ; Boolean isNewRow = false; Boolean isAddDirect = false; Boolean isTextView = false; Boolean isAddDivider = false; int itemCount = 0; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.5f); if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { // no checkbox group so id by answer + offset View c; //Check text of the Choice Start With ($), i must be category if (prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) { StringBuilder sb = new StringBuilder(prompt.getSelectChoiceText(mItems.get(i))); String str = sb.deleteCharAt(0).toString(); c = new TextView(getContext()); ((TextView) c).setText(str); ((TextView) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mQuestionFontsize + 1); ((TextView) c).setTypeface(null, Typeface.BOLD_ITALIC); c.setPadding(70, 10, 10, 10); c.setId(QuestionWidget.newUniqueId()); // assign random id isNewRow = true; itemCount = 0; isTextView = true; mCheckboxes.add(new CheckBox(context)); } else { // checkbox isNewRow = true; isTextView = false; itemCount++; c = new CheckBox(getContext()); c.setTag(Integer.valueOf(i)); c.setId(QuestionWidget.newUniqueId()); ((CheckBox) c).setText(prompt.getSelectChoiceText(mItems.get(i))); ((CheckBox) c).setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); c.setFocusable(!prompt.isReadOnly()); c.setEnabled(!prompt.isReadOnly()); c.setPadding(10, 10, 10, 10); ((CheckBox) c).setLineSpacing(1, 1.15f); mCheckboxes.add((CheckBox) c); } if (!isTextView) for (int vi = 0; vi < ve.size(); vi++) { // match based on value, not key if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) { ((CheckBox) c).setChecked(true); break; } } if (!prompt.getSelectChoiceText(mItems.get(i)).startsWith("$")) { // when clicked, check for readonly before toggling ((CheckBox) c).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { try { if (fieldName.equalsIgnoreCase("typedirt")) { if (mItems.get((Integer) buttonView.getTag()).getValue() .equalsIgnoreCase("other")) { if (isChecked) { PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.setiAnswer321(1); PropertiesUtils.setIsOther321Checked(true); } else { PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.setiAnswer321(0); PropertiesUtils.setIsOther321Checked(false); } } else { PropertiesUtils.getTvQuestion321Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(INVISIBLE); if (PropertiesUtils.isIsOther321Checked() == true) { PropertiesUtils.getTvQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.getEdQuestion321Other().setVisibility(VISIBLE); PropertiesUtils.setiAnswer321(1); } } } if (fieldName.equalsIgnoreCase("taste1")) { if (mItems.get((Integer) buttonView.getTag()).getValue() .equalsIgnoreCase("other_taste")) { if (isChecked) { PropertiesUtils.setiAns333(1); PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE); PropertiesUtils.setIsOther333Checked(true); } else { PropertiesUtils.setiAns333(0); PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE); PropertiesUtils.setIsOther333Checked(false); } } else { PropertiesUtils.getTvQues333Other().setVisibility(INVISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(INVISIBLE); if (PropertiesUtils.isIsOther333Checked() == true) { PropertiesUtils.getTvQues333Other().setVisibility(VISIBLE); PropertiesUtils.getEdQues333Other().setVisibility(VISIBLE); PropertiesUtils.setiAns333(1); } } } } catch (Exception e) { e.printStackTrace(); } if (!mCheckboxInit && mPrompt.isReadOnly()) { if (buttonView.isChecked()) { buttonView.setChecked(false); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.deselect", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } else { buttonView.setChecked(true); Collect.getInstance().getActivityLogger().logInstanceAction(this, "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } } } }); } String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); if (isTextView) { mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (TextView) c, audioURI, imageURI, videoURI, bigImageURI); } else { mediaLayout.setAVT(prompt.getIndex(), "." + Integer.toString(i), (CheckBox) c, audioURI, imageURI, videoURI, bigImageURI); } mediaLayout.setLayoutParams(params); // row_index = i/2 +1; // col_index = i%2; if (itemCount == 2) { isNewRow = false; itemCount = 0; } if (isNewRow) { ll = null; ll = new LinearLayout(getContext()); ll.setOrientation(LinearLayout.HORIZONTAL); ll.addView(mediaLayout); isNewRow = false; isAddDirect = false; isAddDivider = false; try { //if textview (category in choices) or the next element is textView , so must add direct if (isTextView || prompt.getSelectChoiceText(mItems.get(i + 1)).startsWith("$")) isAddDirect = true; } catch (Exception e) { isAddDirect = true; } if (isAddDirect) { addView(ll); isAddDivider = true; } } else { ll.addView(mediaLayout); addView(ll); isAddDivider = true; } // add the dividing line between elements (except for the last element) but not last ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); int size = mItems.size() / 2; // if ( (i+1)/2< size && (i+1)%2==0) { if (isAddDivider && i < mItems.size() - 1) addView(divider); // } } } mCheckboxInit = false; }