use of com.ichi2.anki.widgets.PopupMenuWithIcons in project AnkiChinaAndroid by ankichinateam.
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 mNote = getCurrentMultimediaEditableNote(col);
startMultimediaFieldEditor(index, mNote);
} 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, false);
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) {
Timber.i("NoteEditor:: Add audio clip button pressed");
startMultimediaFieldEditorForField(index, new AudioClipField());
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.widgets.PopupMenuWithIcons 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();
}
});
}
Aggregations