Search in sources :

Example 31 with RadioButton

use of android.widget.RadioButton in project HumaneApp by Ganesh1010.

the class NewNeedActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_need);
    DetailsPopulator detailsPopulator = new DetailsPopulator(this);
    detailsPopulator.getCountryDetailsFromAPI();
    db = new DatabaseHelper(NewNeedActivity.this);
    mainItemDetails = db.getAllMainItemDetails();
    subItemDetails = db.getAllSubItemDetails();
    this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    dateTimeFragment = (SwitchDateTimeDialogFragment) getSupportFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT);
    if (dateTimeFragment == null) {
        dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(getString(R.string.label_datetime_dialog), getString(R.string.positive_button_datetime_picker), getString(R.string.negative_button_datetime_picker));
    }
    Calendar now = Calendar.getInstance();
    hiddenPanel = findViewById(R.id.hiddenPanel_needForm);
    toolbarSubmit = (RelativeLayout) findViewById(R.id.toolbarSubmit);
    final SimpleDateFormat myDateFormat = new SimpleDateFormat("d MMM yyyy", Locale.getDefault());
    final SimpleDateFormat myTimeFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
    dateTimeFragment.startAtCalendarView();
    dateTimeFragment.set24HoursMode(false);
    dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime());
    dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime());
    dateTimeFragment.setDefaultDateTime(new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR), now.get(Calendar.MINUTE), now.get(Calendar.HOUR_OF_DAY) > 12 ? (now.get(Calendar.PM)) : (now.get(Calendar.AM))).getTime());
    try {
        dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault()));
    } catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) {
    }
    dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {

        @Override
        public void onPositiveButtonClick(Date date) {
            datetime = date;
            textView.setText(myDateFormat.format(date) + "  " + myTimeFormat.format(date));
        }

        @Override
        public void onNegativeButtonClick(Date date) {
            textView.setText("");
        }
    });
    dateImage = (ImageView) findViewById(R.id.date_needForm);
    dateImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT);
        }
    });
    textView = (TextView) findViewById(R.id.textView);
    if (savedInstanceState != null)
        textView.setText(savedInstanceState.getCharSequence(STATE_TEXTVIEW));
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView_needForm);
    submit = (Button) findViewById(R.id.submit_needForm);
    fabAdd = (FloatingActionButton) findViewById(R.id.fabAdd_needForm);
    needDetails = new ArrayList<>();
    bottomUp = AnimationUtils.loadAnimation(this, R.anim.bottom_up);
    bottomDown = AnimationUtils.loadAnimation(this, R.anim.bottom_down);
    mainItemSpinner = (Spinner) findViewById(R.id.main_item_spinner_needForm);
    subItemSpinner = (Spinner) findViewById(R.id.sub_item_spinner_needForm);
    itemQuantity = (EditText) findViewById(R.id.itemQuantity_needForm);
    gender = (RadioGroup) findViewById(R.id.gender_needForm);
    age = (EditText) findViewById(R.id.age_needForm);
    clothesLayout = (LinearLayout) findViewById(R.id.clothesLayout_needForm);
    post = (Button) findViewById(R.id.post_needForm);
    cancel = (Button) findViewById(R.id.cancel_needForm);
    ArrayList<ItemSpinnerData> mainItemList = new ArrayList<>();
    for (int i = 0; i < mainItemDetails.size(); i++) {
        switch(mainItemDetails.get(i).getMainItemCode()) {
            case 1:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_food_black));
                break;
            case 2:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_cloth_black));
                break;
            case 3:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_blood_black));
                break;
            case 4:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_grocery_cart_black));
                break;
            case 5:
                mainItemList.add(new ItemSpinnerData(mainItemDetails.get(i).getMainItemName(), R.drawable.ic_stationery_black));
                break;
        }
    }
    MainItemSpinnerAdapter mainItemSpinnerAdapter = new MainItemSpinnerAdapter(NewNeedActivity.this, R.layout.main_item_spinner_layout, R.id.main_item_txt_spinner_needForm, mainItemList);
    mainItemSpinner.setAdapter(mainItemSpinnerAdapter);
    final RadioButton lastGenderRadioBtn = (RadioButton) findViewById(R.id.female);
    mainItemSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String item = ((TextView) findViewById(R.id.main_item_txt_spinner_needForm)).getText().toString();
            mainItem = item;
            ArrayList<ItemSpinnerData> subItemList = new ArrayList<>();
            itemQuantity.setText("");
            itemQuantity.setError(null);
            gender.clearCheck();
            lastGenderRadioBtn.setError(null);
            age.setText("");
            age.setError(null);
            for (int i = 0; i < subItemDetails.size(); i++) if (subItemDetails.get(i).getMainItemCode() == (id + 1))
                subItemList.add(new ItemSpinnerData(subItemDetails.get(i).getSubItemName()));
            SubItemSpinnerAdapter subItemSpinnerAdapter = new SubItemSpinnerAdapter(NewNeedActivity.this, R.layout.sub_item_spinner_layout, R.id.sub_item_txt_spinner_needForm, subItemList);
            subItemSpinner.setAdapter(subItemSpinnerAdapter);
            subItemSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    String item = ((TextView) findViewById(R.id.sub_item_txt_spinner_needForm)).getText().toString();
                    subItem = item;
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
            if (mainItem.equals("Clothes"))
                clothesLayout.setVisibility(View.VISIBLE);
            else
                clothesLayout.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    post.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            NeedItemDetails needItemDetails = new NeedItemDetails();
            int selectedIdGender = gender.getCheckedRadioButtonId();
            radioSexButton = (RadioButton) findViewById(selectedIdGender);
            if (itemQuantity.getText().toString().isEmpty()) {
                dataFilled = false;
                itemQuantity.setError("enter the Quantity");
            } else {
                needItemDetails.setNeed_item_id(++NewNeedActivity.id);
                for (int i = 0; i <= subItemDetails.size(); i++) if (!subItem.isEmpty() && mainItemDetails != null && subItemDetails != null) {
                    if (subItem.equals(subItemDetails.get(i).getSubItemName())) {
                        needItemDetails.setItem_type_id(subItemDetails.get(i).getMainItemCode());
                        needItemDetails.setSub_item_type_id(subItemDetails.get(i).getSubItemCode());
                        break;
                    }
                }
                needItemDetails.setQuantity(Integer.parseInt(itemQuantity.getText().toString()));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
                needItemDetails.setDeadline(sdf.format(datetime));
                dataFilled = true;
            }
            if (mainItem.equals("Clothes")) {
                if (gender.getCheckedRadioButtonId() <= 0) {
                    dataFilled = false;
                    lastGenderRadioBtn.setError("select gender");
                }
                if (age.getText().toString().isEmpty()) {
                    dataFilled = false;
                    age.setError("enter the age");
                } else {
                    needItemDetails.setGender(radioSexButton.getText().toString());
                    needItemDetails.setAge(Integer.parseInt(age.getText().toString()));
                    dataFilled = true;
                }
            }
            if (dataFilled) {
                needDetails.add(needItemDetails);
                recyclerView.setAdapter(new NewNeedsListAdapter(NewNeedActivity.this, needDetails, mainItemDetails, subItemDetails));
                recyclerView.setLayoutManager(new LinearLayoutManager(NewNeedActivity.this));
                hiddenPanel.startAnimation(bottomDown);
                hiddenPanel.setVisibility(View.GONE);
                toolbarSubmit.setVisibility(View.VISIBLE);
                fabAdd.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.VISIBLE);
            }
            Toast.makeText(NewNeedActivity.this, "new need", Toast.LENGTH_SHORT).show();
        }
    });
    cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hiddenPanel.startAnimation(bottomDown);
            hiddenPanel.setVisibility(View.GONE);
            toolbarSubmit.setVisibility(View.VISIBLE);
            fabAdd.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.VISIBLE);
        }
    });
    fabAdd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!isPanelShown()) {
                hiddenPanel.startAnimation(bottomUp);
                hiddenPanel.setVisibility(View.VISIBLE);
                toolbarSubmit.setVisibility(View.GONE);
                fabAdd.setVisibility(View.GONE);
                recyclerView.setVisibility(View.GONE);
            } else {
                hiddenPanel.startAnimation(bottomDown);
                hiddenPanel.setVisibility(View.GONE);
                toolbarSubmit.setVisibility(View.VISIBLE);
                fabAdd.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.VISIBLE);
            }
            itemQuantity.setText("");
            itemQuantity.setError(null);
            gender.clearCheck();
            lastGenderRadioBtn.setError(null);
            age.setText("");
            age.setError(null);
        }
    });
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            gson = new Gson();
            new PostItemDetails().execute();
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextView(android.widget.TextView) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) RadioButton(android.widget.RadioButton) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwitchDateTimeDialogFragment(com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment) Date(java.util.Date) AdapterView(android.widget.AdapterView) SimpleDateFormat(java.text.SimpleDateFormat)

