|
|
|
@ -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 {
|
|
|
|
@ -77,7 +82,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
|
|
|
|
|
|
|
|
|
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
|
|
|
|
//维护
|
|
|
|
|
|
|
|
|
|
//维护_丁梓坚_个性化背景
|
|
|
|
|
private static final int CHOOSE_PHOTO = 1;
|
|
|
|
|
|
|
|
|
|
private PreferenceCategory mAccountCategory;
|
|
|
|
@ -93,12 +99,6 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
|
|
//维护
|
|
|
|
|
//getWindow().setBackgroundDrawableResource(R.drawable.list_background);
|
|
|
|
|
//preference_textview
|
|
|
|
|
//RelativeLayout layout = (RelativeLayout)findViewById(R.id.preference_textview);
|
|
|
|
|
//setContentView(R.layout.activity_welcome);
|
|
|
|
|
|
|
|
|
|
/* using the app icon for navigation */
|
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
|
@ -180,16 +180,27 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
mAccountCategory.addPreference(accountPref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//维护 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//维护_丁梓坚_个性化背景_存储Bitmap
|
|
|
|
|
private Uri bitmap2uri(Bitmap b) {//c.getCacheDir()
|
|
|
|
|
File path = new File(getCacheDir() + "/123.jpeg");
|
|
|
|
|
try {
|
|
|
|
|
OutputStream os = new FileOutputStream(path);
|
|
|
|
|
b.compress(Bitmap.CompressFormat.JPEG, 100, os);
|
|
|
|
|
os.close();
|
|
|
|
|
return Uri.fromFile(path);
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//维护 !
|
|
|
|
|
//维护_丁梓坚_个性化背景_根据相册图片进入裁剪操作
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
|
|
|
|
{
|
|
|
|
@ -197,46 +208,37 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
if (requestCode == 1 && resultCode == Activity.RESULT_OK
|
|
|
|
|
&& data != null)
|
|
|
|
|
{
|
|
|
|
|
Uri selectedImage = data.getData();//返回的是uri
|
|
|
|
|
|
|
|
|
|
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
|
|
|
|
|
SharedPreferences.Editor editor=sharedPreferences.edit();
|
|
|
|
|
Uri selectedImage = data.getData();//返回的是uri
|
|
|
|
|
|
|
|
|
|
//if(!sharedPreferences.contains("PERSONAL_URI")) {
|
|
|
|
|
String [] filePathColumn = {MediaStore.Images.Media.DATA};
|
|
|
|
|
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
|
|
|
|
cursor.moveToFirst();
|
|
|
|
|
|
|
|
|
|
editor.putString("PERSONAL_URI",selectedImage.toString());
|
|
|
|
|
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
|
|
|
|
|
|
|
|
|
editor.putInt("DEFAULT",0);
|
|
|
|
|
|
|
|
|
|
editor.commit();
|
|
|
|
|
String path = cursor.getString(columnIndex);
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeFile(path);
|
|
|
|
|
|
|
|
|
|
//String [] filePathColumn = {MediaStore.Images.Media.DATA};
|
|
|
|
|
//Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
|
|
|
|
//cursor.moveToFirst();
|
|
|
|
|
bitmap2uri(bitmap);
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//维护
|
|
|
|
|
private String[] items2={"本地图片","还原","拍照"};
|
|
|
|
|
//维护_丁梓坚_个性化背景_选择栏
|
|
|
|
|
private String[] items2={"本地图片","还原"};
|
|
|
|
|
|
|
|
|
|
//维护 2
|
|
|
|
|
//维护_丁梓坚_个性化背景_选择栏
|
|
|
|
|
public void chooseBackground() {
|
|
|
|
|
/*
|
|
|
|
|
AlertDialog dialog;
|
|
|
|
@ -248,8 +250,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 +259,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();
|
|
|
|
|
|
|
|
|
@ -284,7 +272,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//维护 3
|
|
|
|
|
//维护_丁梓坚_个性化背景_监听选择
|
|
|
|
|
class backgroundListener implements DialogInterface.OnClickListener{
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -292,31 +280,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);
|
|
|
|
@ -327,13 +294,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//维护 1
|
|
|
|
|
//维护_丁梓坚_个性化背景_加载监听选择
|
|
|
|
|
private void loadBackgroundPreference() {
|
|
|
|
|
//mAccountCategory.removeAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Preference background = new Preference(this);
|
|
|
|
|
//final String defaultAccount = getSyncAccountName(this);
|
|
|
|
|
|
|
|
|
|
background.setTitle("Set Background");
|
|
|
|
|
background.setSummary("Reset menu background you like");
|
|
|
|
|
|
|
|
|
@ -341,17 +307,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
|
|
//@Override
|
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
|
//if (ContextCompat.checkSelfPermission(NotesPreferenceActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
// ActivityCompat.requestPermissions(NotesPreferenceActivity.this, new String[]{Manifest.permission.WRITE_APN_SETTINGS}, 1);
|
|
|
|
|
//} else {
|
|
|
|
|
// NotesPreferenceActivity.this.openAlbum();
|
|
|
|
|
//}
|
|
|
|
|
chooseBackground();
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -400,7 +359,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
private void refreshUI() {
|
|
|
|
|
loadAccountPreference();
|
|
|
|
|
loadSyncButton();
|
|
|
|
|
//维护
|
|
|
|
|
//维护_丁梓坚_个性化背景
|
|
|
|
|
loadBackgroundPreference();
|
|
|
|
|
}
|
|
|
|
|
|