Compare commits

..

1 Commits

Author SHA1 Message Date
王京 69cec30622 字符串统计
3 years ago

@ -1 +1,2 @@
# 小米便签项目维护

@ -133,16 +133,6 @@
<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>

@ -1,272 +0,0 @@
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"));
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));
String save=FileSaveToInside(this,"1234",bitmap);
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("PERSONAL_URI",save);
editor.putInt("DEFAULT",0);
editor.commit();
finish();
}
@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());
}
}

@ -1,12 +0,0 @@
<?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>

@ -1,7 +0,0 @@
<?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>

@ -16,8 +16,6 @@
package net.micode.notes.ui;
import static net.micode.notes.R.drawable.list_background;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
@ -29,19 +27,13 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
//import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.style.BackgroundColorSpan;
import android.util.Log;
@ -60,13 +52,11 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
//维护_丁梓坚_朗读
//import android.support.v7.app.AppCompatActivity;
//维护 添加read
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;
@ -80,9 +70,6 @@ import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
@ -167,12 +154,9 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
private String mUserQuery;
private Pattern mPattern;
//维护_丁梓坚_朗读
//维护 添加Read
private TextToSpeech mNoteRead;
//维护_王京
CharSequence tmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -182,9 +166,9 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
finish();
return;
}
initResources();
}
/**
* Current activity may be killed when the memory is low. Once it is killed, for another time
* user load this activity, we should restore the former state
@ -420,7 +404,7 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
//维护_丁梓坚_朗读
//维护 添加Read
mNoteRead = new TextToSpeech(this, new OnInitListener()
{
@Override
@ -440,55 +424,9 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
}
}
);
//维护_王京
EditText e = findViewById(R.id.note_edit_view);
//CharSequence tmp;
e.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
tmp = charSequence;
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
//NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
//Editable edit = noteEditText.getText();//1.获取text
String s = editable.toString(); //2.将note内容转换为字符串
int len = editable.length(); //内容的长度
for (int i = 0; i < len; i++) {
for (int j = i; j < len; j++) {
Log.i(TAG, s);
String img_fragment = s.substring(i, j + 1); //img_fragment关于图片路径的片段
if (img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")) {
String b = s.substring(0, i);
String c = s.substring(j + 1, len);
s = b + c;
len = len + i - j - 1;
}
}
/* (int k = 0; k < len; k++) {
for (int j = k; j < len; j++) {
String img_fragment = s.substring(k, j + 1); //img_fragment关于图片路径的片段
if (img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")) {
String b = s.substring(0,k);
String c = s.substring(j+1,len);
s = b + c;
len = len + k - j - 16;
}
}
}*/
}
TextView length = findViewById(R.id.length);
length.setText("字符数:" + operateText(s).length());
}
});
}
@Override
protected void onPause() {
super.onPause();
@ -522,7 +460,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);
@ -639,87 +577,17 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
case R.id.menu_delete_remind:
mWorkingNote.setAlertDate(0, false);
break;
//维护_丁梓坚_朗读
//维护 添加read
case R.id.menu_read:
noteRead();
break;
//维护_刘彦辰
case R.id.menu_font_select:
showSingleAlertDiglog();
break;
default:
break;
}
return true;
}
//维护_刘彦辰
public void showSingleAlertDiglog(){
final String[] items = {"默认-普通","默认-非衬线","默认-衬线","默认-等宽","仿宋","黑体","楷体","姚体","隶书","行楷","新魏","中宋"};
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
alertBuilder.setTitle("选择字体");
alertBuilder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch (i) {
case 0:
mNoteEditor.setTypeface(Typeface.DEFAULT);
break;
case 1:
mNoteEditor.setTypeface(Typeface.SANS_SERIF);
break;
case 2:
mNoteEditor.setTypeface(Typeface.SERIF);
break;
case 3:
mNoteEditor.setTypeface(Typeface.MONOSPACE);
break;
case 4:
Typeface typeface0 = Typeface.createFromAsset(getAssets(), "font/simfang.ttf");
mNoteEditor.setTypeface(typeface0);
break;
case 5:
Typeface typeface1 = Typeface.createFromAsset(getAssets(), "font/simhei.ttf");
mNoteEditor.setTypeface(typeface1);
break;
case 6:
Typeface typeface2 = Typeface.createFromAsset(getAssets(), "font/simkai.ttf");
mNoteEditor.setTypeface(typeface2);
break;
case 7:
Typeface typeface3 = Typeface.createFromAsset(getAssets(), "font/FZYTK.TTF");
mNoteEditor.setTypeface(typeface3);
break;
case 8:
Typeface typeface4 = Typeface.createFromAsset(getAssets(), "font/STLITI.TTF");
mNoteEditor.setTypeface(typeface4);
break;
case 9:
Typeface typeface5 = Typeface.createFromAsset(getAssets(), "font/STXINGKA.TTF");
mNoteEditor.setTypeface(typeface5);
break;
case 10:
Typeface typeface6 = Typeface.createFromAsset(getAssets(), "font/STXINWEI.TTF");
mNoteEditor.setTypeface(typeface6);
break;
case 11:
Typeface typeface7 = Typeface.createFromAsset(getAssets(), "font/STZHONGS.TTF");
mNoteEditor.setTypeface(typeface7);
break;
}
Toast.makeText(NoteEditActivity.this, items[i], Toast.LENGTH_SHORT).show();
alertDialog2.dismiss();
}
});
alertDialog2 = alertBuilder.create();
alertDialog2.show();
}
//维护_刘彦辰
private AlertDialog alertDialog2;
//维护_丁梓坚_朗读
//维护 添加read
private void noteRead(){
mNoteRead.speak(mNoteEditor.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
@ -1041,34 +909,4 @@ public class NoteEditActivity extends AppCompatActivity implements OnClickListen
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}
//维护_王京
public void xianshi() {
NoteEditText noteEditText = (NoteEditText) findViewById(R.id.note_edit_view); //获取当前的edit
Editable editable = noteEditText.getText();//1.获取text
String s = editable.toString(); //2.将note内容转换为字符串
int len = editable.length(); //内容的长度
for (int i = 0; i < len; i++) {
for (int j = i; j < len; j++) {
String img_fragment = s.substring(i, j + 1);
if (img_fragment.length() > 15 && img_fragment.endsWith("[/local]") && img_fragment.startsWith("[local]")) {
String b = s.substring(0, i);
String c = s.substring(j + 1, len);
s = b + c;
//Log.i(TAG, s);
len = len + i - j - 1;
}
}
}
TextView length = findViewById(R.id.length);
length.setText("字符数:" + s.length());
}
public String operateText(String str){
String dest = "";
Pattern p = Pattern.compile("\\s*|t|r|n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
return dest;
}
}

@ -39,8 +39,6 @@ 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;
@ -73,9 +71,7 @@ import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
//import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.support.v7.app.AppCompatActivity;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
@ -90,12 +86,9 @@ 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;
import java.io.OutputStream;
import java.util.HashSet;
@ -161,7 +154,7 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
//维护_丁梓坚_个性化背景_刷新界面
//
@Override
public Window getWindow() {
return super.getWindow();
@ -172,22 +165,8 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
super.onCreate(savedInstanceState);
setContentView(layout.note_list);
//维护_丁梓坚_个性化背景_初始化操作
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_READABLE);
//需要先创建图片资源文件SampleCropImage.jpeg用于存放个性背景图片
if(!sharedPreferences.contains("DEFAULT"))
{
Drawable drawable= getResources().getDrawable(list_background);
BitmapDrawable bd = (BitmapDrawable) drawable;
Bitmap b = bd.getBitmap();
File path = new File(getCacheDir() + "/SampleCropImage.jpeg");
try {
OutputStream os = new FileOutputStream(path);
b.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.close();
} catch (Exception ignored) {
}
}
//维护
//getWindow().setBackgroundDrawableResource(R.drawable.);
initResources();
@ -198,29 +177,44 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe
setAppInfoFromRawRes();
}
//维护_丁梓坚_个性化背景_刷新界面
//维护
@Override
protected void onResume() {
super.onResume();
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_READABLE);
//根据DEFAULT的值来判断是否加载个性背景
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_READABLE);//xml
if(sharedPreferences.contains("DEFAULT")){
//默认背景
if(sharedPreferences.getInt("DEFAULT",0)==1)
getWindow().setBackgroundDrawableResource(R.drawable.list_background);
//个性背景
else{
Bitmap bitmap = BitmapFactory.decodeFile(getCacheDir() + "/SampleCropImage.jpeg");
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);
//确实在这里有错
//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);
Drawable drawable =new BitmapDrawable(bitmap);
getWindow().setBackgroundDrawable(drawable);
//layout1.setBackground(drawable);
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
getWindow().setBackgroundDrawable(drawable);
}
}
else
getWindow().setBackgroundDrawableResource(R.drawable.list_background);
//else
//Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
}
@Override

