Skip to content

Commit

Permalink
代码提交信息
Browse files Browse the repository at this point in the history
  • Loading branch information
wohsj110 committed Sep 8, 2017
1 parent 72edcd3 commit aac3306
Show file tree
Hide file tree
Showing 27 changed files with 368 additions and 474 deletions.
3 changes: 0 additions & 3 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,30 @@
import android.graphics.Color;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import meitu.com.mylibrary.simplifyspan.SimplifySpanBuild;
import meitu.com.mylibrary.simplifyspan.other.OnClickableSpanListener;
import meitu.com.mylibrary.simplifyspan.other.SpecialGravity;
import meitu.com.mylibrary.simplifyspan.unit.SpecialClickableUnit;
import meitu.com.mylibrary.simplifyspan.unit.SpecialImageUnit;
import meitu.com.mylibrary.simplifyspan.unit.SpecialTextUnit;
import meitu.com.mylibrary.quickspan.QuickSpanBuild;
import meitu.com.mylibrary.quickspan.other.OnClickableSpanListener;
import meitu.com.mylibrary.quickspan.unit.SpecialClickableUnit;
import meitu.com.mylibrary.quickspan.unit.SpecialImageUnit;
import meitu.com.mylibrary.quickspan.unit.SpecialTextUnit;
import meitu.com.richtextviewproject.Library.utils.RichTextRegex;
import meitu.com.richtextviewproject.Library.widget.SpecialUrlBean;
import meitu.com.richtextviewproject.R;

/**
* Author huangshijie on 2017/9/4.
* E-mail: [email protected]
* Des:
* Des: ContentTextUtil 可以对文字做富文本效果
* Paramas
*/
public class ContentTextUtil {

private static final String AT = "@[\\w\\p{InCJKUnifiedIdeographs}-]{1,26}";// @人
private static final String TOPIC = "#[\\p{Print}\\p{InCJKUnifiedIdeographs}&&[^#]]+#";// ##话题
private static final String URL = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";// url
private static final String ALL = "(" + AT + ")" + "|" + "(" + TOPIC + ")" + "|" + "(" + URL + ")";


public static SimplifySpanBuild getContent(String source, HashMap<String,SpecialUrlBean> urlHashMap, final Context context, TextView textView) {
SimplifySpanBuild mSpanBuild = new SimplifySpanBuild();
public static QuickSpanBuild getContent(String source, HashMap<String,SpecialUrlBean> urlHashMap, final Context context, TextView textView) {
QuickSpanBuild mSpanBuild = new QuickSpanBuild();
int linkNorTextColor = 0xFF483D8B;
int linkPressBgColor = 0xFF87CEFA;
//设置正则
Pattern pattern = Pattern.compile(ALL);
Pattern pattern = Pattern.compile(RichTextRegex.ALL);
Matcher matcher = pattern.matcher(source);
int maxEnd=0;
int preStart=0;
Expand Down Expand Up @@ -103,12 +93,10 @@ public void onClick(TextView tv, String clickText) {
Toast.makeText(context, "Click Text: " + url, Toast.LENGTH_SHORT).show();
}
}).setNormalTextColor(bean.getTextNormalColor()).setPressBgColor(Color.TRANSPARENT).setNormalBgColor(Color.TRANSPARENT)
, new SpecialImageUnit(context,bean.getURLName(),bean.getIcon(), 33, 33,
context.getResources().getDrawable(R.drawable.bg_rectangle,context.getTheme())
, new SpecialImageUnit(context,bean.getURLName(),bean.getIcon(), 33, 33
, context.getResources().getDrawable(R.drawable.bg_rectangle,context.getTheme())
)
.setSpnWidth(-1).setPadding(8)
//.setGravity(SpecialGravity.CENTER)

.setSpnWidth(SpecialImageUnit.WARP_CONTENT).setPadding(8).setSpecialTextSize(32)
);
}else {
mSpanBuild.appendMultiClickable(new SpecialClickableUnit(textView, new OnClickableSpanListener() {
Expand All @@ -117,11 +105,11 @@ public void onClick(TextView tv, String clickText) {
Toast.makeText(context, "Click Text: " + url, Toast.LENGTH_SHORT).show();
}
}).setNormalTextColor(bean.getTextNormalColor()).setPressBgColor(Color.TRANSPARENT).setNormalBgColor(Color.TRANSPARENT)
, new SpecialImageUnit(context,bean.getURLName(), BitmapFactory.decodeResource(context.getResources(), R.drawable.timeline_card_small_web), 33, 33,
context.getResources().getDrawable(R.drawable.bg_rectangle,context.getTheme()))
.setSpnWidth(-1)
//.setGravity(SpecialGravity.CENTER)
, new SpecialImageUnit(context,bean.getURLName(), BitmapFactory.decodeResource(context.getResources(), R.drawable.timeline_card_small_web), 33, 33
, context.getResources().getDrawable(R.drawable.bg_rectangle,context.getTheme())

)
.setSpnWidth(SpecialImageUnit.WARP_CONTENT).setPadding(8).setSpecialTextSize(32)
);
}

