增加个性化背景,朗读,欢迎界面的功能

pull/2/head
Dingzijian 3 years ago
parent 6e70afeb19
commit 8f87ae54e0

@ -133,6 +133,16 @@
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.NoteEditActivity" />
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<activity
android:name=".ui.UCropPictureActivity"
android:label="@string/preferences_title"
android:launchMode="singleTop"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"></activity>
</application>
</manifest>

@ -30,7 +30,7 @@ import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
//import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@ -53,10 +53,12 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
//维护 添加read
import android.support.v7.app.AppCompatActivity;
//import android.support.v7.app.AppCompatActivity;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import androidx.appcompat.app.AppCompatActivity;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote;
@ -460,7 +462,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE);
View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE);

@ -39,6 +39,8 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileUtils;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.Editable;
@ -71,7 +73,9 @@ import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v7.app.AppCompatActivity;
//import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
@ -86,6 +90,8 @@ 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.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -177,6 +183,36 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
setAppInfoFromRawRes();
}
//维护
static void saveBitmap(String name, Bitmap bm, Context mContext) {
Log.d("Save Bitmap", "Ready to save picture");
//指定我们想要存储文件的地址
String TargetPath = mContext.getFilesDir() + "/images/";
Log.d("Save Bitmap", "Save Path=" + TargetPath);
//判断指定文件夹的路径是否存在
//if (!FileUtils.fileIsExist(TargetPath)) {
//Log.d("Save Bitmap", "TargetPath isn't exist");
// } else {
//如果指定文件夹创建成功,那么我们则需要进行图片存储操作
File saveFile = new File(TargetPath, name);
try {
FileOutputStream saveImgOut = new FileOutputStream(saveFile);
// compress - 压缩的意思
bm.compress(Bitmap.CompressFormat.JPEG, 80, saveImgOut);
//存储完成后需要清除相关的进程
saveImgOut.flush();
saveImgOut.close();
Log.d("Save Bitmap", "The picture is save to your phone!");
} catch (IOException ex) {
ex.printStackTrace();
}
}
//维护
//维护
@Override
protected void onResume() {
@ -188,27 +224,16 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
else{
Uri selectedImage= Uri.parse(sharedPreferences.getString("PERSONAL_URI",null));
String [] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//Toast.makeText(this, selectedImage.toString(), Toast.LENGTH_SHORT).show();
String path = cursor.getString(columnIndex);
Bitmap bitmap = BitmapFactory.decodeFile(selectedImage.toString());
//确实在这里有错
//if(path==null)
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
Bitmap bitmap = BitmapFactory.decodeFile(path);
//RelativeLayout layout1 = (RelativeLayout)findViewById(R.id.preference_textview);
//Toast.makeText(this, URi, Toast.LENGTH_SHORT).show();
Drawable drawable =new BitmapDrawable(bitmap);
//layout1.setBackground(drawable);
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
getWindow().setBackgroundDrawable(drawable);
Bitmap bitmap0 = BitmapFactory.decodeFile(selectedImage.toString());
//Toast.makeText(this, URi, Toast.LENGTH_SHORT).show();
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
}
}

