use of android.graphics.EmbossMaskFilter in project AndroidStudy by tinggengyan.
the class HandWritingView method getMaskFilter.
/**
* 功能:设置画笔风格
*/
private MaskFilter getMaskFilter(int mPaintType) {
MaskFilter maskFilter = null;
switch(mPaintType) {
case // 铅笔模糊风格
BLUR:
maskFilter = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
break;
case // 毛笔浮雕风格
EMBOSS:
maskFilter = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
break;
case // 透明水彩风格
TS_PEN:
maskFilter = null;
paint.setAlpha(50);
break;
default:
maskFilter = null;
break;
}
paint.setMaskFilter(maskFilter);
return maskFilter;
}
use of android.graphics.EmbossMaskFilter in project AndroidLife by CaMnter.
the class SpanRecyclerAdapter method setSpanContent.
@SuppressLint("SetTextI18n")
public void setSpanContent(TextView labelTV, TextView contentTV, String content, int position) {
SpannableStringBuilder ssb = new SpannableStringBuilder(content);
String sub = "Save";
int start = content.indexOf("Save");
switch(position) {
case URL_SPAN:
{
labelTV.setText("URLSpan");
ssb.setSpan(new URLSpan("https://github.com/CaMnter"), start, sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
// 在单击链接时凡是有要执行的动作,都必须设置MovementMethod对象
contentTV.setMovementMethod(LinkMovementMethod.getInstance());
// 设置点击后的颜色,这里涉及到ClickableSpan的点击背景
contentTV.setHighlightColor(0xff8FABCC);
break;
}
case UNDERLINE_SPAN:
{
labelTV.setText("UnderlineSpan");
ssb.setSpan(new UnderlineSpan(), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case TYPEFACE_SPAN:
{
labelTV.setText("TypefaceSpan ( Examples include \"monospace\", \"serif\", and \"sans-serif\". )");
ssb.setSpan(new TypefaceSpan("serif"), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case TEXT_APPERARANCE_SPAN:
{
labelTV.setText("TextAppearanceSpan");
ColorStateList colorStateList;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
colorStateList = this.activity.getColorStateList(R.color.selector_apperarance_span);
} else {
colorStateList = this.activity.getResources().getColorStateList(R.color.selector_apperarance_span);
}
ssb.setSpan(new TextAppearanceSpan("serif", Typeface.BOLD_ITALIC, this.activity.getResources().getDimensionPixelSize(R.dimen.text_appearance_span), colorStateList, colorStateList), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case TAB_STOP_SPAN:
{
labelTV.setText("TabStopSpan.Standard");
String[] subs = content.split(" ");
ssb = new SpannableStringBuilder();
/**
* TabStopSpan. Standard related to \t and \n
* TabStopSpan.Standard 跟 \t 和 \n 有关系
*/
for (String sub1 : subs) {
ssb.append("\t").append(sub1).append(" ");
ssb.append("\n");
}
ssb.setSpan(new TabStopSpan.Standard(126), 0, ssb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case SUPERS_SCRIPT_SPAN:
{
labelTV.setText("SuperscriptSpan");
ssb.replace(start, start + sub.length(), "Save6");
Parcel parcel = Parcel.obtain();
parcel.writeInt(6);
int sixPosition = ssb.toString().indexOf("6");
ssb.setSpan(new SuperscriptSpan(parcel), sixPosition, sixPosition + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
parcel.recycle();
contentTV.setText(ssb);
break;
}
case SUB_SCRIPT_SPAN:
{
labelTV.setText("SubscriptSpan");
ssb.replace(start, start + sub.length(), "Save6");
Parcel parcel = Parcel.obtain();
parcel.writeInt(6);
int sixPosition = ssb.toString().indexOf("6");
ssb.setSpan(new SubscriptSpan(parcel), sixPosition, sixPosition + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
parcel.recycle();
contentTV.setText(ssb);
break;
}
case STRIKE_THROUGH_SPAN:
{
labelTV.setText("StrikethroughSpan");
ssb.setSpan(new StrikethroughSpan(), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case SCALE_X_SPAN:
{
labelTV.setText("ScaleXSpan");
ssb.setSpan(new ScaleXSpan(2.0f), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case STYLE_SPAN:
{
labelTV.setText("StyleSpan ( Typeface.NORMAL,Typeface.BOLD,Typeface.ITALIC,Typeface.BOLD_ITALIC ) ");
ssb.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case RELATIVE_SIZE_SPAN:
{
labelTV.setText("RelativeSizeSpan");
ssb.setSpan(new RelativeSizeSpan(6.0f), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case QUOTO_SPAN:
{
labelTV.setText("QuoteSpan");
ssb.setSpan(new QuoteSpan(0xff000000), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case MASK_FILTER_SPAN:
{
labelTV.setText("MaskFilterSpan ( BlurMaskFilter EmbossMaskFilter ) \n Activity: android:hardwareAccelerated=\"false\"\n ");
MaskFilterSpan embossMaskFilterSpan = new MaskFilterSpan(new EmbossMaskFilter(new float[] { 3, 3, 9 }, 3.0f, 12, 16));
ssb.setSpan(embossMaskFilterSpan, start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
String you = "you";
int indexYou = content.indexOf(you);
MaskFilterSpan blurMaskFilterSpan = new MaskFilterSpan(new BlurMaskFilter(3, BlurMaskFilter.Blur.OUTER));
ssb.setSpan(blurMaskFilterSpan, indexYou, indexYou + you.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case LEADING_MARGIN_SPAN:
{
labelTV.setText("LeadingMarginSpan");
ssb.append(" ").append(ssb.toString()).append(ssb.toString()).append(ssb.toString());
ssb.setSpan(new LeadingMarginSpan.Standard(96, 36), 0, ssb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case IMAGE_SPAN:
{
labelTV.setText("ImageSpan");
ssb.replace(start, start + sub.length(), " Save");
ssb.setSpan(new ImageSpan(this.activity, R.drawable.ic_mm_normal, ImageSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case ICON_MARGIN_SPAN:
{
labelTV.setText("IconMarginSpan");
Bitmap bitmap = BitmapFactory.decodeResource(this.activity.getResources(), R.drawable.ic_mm_normal);
ssb.setSpan(new IconMarginSpan(bitmap, 60), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
// bitmap.recycle();
contentTV.setText(ssb);
break;
}
case FOREGROUND_COLOR_SPAN:
{
labelTV.setText("ForegroundColorSpan");
ssb.setSpan(new ForegroundColorSpan(0xff303F9F), start, start + sub.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
contentTV.setText(ssb);
break;
}
case DRAWABLE_MARGIN_SPAN:
{
labelTV.setText("DrawableMarginSpan");
ssb.setSpan(new DrawableMarginSpan(ResourcesUtils.getDrawable(this.activity, R.drawable.ic_mm_normal), 6), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
break;
}
case BULLET_SPAN:
{
labelTV.setText("BulletSpan");
ssb.setSpan(new BulletSpan(66, 0xff303F9F), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
break;
}
case BACKGROUND_COLOR_SPAN:
{
labelTV.setText("BackgroundColorSpan");
String you = "you";
int indexYou = content.indexOf(you);
ssb.setSpan(new BackgroundColorSpan(0x2f303F9F), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(new BackgroundColorSpan(0x2fFF4081), indexYou, indexYou + you.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
break;
}
case ALIGNMENT_SPAN_STANDARD:
{
labelTV.setText("AlignmentSpan.Standard");
ssb.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
break;
}
case ABSOLUTE_SIZE_SPAN:
{
labelTV.setText("AbsoluteSizeSpan");
ssb.setSpan(new AbsoluteSizeSpan(26, true), start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
break;
}
case CLICKABLE_SPAN:
{
labelTV.setText("ClickableSpan ( Please click \"Save\" )");
SpanClickableSpan spanClickableSpan = new SpanClickableSpan(0xffFF4081, new ClickableSpanNoUnderline.OnClickListener<SpanClickableSpan>() {
/**
* ClickableSpan被点击
*
* @param widget widget
* @param span span
*/
@Override
public void onClick(View widget, SpanClickableSpan span) {
String urlString = span.getUrlString();
if (TextUtils.isEmpty(urlString))
return;
Uri uri = Uri.parse(urlString);
Context context = widget.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w("URLSpan", "Activity was not found for intent, " + intent.toString());
}
}
});
spanClickableSpan.setUrlString("https://github.com/CaMnter");
ssb.setSpan(spanClickableSpan, start, start + sub.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
contentTV.setText(ssb);
// 在单击链接时凡是有要执行的动作,都必须设置MovementMethod对象
contentTV.setMovementMethod(LinkMovementMethod.getInstance());
// 设置点击后的颜色,这里涉及到ClickableSpan的点击背景
contentTV.setHighlightColor(0x00000000);
break;
}
}
}
Aggregations