Search in sources :

Example 76 with RadioButton

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();
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) StyledDialog(com.ichi2.themes.StyledDialog) RadioButton(android.widget.RadioButton) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout)

Example 77 with RadioButton

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);
}
Also used : RadioButton(android.widget.RadioButton)

Example 78 with RadioButton

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));
}
Also used : Spinner(android.widget.Spinner) CheckBox(android.widget.CheckBox) CheckedTextView(android.widget.CheckedTextView) RadioButton(android.widget.RadioButton) Checkable(android.widget.Checkable)

Example 79 with RadioButton

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());
}
Also used : RadioGroup(android.widget.RadioGroup) RadioButton(android.widget.RadioButton) Test(org.junit.Test)

Example 80 with RadioButton

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);
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) JSONException(org.json.JSONException) RadioButton(android.widget.RadioButton) ProgressDialog(android.app.ProgressDialog) MoradiaRequest_ADD(com.usp.icmc.taemcasa.MinhasVagas.MoradiaResponse.MoradiaRequest_ADD) Response(com.android.volley.Response) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) CheckBox(android.widget.CheckBox) RequestQueue(com.android.volley.RequestQueue)

Aggregations

RadioButton (android.widget.RadioButton)198 View (android.view.View)100 TextView (android.widget.TextView)69 RadioGroup (android.widget.RadioGroup)43 Button (android.widget.Button)38 Intent (android.content.Intent)36 CheckBox (android.widget.CheckBox)28 EditText (android.widget.EditText)26 ImageView (android.widget.ImageView)21 CompoundButton (android.widget.CompoundButton)19 LayoutInflater (android.view.LayoutInflater)18 ViewGroup (android.view.ViewGroup)18 LinearLayout (android.widget.LinearLayout)17 Bundle (android.os.Bundle)16 AdapterView (android.widget.AdapterView)15 DialogInterface (android.content.DialogInterface)14 Context (android.content.Context)10 ScrollView (android.widget.ScrollView)10 ArrayList (java.util.ArrayList)10 SharedPreferences (android.content.SharedPreferences)9