@ -16,14 +16,10 @@
package net.micode.notes.ui;
import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Notification;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
@ -31,38 +27,47 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
//import android.support.v4.app.ActivityCompat;
//import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.yalantis.ucrop.UCropActivity;
//import com.bumptech.glide.Glide;
import androidx.core.app.ActivityCompat;
import com.yalantis.ucrop.UCrop;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
import net.micode.notes.ui.NotesListActivity;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class NotesPreferenceActivity extends PreferenceActivity {
@ -182,12 +187,68 @@ public class NotesPreferenceActivity extends PreferenceActivity {
//维护 4
private void openAlbum() {
//Intent intent = new Intent("android.intent.action.GET_CONTENT");
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, CHOOSE_PHOTO);
}
//维护
public static String FileSaveToInside(Context context, String fileName, Bitmap bitmap) {
FileOutputStream fos = null;
String path = null;
try {
//设置路径 /Android/data/com.panyko.filesave/Pictures/
File folder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
//判断目录是否存在
//目录不存在时自动创建
if (folder.exists() ||folder.mkdir()) {
File file = new File(folder, fileName);
fos = new FileOutputStream(file);
//写入文件
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
path = file.getAbsolutePath();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
//关闭流
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
//返回路径
return path;
}
//维护
private Uri bitmap2uri(Bitmap b) {//c.getCacheDir()
File path = new File(getCacheDir() + "/123.jpeg");
//L.e("getAbsolutePath==="+path.getAbsolutePath()+" ===getAbsolutePath==="+path.getParent());
Toast.makeText(this, path.toString(), Toast.LENGTH_SHORT).show();
try {
OutputStream os = new FileOutputStream(path);
b.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.close();
return Uri.fromFile(path);
} catch (Exception ignored) {
}
return null;
}
//维护
////_______////////
//Uri转Bitmap,并复制bitmap
//Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
//bmcopy = bitmap.copy(Bitmap.Config.ARGB_8888, true);
/////_______///////
//维护 !
@Override
@ -197,36 +258,43 @@ public class NotesPreferenceActivity extends PreferenceActivity {
if (requestCode == 1 && resultCode == Activity.RESULT_OK
&& data != null)
{
Uri selectedImage = data.getData();//返回的是uri
String [] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String path = cursor.getString(columnIndex);
Bitmap bitmap = BitmapFactory.decodeFile(path);
bitmap2uri(bitmap);
/*
String save_uri=FileSaveToInside(this,"123",bitmap);
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
SharedPreferences.Editor editor=sharedPreferences.edit();
//if(!sharedPreferences.contains("PERSONAL_URI")) {
editor.putString("PERSONAL_URI",selectedImage.toString());
editor.putString("PERSONAL_URI",save_uri);
editor.putInt("DEFAULT",0);
editor.commit();
//}
//String [] filePathColumn = {MediaStore.Images.Media.DATA};
//Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
//cursor.moveToFirst();
*/
//int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//String path = cursor.getString(columnIndex);
Intent intent = new Intent(NotesPreferenceActivity.this, UCropPictureActivity.class);
//Bitmap bitmap = BitmapFactory.decodeFile(path);
//RelativeLayout layout1 = (RelativeLayout)findViewById(R.id.preference_textview);
this.startActivityForResult(intent, 12);
//Drawable drawable =new BitmapDrawable(bitmap);
//layout1.setBackground(drawable);
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
//getWindow().setBackgroundDrawable(drawable);
finish();
}
}
@ -234,7 +302,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
//维护
private String[] items2={"本地图片","还原","拍照"};
private String[] items2={"本地图片","还原"};
//维护 2
public void chooseBackground() {
@ -248,8 +316,6 @@ public class NotesPreferenceActivity extends PreferenceActivity {
.create(); //创建对话框
dialog.show(); //显示对话框
*/
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("选择方式");
//builder.setIcon(R.drawable.ic_launcher);
@ -259,22 +325,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
private void displayImage(String imagePath) {
if (imagePath != null) {
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
Drawable tupian = new BitmapDrawable(bitmap);
} else {
Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
}
}
//维护4.2
private void returnToMenu() {
//EDIT_BACKGROUND = 1;
//Intent intent = new Intent(this, NotesListActivity.class);
//startActivity(intent);
//NotesPreferenceActivity.this.finish();
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
SharedPreferences.Editor editor=sharedPreferences.edit();
@ -292,31 +346,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
switch (which){
case 0://本地图片
//Toast.makeText(NotesPreferenceActivity.this,"2232",Toast.LENGTH_SHORT).show();
openAlbum();
break;
case 1://还原
//int imgID = getResources().getIdentifier("list_background", "drawable",
// "netcode.notes");
//if (imgID != 0) {
// Drawable drawable = getResources().getDrawable(imgID);
// View temp = findViewById(R.id.notification_background);
// temp.setBackgroundDrawable(drawable);
//}
//else{
// Toast.makeText(NotesPreferenceActivity.this,"2232",Toast.LENGTH_SHORT).show();
//}
//FrameLayout rootLayout=(FrameLayout)findViewById(R.id.notification_background);
//if(rootLayout==null)
// Toast.makeText(NotesPreferenceActivity.this,"2232",Toast.LENGTH_SHORT).show();
//else
// rootLayout.setBackgroundResource(R.id.notification_background);
returnToMenu();
break;
default:
throw new IllegalStateException("Unexpected value: " + which);

@ -0,0 +1,274 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.icu.util.Calendar;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.yalantis.ucrop.UCrop;
import net.micode.notes.R;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class UCropPictureActivity extends AppCompatActivity {
Button btnTest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTest = (Button) findViewById(R.id.btn_test);
/*
btnTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startCrop();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});*/
try {
startCrop();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
finish();
}
//维护
public static String FileSaveToInside(Context context, String fileName, Bitmap bitmap) {
FileOutputStream fos = null;
String path = null;
try {
//设置路径 /Android/data/com.panyko.filesave/Pictures/
File folder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
//判断目录是否存在
//目录不存在时自动创建
if (folder.exists() ||folder.mkdir()) {
File file = new File(folder, fileName);
fos = new FileOutputStream(file);
//写入文件
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
path = file.getAbsolutePath();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
//关闭流
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
//返回路径
return path;
}
private void startCrop() throws FileNotFoundException {
//Uri sourceUri = Uri.parse("http://star.xiziwang.net/uploads/allimg/140512/19_140512150412_1.jpg");
//裁剪后保存到文件中
Uri sourceUri = Uri.fromFile(new File(getCacheDir(), "123.jpeg"));
//Toast.makeText(this, sourceUri.toString(), Toast.LENGTH_SHORT).show();
Uri destinationUri = Uri.fromFile(new File(getCacheDir(), "SampleCropImage.jpeg"));
UCrop.of(sourceUri, destinationUri).withAspectRatio(9, 16).withMaxResultSize(2000, 2500).start(this);
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(destinationUri));
//bmcopy = bitmap.copy(Bitmap.Config.ARGB_8888, true);
String save=FileSaveToInside(this,"1234",bitmap);
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
SharedPreferences.Editor editor=sharedPreferences.edit();
//if(!sharedPreferences.contains("PERSONAL_URI")) {
editor.putString("PERSONAL_URI",save);
editor.putInt("DEFAULT",0);
editor.commit();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
//裁切成功
if (requestCode == UCrop.REQUEST_CROP) {
Uri croppedFileUri = UCrop.getOutput(data);
//获取默认的下载目录
String downloadsDirectoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
@SuppressLint({"NewApi", "LocalSuppress"}) String filename = String.format("%d_%s", Calendar.getInstance().getTimeInMillis(), croppedFileUri.getLastPathSegment());
File saveFile = new File(downloadsDirectoryPath, filename);
//保存下载的图片
FileInputStream inStream = null;
FileOutputStream outStream = null;
FileChannel inChannel = null;
FileChannel outChannel = null;
try {
inStream = new FileInputStream(new File(croppedFileUri.getPath()));
outStream = new FileOutputStream(saveFile);
inChannel = inStream.getChannel();
outChannel = outStream.getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
Toast.makeText(this, "裁切后的图片保存在:" + saveFile.getAbsolutePath(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
outChannel.close();
outStream.close();
inChannel.close();
inStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//裁切失败
if (resultCode == UCrop.RESULT_ERROR) {
Toast.makeText(this, "裁切图片失败", Toast.LENGTH_SHORT).show();
}
}
// 专为Android4.4设计的从Uri获取文件绝对路径以前的方法已不好使
@SuppressLint("NewApi")
public static String getPathByUri4kitkat(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
if (isExternalStorageDocument(uri)) {// ExternalStorageProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else if (isDownloadsDocument(uri)) {// DownloadsProvider
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(id));
return getDataColumn(context, contentUri, null, null);
} else if (isMediaDocument(uri)) {// MediaProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] { split[1] };
return getDataColumn(context, contentUri, selection, selectionArgs);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {// MediaStore
// (and
// general)
return getDataColumn(context, uri, null, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {// File
return uri.getPath();
}
return null;
}
/**
* Get the value of the data column for this Uri. This is useful for
* MediaStore Uris, and other file-based ContentProviders.
*
* @param context
* The context.
* @param uri
* The Uri to query.
* @param selection
* (Optional) Filter used in the query.
* @param selectionArgs
* (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = { column };
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
/**
* @param uri
* The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri
* The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri
* The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/picture">
</LinearLayout>

@ -18,6 +18,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preference_textview">
<PreferenceCategory
android:key="pref_sync_account_key">
</PreferenceCategory>

Loading…
Cancel
Save