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);
}
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);
}
}
});
}
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;
}
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));
}
}
}
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();
}
Aggregations