use of android.widget.RadioButton in project material-dialogs by afollestad.
the class MaterialDialog method onItemSelected.
@Override
public boolean onItemSelected(MaterialDialog dialog, View view, int position, CharSequence text, boolean longPress) {
if (!view.isEnabled()) {
return false;
}
if (listType == null || listType == ListType.REGULAR) {
// Default adapter, non choice mode
if (builder.autoDismiss) {
// If auto dismiss is enabled, dismiss the dialog when a list item is selected
dismiss();
}
if (!longPress && builder.listCallback != null) {
builder.listCallback.onSelection(this, view, position, builder.items.get(position));
}
if (longPress && builder.listLongCallback != null) {
return builder.listLongCallback.onLongSelection(this, view, position, builder.items.get(position));
}
} else {
// Default adapter, choice mode
if (listType == ListType.MULTI) {
final CheckBox cb = (CheckBox) view.findViewById(R.id.md_control);
if (!cb.isEnabled()) {
return false;
}
final boolean shouldBeChecked = !selectedIndicesList.contains(position);
if (shouldBeChecked) {
// Add the selection to the states first so the callback includes it (when alwaysCallMultiChoiceCallback)
selectedIndicesList.add(position);
if (builder.alwaysCallMultiChoiceCallback) {
// If the checkbox wasn't previously selected, and the callback returns true, add it to the states and check it
if (sendMultiChoiceCallback()) {
cb.setChecked(true);
} else {
// The callback cancelled selection, remove it from the states
selectedIndicesList.remove(Integer.valueOf(position));
}
} else {
// The callback was not used to check if selection is allowed, just select it
cb.setChecked(true);
}
} else {
// Remove the selection from the states first so the callback does not include it (when alwaysCallMultiChoiceCallback)
selectedIndicesList.remove(Integer.valueOf(position));
if (builder.alwaysCallMultiChoiceCallback) {
// If the checkbox was previously selected, and the callback returns true, remove it from the states and uncheck it
if (sendMultiChoiceCallback()) {
cb.setChecked(false);
} else {
// The callback cancelled unselection, re-add it to the states
selectedIndicesList.add(position);
}
} else {
// The callback was not used to check if the unselection is allowed, just uncheck it
cb.setChecked(false);
}
}
} else if (listType == ListType.SINGLE) {
final RadioButton radio = (RadioButton) view.findViewById(R.id.md_control);
if (!radio.isEnabled()) {
return false;
}
boolean allowSelection = true;
final int oldSelected = builder.selectedIndex;
if (builder.autoDismiss && builder.positiveText == null) {
// If auto dismiss is enabled, and no action button is visible to approve the selection, dismiss the dialog
dismiss();
// Don't allow the selection to be updated since the dialog is being dismissed anyways
allowSelection = false;
// Update selected index and send callback
builder.selectedIndex = position;
sendSingleChoiceCallback(view);
} else if (builder.alwaysCallSingleChoiceCallback) {
// Temporarily set the new index so the callback uses the right one
builder.selectedIndex = position;
// Only allow the radio button to be checked if the callback returns true
allowSelection = sendSingleChoiceCallback(view);
// Restore the old selected index, so the state is updated below
builder.selectedIndex = oldSelected;
}
// Update the checked states
if (allowSelection) {
builder.selectedIndex = position;
radio.setChecked(true);
builder.adapter.notifyItemChanged(oldSelected);
builder.adapter.notifyItemChanged(position);
}
}
}
return true;
}
use of android.widget.RadioButton in project NewPipe by TeamNewPipe.
the class DownloadActivity method showUrlDialog.
private void showUrlDialog() {
// Create the view
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.dialog_url, null);
final EditText name = Utility.findViewById(v, R.id.file_name);
final TextView tCount = Utility.findViewById(v, R.id.threads_count);
final SeekBar threads = Utility.findViewById(v, R.id.threads);
final Toolbar toolbar = Utility.findViewById(v, R.id.toolbar);
final RadioButton audioButton = (RadioButton) Utility.findViewById(v, R.id.audio_button);
threads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
tCount.setText(String.valueOf(progress + 1));
}
@Override
public void onStartTrackingTouch(SeekBar p1) {
}
@Override
public void onStopTrackingTouch(SeekBar p1) {
}
});
int def = mPrefs.getInt(THREADS, 4);
threads.setProgress(def - 1);
tCount.setText(String.valueOf(def));
name.setText(getIntent().getStringExtra("fileName"));
toolbar.setTitle(R.string.add);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
toolbar.inflateMenu(R.menu.dialog_url);
// Show the dialog
final AlertDialog dialog = new AlertDialog.Builder(this).setCancelable(true).setView(v).create();
dialog.show();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.okay) {
String location;
if (audioButton.isChecked()) {
location = NewPipeSettings.getAudioDownloadPath(DownloadActivity.this);
} else {
location = NewPipeSettings.getVideoDownloadPath(DownloadActivity.this);
}
String fName = name.getText().toString().trim();
File f = new File(location, fName);
if (f.exists()) {
Toast.makeText(DownloadActivity.this, R.string.msg_exists, Toast.LENGTH_SHORT).show();
} else {
DownloadManagerService.startMission(DownloadActivity.this, getIntent().getData().toString(), location, fName, audioButton.isChecked(), threads.getProgress() + 1);
mFragment.notifyChange();
mPrefs.edit().putInt(THREADS, threads.getProgress() + 1).commit();
mPendingUrl = null;
dialog.dismiss();
}
return true;
} else {
return false;
}
}
});
}
use of android.widget.RadioButton in project NewPipe by TeamNewPipe.
the class DownloadDialog method download.
//download audio, video or both?
private void download() {
View view = getView();
Bundle arguments = getArguments();
final EditText name = (EditText) view.findViewById(R.id.file_name);
final SeekBar threads = (SeekBar) view.findViewById(R.id.threads);
RadioButton audioButton = (RadioButton) view.findViewById(R.id.audio_button);
RadioButton videoButton = (RadioButton) view.findViewById(R.id.video_button);
String fName = name.getText().toString().trim();
boolean isAudio = audioButton.isChecked();
String url, location, filename;
if (isAudio) {
url = arguments.getString(AUDIO_URL);
location = NewPipeSettings.getAudioDownloadPath(getContext());
filename = fName + arguments.getString(FILE_SUFFIX_AUDIO);
} else {
url = arguments.getString(VIDEO_URL);
location = NewPipeSettings.getVideoDownloadPath(getContext());
filename = fName + arguments.getString(FILE_SUFFIX_VIDEO);
}
DownloadManagerService.startMission(getContext(), url, location, filename, isAudio, threads.getProgress() + 1);
getDialog().dismiss();
}
use of android.widget.RadioButton in project android_frameworks_base by ParanoidAndroid.
the class ClientTest method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button addpbtn = (Button) findViewById(R.id.addpkg);
Button procbtn = (Button) findViewById(R.id.procmsg);
Button delbtn = (Button) findViewById(R.id.delpkg);
Log.v(LOG_TAG, "activity created!!");
addpbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText app_id = (EditText) findViewById(R.id.app_id);
EditText cont = (EditText) findViewById(R.id.cont);
EditText pkg = (EditText) findViewById(R.id.pkg);
EditText cls = (EditText) findViewById(R.id.cls);
RadioButton act = (RadioButton) findViewById(R.id.act);
CheckBox sig = (CheckBox) findViewById(R.id.sig);
CheckBox ftr = (CheckBox) findViewById(R.id.ftr);
try {
if (!mWapPushMan.addPackage(app_id.getText().toString(), cont.getText().toString(), pkg.getText().toString(), cls.getText().toString(), act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY : WapPushManagerParams.APP_TYPE_SERVICE, sig.isChecked(), ftr.isChecked())) {
Log.w(LOG_TAG, "remote add pkg failed...");
mWapPushMan.updatePackage(app_id.getText().toString(), cont.getText().toString(), pkg.getText().toString(), cls.getText().toString(), act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY : WapPushManagerParams.APP_TYPE_SERVICE, sig.isChecked(), ftr.isChecked());
}
} catch (RemoteException e) {
Log.w(LOG_TAG, "remote func failed...");
}
}
});
delbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText app_id = (EditText) findViewById(R.id.app_id);
EditText cont = (EditText) findViewById(R.id.cont);
EditText pkg = (EditText) findViewById(R.id.pkg);
EditText cls = (EditText) findViewById(R.id.cls);
try {
mWapPushMan.deletePackage(app_id.getText().toString(), cont.getText().toString(), pkg.getText().toString(), cls.getText().toString());
// delall.isChecked());
} catch (RemoteException e) {
Log.w(LOG_TAG, "remote func failed...");
}
}
});
procbtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText pdu = (EditText) findViewById(R.id.pdu);
EditText app_id = (EditText) findViewById(R.id.app_id);
EditText cont = (EditText) findViewById(R.id.cont);
// wap.dispatchWapPdu(strToHex(pdu.getText().toString()));
try {
Intent intent = new Intent();
intent.putExtra("transactionId", 0);
intent.putExtra("pduType", 6);
intent.putExtra("header", HexDump.hexStringToByteArray(pdu.getText().toString()));
intent.putExtra("data", HexDump.hexStringToByteArray(pdu.getText().toString()));
mWapPushMan.processMessage(app_id.getText().toString(), cont.getText().toString(), intent);
//HexDump.hexStringToByteArray(pdu.getText().toString()), 0, 6, 5, 5);
} catch (RemoteException e) {
Log.w(LOG_TAG, "remote func failed...");
}
}
});
}
use of android.widget.RadioButton in project Anki-Android by Ramblurr.
the class StudyOptionsFragment method formatRGCardType.
/**
* formatRGCardType
* Returns: RadioGroup - A radio group that contains the options of All Cards, New, and Due cards,
* for the selection of cards when creating a CUSTOM_STUDY_DECKS based on TAGS.
* Takes: context, and resources of the App.
*
* This method just creates the RadioGroup required for the dialog to select tags for a new
* custom study deck.
*/
private RadioGroup formatRGCardType(Context context, Resources res) {
RadioGroup rg = new RadioGroup(context);
final RadioButton[] radioButtonCards = new RadioButton[3];
rg.setOrientation(RadioGroup.HORIZONTAL);
RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
int height = context.getResources().getDrawable(R.drawable.white_btn_radio).getIntrinsicHeight();
//This array contains "All Cards", "New", and "Due", in that order.
String[] text = res.getStringArray(R.array.cards_for_tag_filtered_deck_labels);
for (int i = 0; i < radioButtonCards.length; i++) {
radioButtonCards[i] = new RadioButton(context);
radioButtonCards[i].setClickable(true);
radioButtonCards[i].setText(text[i]);
radioButtonCards[i].setHeight(height * 2);
radioButtonCards[i].setSingleLine();
radioButtonCards[i].setGravity(Gravity.CENTER_VERTICAL);
rg.addView(radioButtonCards[i], lp);
}
rg.check(0);
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) {
mSelectedOption = i;
break;
}
}
}
});
rg.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, height));
return rg;
}
Aggregations