|
|
@ -27,14 +27,18 @@ import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.Menu;
|
|
|
@ -880,4 +884,45 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
private void showToast(int resId, int duration) {
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
Toast.makeText(this, resId, duration).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//路径字符串格式 转换为 图片image格式
|
|
|
|
|
|
|
|
private void convertToImage() {
|
|
|
|
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
|
|
|
|
|
int length = editable.length(); //内容的长度
|
|
|
|
|
|
|
|
//3.截取img片段 [local]+uri+[local],提取uri
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++) {
|
|
|
|
|
|
|
|
for(int j = i; j < length; j++) {
|
|
|
|
|
|
|
|
String img_fragment = noteText.substring(i, j+1); //img_fragment:关于图片路径的片段
|
|
|
|
|
|
|
|
if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")){
|
|
|
|
|
|
|
|
int limit = 7; //[local]为7个字符
|
|
|
|
|
|
|
|
//[local][/local]共15个字符,剩下的为真正的path长度
|
|
|
|
|
|
|
|
int len = img_fragment.length()-15;
|
|
|
|
|
|
|
|
//从[local]之后的len个字符就是path
|
|
|
|
|
|
|
|
String path = img_fragment.substring(limit,limit+len);//获取到了图片路径
|
|
|
|
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
|
|
|
|
Log.d(TAG, "图片的路径是:"+path);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bitmap = BitmapFactory.decodeFile(path);//将图片路径解码为图片格式
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bitmap!=null){ //若图片存在
|
|
|
|
|
|
|
|
Log.d(TAG, "图片不为null");
|
|
|
|
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
|
|
|
|
//4.创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
|
|
|
|
|
|
|
|
String ss = "[local]" + path + "[/local]";
|
|
|
|
|
|
|
|
SpannableString spannableString = new SpannableString(ss);
|
|
|
|
|
|
|
|
//5.将指定的标记对象附加到文本的开始...结束范围
|
|
|
|
|
|
|
|
spannableString.setSpan(imageSpan, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
Log.d(TAG, "Create spannable string success!");
|
|
|
|
|
|
|
|
Editable edit_text = noteEditText.getEditableText();
|
|
|
|
|
|
|
|
edit_text.delete(i,i+len+15); //6.删掉图片路径的文字
|
|
|
|
|
|
|
|
edit_text.insert(i, spannableString); //7.在路径的起始位置插入图片
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|