Edit User V3
Alles funktioniert
This commit is contained in:
parent
0ddf3ca997
commit
9ea3c2bf63
@ -1,5 +1,6 @@
|
|||||||
package at.smartshopper.smartshopper.activitys;
|
package at.smartshopper.smartshopper.activitys;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -8,14 +9,15 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.os.Environment;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -37,8 +39,6 @@ import org.json.JSONException;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -54,11 +54,12 @@ public class EditUser extends Activity {
|
|||||||
private EditText editname;
|
private EditText editname;
|
||||||
private ImageView userbild;
|
private ImageView userbild;
|
||||||
private Button finish, chooseImg;
|
private Button finish, chooseImg;
|
||||||
private Bitmap userBitmap;
|
|
||||||
private Database db;
|
private Database db;
|
||||||
private final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
private final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||||
private Bitmap selectedImage;
|
private Uri uri;
|
||||||
private Uri imageUri;
|
private Intent CamIntent, GalIntent, CropIntent;
|
||||||
|
private File file;
|
||||||
|
public static final int RequestPermissionCode = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -83,25 +84,16 @@ public class EditUser extends Activity {
|
|||||||
String photoUrl = member.getPic();
|
String photoUrl = member.getPic();
|
||||||
|
|
||||||
|
|
||||||
userbild.setImageDrawable(LoadImageFromWebOperations(photoUrl));
|
userbild.setImageDrawable(LoadImageFromWebOperations(photoUrl));
|
||||||
editname.setText(name);
|
editname.setText(name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EnableRuntimePermission();
|
||||||
|
|
||||||
chooseImg.setOnClickListener(new View.OnClickListener() {
|
chooseImg.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
GetImageFromGallery();
|
||||||
getIntent.setType("image/*");
|
// ClickImageFromCamera();
|
||||||
|
|
||||||
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
|
||||||
pickIntent.setType("image/*");
|
|
||||||
|
|
||||||
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
|
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
|
|
||||||
|
|
||||||
startActivityForResult(chooserIntent, 1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -109,6 +101,13 @@ public class EditUser extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ArrayList arlist = new ArrayList();
|
ArrayList arlist = new ArrayList();
|
||||||
|
|
||||||
|
|
||||||
|
userbild.invalidate();
|
||||||
|
BitmapDrawable drawable = (BitmapDrawable) userbild.getDrawable();
|
||||||
|
Bitmap userBitmap = drawable.getBitmap();
|
||||||
|
|
||||||
|
|
||||||
arlist.add(userBitmap);
|
arlist.add(userBitmap);
|
||||||
arlist.add(FirebaseAuth.getInstance().getUid());
|
arlist.add(FirebaseAuth.getInstance().getUid());
|
||||||
Object[] objArr = arlist.toArray();
|
Object[] objArr = arlist.toArray();
|
||||||
@ -193,120 +192,244 @@ public class EditUser extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClickImageFromCamera() {
|
||||||
|
|
||||||
// code for device below 5
|
CamIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
private boolean performCropImage(Uri mFinalImageUri) {
|
|
||||||
Uri mCropImagedUri;
|
|
||||||
try {
|
|
||||||
if (mFinalImageUri != null) {
|
|
||||||
//call the standard crop action intent (the user device may not support it)
|
|
||||||
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
|
||||||
//indicate image type and Uri
|
|
||||||
cropIntent.setDataAndType(mFinalImageUri, "image/*");
|
|
||||||
//set crop properties
|
|
||||||
cropIntent.putExtra("crop", "true");
|
|
||||||
//indicate aspect of desired crop
|
|
||||||
cropIntent.putExtra("aspectX", 1);
|
|
||||||
cropIntent.putExtra("aspectY", 1);
|
|
||||||
cropIntent.putExtra("scale", true);
|
|
||||||
// cropIntent.p
|
|
||||||
//indicate output X and Y
|
|
||||||
cropIntent.putExtra("outputX", 200);
|
|
||||||
cropIntent.putExtra("outputY", 200);
|
|
||||||
//retrieve data on return
|
|
||||||
cropIntent.putExtra("return-data", false);
|
|
||||||
|
|
||||||
File f = new File("CROP_");
|
file = new File(Environment.getExternalStorageDirectory(),
|
||||||
try {
|
"file" + String.valueOf(System.currentTimeMillis()) + ".jpg");
|
||||||
f.createNewFile();
|
uri = Uri.fromFile(file);
|
||||||
} catch (IOException ex) {
|
|
||||||
Log.e("io", ex.getMessage());
|
CamIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
|
||||||
}
|
|
||||||
|
CamIntent.putExtra("return-data", true);
|
||||||
|
|
||||||
|
startActivityForResult(CamIntent, 0);
|
||||||
|
|
||||||
mCropImagedUri = Uri.fromFile(f);
|
|
||||||
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImagedUri);
|
|
||||||
//start the activity - we handle returning in onActivityResult
|
|
||||||
startActivityForResult(cropIntent, 2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (ActivityNotFoundException anfe) {
|
|
||||||
//display an error message
|
|
||||||
String errorMessage = getString('2');
|
|
||||||
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
|
|
||||||
toast.show();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// code for 5 or 6
|
|
||||||
private void performCrop(Uri picUri) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
public void GetImageFromGallery() {
|
||||||
// indicate image type and Uri
|
|
||||||
cropIntent.setDataAndType(picUri, "image/*");
|
GalIntent = new Intent(Intent.ACTION_PICK,
|
||||||
// set crop properties
|
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||||
cropIntent.putExtra("crop", "true");
|
|
||||||
// indicate aspect of desired crop
|
startActivityForResult(Intent.createChooser(GalIntent, "Select Image From Gallery"), 2);
|
||||||
cropIntent.putExtra("aspectX", 1);
|
|
||||||
cropIntent.putExtra("aspectY", 1);
|
}
|
||||||
// indicate output X and Y
|
|
||||||
cropIntent.putExtra("outputX", 200);
|
@Override
|
||||||
cropIntent.putExtra("outputY", 200);
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
// retrieve data on return
|
if (requestCode == 0 && resultCode == RESULT_OK) {
|
||||||
cropIntent.putExtra("return-data", true);
|
|
||||||
// start the activity - we handle returning in onActivityResult
|
ImageCropFunction();
|
||||||
startActivityForResult(cropIntent, 2);
|
|
||||||
|
} else if (requestCode == 2) {
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
|
||||||
|
uri = data.getData();
|
||||||
|
|
||||||
|
ImageCropFunction();
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (requestCode == 1) {
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
|
||||||
|
Bundle bundle = data.getExtras();
|
||||||
|
|
||||||
|
Bitmap bitmap = bundle.getParcelable("data");
|
||||||
|
|
||||||
|
userbild.setImageBitmap(bitmap);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// respond to users whose devices do not support the crop action
|
}
|
||||||
catch (ActivityNotFoundException anfe) {
|
|
||||||
// display an error message
|
public void ImageCropFunction() {
|
||||||
String errorMessage = getString('2');
|
|
||||||
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
|
// Image Crop Code
|
||||||
toast.show();
|
try {
|
||||||
|
CropIntent = new Intent("com.android.camera.action.CROP");
|
||||||
|
|
||||||
|
CropIntent.setDataAndType(uri, "image/*");
|
||||||
|
|
||||||
|
CropIntent.putExtra("crop", "true");
|
||||||
|
CropIntent.putExtra("outputX", 180);
|
||||||
|
CropIntent.putExtra("outputY", 180);
|
||||||
|
CropIntent.putExtra("aspectX", 3);
|
||||||
|
CropIntent.putExtra("aspectY", 4);
|
||||||
|
CropIntent.putExtra("scaleUpIfNeeded", true);
|
||||||
|
CropIntent.putExtra("return-data", true);
|
||||||
|
|
||||||
|
startActivityForResult(CropIntent, 1);
|
||||||
|
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Image Crop Code End Here
|
||||||
|
|
||||||
|
public void EnableRuntimePermission() {
|
||||||
|
|
||||||
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
|
Manifest.permission.CAMERA)) {
|
||||||
|
|
||||||
|
Toast.makeText(this, "CAMERA permission allows us to Access CAMERA app", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
ActivityCompat.requestPermissions(this, new String[]{
|
||||||
|
Manifest.permission.CAMERA}, RequestPermissionCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onRequestPermissionsResult(int RC, String per[], int[] PResult) {
|
||||||
|
|
||||||
final InputStream imageStream;
|
switch (RC) {
|
||||||
|
|
||||||
|
case RequestPermissionCode:
|
||||||
|
|
||||||
if (requestCode == 1) {
|
if (PResult.length > 0 && PResult[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
imageUri = data.getData();
|
|
||||||
try {
|
|
||||||
imageStream = getContentResolver().openInputStream(imageUri);
|
|
||||||
selectedImage = BitmapFactory.decodeStream(imageStream);
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
Toast.makeText(this, "Permission Granted, Now your application can access CAMERA.", Toast.LENGTH_LONG).show();
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
performCrop(imageUri);
|
|
||||||
} else {
|
|
||||||
performCropImage(imageUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (requestCode == 2) {
|
|
||||||
try {
|
|
||||||
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
|
|
||||||
Bundle extras = data.getExtras();
|
|
||||||
selectedImage = extras.getParcelable("data");
|
|
||||||
} else {
|
} else {
|
||||||
selectedImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
|
|
||||||
|
Toast.makeText(this, "Permission Canceled, Now your application cannot access CAMERA.", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
}
|
}
|
||||||
userBitmap = selectedImage;
|
break;
|
||||||
userbild.setImageBitmap(selectedImage);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// // code for device below 5
|
||||||
|
// private boolean performCropImage(Uri mFinalImageUri) {
|
||||||
|
// Uri mCropImagedUri;
|
||||||
|
// try {
|
||||||
|
// if (mFinalImageUri != null) {
|
||||||
|
// //call the standard crop action intent (the user device may not support it)
|
||||||
|
// Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
||||||
|
// //indicate image type and Uri
|
||||||
|
// cropIntent.setDataAndType(mFinalImageUri, "image/*");
|
||||||
|
// //set crop properties
|
||||||
|
// cropIntent.putExtra("crop", "true");
|
||||||
|
// //indicate aspect of desired crop
|
||||||
|
// cropIntent.putExtra("aspectX", 1);
|
||||||
|
// cropIntent.putExtra("aspectY", 1);
|
||||||
|
// cropIntent.putExtra("scale", true);
|
||||||
|
// // cropIntent.p
|
||||||
|
// //indicate output X and Y
|
||||||
|
// cropIntent.putExtra("outputX", 200);
|
||||||
|
// cropIntent.putExtra("outputY", 200);
|
||||||
|
// //retrieve data on return
|
||||||
|
// cropIntent.putExtra("return-data", false);
|
||||||
|
//
|
||||||
|
// File f = new File("CROP_");
|
||||||
|
// try {
|
||||||
|
// f.createNewFile();
|
||||||
|
// } catch (IOException ex) {
|
||||||
|
// Log.e("io", ex.getMessage());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// mCropImagedUri = Uri.fromFile(f);
|
||||||
|
// cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImagedUri);
|
||||||
|
// //start the activity - we handle returning in onActivityResult
|
||||||
|
// startActivityForResult(cropIntent, 2);
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// } catch (ActivityNotFoundException anfe) {
|
||||||
|
// //display an error message
|
||||||
|
// String errorMessage = getString('2');
|
||||||
|
// Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
|
||||||
|
// toast.show();
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // code for 5 or 6
|
||||||
|
// private void performCrop(Uri picUri) {
|
||||||
|
// try {
|
||||||
|
//
|
||||||
|
// Intent cropIntent = new Intent("com.android.camera.action.CROP");
|
||||||
|
// // indicate image type and Uri
|
||||||
|
// cropIntent.setDataAndType(picUri, "image/*");
|
||||||
|
// // set crop properties
|
||||||
|
// cropIntent.putExtra("crop", "true");
|
||||||
|
// // indicate aspect of desired crop
|
||||||
|
// cropIntent.putExtra("aspectX", 1);
|
||||||
|
// cropIntent.putExtra("aspectY", 1);
|
||||||
|
// // indicate output X and Y
|
||||||
|
// cropIntent.putExtra("outputX", 200);
|
||||||
|
// cropIntent.putExtra("outputY", 200);
|
||||||
|
// // retrieve data on return
|
||||||
|
// cropIntent.putExtra("return-data", true);
|
||||||
|
// // start the activity - we handle returning in onActivityResult
|
||||||
|
// startActivityForResult(cropIntent, 2);
|
||||||
|
// }
|
||||||
|
// // respond to users whose devices do not support the crop action
|
||||||
|
// catch (ActivityNotFoundException anfe) {
|
||||||
|
// // display an error message
|
||||||
|
// String errorMessage = getString('2');
|
||||||
|
// Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
|
||||||
|
// toast.show();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
//
|
||||||
|
// final InputStream imageStream;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (requestCode == 1) {
|
||||||
|
// imageUri = data.getData();
|
||||||
|
// try {
|
||||||
|
// imageStream = getContentResolver().openInputStream(imageUri);
|
||||||
|
// BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
// options.inJustDecodeBounds = true;
|
||||||
|
// selectedImage = BitmapFactory.decodeFile(imageUri.toString(), options);
|
||||||
|
//
|
||||||
|
// } catch (FileNotFoundException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
// performCrop(imageUri);
|
||||||
|
// } else {
|
||||||
|
// performCropImage(imageUri);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } else if (requestCode == 2) {
|
||||||
|
// try {
|
||||||
|
// if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
// Bundle extras = data.getExtras();
|
||||||
|
// selectedImage = extras.getParcelable("data");
|
||||||
|
// } else {
|
||||||
|
// selectedImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// userBitmap = selectedImage;
|
||||||
|
// userbild.setImageBitmap(selectedImage);
|
||||||
|
// } catch (FileNotFoundException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private Uri getImageUri(Context context, Bitmap inImage) {
|
||||||
|
// ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
|
// inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
|
||||||
|
// String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), inImage, "Title", null);
|
||||||
|
// return Uri.parse(path);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
private Drawable LoadImageFromWebOperations(String url) {
|
private Drawable LoadImageFromWebOperations(String url) {
|
||||||
try {
|
try {
|
||||||
InputStream is = (InputStream) new URL(url).getContent();
|
InputStream is = (InputStream) new URL(url).getContent();
|
||||||
@ -324,6 +447,7 @@ public class EditUser extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Object... objects) {
|
protected String doInBackground(Object... objects) {
|
||||||
|
// Log.d("SmartShopper", objects[0].toString() + objects[1].toString());
|
||||||
final StorageReference storageRef = storage.getReference("/" + objects[1]);
|
final StorageReference storageRef = storage.getReference("/" + objects[1]);
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user