Search in sources :

Example 1 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project AnkiChinaAndroid by ankichinateam.

the class NoteEditor method updateFieldsFromMap.

/**
 * Update all the field EditText views based on the currently selected note type and the mModelChangeFieldMap
 */
private void updateFieldsFromMap(Model newModel) {
    FieldChangeType type = FieldChangeType.refreshWithMap(newModel, mModelChangeFieldMap, shouldReplaceNewlines());
    populateEditFields(type, true);
    updateCards(newModel);
}
Also used : FieldChangeType(com.ichi2.anki.noteeditor.FieldState.FieldChangeType)

Example 2 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project AnkiChinaAndroid by ankichinateam.

the class FieldState method createFields.

@NonNull
protected List<FieldEditLine> createFields(FieldChangeType type) {
    String[][] fields = getFields(type);
    List<FieldEditLine> editLines = new ArrayList<>(fields.length);
    for (int i = 0; i < fields.length; i++) {
        FieldEditLine edit_line_view = new FieldEditLine(mEditor);
        editLines.add(edit_line_view);
        edit_line_view.setName(fields[i][0]);
        edit_line_view.setContent(fields[i][1], type.replaceNewlines);
        edit_line_view.setOrd(i);
    }
    return editLines;
}
Also used : ArrayList(java.util.ArrayList) FieldEditLine(com.ichi2.anki.FieldEditLine) NonNull(androidx.annotation.NonNull)

Example 3 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project Anki-Android by ankidroid.

the class NoteEditor method updateFieldsFromMap.

/**
 * Update all the field EditText views based on the currently selected note type and the mModelChangeFieldMap
 */
private void updateFieldsFromMap(Model newModel) {
    FieldChangeType type = FieldChangeType.refreshWithMap(newModel, mModelChangeFieldMap, shouldReplaceNewlines());
    populateEditFields(type, true);
    updateCards(newModel);
}
Also used : FieldChangeType(com.ichi2.anki.noteeditor.FieldState.FieldChangeType)

Example 4 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project Anki-Android by ankidroid.

the class NoteEditor method populateEditFields.

