|
|
@ -1081,100 +1081,105 @@ public class FragmentCompose extends FragmentBase {
|
|
|
|
private boolean onActionStyle(int action) {
|
|
|
|
private boolean onActionStyle(int action) {
|
|
|
|
Log.i("Style action=" + action);
|
|
|
|
Log.i("Style action=" + action);
|
|
|
|
|
|
|
|
|
|
|
|
int start = etBody.getSelectionStart();
|
|
|
|
try {
|
|
|
|
int end = etBody.getSelectionEnd();
|
|
|
|
int start = etBody.getSelectionStart();
|
|
|
|
|
|
|
|
int end = etBody.getSelectionEnd();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
|
|
|
|
if (end < 0)
|
|
|
|
|
|
|
|
end = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
|
|
|
|
int tmp = start;
|
|
|
|
|
|
|
|
start = end;
|
|
|
|
|
|
|
|
end = tmp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
SpannableString ss = new SpannableString(etBody.getText());
|
|
|
|
start = 0;
|
|
|
|
|
|
|
|
if (end < 0)
|
|
|
|
switch (action) {
|
|
|
|
end = 0;
|
|
|
|
case R.id.menu_bold:
|
|
|
|
|
|
|
|
case R.id.menu_italic: {
|
|
|
|
|
|
|
|
int style = (action == R.id.menu_bold ? Typeface.BOLD : Typeface.ITALIC);
|
|
|
|
|
|
|
|
boolean has = false;
|
|
|
|
|
|
|
|
for (StyleSpan span : ss.getSpans(start, end, StyleSpan.class))
|
|
|
|
|
|
|
|
if (span.getStyle() == style) {
|
|
|
|
|
|
|
|
has = true;
|
|
|
|
|
|
|
|
ss.removeSpan(span);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
if (!has)
|
|
|
|
int tmp = start;
|
|
|
|
ss.setSpan(new StyleSpan(style), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
start = end;
|
|
|
|
|
|
|
|
end = tmp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpannableString ss = new SpannableString(etBody.getText());
|
|
|
|
etBody.setText(ss);
|
|
|
|
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
return true;
|
|
|
|
case R.id.menu_bold:
|
|
|
|
}
|
|
|
|
case R.id.menu_italic: {
|
|
|
|
|
|
|
|
int style = (action == R.id.menu_bold ? Typeface.BOLD : Typeface.ITALIC);
|
|
|
|
case R.id.menu_underline: {
|
|
|
|
boolean has = false;
|
|
|
|
boolean has = false;
|
|
|
|
for (StyleSpan span : ss.getSpans(start, end, StyleSpan.class))
|
|
|
|
for (UnderlineSpan span : ss.getSpans(start, end, UnderlineSpan.class)) {
|
|
|
|
if (span.getStyle() == style) {
|
|
|
|
|
|
|
|
has = true;
|
|
|
|
has = true;
|
|
|
|
ss.removeSpan(span);
|
|
|
|
ss.removeSpan(span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!has)
|
|
|
|
if (!has)
|
|
|
|
ss.setSpan(new StyleSpan(style), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
ss.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
|
|
|
|
etBody.setText(ss);
|
|
|
|
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
etBody.setText(ss);
|
|
|
|
}
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.menu_underline: {
|
|
|
|
return true;
|
|
|
|
boolean has = false;
|
|
|
|
|
|
|
|
for (UnderlineSpan span : ss.getSpans(start, end, UnderlineSpan.class)) {
|
|
|
|
|
|
|
|
has = true;
|
|
|
|
|
|
|
|
ss.removeSpan(span);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!has)
|
|
|
|
case R.id.menu_size: {
|
|
|
|
ss.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
RelativeSizeSpan[] spans = ss.getSpans(start, end, RelativeSizeSpan.class);
|
|
|
|
|
|
|
|
float size = (spans.length > 0 ? spans[0].getSizeChange() : 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
etBody.setText(ss);
|
|
|
|
// Match small/big
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
if (size == 0.8f)
|
|
|
|
|
|
|
|
size = 1.0f;
|
|
|
|
return true;
|
|
|
|
else if (size == 1.0)
|
|
|
|
}
|
|
|
|
size = 1.25f;
|
|
|
|
|
|
|
|
else
|
|
|
|
case R.id.menu_size: {
|
|
|
|
size = 0.8f;
|
|
|
|
RelativeSizeSpan[] spans = ss.getSpans(start, end, RelativeSizeSpan.class);
|
|
|
|
|
|
|
|
float size = (spans.length > 0 ? spans[0].getSizeChange() : 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Match small/big
|
|
|
|
for (RelativeSizeSpan span : spans)
|
|
|
|
if (size == 0.8f)
|
|
|
|
ss.removeSpan(span);
|
|
|
|
size = 1.0f;
|
|
|
|
|
|
|
|
else if (size == 1.0)
|
|
|
|
|
|
|
|
size = 1.25f;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
size = 0.8f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (RelativeSizeSpan span : spans)
|
|
|
|
if (size != 1.0f)
|
|
|
|
ss.removeSpan(span);
|
|
|
|
ss.setSpan(new RelativeSizeSpan(size), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
|
|
|
|
if (size != 1.0f)
|
|
|
|
etBody.setText(ss);
|
|
|
|
ss.setSpan(new RelativeSizeSpan(size), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
|
|
|
|
|
|
|
|
etBody.setText(ss);
|
|
|
|
return true;
|
|
|
|
etBody.setSelection(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
case R.id.menu_color: {
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
|
|
|
args.putInt("start", start);
|
|
|
|
|
|
|
|
args.putInt("end", end);
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.menu_color: {
|
|
|
|
ForegroundColorSpan[] spans = ss.getSpans(start, end, ForegroundColorSpan.class);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
int color = (spans.length > 0 ? spans[0].getForegroundColor() : Color.TRANSPARENT);
|
|
|
|
args.putInt("start", start);
|
|
|
|
|
|
|
|
args.putInt("end", end);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ForegroundColorSpan[] spans = ss.getSpans(start, end, ForegroundColorSpan.class);
|
|
|
|
FragmentDialogColor fragment = new FragmentDialogColor();
|
|
|
|
int color = (spans.length > 0 ? spans[0].getForegroundColor() : Color.TRANSPARENT);
|
|
|
|
fragment.initialize(R.string.title_style_color, color, args, getContext());
|
|
|
|
|
|
|
|
fragment.setTargetFragment(FragmentCompose.this, REQUEST_COLOR);
|
|
|
|
|
|
|
|
fragment.show(getFragmentManager(), "account:color");
|
|
|
|
|
|
|
|
|
|
|
|
FragmentDialogColor fragment = new FragmentDialogColor();
|
|
|
|
return true;
|
|
|
|
fragment.initialize(R.string.title_style_color, color, args, getContext());
|
|
|
|
}
|
|
|
|
fragment.setTargetFragment(FragmentCompose.this, REQUEST_COLOR);
|
|
|
|
|
|
|
|
fragment.show(getFragmentManager(), "account:color");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
default:
|
|
|
|
Log.e(ex);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|