Skip to content

Commit

Permalink
加入使用说明,代码示例
Browse files Browse the repository at this point in the history
  • Loading branch information
sendtion authored Oct 26, 2016
1 parent bb46fc6 commit 4d36e3d
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,82 @@
![笔记详情](http://img.blog.csdn.net/20161026140122507)

## 使用方式
### 作为类库
1. 作为类库
把xrichtext作为一个module导入你的工程。
把xrichtext中的文件拷贝到你的工程,可以在你的工程中建一个xrichtextming包名,并把文件拷贝进去。

### gradle依赖
2. gradle依赖
稍后支持。

## 具体使用
在xml布局中添加基于EditText编辑器(可编辑)

<com.sendtion.xrichtext.RichTextEditor
android:id="@+id/et_new_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/>

在xml布局中添加基于TextView编辑器(不可编辑)

<com.sendtion.xrichtext.RichTextView
android:id="@+id/tv_note_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/>

**我把数据保存为了html格式,生成字符串存储到了数据库。**
### 生成数据

String noteContent = getEditData();

private String getEditData() {
List<RichTextEditor.EditData> editList = et_new_content.buildEditData();
StringBuffer content = new StringBuffer();
for (RichTextEditor.EditData itemData : editList) {
if (itemData.inputStr != null) {
content.append(itemData.inputStr);
} else if (itemData.imagePath != null) {
content.append("<img src=\"").append(itemData.imagePath).append("\"/>");
}
}
return content.toString();
}

### 显示数据

et_new_content.post(new Runnable() {
@Override
public void run() {
showEditData(content);
}
});
protected void showEditData(String content) {
et_new_content.clearAllLayout();
List<String> textList = StringUtils.cutStringByImgTag(content);
for (int i = 0; i < textList.size(); i++) {
String text = textList.get(i);
if (text.contains("<img")) {
String imagePath = StringUtils.getImgSrc(text);
int width = ScreenUtils.getScreenWidth(this);
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);
}
}
}

### 具体的使用方式,请参考Demo代码。

## 感谢
本库在前人的基础上进行修改,感谢各位大神的辛苦劳作!
参考了以下项目:
Expand Down

0 comments on commit 4d36e3d

Please sign in to comment.