Search in sources :

Example 66 with RadioGroup

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

the class HugeBackupActivity method populateUI.

/**
     * Configure the UI based on our persistent data, creating the
     * data file and establishing defaults if necessary.
     */
void populateUI() {
    RandomAccessFile file;
    // Default values in case there's no data file yet
    int whichFilling = R.id.pastrami;
    boolean addMayo = false;
    boolean addTomato = false;
    /** Hold the data-access lock around access to the file */
    synchronized (HugeBackupActivity.sDataLock) {
        boolean exists = mDataFile.exists();
        try {
            file = new RandomAccessFile(mDataFile, "rw");
            if (exists) {
                Log.v(TAG, "datafile exists");
                whichFilling = file.readInt();
                addMayo = file.readBoolean();
                addTomato = file.readBoolean();
                Log.v(TAG, "  mayo=" + addMayo + " tomato=" + addTomato + " filling=" + whichFilling);
            } else {
                // The default values were configured above: write them
                // to the newly-created file.
                Log.v(TAG, "creating default datafile");
                writeDataToFileLocked(file, addMayo, addTomato, whichFilling);
                // We also need to perform an initial backup; ask for one
                mBackupManager.dataChanged();
            }
        } catch (IOException ioe) {
        }
    }
    /** Now that we've processed the file, build the UI outside the lock */
    mFillingGroup.check(whichFilling);
    mAddMayoCheckbox.setChecked(addMayo);
    mAddTomatoCheckbox.setChecked(addTomato);
    /**
         * We also want to record the new state when the user makes changes,
         * so install simple observers that do this
         */
    mFillingGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // As with the checkbox listeners, rewrite the
            // entire state file
            Log.v(TAG, "New radio item selected: " + checkedId);
            recordNewUIState();
        }
    });
    CompoundButton.OnCheckedChangeListener checkListener = new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // Whichever one is altered, we rewrite the entire UI state
            Log.v(TAG, "Checkbox toggled: " + buttonView);
            recordNewUIState();
        }
    };
    mAddMayoCheckbox.setOnCheckedChangeListener(checkListener);
    mAddTomatoCheckbox.setOnCheckedChangeListener(checkListener);
}
Also used : RandomAccessFile(java.io.RandomAccessFile) RadioGroup(android.widget.RadioGroup) IOException(java.io.IOException) CompoundButton(android.widget.CompoundButton)

Example 67 with RadioGroup

use of android.widget.RadioGroup in project android-segmented-control by Kaopiz.

the class SegmentedGroup method updateBackground.

private void updateBackground(View view) {
    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 68 with RadioGroup

use of android.widget.RadioGroup in project aware-client by denzilferreira.

the class ESM_Radio method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View ui = inflater.inflate(R.layout.esm_radio, null);
    builder.setView(ui);
    esm_dialog = builder.create();
    esm_dialog.setCanceledOnTouchOutside(false);
    try {
        TextView esm_title = (TextView) ui.findViewById(R.id.esm_title);
        esm_title.setText(getTitle());
        TextView esm_instructions = (TextView) ui.findViewById(R.id.esm_instructions);
        esm_instructions.setText(getInstructions());
        final RadioGroup radioOptions = (RadioGroup) ui.findViewById(R.id.esm_radio);
        radioOptions.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
        final JSONArray radios = getRadios();
        for (int i = 0; i < radios.length(); i++) {
            final RadioButton radioOption = new RadioButton(getActivity());
            radioOption.setId(i);
            radioOption.setText(radios.getString(i));
            radioOptions.addView(radioOption);
            if (radios.getString(i).equals(getResources().getString(R.string.aware_esm_other))) {
                radioOption.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final Dialog editOther = new Dialog(getActivity());
                        editOther.setTitle(getResources().getString(R.string.aware_esm_other_follow));
                        editOther.getWindow().setGravity(Gravity.TOP);
                        editOther.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
                        LinearLayout editor = new LinearLayout(getActivity());
                        editor.setOrientation(LinearLayout.VERTICAL);
                        editOther.setContentView(editor);
                        editOther.show();
                        final EditText otherText = new EditText(getActivity());
                        otherText.setHint(getResources().getString(R.string.aware_esm_other_follow));
                        editor.addView(otherText);
                        otherText.requestFocus();
                        editOther.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
                        Button confirm = new Button(getActivity());
                        confirm.setText("OK");
                        confirm.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (otherText.length() > 0)
                                    radioOption.setText(otherText.getText());
                                editOther.dismiss();
                            }
                        });
                        editor.addView(confirm);
                    }
                });
            }
        }
        Button cancel_radio = (Button) ui.findViewById(R.id.esm_cancel);
        cancel_radio.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                esm_dialog.cancel();
            }
        });
        Button submit_radio = (Button) ui.findViewById(R.id.esm_submit);
        submit_radio.setText(getSubmitButton());
        submit_radio.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Provider.ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    RadioGroup radioOptions = (RadioGroup) ui.findViewById(R.id.esm_radio);
                    if (radioOptions.getCheckedRadioButtonId() != -1) {
                        RadioButton selected = (RadioButton) radioOptions.getChildAt(radioOptions.getCheckedRadioButtonId());
                        rowData.put(ESM_Provider.ESM_Data.ANSWER, String.valueOf(selected.getText()).trim());
                    }
                    rowData.put(ESM_Provider.ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                    getContext().getContentResolver().update(ESM_Provider.ESM_Data.CONTENT_URI, rowData, ESM_Provider.ESM_Data._ID + "=" + getID(), null);
                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    answer.putExtra(ESM.EXTRA_ANSWER, rowData.getAsString(ESM_Provider.ESM_Data.ANSWER));
                    getActivity().sendBroadcast(answer);
                    if (Aware.DEBUG)
                        Log.d(Aware.TAG, "Answer:" + rowData.toString());
                    esm_dialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return esm_dialog;
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) ContentValues(android.content.ContentValues) RadioGroup(android.widget.RadioGroup) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) RadioButton(android.widget.RadioButton) Button(android.widget.Button) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) NonNull(android.support.annotation.NonNull)

