Search in sources :

Example 1 with FixedEditText

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();
}
Also used : Spinner(android.widget.Spinner) FixedEditText(com.ichi2.ui.FixedEditText) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with FixedEditText

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();
}
Also used : ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FixedEditText(com.ichi2.ui.FixedEditText) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Example 3 with FixedEditText

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();
}
Also used : ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FixedEditText(com.ichi2.ui.FixedEditText) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Example 4 with FixedEditText

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);
}
Also used : ImageView(android.widget.ImageView) FixedEditText(com.ichi2.ui.FixedEditText) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint)

Example 5 with FixedEditText

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();
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) TaskManager(com.ichi2.async.TaskManager) NonNull(androidx.annotation.NonNull) Pair(android.util.Pair) Intent(android.content.Intent) ModelBrowserContextMenu(com.ichi2.anki.dialogs.ModelBrowserContextMenu) Random(java.util.Random) Collection(com.ichi2.libanki.Collection) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ActionBar(androidx.appcompat.app.ActionBar) WidgetStatus(com.ichi2.widget.WidgetStatus) Menu(android.view.Menu) View(android.view.View) Model(com.ichi2.libanki.Model) START(com.ichi2.anim.ActivityTransitionAnimation.Direction.START) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) StdModels(com.ichi2.libanki.StdModels) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) CollectionTask(com.ichi2.async.CollectionTask) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) Utils.checksum(com.ichi2.libanki.Utils.checksum) ListView(android.widget.ListView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FixedEditText(com.ichi2.ui.FixedEditText) Activity(android.app.Activity) EditText(android.widget.EditText) Model(com.ichi2.libanki.Model) FixedEditText(com.ichi2.ui.FixedEditText)

Aggregations

FixedEditText (com.ichi2.ui.FixedEditText)6 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 CollectionTask (com.ichi2.async.CollectionTask)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 DisplayMetrics (android.util.DisplayMetrics)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1