Search in sources :

Example 1 with FieldEditLine

use of com.ichi2.anki.FieldEditLine in project AnkiChinaAndroid by ankichinateam.

the class FieldState method recreateFieldsFromState.

private List<FieldEditLine> recreateFieldsFromState() {
    List<FieldEditLine> editLines = new ArrayList<>(mSavedFieldData.size());
    for (AbsSavedState state : mSavedFieldData) {
        FieldEditLine edit_line_view = new FieldEditLine(mEditor);
        if (edit_line_view.getId() == 0) {
            edit_line_view.setId(ViewCompat.generateViewId());
        }
        edit_line_view.loadState(state);
        editLines.add(edit_line_view);
    }
    return editLines;
}
Also used : AbsSavedState(android.view.AbsSavedState) ArrayList(java.util.ArrayList) FieldEditLine(com.ichi2.anki.FieldEditLine)

Example 2 with FieldEditLine

use of com.ichi2.anki.FieldEditLine 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 FieldEditLine

use of com.ichi2.anki.FieldEditLine 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 4 with FieldEditLine

use of com.ichi2.anki.FieldEditLine 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)

Example 5 with FieldEditLine

use of com.ichi2.anki.FieldEditLine in project AnkiChinaAndroid by ankichinateam.

the class FieldState method loadFieldEditLines.

@NonNull
public List<FieldEditLine> loadFieldEditLines(FieldChangeType type) {
    List<FieldEditLine> fieldEditLines;
    if (type.mType == Type.INIT && mSavedFieldData != null) {
        fieldEditLines = recreateFieldsFromState();
        mSavedFieldData = null;
    } else {
        fieldEditLines = createFields(type);
    }
    for (FieldEditLine l : fieldEditLines) {
        l.setId(ViewCompat.generateViewId());
    }
    if (type.mType == Type.CLEAR_KEEP_STICKY) {
        // we use the UI values here as the model will post-processing steps (newline -> br).
        String[] currentFieldStrings = mEditor.getCurrentFieldStrings();
        JSONArray flds = mEditor.getCurrentFields();
        for (int fldIdx = 0; fldIdx < flds.length(); fldIdx++) {
            if (flds.getJSONObject(fldIdx).getBoolean("sticky")) {
                fieldEditLines.get(fldIdx).setContent(currentFieldStrings[fldIdx], type.replaceNewlines);
            }
        }
    }
    if (type.mType == Type.CHANGE_FIELD_COUNT) {
        String[] currentFieldStrings = mEditor.getCurrentFieldStrings();
        for (int i = 0; i < Math.min(currentFieldStrings.length, fieldEditLines.size()); i++) {
            fieldEditLines.get(i).setContent(currentFieldStrings[i], type.replaceNewlines);
        }
    }
    return fieldEditLines;
}
Also used : JSONArray(com.ichi2.utils.JSONArray) FieldEditLine(com.ichi2.anki.FieldEditLine) NonNull(androidx.annotation.NonNull)

Aggregations

FieldEditLine (com.ichi2.anki.FieldEditLine)3 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 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 ArrayList (java.util.ArrayList)2 AbsSavedState (android.view.AbsSavedState)1 AudioClipField (com.ichi2.anki.multimediacard.fields.AudioClipField)1 MediaClipField (com.ichi2.anki.multimediacard.fields.MediaClipField)1 JSONArray (com.ichi2.utils.JSONArray)1