|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
@ -30,19 +31,28 @@ import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.location.Address;
|
|
|
|
|
import android.location.Geocoder;
|
|
|
|
|
import android.location.Location;
|
|
|
|
|
import android.location.LocationListener;
|
|
|
|
|
import android.location.LocationManager;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.Spannable;
|
|
|
|
|
import android.text.SpannableString;
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
@ -68,17 +78,24 @@ import net.micode.notes.data.Notes.TextNote;
|
|
|
|
|
import net.micode.notes.model.WorkingNote;
|
|
|
|
|
import net.micode.notes.model.WorkingNote.NoteSettingChangedListener;
|
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
import net.micode.notes.tool.ImageUtils;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
|
|
|
|
|
import net.micode.notes.tool.ScreenUtils;
|
|
|
|
|
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
|
|
|
|
|
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.security.Timestamp;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -86,7 +103,7 @@ import java.util.Locale;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import android.support.v13.app.ActivityCompat;
|
|
|
|
|
|
|
|
|
|
public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
NoteSettingChangedListener, OnTextViewChangeListener {
|
|
|
|
@ -287,6 +304,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
initNoteScreen();
|
|
|
|
|
initImage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
@ -658,8 +676,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
case R.id.menu_delete_remind:
|
|
|
|
|
mWorkingNote.setAlertDate(0, false);
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_Insert_Image:
|
|
|
|
|
Intent albumIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
|
albumIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
|
|
|
|
|
startActivityForResult(albumIntent, 1);
|
|
|
|
|
break;
|
|
|
|
|
case R.id.menu_private_folder:
|
|
|
|
|
moveToPrivateFolder();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -1095,4 +1119,113 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {//处理从图库中返回的图片。
|
|
|
|
|
|
|
|
|
|
if (requestCode == 1) {//callGallery()方法是以请求码为1来开启活动的,此处为响应活动结束
|
|
|
|
|
try {
|
|
|
|
|
// 获得图片的资源标识符
|
|
|
|
|
Uri originalUri = data.getData();
|
|
|
|
|
String[] proj = {MediaStore.Images.Media.DATA};
|
|
|
|
|
//从数据库中查询
|
|
|
|
|
Cursor cursor = getContentResolver().query(originalUri, proj, null, null, null);
|
|
|
|
|
//获得用户选择的图片的索引值
|
|
|
|
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
|
|
|
|
// 将光标移至开头 ,这个很重要,不小心很容易引起越界
|
|
|
|
|
cursor.moveToFirst();
|
|
|
|
|
// 最后根据索引值获取图片路径
|
|
|
|
|
String path = cursor.getString(column_index);
|
|
|
|
|
//插入图片
|
|
|
|
|
insertImg(path);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "图片插入失败", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initImage() {
|
|
|
|
|
String input = String.valueOf(mWorkingNote.getContent());
|
|
|
|
|
if(!input.equals("null")) {//创建新便签时,input的值是“null”,必须判断,不然创建的新便签都会有一个null的字符串
|
|
|
|
|
Pattern p = Pattern.compile("\\<img src=\".*?\"\\/>");
|
|
|
|
|
Matcher m = p.matcher(input);
|
|
|
|
|
SpannableString spannable = new SpannableString(input);
|
|
|
|
|
while (m.find()) {
|
|
|
|
|
String s = m.group();
|
|
|
|
|
int start = m.start();
|
|
|
|
|
int end = m.end();
|
|
|
|
|
String path = s.replaceAll("\\<img src=\"|\"\\/>", "").trim();//得到路径
|
|
|
|
|
|
|
|
|
|
int width = ScreenUtils.getScreenWidth(NoteEditActivity.this);//屏幕的宽度
|
|
|
|
|
//int height = ScreenUtils.getScreenHeight(NoteEditActivity.this);
|
|
|
|
|
try {
|
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
|
|
|
|
|
//适应屏幕,锁定横纵比缩小图片。
|
|
|
|
|
bitmap = ImageUtils.zoomImage(bitmap, (width - 32) * 0.8,
|
|
|
|
|
bitmap.getHeight() / (bitmap.getWidth() / ((width - 32) * 0.8)));
|
|
|
|
|
ImageSpan imageSpan = new ImageSpan(NoteEditActivity.this, bitmap);
|
|
|
|
|
spannable.setSpan(imageSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mNoteEditor.setVisibility(View.VISIBLE);
|
|
|
|
|
mNoteEditor.setText(spannable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SpannableString getBitmapMime(String path, String tagPath) {
|
|
|
|
|
SpannableString ss = new SpannableString(tagPath);//这里使用加了<img>标签的图片路径
|
|
|
|
|
int width = ScreenUtils.getScreenWidth(NoteEditActivity.this);
|
|
|
|
|
//int height = ScreenUtils.getScreenHeight(NoteEditActivity.this);
|
|
|
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
|
|
|
//路径对应的图片
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
|
|
|
|
|
//适应屏幕,锁定横纵比缩小图片。
|
|
|
|
|
bitmap = ImageUtils.zoomImage(bitmap, (width - 32) * 0.8,
|
|
|
|
|
bitmap.getHeight() / (bitmap.getWidth() / ((width - 32) * 0.8)));
|
|
|
|
|
ImageSpan imageSpan = new ImageSpan(this, bitmap);
|
|
|
|
|
ss.setSpan(imageSpan, 0, tagPath.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
return ss;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertImg(String path) {
|
|
|
|
|
String tagPath = "<img src=\"" + path + "\"/>";//为图片路径加上<img>标签
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(path);//根据路径找到图片
|
|
|
|
|
if (bitmap != null) {
|
|
|
|
|
//格式化存储路径
|
|
|
|
|
SpannableString ss = getBitmapMime(path, tagPath);
|
|
|
|
|
//将图片插入文本视图
|
|
|
|
|
insertPhotoToEditText(ss);
|
|
|
|
|
Log.d("insertimage", path + "与" + tagPath);
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(NoteEditActivity.this, "插入失败,无读写存储权限,请到权限中心开启", Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertPhotoToEditText(SpannableString ss) {//把文本插入便签,如
|
|
|
|
|
Editable et = mNoteEditor.getText();
|
|
|
|
|
int start = mNoteEditor.getSelectionStart();
|
|
|
|
|
ss.getSpans(0, ss.length(), ImageSpan.class);
|
|
|
|
|
// 将图片添加进EditText中
|
|
|
|
|
if(start < 0 || start >= et.length()){
|
|
|
|
|
//如果是在文本的结尾
|
|
|
|
|
et.append(ss);
|
|
|
|
|
}else{
|
|
|
|
|
//如果是在文本的中间
|
|
|
|
|
et.insert(start, ss);
|
|
|
|
|
}
|
|
|
|
|
//将图片路径写入数据库——非常关键,否则无法显示图片
|
|
|
|
|
mWorkingNote.setWorkingText(et+"\n");
|
|
|
|
|
mNoteEditor.setText(et);
|
|
|
|
|
mNoteEditor.setSelection(start + ss.length());
|
|
|
|
|
mNoteEditor.setFocusableInTouchMode(true);
|
|
|
|
|
mNoteEditor.setFocusable(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|