|
|
|
@ -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);
|
|
|
|
|