Skip to content

Commit

Permalink
添加自定义属性,开放图片点击和删除接口
Browse files Browse the repository at this point in the history
  • Loading branch information
sendtion committed Jun 22, 2018
1 parent bd6da81 commit e6e9dd0
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.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 @@ -43,8 +43,8 @@ private void initCrashReport() {
private void initEmailReporter() {
EmailReporter email = new EmailReporter(this);
email.setReceiver("[email protected]");//收件人
email.setSender("xxxxx@163.com");//发送人邮箱
email.setSendPassword("");//邮箱的客户端授权码,注意不是邮箱密码
email.setSender("sendtion2018@163.com");//发送人邮箱
email.setSendPassword("xrichtext2018");//邮箱的客户端授权码,注意不是邮箱密码
email.setSMTPHost("smtp.163.com");//SMTP地址
email.setPort("465");//SMTP 端口
LogReport.getInstance().setUploadType(email);
Expand Down
50 changes: 48 additions & 2 deletions app/src/main/java/com/sendtion/xrichtextdemo/ui/NewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -119,15 +120,28 @@ public void onClick(View view) {
tv_new_time = (TextView) findViewById(R.id.tv_new_time);
tv_new_group = (TextView) findViewById(R.id.tv_new_group);

et_new_content.setOnDeleteImageListener(new RichTextEditor.OnDeleteImageListener() {
// 图片删除事件
et_new_content.setOnRtImageDeleteListener(new RichTextEditor.OnRtImageDeleteListener() {

@Override
public void onDeleteImage(String imagePath) {
public void onRtImageDelete(String imagePath) {
boolean isOK = SDCardUtil.deleteFile(imagePath);
if (isOK){
showToast("删除成功:"+imagePath);
}
}
});
// 图片点击事件
et_new_content.setOnRtImageClickListener(new RichTextEditor.OnRtImageClickListener() {
@Override
public void onRtImageClick(String imagePath) {
List<String> imageList = StringUtils.getTextFromHtml(myContent, true);
int currentPosition = imageList.indexOf(imagePath);
showToast("点击图片:"+currentPosition+":"+imagePath);
}
});

openSoftKeyInput();//打开软键盘显示

Intent intent = getIntent();
flag = intent.getIntExtra("flag", 0);//0新建,1编辑
Expand Down Expand Up @@ -170,6 +184,37 @@ public void run() {

}

/**
* 关闭软键盘
*/
private void closeSoftKeyInput(){
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
//boolean isOpen=imm.isActive();//isOpen若返回true,则表示输入法打开
if (imm.isActive()){
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
//imm.hideSoftInputFromInputMethod();//据说无效
//imm.hideSoftInputFromWindow(et_content.getWindowToken(), 0); //强制隐藏键盘
//如果输入法在窗口上已经显示,则隐藏,反之则显示
//imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}

/**
* 打开软键盘
*/
private void openSoftKeyInput(){
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
//boolean isOpen=imm.isActive();//isOpen若返回true,则表示输入法打开
if (!imm.isActive()){
et_new_content.requestFocus();
//第二个参数可设置为0
//imm.showSoftInput(et_content, InputMethodManager.SHOW_FORCED);//强制显示
imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(),
InputMethodManager.SHOW_FORCED);
}
}

/**
* 异步方式显示数据
* @param html
Expand Down Expand Up @@ -317,6 +362,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_insert_image:
closeSoftKeyInput();//关闭软键盘
callGallery();
break;
case R.id.action_new_save:
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/com/sendtion/xrichtextdemo/ui/NoteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import com.sendtion.xrichtextdemo.db.GroupDao;
import com.sendtion.xrichtextdemo.db.NoteDao;
import com.sendtion.xrichtextdemo.util.CommonUtil;
import com.sendtion.xrichtextdemo.util.SDCardUtil;
import com.sendtion.xrichtextdemo.util.StringUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import rx.Observable;
Expand Down Expand Up @@ -97,6 +96,23 @@ public void onClick(View view) {
tv_note_time = (TextView) findViewById(R.id.tv_note_time);
tv_note_group = (TextView) findViewById(R.id.tv_note_group);

// 图片点击事件
tv_note_content.setOnRtImageClickListener(new RichTextView.OnRtImageClickListener() {
@Override
public void onRtImageClick(String imagePath) {
ArrayList<String> imageList = StringUtils.getTextFromHtml(myContent, true);
int currentPosition = imageList.indexOf(imagePath);
showToast("点击图片:"+currentPosition+":"+imagePath);

//点击图片预览
// PhotoPreview.builder()
// .setPhotos(imageList)
// .setCurrentItem(currentPosition)
// .setShowDeleteButton(false)
// .start(NoteActivity.this);
}
});

Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("data");
note = (Note) bundle.getSerializable("note");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public static SpannableStringBuilder highlight(String text, String target) {
* @param isGetImage true获取图片,false获取文本
* @return
*/
public static List<String> getTextFromHtml(String html, boolean isGetImage){
List<String> imageList = new ArrayList<>();
List<String> textList = new ArrayList<>();
public static ArrayList<String> getTextFromHtml(String html, boolean isGetImage){
ArrayList<String> imageList = new ArrayList<>();
ArrayList<String> textList = new ArrayList<>();
//根据img标签分割出图片和字符串
List<String> list = cutStringByImgTag(html);
for (int i = 0; i < list.size(); i++) {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/res/layout/content_new.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@
android:layout_height="match_parent"
app:rt_editor_image_height="500"
app:rt_editor_image_bottom="10"
app:rt_editor_show_border="false"
app:rt_editor_image_border_width="5"
app:rt_editor_image_border_color="@color/colorAccent"
app:rt_editor_text_init_hint="在这里输入内容"
app:rt_editor_text_size="20"
app:rt_editor_text_size="16"
app:rt_editor_text_color="@color/colorAccent"/>

</LinearLayout>
5 changes: 1 addition & 4 deletions app/src/main/res/layout/content_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@
android:id="@+id/tv_note_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rt_view_image_height="500"
app:rt_view_image_height="0"
app:rt_view_image_bottom="10"
app:rt_view_show_border="true"
app:rt_view_image_border_width="5"
app:rt_view_image_border_color="@color/colorAccent"
app:rt_view_text_size="16"
app:rt_view_text_color="@color/colorAccent"/>

Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-w820dp/dimens.xml

This file was deleted.

5 changes: 2 additions & 3 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
Expand All @@ -13,7 +14,5 @@
<dimen name="text_size_18">18sp</dimen>
<dimen name="text_size_20">20sp</dimen>


<dimen name="grid_expected_size">120dp</dimen>

</resources>
</resources>
4 changes: 3 additions & 1 deletion xrichtext/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sendtion.xrichtext">

<application android:allowBackup="true" android:label="@string/app_name"
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
public class DataImageView extends ImageView {

private boolean showBorder = false; //是否显示边框
private int borderColor = getResources().getColor(R.color.grey_600);//边框颜色
private int borderWidth = 2;//边框大小
private int borderColor = Color.GRAY;//边框颜色
private int borderWidth = 5;//边框大小

private String absolutePath;
private Bitmap bitmap;
Expand Down Expand Up @@ -73,8 +73,9 @@ protected void onDraw(Canvas canvas) {
if (showBorder) {
//画边框
Rect rec = canvas.getClipBounds();
rec.bottom -= 2;
rec.right -= 2;
// 这两句可以使底部和右侧边框更大
//rec.bottom -= 2;
//rec.right -= 2;
//画笔
Paint paint = new Paint();
paint.setColor(borderColor);//设置颜色
Expand Down
Loading

0 comments on commit e6e9dd0

Please sign in to comment.