-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
368 additions
and
474 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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() { | ||
|
@@ -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) | ||
); | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
app/src/main/java/meitu/com/richtextviewproject/Library/utils/RichTextRegex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + ")"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.