From 5f1eb416ab1d9abf0ada1386fa814a677ebf2843 Mon Sep 17 00:00:00 2001 From: Dingzijian <1418626018@qq.com> Date: Fri, 21 Oct 2022 20:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=B8=AA=E6=80=A7=E5=8C=96=E4=B8=BB=E7=95=8C=E9=9D=A2=E4=BC=9A?= =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E6=98=BE=E7=A4=BA=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micode/notes/ui/NotesListActivity.java | 58 +++++------------- .../notes/ui/NotesPreferenceActivity.java | 61 +------------------ .../micode/notes/ui/UCropPictureActivity.java | 5 +- 3 files changed, 17 insertions(+), 107 deletions(-) diff --git a/src/Notes-master/java/net/micode/notes/ui/NotesListActivity.java b/src/Notes-master/java/net/micode/notes/ui/NotesListActivity.java index 767d34c..7e0075e 100644 --- a/src/Notes-master/java/net/micode/notes/ui/NotesListActivity.java +++ b/src/Notes-master/java/net/micode/notes/ui/NotesListActivity.java @@ -95,6 +95,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.util.HashSet; @@ -160,7 +161,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(); @@ -171,9 +172,16 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe super.onCreate(savedInstanceState); setContentView(layout.note_list); - //维护 - //getWindow().setBackgroundDrawableResource(R.drawable.); - + 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) { + } initResources(); @@ -184,34 +192,6 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe } - //维护 - 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 @@ -222,24 +202,16 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe if(sharedPreferences.getInt("DEFAULT",0)==1) getWindow().setBackgroundDrawableResource(R.drawable.list_background); else{ - Uri selectedImage= Uri.parse(sharedPreferences.getString("PERSONAL_URI",null)); - - Bitmap bitmap = BitmapFactory.decodeFile(selectedImage.toString()); - - //Toast.makeText(this, URi, Toast.LENGTH_SHORT).show(); - + Bitmap bitmap = BitmapFactory.decodeFile(getCacheDir() + "/SampleCropImage.jpeg"); Drawable drawable =new BitmapDrawable(bitmap); 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(); } } + else + getWindow().setBackgroundDrawableResource(R.drawable.list_background); - - //else - //Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show(); } @Override diff --git a/src/Notes-master/java/net/micode/notes/ui/NotesPreferenceActivity.java b/src/Notes-master/java/net/micode/notes/ui/NotesPreferenceActivity.java index 4983504..d874b91 100644 --- a/src/Notes-master/java/net/micode/notes/ui/NotesPreferenceActivity.java +++ b/src/Notes-master/java/net/micode/notes/ui/NotesPreferenceActivity.java @@ -192,46 +192,11 @@ public class NotesPreferenceActivity extends PreferenceActivity { 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(); + //Toast.makeText(this, path.toString(), Toast.LENGTH_SHORT).show(); try { OutputStream os = new FileOutputStream(path); b.compress(Bitmap.CompressFormat.JPEG, 100, os); @@ -242,14 +207,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { return null; } - //维护 - ////_______//////// - //Uri转Bitmap,并复制bitmap - - //Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); - //bmcopy = bitmap.copy(Bitmap.Config.ARGB_8888, true); - /////_______/////// - //维护 ! @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) @@ -275,22 +232,6 @@ public class NotesPreferenceActivity extends PreferenceActivity { 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",save_uri); - - editor.putInt("DEFAULT",0); - - editor.commit(); - - */ - Intent intent = new Intent(NotesPreferenceActivity.this, UCropPictureActivity.class); this.startActivityForResult(intent, 12); diff --git a/src/Notes-master/java/net/micode/notes/ui/UCropPictureActivity.java b/src/Notes-master/java/net/micode/notes/ui/UCropPictureActivity.java index 8f6aa72..748b8c1 100644 --- a/src/Notes-master/java/net/micode/notes/ui/UCropPictureActivity.java +++ b/src/Notes-master/java/net/micode/notes/ui/UCropPictureActivity.java @@ -103,26 +103,23 @@ public class UCropPictureActivity extends AppCompatActivity { //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(); + finish(); } @Override