Commit 44a750d6 authored by dilshan-98's avatar dilshan-98

Few functions were implemented (Set image path, Display the image, Convert...

Few functions were implemented (Set image path, Display the image, Convert bitmap image to uri path) and response receiving was coded partially
parent 2e464661
......@@ -6,11 +6,15 @@ import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.webkit.MimeTypeMap;
import android.widget.Button;
......@@ -19,6 +23,7 @@ import android.widget.Toast;
import com.app.smartphotoeditor.R;
import java.io.ByteArrayOutputStream;
import java.io.File;
import okhttp3.MediaType;
......@@ -26,6 +31,7 @@ import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class BackgroundCustomization extends AppCompatActivity
{
......@@ -66,6 +72,7 @@ public class BackgroundCustomization extends AppCompatActivity
if(filePath==null)
{
Toast.makeText(BackgroundCustomization.this,"Select An Image", Toast.LENGTH_LONG).show();
}else{
progress = new ProgressDialog(BackgroundCustomization.this);
......@@ -108,13 +115,28 @@ public class BackgroundCustomization extends AppCompatActivity
try
{
//Receive Response
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
Toast.makeText(BackgroundCustomization.this, response.body().string(), Toast.LENGTH_LONG).show();
// if(!response.isSuccessful()){
// throw new Exception("Error: "+response);
// }
progress.dismiss();
// openEditActivity();
}catch (Exception e)
{
e.printStackTrace();
progress.dismiss();
openEditActivity();
}
}
});
t.start();
}else{
//Not in correct file format
}
......@@ -143,6 +165,48 @@ public class BackgroundCustomization extends AppCompatActivity
{
Intent pickPhoto = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickPhoto.setType("image/*");
startActivityForResult(pickPhoto,1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent ImageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, ImageReturnedIntent);
if(requestCode==1){
Uri selectedImage = ImageReturnedIntent.getData();
filePath = getPath(selectedImage);
fileExtn = filePath.substring(filePath.lastIndexOf(".")+1);
image.setImageURI(selectedImage);
}
}
public String getPath(Uri uri){
String[] projection = {MediaStore.MediaColumns.DATA};
//store query result in cursor variable
Cursor cursor = getContentResolver().query(uri,projection,null,null,null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
String imagePath = cursor.getString(column_index);
//Test Output
Log.d("Image Path : " , imagePath);
//return string
return cursor.getString(column_index);
}
//function to convert Bitmap image into URI path
public Uri getImageUri(Context inContxt, Bitmap InImage){
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
InImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContxt.getContentResolver(), InImage, "CapturedImage",null);
return Uri.parse(path);
}
public static void verifyStoragePermissions(Activity activity)
......@@ -161,5 +225,8 @@ public class BackgroundCustomization extends AppCompatActivity
}
}
public void openEditActivity(){
Intent intent = new Intent(this, Selectedit.class);
startActivity(intent);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment