use of android.widget.RadioButton in project Anki-Android by Ramblurr.
the class ChartBuilder method getStatisticsDialog.
public static StyledDialog getStatisticsDialog(Context context, DialogInterface.OnClickListener listener, boolean showWholeDeckSelection) {
StyledDialog.Builder builder = new StyledDialog.Builder(context);
builder.setTitle(context.getString(R.string.statistics_type_title));
builder.setIcon(android.R.drawable.ic_menu_sort_by_size);
// set items
String[] items = new String[3];
items[0] = context.getResources().getString(R.string.stats_forecast);
items[1] = context.getResources().getString(R.string.stats_review_count);
items[2] = context.getResources().getString(R.string.stats_review_time);
builder.setItems(items, listener);
// period selection
final RadioButton[] statisticRadioButtons = new RadioButton[3];
RadioGroup rg = new RadioGroup(context);
rg.setOrientation(RadioGroup.HORIZONTAL);
RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
Resources res = context.getResources();
String[] text = res.getStringArray(R.array.stats_period);
int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
for (int i = 0; i < statisticRadioButtons.length; i++) {
statisticRadioButtons[i] = new RadioButton(context);
statisticRadioButtons[i].setClickable(true);
statisticRadioButtons[i].setText(" " + text[i]);
statisticRadioButtons[i].setHeight(height * 2);
statisticRadioButtons[i].setSingleLine();
statisticRadioButtons[i].setBackgroundDrawable(null);
statisticRadioButtons[i].setGravity(Gravity.CENTER_VERTICAL);
rg.addView(statisticRadioButtons[i], lp);
}
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
int checked = arg0.getCheckedRadioButtonId();
for (int i = 0; i < 3; i++) {
if (arg0.getChildAt(i).getId() == checked) {
AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("statsType", i).commit();
break;
}
}
}
});
rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
statisticRadioButtons[Math.min(AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getInt("statsType", Stats.TYPE_MONTH), Stats.TYPE_LIFE)].setChecked(true);
if (showWholeDeckSelection) {
// collection/current deck
final RadioButton[] statisticRadioButtons2 = new RadioButton[2];
RadioGroup rg2 = new RadioGroup(context);
rg2.setOrientation(RadioGroup.HORIZONTAL);
String[] text2 = res.getStringArray(R.array.stats_range);
for (int i = 0; i < statisticRadioButtons2.length; i++) {
statisticRadioButtons2[i] = new RadioButton(context);
statisticRadioButtons2[i].setClickable(true);
statisticRadioButtons2[i].setText(" " + text2[i]);
statisticRadioButtons2[i].setHeight(height * 2);
statisticRadioButtons2[i].setSingleLine();
statisticRadioButtons2[i].setBackgroundDrawable(null);
statisticRadioButtons2[i].setGravity(Gravity.CENTER_VERTICAL);
rg2.addView(statisticRadioButtons2[i], lp);
}
rg2.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putBoolean("statsRange", arg0.getCheckedRadioButtonId() == arg0.getChildAt(0).getId()).commit();
}
});
rg2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
statisticRadioButtons2[AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).getBoolean("statsRange", true) ? 0 : 1].setChecked(true);
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
ll.addView(rg);
ll.addView(rg2);
builder.setView(ll, false, true);
} else {
builder.setView(rg, false, true);
}
return builder.create();
}
use of android.widget.RadioButton in project enroscar by stanfy.
the class RelativeRadioGroup method addView.
@Override
public void addView(final View child, final int index, final ViewGroup.LayoutParams params) {
if (child instanceof RadioButton) {
final RadioButton button = (RadioButton) child;
if (button.isChecked()) {
mProtectFromCheckedChange = true;
if (mCheckedId != -1) {
setCheckedStateForView(mCheckedId, false);
}
mProtectFromCheckedChange = false;
setCheckedId(button.getId());
}
}
super.addView(child, index, params);
}
use of android.widget.RadioButton in project double-espresso by JakeWharton.
the class ViewMatchersTest method testCheckBoxMatchers.
public void testCheckBoxMatchers() {
assertFalse(isChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
assertFalse(isNotChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
CheckBox checkBox = new CheckBox(getInstrumentation().getTargetContext());
checkBox.setChecked(true);
assertTrue(isChecked().matches(checkBox));
assertFalse(isNotChecked().matches(checkBox));
checkBox.setChecked(false);
assertFalse(isChecked().matches(checkBox));
assertTrue(isNotChecked().matches(checkBox));
RadioButton radioButton = new RadioButton(getInstrumentation().getTargetContext());
radioButton.setChecked(false);
assertFalse(isChecked().matches(radioButton));
assertTrue(isNotChecked().matches(radioButton));
radioButton.setChecked(true);
assertTrue(isChecked().matches(radioButton));
assertFalse(isNotChecked().matches(radioButton));
CheckedTextView checkedText = new CheckedTextView(getInstrumentation().getTargetContext());
checkedText.setChecked(false);
assertFalse(isChecked().matches(checkedText));
assertTrue(isNotChecked().matches(checkedText));
checkedText.setChecked(true);
assertTrue(isChecked().matches(checkedText));
assertFalse(isNotChecked().matches(checkedText));
Checkable checkable = new Checkable() {
@Override
public boolean isChecked() {
return true;
}
@Override
public void setChecked(boolean ignored) {
}
@Override
public void toggle() {
}
};
assertFalse(isChecked().matches(checkable));
assertFalse(isNotChecked().matches(checkable));
}
use of android.widget.RadioButton in project robolectric by robolectric.
the class ShadowRadioButtonTest method shouldInformRadioGroupThatItIsChecked.
@Test
public void shouldInformRadioGroupThatItIsChecked() {
RadioButton radioButton1 = new RadioButton(context);
radioButton1.setId(99);
RadioButton radioButton2 = new RadioButton(context);
radioButton2.setId(100);
RadioGroup radioGroup = new RadioGroup(context);
radioGroup.addView(radioButton1);
radioGroup.addView(radioButton2);
radioButton1.setChecked(true);
assertThat(radioGroup.getCheckedRadioButtonId()).isEqualTo(radioButton1.getId());
radioButton2.setChecked(true);
assertThat(radioGroup.getCheckedRadioButtonId()).isEqualTo(radioButton2.getId());
}
use of android.widget.RadioButton in project TaEmCasa by Dionen.
the class AdicionarMoradia method cadastrarMoradia.
/**
* Coleta os dados do formulário de registro de uma moradia e os insere na database.
* Ainda não checa se todos os dados foram inseridos
* @param view
*/
private void cadastrarMoradia(View view) {
final Context context = getApplicationContext();
// 0 = Não aceita animais, 1 = aceita animais
String animais = "0";
// 0 = Apartamento, 1 = República
String perfil;
// 0 = Calma, 1 = Agitada
String tipo;
EditText titulo = (EditText) findViewById(R.id.nomeMoradia);
EditText logradouro = (EditText) findViewById(R.id.logradouro);
EditText numero = (EditText) findViewById(R.id.numero);
EditText bairro = (EditText) findViewById(R.id.bairro);
EditText complemento = (EditText) findViewById(R.id.complemento);
EditText cidade = (EditText) findViewById(R.id.cidade);
EditText estado = (EditText) findViewById(R.id.estado);
RadioButton apartamento = (RadioButton) findViewById(R.id.apartamento);
RadioButton republica = (RadioButton) findViewById(R.id.republica);
RadioButton calma = (RadioButton) findViewById(R.id.calma);
RadioButton agitada = (RadioButton) findViewById(R.id.agitada);
EditText nMoradores = (EditText) findViewById(R.id.nMoradores);
CheckBox aceitamAnimais = (CheckBox) findViewById(R.id.aceitamAnimais);
EditText telefone = (EditText) findViewById(R.id.telefone);
EditText descricao = (EditText) findViewById(R.id.descricao);
final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Adicionando nova moradia...");
// disable dismiss by tapping outside of the dialog
progress.setCancelable(false);
progress.show();
if (calma.isChecked()) {
tipo = "0";
} else {
tipo = "1";
}
if (apartamento.isChecked()) {
perfil = "0";
} else {
perfil = "1";
}
if (aceitamAnimais.isChecked())
animais = "1";
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
progress.dismiss();
if (success) {
// MORADIA CRIADA
Toast toast = Toast.makeText(context, "Moradia cadastrada com sucesso", Toast.LENGTH_SHORT);
toast.show();
finish();
} else {
Toast toast = Toast.makeText(context, "Cadastro não autorizado", Toast.LENGTH_SHORT);
toast.show();
}
} catch (JSONException e) {
// PROBLEMAS
e.printStackTrace();
Toast toast = Toast.makeText(context, "Erro ao acessar database", Toast.LENGTH_SHORT);
toast.show();
}
}
};
MoradiaRequest_ADD moradiaRequest = new MoradiaRequest_ADD(user_email, titulo.getText().toString(), descricao.getText().toString(), logradouro.getText().toString(), numero.getText().toString(), complemento.getText().toString(), bairro.getText().toString(), cidade.getText().toString(), estado.getText().toString(), telefone.getText().toString(), BitMapToString(imagem), tipo, perfil, nMoradores.getText().toString(), animais, responseListener);
RequestQueue queue = Volley.newRequestQueue(AdicionarMoradia.this);
queue.add(moradiaRequest);
}
Aggregations