use of com.ichi2.anki.multimediacard.activity.PickStringDialogFragment in project Anki-Android by Ramblurr.
the class BasicTextFieldController method createTranslateButton.
// Here is all the functionality to provide translations
private void createTranslateButton(LinearLayout layoutTool, LayoutParams ps) {
Button btnTranslate = new Button(mActivity);
btnTranslate.setText(gtxt(R.string.multimedia_editor_text_field_editing_translate));
btnTranslate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String source = mEditText.getText().toString();
// Checks and warnings
if (source.length() == 0) {
showToast(gtxt(R.string.multimedia_editor_text_field_editing_no_text));
return;
}
if (source.contains(" ")) {
showToast(gtxt(R.string.multimedia_editor_text_field_editing_many_words));
}
// Pick from two translation sources
PickStringDialogFragment fragment = new PickStringDialogFragment();
ArrayList<String> translationSources = new ArrayList<String>();
translationSources.add("Glosbe.com");
translationSources.add("ColorDict");
fragment.setChoices(translationSources);
fragment.setOnclickListener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
startTranslationWithGlosbe();
} else if (which == 1) {
startTranslationWithColorDict();
}
}
});
fragment.setTitle(gtxt(R.string.multimedia_editor_trans_pick_translation_source));
fragment.show(mActivity.getSupportFragmentManager(), "pick.translation.source");
}
});
layoutTool.addView(btnTranslate, ps);
// flow continues in Start Translation with...
}
use of com.ichi2.anki.multimediacard.activity.PickStringDialogFragment in project Anki-Android by Ramblurr.
the class TranslationActivity method showPickTranslationDialog.
private void showPickTranslationDialog() {
if (mTranslation.startsWith("FAILED")) {
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString());
return;
}
Gson gson = new Gson();
Response resp = gson.fromJson(mTranslation, Response.class);
if (resp == null) {
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString());
return;
}
if (!resp.getResult().contentEquals("ok")) {
if (!mSource.toLowerCase(Locale.getDefault()).contentEquals(mSource)) {
showToastLong(gtxt(R.string.multimedia_editor_word_search_try_lower_case));
}
returnFailure(getText(R.string.multimedia_editor_trans_getting_failure).toString());
return;
}
mPossibleTranslations = parseJson(resp, mLangCodeTo);
if (mPossibleTranslations.size() == 0) {
if (!mSource.toLowerCase(Locale.getDefault()).contentEquals(mSource)) {
showToastLong(gtxt(R.string.multimedia_editor_word_search_try_lower_case));
}
returnFailure(getText(R.string.multimedia_editor_error_word_not_found).toString());
return;
}
PickStringDialogFragment fragment = new PickStringDialogFragment();
fragment.setChoices(mPossibleTranslations);
fragment.setOnclickListener(this);
fragment.setTitle(getText(R.string.multimedia_editor_trans_pick_translation).toString());
fragment.show(this.getSupportFragmentManager(), "pick.translation");
}
use of com.ichi2.anki.multimediacard.activity.PickStringDialogFragment in project Anki-Android by Ramblurr.
the class BasicTextFieldController method createCloneButton.
/**
* @param activity
* @param layoutTools This creates a button, which will call a dialog, allowing to pick from another note's fields
* one, and use it's value in the current one.
* @param p
*/
private void createCloneButton(LinearLayout layoutTools, LayoutParams p) {
// Makes sense only for two and more fields
if (mNote.getNumberOfFields() > 1) {
// Should be more than one text not empty fields for clone to make
// sense
mPossibleClones = new ArrayList<String>();
int numTextFields = 0;
for (int i = 0; i < mNote.getNumberOfFields(); ++i) {
// Sort out non text and empty fields
IField curField = mNote.getField(i);
if (curField == null) {
continue;
}
if (curField.getType() != EFieldType.TEXT) {
continue;
}
if (curField.getText() == null) {
continue;
}
if (curField.getText().length() == 0) {
continue;
}
// as well as the same field
if (curField.getText().contentEquals(mField.getText())) {
continue;
}
// collect clone sources
mPossibleClones.add(curField.getText());
++numTextFields;
}
// Nothing to clone from
if (numTextFields < 1) {
return;
}
Button btnOtherField = new Button(mActivity);
btnOtherField.setText(gtxt(R.string.multimedia_editor_text_field_editing_clone));
layoutTools.addView(btnOtherField, p);
final BasicTextFieldController controller = this;
btnOtherField.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
PickStringDialogFragment fragment = new PickStringDialogFragment();
fragment.setChoices(mPossibleClones);
fragment.setOnclickListener(controller);
fragment.setTitle(gtxt(R.string.multimedia_editor_text_field_editing_clone_source));
fragment.show(mActivity.getSupportFragmentManager(), "pick.clone");
// flow continues in the onClick function
}
});
}
}
Aggregations