Example 69 with RadioGroup

use of android.widget.RadioGroup in project J2ME-Loader by nikita36078.

the class ChoiceGroup method initButtonGroup.

private void initButtonGroup() {
    buttongroup.setOrientation(LinearLayout.VERTICAL);
    Context context = getOwnerForm().getParentActivity();
    int size = selected.size();
    if (buttongroup instanceof RadioGroup) {
        for (int i = 0; i < size; i++) {
            addButton(new RadioButton(context), i, strings.get(i), images.get(i), selected.get(i));
        }
    } else {
        for (int i = 0; i < size; i++) {
            addButton(new CheckBox(context), i, strings.get(i), images.get(i), selected.get(i));
        }
    }
}
Also used : Context(android.content.Context) RadioGroup(android.widget.RadioGroup) CheckBox(android.widget.CheckBox) RadioButton(android.widget.RadioButton)

Example 70 with RadioGroup

use of android.widget.RadioGroup in project cloudrail-si-android-sdk by CloudRail.

the class MainActivity method onClick.

@Override
public void onClick(View view) {
    RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
    final SMS service;
    switch(radioGroup.getCheckedRadioButtonId()) {
        case R.id.twilioRadioButton:
            {
                service = twilio;
                break;
            }
        case R.id.twizoRadioButton:
            {
                service = twizo;
                break;
            }
        case R.id.nexmoRadioButton:
            {
                service = nexmo;
                break;
            }
        default:
            throw new RuntimeException("Unknown Button ID!!");
    }
    final String fromName = ((EditText) findViewById(R.id.senderEditText)).getText().toString().trim();
    final String toNumber = ((EditText) findViewById(R.id.receiverEditText)).getText().toString().trim();
    final String message = ((EditText) findViewById(R.id.messageEditText)).getText().toString().trim();
    String serviceStr = "twilio";
    if (service == twizo)
        serviceStr = "twizo";
    if (service == nexmo)
        serviceStr = "nexmo";
    System.out.println("from: " + fromName + "  to: " + toNumber + "  with: " + serviceStr + "  message: " + message);
    new Thread(new Runnable() {

        @Override
        public void run() {
            service.sendSMS(fromName, toNumber, message);
        }
    }).start();
}
Also used : EditText(android.widget.EditText) RadioGroup(android.widget.RadioGroup) SMS(com.cloudrail.si.interfaces.SMS)

Aggregations

RadioGroup (android.widget.RadioGroup)70 View (android.view.View)30 TextView (android.widget.TextView)23 RadioButton (android.widget.RadioButton)17 OnCheckedChangeListener (android.widget.RadioGroup.OnCheckedChangeListener)13 Button (android.widget.Button)10 CompoundButton (android.widget.CompoundButton)9 Validator (com.mobsandgeeks.saripaar.Validator)8 DialogInterface (android.content.DialogInterface)7 EditText (android.widget.EditText)7 Intent (android.content.Intent)6 AlertDialog (android.support.v7.app.AlertDialog)6 CheckBox (android.widget.CheckBox)6 LinearLayout (android.widget.LinearLayout)6 ImageView (android.widget.ImageView)5 IOException (java.io.IOException)5 RandomAccessFile (java.io.RandomAccessFile)5 Test (org.junit.Test)5 CardView (android.support.v7.widget.CardView)4 ScrollView (android.widget.ScrollView)4