|
|
@ -167,7 +167,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
private String mUserQuery;
|
|
|
|
private String mUserQuery;
|
|
|
|
private Pattern mPattern;
|
|
|
|
private Pattern mPattern;
|
|
|
|
|
|
|
|
|
|
|
|
private final int PHOTO_REQUEST = 1;//请求码
|
|
|
|
private final int PHOTO_REQUEST = 1;//霂瑟<EFBFBD><EFBFBD>?
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@ -188,9 +188,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
public void onClick(View view) {
|
|
|
|
Log.d(TAG, "onClick: click add image button");
|
|
|
|
Log.d(TAG, "onClick: click add image button");
|
|
|
|
//ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
|
|
|
|
//ACTION_GET_CONTENT: <EFBFBD><EFBFBD>捂<EFBFBD>冽<EFBFBD><EFBFBD>㗇𥋘<EFBFBD>寞<EFBFBD>蝘滨掩<EFBFBD><EFBFBD>㺭<EFBFBD>殷<EFBFBD>撟嗉<EFBFBD><EFBFBD>痹<EFBFBD><EFBFBD>寞<EFBFBD>蝘滨掩<EFBFBD><EFBFBD>㺭<EFBFBD>殷<EFBFBD><EFBFBD>找<EFBFBD>撘删㮾<EFBFBD><EFBFBD><EFBFBD>敶蓥<EFBFBD>畾菟𨺗嚗?
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
//Category属性用于指定当前动作(Action)被执行的环境.
|
|
|
|
//Category撅墧<EFBFBD>抒鍂鈭擧<EFBFBD>摰𡁜<EFBFBD><EFBFBD>滚𢆡雿頣<EFBFBD>Action嚗㕑◤<EFBFBD>扯<EFBFBD><EFBFBD><EFBFBD>㴓憓?
|
|
|
|
//CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent
|
|
|
|
//CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent
|
|
|
|
loadImage.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
loadImage.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
loadImage.setType("image/*");
|
|
|
|
loadImage.setType("image/*");
|
|
|
@ -300,7 +300,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onResume() {//能获得用户焦点:可以操作
|
|
|
|
protected void onResume() {//能获得用户焦点:可以操作
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
initNoteScreen();//初始化便签屏幕
|
|
|
|
initNoteScreen();//<EFBFBD>嘥<EFBFBD><EFBFBD>碶噶蝑曉<EFBFBD>撟?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
private void initNoteScreen() {
|
|
|
@ -487,40 +487,40 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//路径字符串格式 转换为 图片image格式
|
|
|
|
//頝臬<EFBFBD>摮㛖泵銝脫聢撘?頧祆揢銝?<3F>曄<EFBFBD>image<67>澆<EFBFBD>
|
|
|
|
private void convertToImage() {
|
|
|
|
private void convertToImage() {
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
Editable editable = noteEditText.getText();//1.获取text
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
|
String noteText = editable.toString(); //2.将note内容转换为字符串
|
|
|
|
int length = editable.length(); //内容的长度
|
|
|
|
int length = editable.length(); //<EFBFBD><EFBFBD>捆<EFBFBD><EFBFBD>鵭摨?
|
|
|
|
//3.截取img片段 [local]+uri+[local],提取uri
|
|
|
|
//3.截取img片段 [local]+uri+[local],提取uri
|
|
|
|
for(int i = 0; i < length; i++) {
|
|
|
|
for(int i = 0; i < length; i++) {
|
|
|
|
for(int j = i; j < length; j++) {
|
|
|
|
for(int j = i; j < length; j++) {
|
|
|
|
String img_fragment = noteText.substring(i, j+1); //img_fragment:关于图片路径的片段
|
|
|
|
String img_fragment = noteText.substring(i, j+1); //img_fragment:关于图片路径的片段
|
|
|
|
if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")){
|
|
|
|
if(img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")){
|
|
|
|
int limit = 7; //[local]为7个字符
|
|
|
|
int limit = 7; //[local]銝?銝芸<E98A9D>蝚?
|
|
|
|
//[local][/local]共15个字符,剩下的为真正的path长度
|
|
|
|
//[local][/local]<EFBFBD>?5銝芸<E98A9D>蝚佗<E89D9A><E4BD97>拐<EFBFBD><E68B90><EFBFBD>蛹<EFBFBD><E89BB9>迤<EFBFBD><E8BFA4>ath<74>踹漲
|
|
|
|
int len = img_fragment.length()-15;
|
|
|
|
int len = img_fragment.length()-15;
|
|
|
|
//从[local]之后的len个字符就是path
|
|
|
|
//从[local]之后的len个字符就是path
|
|
|
|
String path = img_fragment.substring(limit,limit+len);//获取到了图片路径
|
|
|
|
String path = img_fragment.substring(limit,limit+len);//获取到了图片路径
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
Log.d(TAG, "图片的路径是:"+path);
|
|
|
|
Log.d(TAG, "<EFBFBD>曄<EFBFBD><EFBFBD><EFBFBD>楝敺<EFBFBD>糓嚗?+path);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bitmap = BitmapFactory.decodeFile(path);//将图片路径解码为图片格式
|
|
|
|
bitmap = BitmapFactory.decodeFile(path);//将图片路径解码为图片格式
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(bitmap!=null){ //若图片存在
|
|
|
|
if(bitmap!=null){ //<EFBFBD>亙㦛<EFBFBD><EFBFBD><EFBFBD><EFBFBD>?
|
|
|
|
Log.d(TAG, "图片不为null");
|
|
|
|
Log.d(TAG, "图片不为null");
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
//4.创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
|
|
|
|
//4.<EFBFBD>𥕦遣銝<EFBFBD>銝杵pannableString撖寡情嚗䔶誑靘踵<EFBFBD><EFBFBD>亦鍂ImageSpan撖寡情撠<EFBFBD><EFBFBD><EFBFBD><EFBFBD>㦛<EFBFBD>?
|
|
|
|
String ss = "[local]" + path + "[/local]";
|
|
|
|
String ss = "[local]" + path + "[/local]";
|
|
|
|
SpannableString spannableString = new SpannableString(ss);
|
|
|
|
SpannableString spannableString = new SpannableString(ss);
|
|
|
|
//5.将指定的标记对象附加到文本的开始...结束范围
|
|
|
|
//5.撠<EFBFBD><EFBFBD>摰𡁶<EFBFBD><EFBFBD><EFBFBD>扇撖寡情<EFBFBD><EFBFBD><EFBFBD><EFBFBD>唳<EFBFBD><EFBFBD>祉<EFBFBD>撘<EFBFBD>憪?..蝏𤘪<E89D8F><F0A498AA><EFBFBD>凒
|
|
|
|
spannableString.setSpan(imageSpan, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
spannableString.setSpan(imageSpan, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
Log.d(TAG, "Create spannable string success!");
|
|
|
|
Log.d(TAG, "Create spannable string success!");
|
|
|
|
Editable edit_text = noteEditText.getEditableText();
|
|
|
|
Editable edit_text = noteEditText.getEditableText();
|
|
|
|
edit_text.delete(i,i+len+15); //6.删掉图片路径的文字
|
|
|
|
edit_text.delete(i,i+len+15); //6.<EFBFBD>䭾<EFBFBD><EFBFBD>曄<EFBFBD>頝臬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>摮?
|
|
|
|
edit_text.insert(i, spannableString); //7.在路径的起始位置插入图片
|
|
|
|
edit_text.insert(i, spannableString); //7.在路径的起始位置插入图片
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -980,7 +980,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mEditTextList.setVisibility(View.GONE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
convertToImage(); //退出清单模式,应该将有图片的地方显示出来
|
|
|
|
convertToImage(); //<EFBFBD><EFBFBD><EFBFBD>箸<EFBFBD><EFBFBD>閙芋撘𧶏<EFBFBD>摨磰砲撠<EFBFBD><EFBFBD><EFBFBD>曄<EFBFBD><EFBFBD><EFBFBD>𧑐<EFBFBD>寞遬蝷箏枂<EFBFBD>?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1080,7 +1080,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
ContentResolver resolver = getContentResolver();
|
|
|
|
switch (requestCode) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case PHOTO_REQUEST:
|
|
|
|
case PHOTO_REQUEST:
|
|
|
|
Uri originalUri = intent.getData(); //1.获得图片的真实路径
|
|
|
|
Uri originalUri = intent.getData(); //1.<EFBFBD>瑕<EFBFBD><EFBFBD>曄<EFBFBD><EFBFBD><EFBFBD><EFBFBD>摰噼楝敺?
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bitmap = BitmapFactory.decodeStream(resolver.openInputStream(originalUri));//2.解码图片
|
|
|
|
bitmap = BitmapFactory.decodeStream(resolver.openInputStream(originalUri));//2.解码图片
|
|
|
@ -1096,15 +1096,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
String path = getPath(this,originalUri);
|
|
|
|
String path = getPath(this,originalUri);
|
|
|
|
//4.使用[local][/local]将path括起来,用于之后方便识别图片路径在note中的位置
|
|
|
|
//4.使用[local][/local]将path括起来,用于之后方便识别图片路径在note中的位置
|
|
|
|
String img_fragment= "[local]" + path + "[/local]";
|
|
|
|
String img_fragment= "[local]" + path + "[/local]";
|
|
|
|
//创建一个SpannableString对象,以便插入用ImageSpan对象封装的图像
|
|
|
|
//<EFBFBD>𥕦遣銝<EFBFBD>銝杵pannableString撖寡情嚗䔶誑靘踵<EFBFBD><EFBFBD>亦鍂ImageSpan撖寡情撠<EFBFBD><EFBFBD><EFBFBD><EFBFBD>㦛<EFBFBD>?
|
|
|
|
SpannableString spannableString = new SpannableString(img_fragment);
|
|
|
|
SpannableString spannableString = new SpannableString(img_fragment);
|
|
|
|
spannableString.setSpan(imageSpan, 0, img_fragment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
spannableString.setSpan(imageSpan, 0, img_fragment.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
//5.将选择的图片追加到EditText中光标所在位置
|
|
|
|
//5.撠<EFBFBD><EFBFBD>㗇𥋘<EFBFBD><EFBFBD>㦛<EFBFBD><EFBFBD>蕭<EFBFBD>惩<EFBFBD>EditText銝剖<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>其<EFBFBD>蝵?
|
|
|
|
NoteEditText e = (NoteEditText) findViewById(R.id.note_edit_view);
|
|
|
|
NoteEditText e = (NoteEditText) findViewById(R.id.note_edit_view);
|
|
|
|
int index = e.getSelectionStart(); //获取光标所在位置
|
|
|
|
int index = e.getSelectionStart(); //<EFBFBD>瑕<EFBFBD><EFBFBD>㗇<EFBFBD><EFBFBD><EFBFBD><EFBFBD>其<EFBFBD>蝵?
|
|
|
|
Log.d(TAG, "Index是: " + index);
|
|
|
|
Log.d(TAG, "Index<EFBFBD>? " + index);
|
|
|
|
Editable edit_text = e.getEditableText();
|
|
|
|
Editable edit_text = e.getEditableText();
|
|
|
|
edit_text.insert(index, spannableString); //将图片插入到光标所在位置
|
|
|
|
edit_text.insert(index, spannableString); //撠<EFBFBD>㦛<EFBFBD><EFBFBD><EFBFBD><EFBFBD>亙<EFBFBD><EFBFBD>㗇<EFBFBD><EFBFBD><EFBFBD><EFBFBD>其<EFBFBD>蝵?
|
|
|
|
|
|
|
|
|
|
|
|
mWorkingNote.mContent = e.getText().toString();
|
|
|
|
mWorkingNote.mContent = e.getText().toString();
|
|
|
|
//6.把改动提交到数据库中,两个数据库表都要改的
|
|
|
|
//6.把改动提交到数据库中,两个数据库表都要改的
|
|
|
@ -1180,7 +1180,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取数据列_获取此 Uri 的数据列的值。这对MediaStore Uris 和其他基于文件的 ContentProvider。
|
|
|
|
//<EFBFBD>瑕<EFBFBD><EFBFBD>唳旿<EFBFBD>𨭣<EFBFBD>瑕<EFBFBD>甇?Uri <20><>㺭<EFBFBD>桀<EFBFBD><E6A180><EFBFBD><EFBFBD>潦<EFBFBD><E6BDA6><EFBFBD>撖遍ediaStore Uris <20><><EFBFBD>隞硋抅鈭擧<E988AD>隞嗥<E99A9E> ContentProvider<65>?
|
|
|
|
public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
public String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
Cursor cursor = null;
|
|
|
@ -1201,17 +1201,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//是否为外部存储文件
|
|
|
|
//<EFBFBD>臬炏銝箏<EFBFBD><EFBFBD>典<EFBFBD><EFBFBD>冽<EFBFBD>隞?
|
|
|
|
// public boolean isExternalStorageDocument(Uri uri) {
|
|
|
|
// public boolean isExternalStorageDocument(Uri uri) {
|
|
|
|
// return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
|
|
// return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// //是否为下载文件
|
|
|
|
// //<EFBFBD>臬炏銝箔<EFBFBD>頧賣<EFBFBD>隞?
|
|
|
|
// public boolean isDownloadsDocument(Uri uri) {
|
|
|
|
// public boolean isDownloadsDocument(Uri uri) {
|
|
|
|
// return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
|
|
// return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//是否为媒体文件
|
|
|
|
//<EFBFBD>臬炏銝箏<EFBFBD>雿𤘪<EFBFBD>隞?
|
|
|
|
public boolean isMediaDocument(Uri uri) {
|
|
|
|
public boolean isMediaDocument(Uri uri) {
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
}
|
|
|
|