use of com.ichi2.anki.noteeditor.CustomToolbarButton in project AnkiChinaAndroid by ankichinateam.
the class NoteEditor method updateToolbar.
private void updateToolbar() {
if (mToolbar == null) {
return;
}
if (shouldHideToolbar()) {
mToolbar.setVisibility(View.GONE);
return;
} else {
mToolbar.setVisibility(View.VISIBLE);
}
mToolbar.clearCustomItems();
View clozeIcon = mToolbar.getClozeIcon();
if (Models.isCloze(mEditorNote.model())) {
Toolbar.TextFormatter clozeFormatter = s -> {
Toolbar.TextWrapper.StringFormat stringFormat = new Toolbar.TextWrapper.StringFormat();
String prefix = "{{c" + getNextClozeIndex() + "::";
stringFormat.result = prefix + s + "}}";
if (s.length() == 0) {
stringFormat.start = prefix.length();
stringFormat.end = prefix.length();
} else {
stringFormat.start = 0;
stringFormat.end = stringFormat.result.length();
}
return stringFormat;
};
clozeIcon.setOnClickListener(l -> mToolbar.onFormat(clozeFormatter));
clozeIcon.setVisibility(View.VISIBLE);
} else {
clozeIcon.setVisibility(View.GONE);
}
ArrayList<CustomToolbarButton> buttons = getToolbarButtons();
for (CustomToolbarButton b : buttons) {
// 0th button shows as '1' and is Ctrl + 1
int visualIndex = b.getIndex() + 1;
String text = Integer.toString(visualIndex);
Drawable bmp = mToolbar.createDrawableForString(text);
View v = mToolbar.insertItem(0, bmp, b.toFormatter());
// Allow Ctrl + 1...Ctrl + 0 for item 10.
v.setTag(Integer.toString(visualIndex % 10));
v.setOnLongClickListener(discard -> {
suggestRemoveButton(b);
return true;
});
}
// Let the user add more buttons (always at the end).
mToolbar.insertItem(0, R.drawable.ic_add_toolbar_icon, this::displayAddToolbarDialog);
}
use of com.ichi2.anki.noteeditor.CustomToolbarButton in project Anki-Android by ankidroid.
the class NoteEditor method updateToolbar.
private void updateToolbar() {
if (mToolbar == null) {
return;
}
View editorLayout = findViewById(R.id.note_editor_layout);
int bottomMargin = shouldHideToolbar() ? 0 : (int) getResources().getDimension(R.dimen.note_editor_toolbar_height);
MarginLayoutParams params = (MarginLayoutParams) editorLayout.getLayoutParams();
params.bottomMargin = bottomMargin;
editorLayout.setLayoutParams(params);
if (shouldHideToolbar()) {
mToolbar.setVisibility(View.GONE);
return;
} else {
mToolbar.setVisibility(View.VISIBLE);
}
mToolbar.clearCustomItems();
View clozeIcon = mToolbar.getClozeIcon();
if (mEditorNote.model().isCloze()) {
Toolbar.TextFormatter clozeFormatter = s -> {
Toolbar.TextWrapper.StringFormat stringFormat = new Toolbar.TextWrapper.StringFormat();
String prefix = "{{c" + getNextClozeIndex() + "::";
stringFormat.result = prefix + s + "}}";
if (s.length() == 0) {
stringFormat.start = prefix.length();
stringFormat.end = prefix.length();
} else {
stringFormat.start = 0;
stringFormat.end = stringFormat.result.length();
}
return stringFormat;
};
clozeIcon.setOnClickListener(l -> mToolbar.onFormat(clozeFormatter));
clozeIcon.setVisibility(View.VISIBLE);
} else {
clozeIcon.setVisibility(View.GONE);
}
ArrayList<CustomToolbarButton> buttons = getToolbarButtons();
for (CustomToolbarButton b : buttons) {
// 0th button shows as '1' and is Ctrl + 1
int visualIndex = b.getIndex() + 1;
String text = Integer.toString(visualIndex);
if (!b.getButtonText().isEmpty()) {
text = b.getButtonText();
}
Drawable bmp = mToolbar.createDrawableForString(text);
View v = mToolbar.insertItem(0, bmp, b.toFormatter());
// Allow Ctrl + 1...Ctrl + 0 for item 10.
v.setTag(Integer.toString(visualIndex % 10));
v.setOnLongClickListener(discard -> {
suggestRemoveButton(b);
return true;
});
}
// Let the user add more buttons (always at the end).
// Sets the add custom tag icon color.
final Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_toolbar_icon, null);
drawable.setTint(Themes.getColorFromAttr(NoteEditor.this, R.attr.toolbarIconColor));
mToolbar.insertItem(0, drawable, this::displayAddToolbarDialog);
}
use of com.ichi2.anki.noteeditor.CustomToolbarButton in project Anki-Android by ankidroid.
the class NoteEditor method addToolbarButton.
private void addToolbarButton(String buttonText, String prefix, String suffix) {
if (TextUtils.isEmpty(prefix) && TextUtils.isEmpty(suffix)) {
return;
}
ArrayList<CustomToolbarButton> toolbarButtons = getToolbarButtons();
toolbarButtons.add(new CustomToolbarButton(toolbarButtons.size(), buttonText, prefix, suffix));
saveToolbarButtons(toolbarButtons);
updateToolbar();
}
use of com.ichi2.anki.noteeditor.CustomToolbarButton in project AnkiChinaAndroid by ankichinateam.
the class NoteEditor method addToolbarButton.
private void addToolbarButton(String prefix, String suffix) {
if (TextUtils.isEmpty(prefix) && TextUtils.isEmpty(suffix)) {
return;
}
ArrayList<CustomToolbarButton> toolbarButtons = getToolbarButtons();
toolbarButtons.add(new CustomToolbarButton(toolbarButtons.size(), prefix, suffix));
saveToolbarButtons(toolbarButtons);
updateToolbar();
}
Aggregations