use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.
the class ModelBrowser method addNewNoteTypeDialog.
/*
*Creates the dialogue box to select a note type, add a name, and then clone it
*/
private void addNewNoteTypeDialog() {
initializeNoteTypeList();
final Spinner addSelectionSpinner = new Spinner(this);
ArrayAdapter<String> newModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item, mNewModelLabels);
addSelectionSpinner.setAdapter(newModelAdapter);
new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).customView(addSelectionSpinner, true).onPositive((dialog, which) -> {
mModelNameInput = new FixedEditText(ModelBrowser.this);
mModelNameInput.setSingleLine();
final boolean isStdModel = addSelectionSpinner.getSelectedItemPosition() < mNewModelLabels.size();
// Try to find a unique model name. Add "clone" if cloning, and random digits if necessary.
String suggestedName = mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition());
if (!isStdModel) {
suggestedName += " " + getResources().getString(R.string.model_clone_suffix);
}
if (mExistingModelNames.contains(suggestedName)) {
suggestedName = randomizeName(suggestedName);
}
mModelNameInput.setText(suggestedName);
mModelNameInput.setSelection(mModelNameInput.getText().length());
// Create textbox to name new model
new MaterialEditTextDialog.Builder(ModelBrowser.this, mModelNameInput).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).onPositive((innerDialog, innerWhich) -> {
String modelName = mModelNameInput.getText().toString();
addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition());
}).negativeText(R.string.dialog_cancel).show();
}).negativeText(R.string.dialog_cancel).show();
}
use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.
the class ModelFieldEditor method addFieldDialog.
/*
* Creates a dialog to create a field
*/
private void addFieldDialog() {
mFieldNameInput = new FixedEditText(this);
mFieldNameInput.setSingleLine(true);
new MaterialEditTextDialog.Builder(this, mFieldNameInput).title(R.string.model_field_editor_add).positiveText(R.string.dialog_ok).onPositive((dialog, which) -> {
// Name is valid, now field is added
changeHandler listener = changeFieldHandler();
String fieldName = _uniqueName(mFieldNameInput);
try {
addField(fieldName, listener, true);
} catch (ConfirmModSchemaException e) {
e.log();
// Create dialogue to for schema change
ConfirmationDialog c = new ConfirmationDialog();
c.setArgs(getResources().getString(R.string.full_sync_confirmation));
Runnable confirm = () -> {
try {
addField(fieldName, listener, false);
} catch (ConfirmModSchemaException e1) {
e1.log();
// This should never be thrown
}
dismissContextMenu();
};
c.setConfirm(confirm);
c.setCancel(mConfirmDialogCancel);
ModelFieldEditor.this.showDialogFragment(c);
}
mCol.getModels().update(mMod);
fullRefreshList();
}).negativeText(R.string.dialog_cancel).show();
}
use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.
the class ModelFieldEditor method renameFieldDialog.
/*
* Creates a dialog to rename the currently selected field
* Processing time is constant
*/
private void renameFieldDialog() {
mFieldNameInput = new FixedEditText(this);
mFieldNameInput.setSingleLine(true);
mFieldNameInput.setText(mFieldLabels.get(mCurrentPos));
mFieldNameInput.setSelection(mFieldNameInput.getText().length());
new MaterialEditTextDialog.Builder(this, mFieldNameInput).title(R.string.model_field_editor_rename).positiveText(R.string.rename).onPositive((dialog, which) -> {
String fieldName = _uniqueName(mFieldNameInput);
if (fieldName == null) {
return;
}
// Field is valid, now rename
try {
renameField();
} catch (ConfirmModSchemaException e) {
e.log();
// Handler mod schema confirmation
ConfirmationDialog c = new ConfirmationDialog();
c.setArgs(getResources().getString(R.string.full_sync_confirmation));
Runnable confirm = () -> {
mCol.modSchemaNoCheck();
try {
renameField();
} catch (ConfirmModSchemaException e1) {
e1.log();
// This should never be thrown
}
dismissContextMenu();
};
c.setConfirm(confirm);
c.setCancel(mConfirmDialogCancel);
ModelFieldEditor.this.showDialogFragment(c);
}
}).negativeText(R.string.dialog_cancel).show();
}
use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.
the class BasicImageFieldController method drawUIComponents.
private void drawUIComponents(Context context) {
DisplayMetrics metrics = getDisplayMetrics();
int height = metrics.heightPixels;
int width = metrics.widthPixels;
mImagePreview = new ImageView(mActivity);
mImagePreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
mImagePreview.setAdjustViewBounds(true);
mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
mImagePreview.setMaxWidth((int) Math.round(width * 0.6));
mImageFileSize = new FixedEditText(context);
mImageFileSize.setMaxWidth((int) Math.round(width * 0.6));
mImageFileSize.setEnabled(false);
mImageFileSize.setGravity(Gravity.CENTER_HORIZONTAL);
mImageFileSize.setBackground(null);
mImageFileSize.setVisibility(View.GONE);
// #5513 - Image compression failed, but we'll confuse most users if we tell them that. Instead, just imply that
// there's an action that they can take.
mImageFileSizeWarning = new FixedEditText(context);
mImageFileSizeWarning.setMaxWidth((int) Math.round(width * 0.6));
mImageFileSizeWarning.setEnabled(false);
// Orange-Red
mImageFileSizeWarning.setTextColor(Color.parseColor("#FF4500"));
mImageFileSizeWarning.setGravity(Gravity.CENTER_HORIZONTAL);
mImageFileSizeWarning.setVisibility(View.GONE);
mImageFileSize.setBackground(null);
mImageFileSizeWarning.setText(R.string.multimedia_editor_image_compression_failed);
}
use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.
the class ModelBrowser method renameModelDialog.
/*
* Displays a confirmation box asking if you want to rename the note type and then renames it if confirmed
*/
private void renameModelDialog() {
initializeNoteTypeList();
mModelNameInput = new FixedEditText(this);
mModelNameInput.setSingleLine(true);
mModelNameInput.setText(mModels.get(mModelListPosition).getString("name"));
mModelNameInput.setSelection(mModelNameInput.getText().length());
new MaterialEditTextDialog.Builder(this, mModelNameInput).title(R.string.rename_model).positiveText(R.string.rename).negativeText(R.string.dialog_cancel).onPositive((dialog, which) -> {
Model model = mModels.get(mModelListPosition);
String deckName = mModelNameInput.getText().toString().replaceAll("[\"\\n\\r]", "");
if (mExistingModelNames.contains(deckName)) {
deckName = randomizeName(deckName);
}
if (deckName.length() > 0) {
model.put("name", deckName);
mCol.getModels().update(model);
mModels.get(mModelListPosition).put("name", deckName);
mModelDisplayList.set(mModelListPosition, new DisplayPair(mModels.get(mModelListPosition).getString("name"), mCardCounts.get(mModelListPosition)));
refreshList();
} else {
showToast(getResources().getString(R.string.toast_empty_name));
}
}).show();
}
Aggregations