private void populateEditFields(FieldChangeType type, boolean editModelMode) {
    List<FieldEditLine> editLines = mFieldState.loadFieldEditLines(type);
    mFieldsLayoutContainer.removeAllViews();
    mCustomViewIds.clear();
    mEditFields = new LinkedList<>();
    // Use custom font if selected from preferences
    Typeface customTypeface = null;
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    String customFont = preferences.getString("browserEditorFont", "");
    if (!"".equals(customFont)) {
        customTypeface = AnkiFont.getTypeface(this, customFont);
    }
    ClipboardManager clipboard = ContextCompat.getSystemService(this, ClipboardManager.class);
    FieldEditLine previous = null;
    mCustomViewIds.ensureCapacity(editLines.size());
    for (int i = 0; i < editLines.size(); i++) {
        FieldEditLine edit_line_view = editLines.get(i);
        mCustomViewIds.add(edit_line_view.getId());
        FieldEditText newTextbox = edit_line_view.getEditText();
        newTextbox.setImagePasteListener(this::onImagePaste);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            if (i == 0) {
                findViewById(R.id.note_deck_spinner).setNextFocusForwardId(newTextbox.getId());
            }
            if (previous != null) {
                previous.getLastViewInTabOrder().setNextFocusForwardId(newTextbox.getId());
            }
        }
        previous = edit_line_view;
        edit_line_view.setEnableAnimation(animationEnabled());
        // TODO: Remove the >= M check - one callback works on API 11.
        if (CompatHelper.getSdkVersion() >= Build.VERSION_CODES.M) {
            // Use custom implementation of ActionMode.Callback customize selection and insert menus
            Field f = new Field(getFieldByIndex(i), getCol());
            ActionModeCallback actionModeCallback = new ActionModeCallback(newTextbox, f);
            edit_line_view.setActionModeCallbacks(actionModeCallback);
        }
        edit_line_view.setTypeface(customTypeface);
        edit_line_view.setHintLocale(getHintLocaleForField(edit_line_view.getName()));
        initFieldEditText(newTextbox, i, !editModelMode);
        mEditFields.add(newTextbox);
        SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(this);
        if (prefs.getInt("note_editor_font_size", -1) > 0) {
            newTextbox.setTextSize(prefs.getInt("note_editor_font_size", -1));
        }
        newTextbox.setCapitalize(prefs.getBoolean("note_editor_capitalize", true));
        ImageButton mediaButton = edit_line_view.getMediaButton();
        ImageButton toggleStickyButton = edit_line_view.getToggleSticky();
        // Load icons from attributes
        int[] icons = Themes.getResFromAttr(this, new int[] { R.attr.attachFileImage, R.attr.upDownImage, R.attr.toggleStickyImage });
        // Make the icon change between media icon and switch field icon depending on whether editing note type
        if (editModelMode && allowFieldRemapping()) {
            // Allow remapping if originally more than two fields
            mediaButton.setBackgroundResource(icons[1]);
            setRemapButtonListener(mediaButton, i);
            toggleStickyButton.setBackgroundResource(0);
        } else if (editModelMode && !allowFieldRemapping()) {
            mediaButton.setBackgroundResource(0);
            toggleStickyButton.setBackgroundResource(0);
        } else {
            // Use media editor button if not changing note type
            mediaButton.setBackgroundResource(icons[0]);
            setMMButtonListener(mediaButton, i);
            // toggle sticky button
            toggleStickyButton.setBackgroundResource(icons[2]);
            setToggleStickyButtonListener(toggleStickyButton, i);
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && previous != null) {
            previous.getLastViewInTabOrder().setNextFocusForwardId(R.id.CardEditorTagButton);
        }
        mediaButton.setContentDescription(getString(R.string.multimedia_editor_attach_mm_content, edit_line_view.getName()));
        toggleStickyButton.setContentDescription(getString(R.string.note_editor_toggle_sticky, edit_line_view.getName()));
        mFieldsLayoutContainer.addView(edit_line_view);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Typeface(android.graphics.Typeface) SharedPreferences(android.content.SharedPreferences) SuppressLint(android.annotation.SuppressLint) AudioRecordingField(com.ichi2.anki.multimediacard.fields.AudioRecordingField) IField(com.ichi2.anki.multimediacard.fields.IField) ImageField(com.ichi2.anki.multimediacard.fields.ImageField) TextField(com.ichi2.anki.multimediacard.fields.TextField) MediaClipField(com.ichi2.anki.multimediacard.fields.MediaClipField) ImageButton(android.widget.ImageButton)

Example 5 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project AnkiChinaAndroid by ankichinateam.

the class NoteEditor method populateEditFields.

private void populateEditFields(FieldChangeType type, boolean editModelMode) {
    List<FieldEditLine> editLines = mFieldState.loadFieldEditLines(type);
    mFieldsLayoutContainer.removeAllViews();
    mCustomViewIds.clear();
    mEditFields = new LinkedList<>();
    // Use custom font if selected from preferences
    Typeface mCustomTypeface = null;
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    String customFont = preferences.getString("browserEditorFont", "");
    if (!"".equals(customFont)) {
        mCustomTypeface = AnkiFont.getTypeface(this, customFont);
    }
    ClipboardManager clipboard = ContextCompat.getSystemService(this, ClipboardManager.class);
    FieldEditLine previous = null;
    mCustomViewIds.ensureCapacity(editLines.size());
    for (int i = 0; i < editLines.size(); i++) {
        FieldEditLine edit_line_view = editLines.get(i);
        mCustomViewIds.add(edit_line_view.getId());
        FieldEditText newTextbox = edit_line_view.getEditText();
        newTextbox.setImagePasteListener(this::onImagePaste);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
            if (i == 0) {
                findViewById(R.id.note_deck_spinner).setNextFocusForwardId(newTextbox.getId());
            }
            if (previous != null) {
                previous.getLastViewInTabOrder().setNextFocusForwardId(newTextbox.getId());
            }
        }
        previous = edit_line_view;
        edit_line_view.setEnableAnimation(animationEnabled());
        // TODO: Remove the >= M check - one callback works on API 11.
        if (CompatHelper.getSdkVersion() >= Build.VERSION_CODES.M) {
            // Use custom implementation of ActionMode.Callback customize selection and insert menus
            Field f = new Field(getFieldByIndex(i), getCol());
            ActionModeCallback actionModeCallback = new ActionModeCallback(newTextbox, f);
            edit_line_view.setActionModeCallbacks(actionModeCallback);
        }
        edit_line_view.setTypeface(mCustomTypeface);
        edit_line_view.setHintLocale(getHintLocaleForField(edit_line_view.getName()));
        initFieldEditText(newTextbox, i, !editModelMode);
        mEditFields.add(newTextbox);
        SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(this);
        if (prefs.getInt("note_editor_font_size", -1) > 0) {
            newTextbox.setTextSize(prefs.getInt("note_editor_font_size", -1));
        }
        newTextbox.setCapitalize(prefs.getBoolean("note_editor_capitalize", true));
        ImageButton mediaButton = edit_line_view.getMediaButton();
        // Load icons from attributes
        int[] icons = Themes.getResFromAttr(this, new int[] { R.attr.attachFileImage, R.attr.upDownImage });
        // Make the icon change between media icon and switch field icon depending on whether editing note type
        if (editModelMode && allowFieldRemapping()) {
            // Allow remapping if originally more than two fields
            mediaButton.setBackgroundResource(icons[1]);
            setRemapButtonListener(mediaButton, i);
        } else if (editModelMode && !allowFieldRemapping()) {
            mediaButton.setBackgroundResource(0);
        } else {
            // Use media editor button if not changing note type
            mediaButton.setBackgroundResource(icons[0]);
            setMMButtonListener(mediaButton, i);
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && previous != null) {
            previous.getLastViewInTabOrder().setNextFocusForwardId(R.id.CardEditorTagButton);
        }
        mediaButton.setContentDescription(getString(R.string.multimedia_editor_attach_mm_content, edit_line_view.getName()));
        mFieldsLayoutContainer.addView(edit_line_view);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Typeface(android.graphics.Typeface) SharedPreferences(android.content.SharedPreferences) SuppressLint(android.annotation.SuppressLint) AudioRecordingField(com.ichi2.anki.multimediacard.fields.AudioRecordingField) IField(com.ichi2.anki.multimediacard.fields.IField) ImageField(com.ichi2.anki.multimediacard.fields.ImageField) TextField(com.ichi2.anki.multimediacard.fields.TextField) AudioClipField(com.ichi2.anki.multimediacard.fields.AudioClipField) ImageButton(android.widget.ImageButton)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 ClipboardManager (android.content.ClipboardManager)2 SharedPreferences (android.content.SharedPreferences)2 Typeface (android.graphics.Typeface)2 ImageButton (android.widget.ImageButton)2 NonNull (androidx.annotation.NonNull)2 FieldEditLine (com.ichi2.anki.FieldEditLine)2 IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)2 AudioRecordingField (com.ichi2.anki.multimediacard.fields.AudioRecordingField)2 IField (com.ichi2.anki.multimediacard.fields.IField)2 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)2 TextField (com.ichi2.anki.multimediacard.fields.TextField)2 MultimediaEditableNote (com.ichi2.anki.multimediacard.impl.MultimediaEditableNote)2 FieldChangeType (com.ichi2.anki.noteeditor.FieldState.FieldChangeType)2 Model (com.ichi2.libanki.Model)2 Note (com.ichi2.libanki.Note)2 AudioClipField (com.ichi2.anki.multimediacard.fields.AudioClipField)1 MediaClipField (com.ichi2.anki.multimediacard.fields.MediaClipField)1 JSONArray (com.ichi2.utils.JSONArray)1 ArrayList (java.util.ArrayList)1