Example 32 with RadioButton

use of android.widget.RadioButton in project JustAndroid by chinaltz.

the class SegmentedGroup method updateBackground.

private void updateBackground(View view) {
    if (!isInEditMode()) {
        int checked = mLayoutSelector.getSelected();
        int unchecked = mLayoutSelector.getUnselected();
        //Set text color
        ColorStateList colorStateList = new ColorStateList(new int[][] { { -android.R.attr.state_checked }, { android.R.attr.state_checked } }, new int[] { mTintColor, mCheckedTextColor });
        ((Button) view).setTextColor(colorStateList);
        //Redraw with tint color
        Drawable checkedDrawable = resources.getDrawable(checked).mutate();
        Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
        ((GradientDrawable) checkedDrawable).setColor(mTintColor);
        ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
        ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
        ((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor);
        //Set proper radius
        ((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
        ((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
        GradientDrawable maskDrawable = (GradientDrawable) resources.getDrawable(unchecked).mutate();
        maskDrawable.setStroke(mMarginDp, mTintColor);
        maskDrawable.setColor(mUnCheckedTintColor);
        maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
        int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
        maskDrawable.setColor(maskColor);
        LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] { uncheckedDrawable, maskDrawable });
        Drawable[] drawables = { uncheckedDrawable, checkedDrawable };
        TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
        if (((RadioButton) view).isChecked()) {
            transitionDrawable.reverseTransition(0);
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_pressed }, pressedDrawable);
        stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable);
        mDrawableMap.put(view.getId(), transitionDrawable);
        //Set button background
        if (Build.VERSION.SDK_INT >= 16) {
            view.setBackground(stateListDrawable);
        } else {
            view.setBackgroundDrawable(stateListDrawable);
        }
        super.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                TransitionDrawable current = mDrawableMap.get(checkedId);
                current.reverseTransition(200);
                if (mLastCheckId != 0) {
                    TransitionDrawable last = mDrawableMap.get(mLastCheckId);
                    if (last != null)
                        last.reverseTransition(200);
                }
                mLastCheckId = checkedId;
                if (mCheckedChangeListener != null) {
                    mCheckedChangeListener.onCheckedChanged(group, checkedId);
                }
            }
        });
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) RadioGroup(android.widget.RadioGroup) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RadioButton(android.widget.RadioButton) Button(android.widget.Button) LayerDrawable(android.graphics.drawable.LayerDrawable)