Expand All @@ -131,13 +119,6 @@ public void onClick(TextView tv, String clickText) {
mSpanBuild.append(source.substring(maxEnd,source.length()));

}
mSpanBuild.append(new SpecialTextUnit("@英雄联盟", linkNorTextColor).setClickableUnit(new SpecialClickableUnit(textView, new OnClickableSpanListener() {
@Override
public void onClick(TextView tv, String clickText) {

}
}).setPressBgColor(linkPressBgColor)));

return mSpanBuild;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package meitu.com.richtextviewproject.Library.utils;

/**
* Created by meitu on 2017/9/8.
*/

public class RichTextRegex {
public static final String AT = "@[\\w\\p{InCJKUnifiedIdeographs}-]{1,26}";// @人
public static final String TOPIC = "#[\\p{Print}\\p{InCJKUnifiedIdeographs}&&[^#]]+#";// ##话题
public static final String URL = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";// url
public static final String ALL = "(" + AT + ")" + "|" + "(" + TOPIC + ")" + "|" + "(" + URL + ")";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* Paramas
*/

/**
* 富文本的实体类
*/
public class RichTextBean {
private String mTextcontent;
private HashMap<String, SpecialUrlBean> mUrlHashMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package meitu.com.richtextviewproject.Library.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
Expand All @@ -17,7 +13,8 @@

import java.util.HashMap;
import java.util.Map;
import meitu.com.mylibrary.simplifyspan.SimplifySpanBuild;

import meitu.com.mylibrary.quickspan.QuickSpanBuild;
import meitu.com.richtextviewproject.Library.process.ContentTextUtil;
import meitu.com.richtextviewproject.R;

Expand All @@ -30,7 +27,7 @@ public class RichTextViewHelper{

public static void setRichText(final TextView textView, final RichTextBean richTextBean) {
final long startTime = System.currentTimeMillis();
SimplifySpanBuild spanBuild = ContentTextUtil.getContent(richTextBean.getTextcontent(),richTextBean.getUrlHashMap(), textView.getContext(), textView);
QuickSpanBuild spanBuild = ContentTextUtil.getContent(richTextBean.getTextcontent(),richTextBean.getUrlHashMap(), textView.getContext(), textView);
textView.setText(spanBuild.build());
Log.e("耗时","耗时=="+(System.currentTimeMillis()-startTime));
BitmapFactory.Options decodingOptions = new BitmapFactory.Options();
Expand Down Expand Up @@ -58,7 +55,7 @@ public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (checkLoadAll(richTextBean.getUrlHashMap())) {
Log.e("耗时","异步加载图片耗时=="+(System.currentTimeMillis()-startTimeAsync));
long startTime = System.currentTimeMillis();
SimplifySpanBuild spanBuild = ContentTextUtil.getContent(richTextBean.getTextcontent(), richTextBean.getUrlHashMap(), textView.getContext(), textView);
QuickSpanBuild spanBuild = ContentTextUtil.getContent(richTextBean.getTextcontent(), richTextBean.getUrlHashMap(), textView.getContext(), textView);
textView.setText(spanBuild.build());
Log.e("耗时","耗时=="+(System.currentTimeMillis()-startTime));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.graphics.Bitmap;
import android.graphics.Color;

/**
* 需要被替换的 Url 实体类
*/
public class SpecialUrlBean {
private String mMainURL;
private String mURLName;
Expand Down
Loading

0 comments on commit aac3306

Please sign in to comment.