@ -16,10 +16,14 @@
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;
@ -27,47 +31,38 @@ 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 java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import net.micode.notes.ui.NotesListActivity;
public class NotesPreferenceActivity extends PreferenceActivity {
@ -82,8 +77,7 @@ 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;
@ -99,6 +93,12 @@ 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,27 +180,16 @@ 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)
{
@ -208,37 +197,46 @@ 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();
SharedPreferences sharedPreferences=getSharedPreferences("data1", Context.MODE_WORLD_WRITEABLE);//xml
SharedPreferences.Editor editor=sharedPreferences.edit();
//if(!sharedPreferences.contains("PERSONAL_URI")) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
editor.putString("PERSONAL_URI",selectedImage.toString());
editor.putInt("DEFAULT",0);
String path = cursor.getString(columnIndex);
editor.commit();
//}
Bitmap bitmap = BitmapFactory.decodeFile(path);
bitmap2uri(bitmap);
//String [] filePathColumn = {MediaStore.Images.Media.DATA};
//Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
//cursor.moveToFirst();
Intent intent = new Intent(NotesPreferenceActivity.this, UCropPictureActivity.class);
//int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
//String path = cursor.getString(columnIndex);
this.startActivityForResult(intent, 12);
//Bitmap bitmap = BitmapFactory.decodeFile(path);
//RelativeLayout layout1 = (RelativeLayout)findViewById(R.id.preference_textview);
//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;
@ -250,6 +248,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
.create(); //创建对话框
dialog.show(); //显示对话框
*/
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("选择方式");
//builder.setIcon(R.drawable.ic_launcher);
@ -259,10 +259,22 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
private void displayImage(String imagePath) {
if (imagePath != null) {
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
Drawable tupian = new BitmapDrawable(bitmap);
//维护_丁梓坚_个性化背景_选择默认背景
private void returnToMenu() {
} 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();
@ -272,7 +284,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
finish();
}
//维护_丁梓坚_个性化背景_监听选择
//维护 3
class backgroundListener implements DialogInterface.OnClickListener{
@Override
@ -280,10 +292,31 @@ 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);
@ -294,12 +327,13 @@ 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");
@ -307,10 +341,17 @@ 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;
}
});
@ -359,7 +400,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
//维护_丁梓坚_个性化背景
//维护
loadBackgroundPreference();
}

@ -10,7 +10,6 @@ import android.app.Activity;
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*/
//维护_丁梓坚_欢迎界面
public class WelcomeActivity extends Activity {
Handler mHandler=new Handler();

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save