use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.
the class NoteEditor method setMMButtonListener.
private void setMMButtonListener(ImageButton mediaButton, final int index) {
mediaButton.setOnClickListener(v -> {
Timber.i("NoteEditor:: Multimedia button pressed for field %d", index);
if (mEditorNote.items()[index][1].length() > 0) {
final Collection col = CollectionHelper.getInstance().getCol(NoteEditor.this);
// If the field already exists then we start the field editor, which figures out the type
// automatically
IMultimediaEditableNote note = getCurrentMultimediaEditableNote(col);
startMultimediaFieldEditor(index, note);
} else {
// Otherwise we make a popup menu allowing the user to choose between audio/image/text field
// TODO: Update the icons for dark material theme, then can set 3rd argument to true
PopupMenuWithIcons popup = new PopupMenuWithIcons(NoteEditor.this, v, true);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.popupmenu_multimedia_options, popup.getMenu());
popup.setOnMenuItemClickListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.menu_multimedia_audio) {
Timber.i("NoteEditor:: Record audio button pressed");
startMultimediaFieldEditorForField(index, new AudioRecordingField());
return true;
} else if (itemId == R.id.menu_multimedia_audio_clip || itemId == R.id.menu_multimedia_video_clip) {
Timber.i("NoteEditor:: Add audio clip button pressed");
startMultimediaFieldEditorForField(index, new MediaClipField());
return true;
} else if (itemId == R.id.menu_multimedia_photo) {
Timber.i("NoteEditor:: Add image button pressed");
startMultimediaFieldEditorForField(index, new ImageField());
return true;
} else if (itemId == R.id.menu_multimedia_text) {
Timber.i("NoteEditor:: Advanced editor button pressed");
startAdvancedTextEditor(index);
return true;
} else if (itemId == R.id.menu_multimedia_clear_field) {
Timber.i("NoteEditor:: Clear field button pressed");
clearField(index);
}
return false;
});
if (AdaptionUtil.isRestrictedLearningDevice()) {
popup.getMenu().findItem(R.id.menu_multimedia_photo).setVisible(false);
popup.getMenu().findItem(R.id.menu_multimedia_text).setVisible(false);
}
popup.show();
}
});
}
use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.
the class MultimediaEditFieldActivity method toAudioClipField.
protected void toAudioClipField() {
if (mField.getType() != EFieldType.MEDIA_CLIP) {
ChangeUIRequest request = ChangeUIRequest.uiChange(new MediaClipField());
recreateEditingUi(request);
}
}
use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.
the class NoteServiceTest method importAudioWithSameNameTest.
/**
* Tests if after importing:
*
* * New file keeps its name
* * File with same name, but different content, has its name changed
* * File with same name and content don't have its name changed
*
* @throws IOException if new created files already exist on temp directory
*/
@Test
public void importAudioWithSameNameTest() throws IOException {
File f1 = directory.newFile("audio.mp3");
File f2 = directory2.newFile("audio.mp3");
// write a line in the file so the file's length isn't 0
try (FileWriter fileWriter = new FileWriter(f1)) {
fileWriter.write("1");
}
// do the same to the second file, but with different data
try (FileWriter fileWriter = new FileWriter(f2)) {
fileWriter.write("2");
}
MediaClipField fld1 = new MediaClipField();
fld1.setAudioPath(f1.getAbsolutePath());
MediaClipField fld2 = new MediaClipField();
fld2.setAudioPath(f2.getAbsolutePath());
// third field to test if name is kept after reimporting the same file
MediaClipField fld3 = new MediaClipField();
fld3.setAudioPath(f1.getAbsolutePath());
NoteService.importMediaToDirectory(mTestCol, fld1);
File o1 = new File(mTestCol.getMedia().dir(), f1.getName());
NoteService.importMediaToDirectory(mTestCol, fld2);
File o2 = new File(mTestCol.getMedia().dir(), f2.getName());
NoteService.importMediaToDirectory(mTestCol, fld3);
// creating a third outfile isn't necessary because it should be equal to the first one
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld1.getAudioPath());
assertNotEquals("path should be different to the new file made in NoteService.importMediaToDirectory", o2.getAbsolutePath(), fld2.getAudioPath());
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld3.getAudioPath());
}
use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.
the class NoteServiceTest method importAudioClipToDirectoryTest.
@Test
public void importAudioClipToDirectoryTest() throws IOException {
File fileAudio = directory.newFile("testaudio.wav");
// writes a line in the file so the file's length isn't 0
try (FileWriter fileWriter = new FileWriter(fileAudio)) {
fileWriter.write("line1");
}
MediaClipField audioField = new MediaClipField();
audioField.setAudioPath(fileAudio.getAbsolutePath());
NoteService.importMediaToDirectory(mTestCol, audioField);
File outFile = new File(mTestCol.getMedia().dir(), fileAudio.getName());
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", outFile.getAbsolutePath(), audioField.getAudioPath());
}
use of com.ichi2.anki.multimediacard.fields.MediaClipField in project Anki-Android by ankidroid.
the class NoteServiceTest method importImageWithSameNameTest.
// Similar test like above, but with an ImageField instead of a MediaClipField
@Test
public void importImageWithSameNameTest() throws IOException {
File f1 = directory.newFile("img.png");
File f2 = directory2.newFile("img.png");
// write a line in the file so the file's length isn't 0
try (FileWriter fileWriter = new FileWriter(f1)) {
fileWriter.write("1");
}
// do the same to the second file, but with different data
try (FileWriter fileWriter = new FileWriter(f2)) {
fileWriter.write("2");
}
ImageField fld1 = new ImageField();
fld1.setImagePath(f1.getAbsolutePath());
ImageField fld2 = new ImageField();
fld2.setImagePath(f2.getAbsolutePath());
// third field to test if name is kept after reimporting the same file
ImageField fld3 = new ImageField();
fld3.setImagePath(f1.getAbsolutePath());
NoteService.importMediaToDirectory(mTestCol, fld1);
File o1 = new File(mTestCol.getMedia().dir(), f1.getName());
NoteService.importMediaToDirectory(mTestCol, fld2);
File o2 = new File(mTestCol.getMedia().dir(), f2.getName());
NoteService.importMediaToDirectory(mTestCol, fld3);
// creating a third outfile isn't necessary because it should be equal to the first one
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld1.getImagePath());
assertNotEquals("path should be different to the new file made in NoteService.importMediaToDirectory", o2.getAbsolutePath(), fld2.getImagePath());
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld3.getImagePath());
}
Aggregations