private void galleryAddPic()
{
Toast.makeText(this,"gelleyAddPic", Toast.LENGTH_SHORT).show();
Toast.makeText(this, mCurrentPhotoPath, Toast.LENGTH_SHORT).show();
final Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File file = new File(mCurrentPhotoPath);
contentUri = Uri.fromFile(file);
intent.setData(contentUri);
onWindowFocusChanged(true);
int targetW = imageViewW;
int targetH = imageViewH;
// Get the dimensions of the bitmap
bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
//Toast.makeText(this, String.valueOf(scaleFactor), Toast.LENGTH_SHORT).show();
ExifInterface exif = null;
try {
exif = new ExifInterface(mCurrentPhotoPath);
} catch (IOException e) {
e.printStackTrace();
}
exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
exifDegree = exifOrientationToDegrees(exifOrientation);
bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
// ------------------------------------------------------------- image Upload
/**/ Log.i("Upload", "Upload Start");
storageRef = storage.getReferenceFromUrl("gs").child("images/"+imageFileName);
storageRef.putFile(contentUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
downloadImageFile(intent);
Log.i("File Upload","File Upload Success");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.i("File Upload","File Upload Failed");
}
});
}
private void downloadImageFile(final Intent intent)
{
StorageReference gsReference = storage.getReferenceFromUrl("gs");
StorageReference pathReference = gsReference.child("images/"+imageFileName);
try
{
File localFile = File.createTempFile("images", "jpg");
pathReference.getFile(localFile)
.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(MainActivity.this, "Download Success", Toast.LENGTH_SHORT).show();
Log.i("Download", "Download Success");
imageDownload = true;
onWindowFocusChanged(true);
setImageFile(intent);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle failed download
// ...
}
});
/* pathReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
Toast.makeText(MainActivity.this, "Download Success", Toast.LENGTH_SHORT).show();
Log.i("File Download","Download Success");
imageDownload = true;
onWindowFocusChanged(true);
setImageFile(intent);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setImageFile(Intent intent)
{
Log.i("setImage","setImageFile Start");
if(imageDownload == true)
{
// imageView.setImageBitmap(bitmap);
imageView.setImageBitmap(rotate(bitmap, exifDegree));
Toast.makeText(this, String.valueOf(bitmap), Toast.LENGTH_SHORT).show();
sendBroadcast(intent);
imageDownload = false;
}
}