Search in sources :

Example 1 with MultimediaEditableNote

use of com.ichi2.anki.multimediacard.impl.MultimediaEditableNote in project Anki-Android by Ramblurr.

the class MultimediaCardEditorActivity method changeCurrentModel.

/**
     * Change current model for the Note. Changes both MultimediaNote and the mEditorNote (Note Object) and copies
     * existing values to both.
     * 
     * @param newId
     */
protected void changeCurrentModel(long newId) {
    try {
        JSONObject currentModel = mCol.getModels().get(newId);
        mCol.getModels().setCurrent(currentModel);
        JSONObject cdeck = mCol.getDecks().current();
        cdeck.put("mid", newId);
        mCol.getDecks().save(cdeck);
        int size = mNote.getNumberOfFields();
        String[] oldValues = new String[size];
        for (int i = 0; i < size; i++) {
            oldValues[i] = mNote.getField(i).getFormattedValue();
        }
        mEditorNote = new Note(mCol, currentModel);
        mEditorNote.model().put("did", mCurrentDid);
        MultimediaEditableNote newNote = NoteService.createEmptyNote(currentModel);
        for (int i = 0; i < newNote.getNumberOfFields(); i++) {
            if (i < mNote.getNumberOfFields()) {
                newNote.setField(i, mNote.getField(i));
            }
        }
        mNote = newNote;
    } catch (JSONException e) {
        Log.e("Multimedia Editor", e.getMessage());
    }
}
Also used : IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) JSONObject(org.json.JSONObject) Note(com.ichi2.libanki.Note) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) JSONException(org.json.JSONException) SuppressLint(android.annotation.SuppressLint)

Example 2 with MultimediaEditableNote

use of com.ichi2.anki.multimediacard.impl.MultimediaEditableNote in project Anki-Android by Ramblurr.

the class MultimediaCardEditorActivity method save.

private void save() {
    NoteService.saveMedia((MultimediaEditableNote) mNote);
    NoteService.updateJsonNoteFromMultimediaNote(mNote, mEditorNote);
    TaskListener listener = new TaskListener() {

        @Override
        public void onProgressUpdate(TaskData... values) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onPreExecute() {
        // TODO Auto-generated method stub
        }

        @Override
        public void onPostExecute(TaskData result) {
        // TODO Auto-generated method stub
        }
    };
    if (mAddNote) {
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, listener, new DeckTask.TaskData(mEditorNote));
    } else {
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, listener, new DeckTask.TaskData(mCol.getSched(), mCard, false));
    }
    setResult(Activity.RESULT_OK);
    finish();
    animateRight();
}
Also used : TaskListener(com.ichi2.async.DeckTask.TaskListener) TaskData(com.ichi2.async.DeckTask.TaskData) DeckTask(com.ichi2.async.DeckTask) TaskData(com.ichi2.async.DeckTask.TaskData)

Example 3 with MultimediaEditableNote

use of com.ichi2.anki.multimediacard.impl.MultimediaEditableNote in project Anki-Android by Ramblurr.

the class MockNoteFactory method makeNote.

public static IMultimediaEditableNote makeNote() {
    MultimediaEditableNote note = new MultimediaEditableNote();
    note.setNumFields(4);
    TextField tf = new TextField();
    tf.setText("world");
    note.setField(0, tf);
    TextField tf2 = new TextField();
    tf2.setText("Welt");
    note.setField(1, tf2);
    TextField tf3 = new TextField();
    tf3.setText("Übung");
    note.setField(2, tf3);
    ImageField imageField = new ImageField();
    imageField.setImagePath("/mnt/sdcard/img/1.jpg");
    note.setField(3, imageField);
    return note;
}
Also used : ImageField(com.ichi2.anki.multimediacard.fields.ImageField) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) TextField(com.ichi2.anki.multimediacard.fields.TextField)

Example 4 with MultimediaEditableNote

use of com.ichi2.anki.multimediacard.impl.MultimediaEditableNote in project Anki-Android by Ramblurr.

the class NoteService method updateMultimediaNoteFromJsonNote.

public static void updateMultimediaNoteFromJsonNote(final Note editorNoteSrc, final IMultimediaEditableNote noteDst) {
    if (noteDst instanceof MultimediaEditableNote) {
        MultimediaEditableNote mmNote = (MultimediaEditableNote) noteDst;
        String[] values = editorNoteSrc.getFields();
        for (int i = 0; i < values.length; i++) {
            String value = values[i];
            IField field = null;
            if (value.startsWith("<img")) {
                field = new ImageField();
            } else if (value.startsWith("[sound:")) {
                field = new AudioField();
            } else {
                field = new TextField();
            }
            field.setFormattedString(value);
            mmNote.setField(i, field);
        }
        mmNote.setModelId(editorNoteSrc.getMid());
    // TODO: set current id of the note as well
    }
}
Also used : AudioField(com.ichi2.anki.multimediacard.fields.AudioField) ImageField(com.ichi2.anki.multimediacard.fields.ImageField) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) TextField(com.ichi2.anki.multimediacard.fields.TextField) IField(com.ichi2.anki.multimediacard.fields.IField)

Example 5 with MultimediaEditableNote

use of com.ichi2.anki.multimediacard.impl.MultimediaEditableNote in project Anki-Android by Ramblurr.

the class NoteService method updateJsonNoteFromMultimediaNote.

/**
     * Updates the JsonNote field values from MultimediaEditableNote When both notes are using the same Model, it updaes
     * the destination field values with source values. If models are different it throws an Exception
     * 
     * @param mNoteSrc
     * @param mEditorNoteDst
     */
public static void updateJsonNoteFromMultimediaNote(final IMultimediaEditableNote noteSrc, final Note editorNoteDst) {
    if (noteSrc instanceof MultimediaEditableNote) {
        MultimediaEditableNote mmNote = (MultimediaEditableNote) noteSrc;
        if (mmNote.getModelId() != editorNoteDst.getMid()) {
            throw new RuntimeException("Source and Destination Note ID do not match.");
        }
        int totalFields = mmNote.getNumberOfFields();
        for (int i = 0; i < totalFields; i++) {
            editorNoteDst.values()[i] = mmNote.getField(i).getFormattedValue();
        }
    }
}
Also used : MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote)

Aggregations

IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)6 MultimediaEditableNote (com.ichi2.anki.multimediacard.impl.MultimediaEditableNote)5 TextField (com.ichi2.anki.multimediacard.fields.TextField)4 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)3 IField (com.ichi2.anki.multimediacard.fields.IField)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 AudioField (com.ichi2.anki.multimediacard.fields.AudioField)1 DeckTask (com.ichi2.async.DeckTask)1 TaskData (com.ichi2.async.DeckTask.TaskData)1 TaskListener (com.ichi2.async.DeckTask.TaskListener)1 Note (com.ichi2.libanki.Note)1 JSONArray (org.json.JSONArray)1