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);
}
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;
}
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);
}
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);
}
}
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);
}
}
Aggregations