Skip to content

Commit e6e9dd0

Browse files
committed
添加自定义属性,开放图片点击和删除接口
1 parent bd6da81 commit e6e9dd0

File tree

16 files changed

+197
-167
lines changed

16 files changed

+197
-167
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/sendtion/xrichtextdemo/MyApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ private void initCrashReport() {
4343
private void initEmailReporter() {
4444
EmailReporter email = new EmailReporter(this);
4545
email.setReceiver("[email protected]");//收件人
46-
email.setSender("xxxxx@163.com");//发送人邮箱
47-
email.setSendPassword("");//邮箱的客户端授权码,注意不是邮箱密码
46+
email.setSender("sendtion2018@163.com");//发送人邮箱
47+
email.setSendPassword("xrichtext2018");//邮箱的客户端授权码,注意不是邮箱密码
4848
email.setSMTPHost("smtp.163.com");//SMTP地址
4949
email.setPort("465");//SMTP 端口
5050
LogReport.getInstance().setUploadType(email);

app/src/main/java/com/sendtion/xrichtextdemo/ui/NewActivity.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.view.Menu;
1313
import android.view.MenuItem;
1414
import android.view.View;
15+
import android.view.inputmethod.InputMethodManager;
1516
import android.widget.EditText;
1617
import android.widget.TextView;
1718
import android.widget.Toast;
@@ -119,15 +120,28 @@ public void onClick(View view) {
119120
tv_new_time = (TextView) findViewById(R.id.tv_new_time);
120121
tv_new_group = (TextView) findViewById(R.id.tv_new_group);
121122

122-
et_new_content.setOnDeleteImageListener(new RichTextEditor.OnDeleteImageListener() {
123+
// 图片删除事件
124+
et_new_content.setOnRtImageDeleteListener(new RichTextEditor.OnRtImageDeleteListener() {
125+
123126
@Override
124-
public void onDeleteImage(String imagePath) {
127+
public void onRtImageDelete(String imagePath) {
125128
boolean isOK = SDCardUtil.deleteFile(imagePath);
126129
if (isOK){
127130
showToast("删除成功:"+imagePath);
128131
}
129132
}
130133
});
134+
// 图片点击事件
135+
et_new_content.setOnRtImageClickListener(new RichTextEditor.OnRtImageClickListener() {
136+
@Override
137+
public void onRtImageClick(String imagePath) {
138+
List<String> imageList = StringUtils.getTextFromHtml(myContent, true);
139+
int currentPosition = imageList.indexOf(imagePath);
140+
showToast("点击图片:"+currentPosition+":"+imagePath);
141+
}
142+
});
143+
144+
openSoftKeyInput();//打开软键盘显示
131145

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

171185
}
172186

187+
/**
188+
* 关闭软键盘
189+
*/
190+
private void closeSoftKeyInput(){
191+
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
192+
//boolean isOpen=imm.isActive();//isOpen若返回true,则表示输入法打开
193+
if (imm.isActive()){
194+
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
195+
InputMethodManager.HIDE_NOT_ALWAYS);
196+
//imm.hideSoftInputFromInputMethod();//据说无效
197+
//imm.hideSoftInputFromWindow(et_content.getWindowToken(), 0); //强制隐藏键盘
198+
//如果输入法在窗口上已经显示,则隐藏,反之则显示
199+
//imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
200+
}
201+
}
202+
203+
/**
204+
* 打开软键盘
205+
*/
206+
private void openSoftKeyInput(){
207+
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
208+
//boolean isOpen=imm.isActive();//isOpen若返回true,则表示输入法打开
209+
if (!imm.isActive()){
210+
et_new_content.requestFocus();
211+
//第二个参数可设置为0
212+
//imm.showSoftInput(et_content, InputMethodManager.SHOW_FORCED);//强制显示
213+
imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(),
214+
InputMethodManager.SHOW_FORCED);
215+
}
216+
}
217+
173218
/**
174219
* 异步方式显示数据
175220
* @param html
@@ -317,6 +362,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
317362
public boolean onOptionsItemSelected(MenuItem item) {
318363
switch (item.getItemId()){
319364
case R.id.action_insert_image:
365+
closeSoftKeyInput();//关闭软键盘
320366
callGallery();
321367
break;
322368
case R.id.action_new_save:

app/src/main/java/com/sendtion/xrichtextdemo/ui/NoteActivity.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import com.sendtion.xrichtextdemo.db.GroupDao;
2020
import com.sendtion.xrichtextdemo.db.NoteDao;
2121
import com.sendtion.xrichtextdemo.util.CommonUtil;
22-
import com.sendtion.xrichtextdemo.util.SDCardUtil;
2322
import com.sendtion.xrichtextdemo.util.StringUtils;
2423

25-
import java.io.File;
24+
import java.util.ArrayList;
2625
import java.util.List;
2726

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

99+
// 图片点击事件
100+
tv_note_content.setOnRtImageClickListener(new RichTextView.OnRtImageClickListener() {
101+
@Override
102+
public void onRtImageClick(String imagePath) {
103+
ArrayList<String> imageList = StringUtils.getTextFromHtml(myContent, true);
104+
int currentPosition = imageList.indexOf(imagePath);
105+
showToast("点击图片:"+currentPosition+":"+imagePath);
106+
107+
//点击图片预览
108+
// PhotoPreview.builder()
109+
// .setPhotos(imageList)
110+
// .setCurrentItem(currentPosition)
111+
// .setShowDeleteButton(false)
112+
// .start(NoteActivity.this);
113+
}
114+
});
115+
100116
Intent intent = getIntent();
101117
Bundle bundle = intent.getBundleExtra("data");
102118
note = (Note) bundle.getSerializable("note");

app/src/main/java/com/sendtion/xrichtextdemo/util/StringUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public static SpannableStringBuilder highlight(String text, String target) {
100100
* @param isGetImage true获取图片,false获取文本
101101
* @return
102102
*/
103-
public static List<String> getTextFromHtml(String html, boolean isGetImage){
104-
List<String> imageList = new ArrayList<>();
105-
List<String> textList = new ArrayList<>();
103+
public static ArrayList<String> getTextFromHtml(String html, boolean isGetImage){
104+
ArrayList<String> imageList = new ArrayList<>();
105+
ArrayList<String> textList = new ArrayList<>();
106106
//根据img标签分割出图片和字符串
107107
List<String> list = cutStringByImgTag(html);
108108
for (int i = 0; i < list.size(); i++) {

app/src/main/res/layout/content_new.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@
5151
android:layout_height="match_parent"
5252
app:rt_editor_image_height="500"
5353
app:rt_editor_image_bottom="10"
54-
app:rt_editor_show_border="false"
55-
app:rt_editor_image_border_width="5"
56-
app:rt_editor_image_border_color="@color/colorAccent"
5754
app:rt_editor_text_init_hint="在这里输入内容"
58-
app:rt_editor_text_size="20"
55+
app:rt_editor_text_size="16"
5956
app:rt_editor_text_color="@color/colorAccent"/>
6057

6158
</LinearLayout>

app/src/main/res/layout/content_note.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@
4848
android:id="@+id/tv_note_content"
4949
android:layout_width="match_parent"
5050
android:layout_height="match_parent"
51-
app:rt_view_image_height="500"
51+
app:rt_view_image_height="0"
5252
app:rt_view_image_bottom="10"
53-
app:rt_view_show_border="true"
54-
app:rt_view_image_border_width="5"
55-
app:rt_view_image_border_color="@color/colorAccent"
5653
app:rt_view_text_size="16"
5754
app:rt_view_text_color="@color/colorAccent"/>
5855

app/src/main/res/values-w820dp/dimens.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/src/main/res/values/dimens.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<resources>
23
<!-- Default screen margins, per the Android Design guidelines. -->
34
<dimen name="activity_horizontal_margin">16dp</dimen>
@@ -13,7 +14,5 @@
1314
<dimen name="text_size_18">18sp</dimen>
1415
<dimen name="text_size_20">20sp</dimen>
1516

16-
1717
<dimen name="grid_expected_size">120dp</dimen>
18-
19-
</resources>
18+
</resources>

xrichtext/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.sendtion.xrichtext">
33

4-
<application android:allowBackup="true" android:label="@string/app_name"
4+
<application
5+
android:allowBackup="true"
6+
android:label="@string/app_name"
57
android:supportsRtl="true">
68

79
</application>

0 commit comments

Comments
 (0)