Search in sources :

Example 6 with MultimediaEditableNote

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

the class NoteService method createEmptyNote.

/**
     * Creates an empty Note from given Model
     * 
     * @param model the model in JSOBObject format
     * @return a new note instance
     */
public static MultimediaEditableNote createEmptyNote(JSONObject model) {
    try {
        JSONArray fieldsArray = model.getJSONArray("flds");
        int numOfFields = fieldsArray.length();
        if (numOfFields > 0) {
            MultimediaEditableNote note = new MultimediaEditableNote();
            note.setNumFields(numOfFields);
            for (int i = 0; i < numOfFields; i++) {
                JSONObject fieldObject = fieldsArray.getJSONObject(i);
                TextField uiTextField = new TextField();
                uiTextField.setName(fieldObject.getString("name"));
                uiTextField.setText(fieldObject.getString("name"));
                note.setField(i, uiTextField);
            }
            note.setModelId(model.getLong("id"));
            return note;
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TextField(com.ichi2.anki.multimediacard.fields.TextField) JSONException(org.json.JSONException)

Example 7 with MultimediaEditableNote

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

the class NoteService method saveMedia.

/**
     * Saves the multimedia associated with this card to proper path inside anki folder. For each field associated with
     * the note it checks for the following condition a. The field content should have changed b. The field content does
     * not already point to a media inside anki media path If both condition satisfies then it copies the file inside
     * the media path and deletes the file referenced by the note
     * 
     * @param note
     */
public static void saveMedia(final MultimediaEditableNote noteNew) {
    // if (noteNew.getModelId() == noteOld.getModelId())
    // {
    // int fieldCount = noteNew.getNumberOfFields();
    // for (int i = 0; i < fieldCount; i++)
    // {
    // IField newField = noteNew.getField(i);
    // IField oldField = noteOld.getField(i);
    // if
    // (newField.getFormattedValue().equals(oldField.getFormattedValue()))
    // {
    // continue;
    // }
    // importMediaToDirectory(newField);
    // }
    // }
    // else
    // {
    int fieldCount = noteNew.getNumberOfFields();
    for (int i = 0; i < fieldCount; i++) {
        IField newField = noteNew.getField(i);
        importMediaToDirectory(newField);
    }
// }
}
Also used : IField(com.ichi2.anki.multimediacard.fields.IField)

Example 8 with MultimediaEditableNote

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

the class NoteFactory method createNote.

public static IMultimediaEditableNote createNote() {
    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) IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) TextField(com.ichi2.anki.multimediacard.fields.TextField)

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