Merge pull request '修复第一次个性化主界面会延迟显示图片的bug' (#3) from dingzijian_branch into develop

pull/6/head
pz4kybsvg 3 years ago
commit fc0aeab379

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

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

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

Loading…
Cancel
Save