Example 33 with RadioButton

use of android.widget.RadioButton in project LiveLessons by douglascraigschmidt.

the class AndroidPlatform method buttonToggled.

/**
     * Retrieves textual input of the toggled button determined by the
     * user.
     */
private String buttonToggled() {
    Log.e("AndroidPlatform", "buttonToggled");
    /** Checks the format radio group for checked buttons. */
    RadioGroup rg = (RadioGroup) activity.findViewById(R.id.rad1);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
        return ("format" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    /** Checks the print radio group for checked buttons. */
    rg = (RadioGroup) activity.findViewById(R.id.rad2);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled()) {
        ((TextView) activity.findViewById(R.id.tv)).setText("");
        return ("print" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    }
    /** Checks the eval radio group for checked buttons. */
    rg = (RadioGroup) activity.findViewById(R.id.rad3);
    for (int i = 0; i < rg.getChildCount(); i++) if (((RadioButton) rg.getChildAt(i)).isChecked() && ((RadioButton) rg.getChildAt(i)).isEnabled())
        return ("eval" + " " + (String) ((TextView) rg.getChildAt(i)).getText()).toLowerCase();
    /** Checks the set checkbox. */
    CheckBox cb = (CheckBox) activity.findViewById(R.id.cb);
    if (cb.isChecked() && cb.isEnabled())
        return ("set" + (String) ((TextView) cb).getText()).toLowerCase();
    return "expr";
}
Also used : RadioGroup(android.widget.RadioGroup) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) RadioButton(android.widget.RadioButton)

Example 34 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 35 with RadioButton

use of android.widget.RadioButton in project android_frameworks_base by crdroidandroid.

the class ElementLayoutActivity method createRadioButton.

private void createRadioButton() {
    RadioButton button = new RadioButton(this);
    button.setText("RadioButton:" + mRandom.nextInt());
    mLayout.addView(button);
}
Also used : RadioButton(android.widget.RadioButton)

Aggregations

RadioButton (android.widget.RadioButton)90 View (android.view.View)48 TextView (android.widget.TextView)35 Button (android.widget.Button)19 CheckBox (android.widget.CheckBox)18 RadioGroup (android.widget.RadioGroup)18 EditText (android.widget.EditText)13 Intent (android.content.Intent)12 Bundle (android.os.Bundle)10 CompoundButton (android.widget.CompoundButton)10 ImageView (android.widget.ImageView)10 ViewGroup (android.view.ViewGroup)8 LayoutInflater (android.view.LayoutInflater)7 AdapterView (android.widget.AdapterView)7 ScrollView (android.widget.ScrollView)7 RemoteException (android.os.RemoteException)6 SeekBar (android.widget.SeekBar)6 Test (org.junit.Test)6 AlertDialog (android.support.v7.app.AlertDialog)5 Context (android.content.Context)4