Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Sugar
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王海
Sugar
Commits
583ff668
Commit
583ff668
authored
Dec 16, 2016
by
sendtion
Committed by
GitHub
Dec 16, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加gradle依赖和Maven依赖
增加gradle依赖和Maven依赖方式
parent
4d36e3d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
55 deletions
+106
-55
README.md
README.md
+106
-55
No files found.
README.md
View file @
583ff668
# XRichText
# XRichText
[

](https://jitpack.io/#sendtion/XRichText)
一个Android富文本类库,支持图文混排,支持编辑和预览,支持插入和删除图片。
一个Android富文本类库,支持图文混排,支持编辑和预览,支持插入和删除图片。
### 实现的原理:
### 实现的原理:
...
@@ -12,80 +14,112 @@
...
@@ -12,80 +14,112 @@


## 使用方式
## 使用方式
1.
作为类库
#### 1. 作为module导入
把xrichtext作为一个module导入你的工程。
把xrichtext作为一个module导入你的工程。
把xrichtext中的文件拷贝到你的工程,可以在你的工程中建一个xrichtextming包名,并把文件拷贝进去。
2.
gradle依赖
#### 2. gradle依赖
稍后支持。
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.sendtion:XRichText:1.0'
}
```
#### 3. Maven方式
```
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.sendtion</groupId>
<artifactId>XRichText</artifactId>
<version>1.0</version>
</dependency>
```
## 具体使用
## 具体使用
在xml布局中添加基于EditText编辑器(可编辑)
在xml布局中添加基于EditText编辑器(可编辑)
```
<com.sendtion.xrichtext.RichTextEditor
<com.sendtion.xrichtext.RichTextEditor
android:id="@+id/et_new_content"
android:id="@+id/et_new_content"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="match_parent"
android:textSize="@dimen/text_size_16"
android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/>
android:textColor="@color/grey_600"/>
```
在xml布局中添加基于TextView编辑器(不可编辑)
在xml布局中添加基于TextView编辑器(不可编辑)
```
<com.sendtion.xrichtext.RichTextView
<com.sendtion.xrichtext.RichTextView
android:id="@+id/tv_note_content"
android:id="@+id/tv_note_content"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="match_parent"
android:textSize="@dimen/text_size_16"
android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/>
android:textColor="@color/grey_600"/>
```
**我把数据保存为了html格式,生成字符串存储到了数据库。**
**我把数据保存为了html格式,生成字符串存储到了数据库。**
### 生成数据
### 生成数据
```
String noteContent = getEditData();
String noteContent = getEditData();
private String getEditData() {
List<RichTextEditor.EditData> editList = et_new_content.buildEditData();
private String getEditData() {
StringBuffer content = new StringBuffer();
List<RichTextEditor.EditData> editList = et_new_content.buildEditData();
for (RichTextEditor.EditData itemData : editList) {
StringBuffer content = new StringBuffer();
if (itemData.inputStr != null) {
for (RichTextEditor.EditData itemData : editList) {
content.append(itemData.inputStr);
if (itemData.inputStr != null) {
} else if (itemData.imagePath != null) {
content.append(itemData.inputStr);
content.append("<img src=\"").append(itemData.imagePath).append("\"/>");
} else if (itemData.imagePath != null) {
content.append("<img src=\"").append(itemData.imagePath).append("\"/>");
}
}
}
return content.toString();
}
}
return content.toString();
}
```
### 显示数据
### 显示数据
```
et_new_content.post(new Runnable() {
@Override
public void run() {
showEditData(content);
}
});
et_new_content.post(new Runnable() {
protected void showEditData(String content) {
@Override
et_new_content.clearAllLayout();
public void run() {
List<String> textList = StringUtils.cutStringByImgTag(content);
showEditData(content);
for (int i = 0; i < textList.size(); i++) {
}
String text = textList.get(i);
});
if (text.contains("<img")) {
String imagePath = StringUtils.getImgSrc(text);
protected void showEditData(String content) {
int width = ScreenUtils.getScreenWidth(this);
et_new_content.clearAllLayout();
int height = ScreenUtils.getScreenHeight(this);
List<String> textList = StringUtils.cutStringByImgTag(content);
et_new_content.measure(0,0);
for (int i = 0; i < textList.size(); i++) {
Bitmap bitmap = ImageUtils.getSmallBitmap(imagePath, width, height);
String text = textList.get(i);
if (bitmap != null){
if (text.contains("<img")) {
et_new_content.addImageViewAtIndex(et_new_content.getLastIndex(), bitmap, imagePath);
String imagePath = StringUtils.getImgSrc(text);
} else {
int width = ScreenUtils.getScreenWidth(this);
et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);
int height = ScreenUtils.getScreenHeight(this);
et_new_content.measure(0,0);
Bitmap bitmap = ImageUtils.getSmallBitmap(imagePath, width, height);
if (bitmap != null){
et_new_content.addImageViewAtIndex(et_new_content.getLastIndex(), bitmap, imagePath);
} else {
et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);
}
et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);
}
}
et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);
}
}
}
}
}
```
### 具体的使用方式,请参考Demo代码。
### 具体的使用方式,请参考Demo代码。
## 感谢
## 感谢
...
@@ -99,3 +133,20 @@
...
@@ -99,3 +133,20 @@
-
CSDN:http://blog.csdn.net/shuyou612
-
CSDN:http://blog.csdn.net/shuyou612
-
GitHub:https://github.com/sendtion
-
GitHub:https://github.com/sendtion
-
欢迎大家fork、star,也欢迎大家参与修改。
-
欢迎大家fork、star,也欢迎大家参与修改。
## License
```
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment