Skip to content

Commit

Permalink
Merge pull request #17 from EPICSGroup/ibrahim
Browse files Browse the repository at this point in the history
Ibrahim image attach form
  • Loading branch information
seford authored Apr 21, 2021
2 parents 5376663 + ede96f2 commit 31a59c6
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation 'com.google.firebase:firebase-auth:19.4.0'
implementation 'com.github.addisonelliott:SegmentedButton:3.1.9'
implementation 'com.google.firebase:firebase-firestore:21.6.0'
implementation 'com.google.firebase:firebase-storage:19.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sf.stormwaterutilityandroid">


<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"

android:theme="@style/Theme.StormWaterUtilityAndroid">
<activity android:name=".ImageAttachForm"></activity>
<activity android:name=".Settings" />
<activity android:name=".MainMenu">

android:theme="@style/Theme.StormWaterUtilityAndroid"
android:requestLegacyExternalStorage="true">

Expand All @@ -27,12 +37,21 @@
<activity android:name=".PDFCreator" />
<activity android:name=".Grapher" />
<activity android:name=".Login">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".WaterWay.WaterWayNav"></activity>
<activity android:name=".Construction.ConstructionNav"></activity>
<activity android:name=".Reset_password" />
<activity android:name=".SampleFordm" />
<activity android:name=".InspectionForm" />
<activity android:name=".Login" />

<activity android:name=".SignUp" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public class ConstructionFormData implements Serializable {
List<String> answers;
List<String> imgLink;


public ConstructionFormData(String contact, String date, String inspector,
String location, List<String> answers, List<String> imgLinks) {
data = new HashMap<>();
data.put("contact", contact);
data.put("date", date);
data.put("inspector", inspector);
data.put("location", location);
data.put("answers", answers);
data.put("imgLinks", imgLinks);

public ConstructionFormData(String contact, String date, String inspector, Date timestamp, String location,
GeoPoint geoPoint, List<String> answers, List<String> imgLinks) {
this.contact = contact;
Expand Down Expand Up @@ -119,6 +130,7 @@ public List<String> getImgLink() {

public void setImgLink(List<String> imgLink) {
this.imgLink = imgLink;

}

public Map<String, Object> getMap() {
Expand Down
200 changes: 200 additions & 0 deletions app/src/main/java/com/sf/stormwaterutilityandroid/ImageAttachForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
package com.sf.stormwaterutilityandroid;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.Nullable;

public class ImageAttachForm extends AppCompatActivity {
private static final int OPEN_GALLERY_REQUEST = 2;
private static final int OPEN_CAMERA_REQUEST = 3;

private Button uploadCameraImageBtn;
private Button uploadGalleryImageBtn;
private Button uploadImageBackBtn;


private ArrayList<Uri> imageURIs;

private ArrayList<ImageView> imageViews;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_attach_form);

this.uploadCameraImageBtn = findViewById(R.id.uploadCameraImageBtn);
this.uploadGalleryImageBtn = findViewById(R.id.uploadGalleryImageBtn);
this.uploadImageBackBtn = findViewById(R.id.uploadImageBackBtn);

// this.imageView = findViewById(R.id.ImageView1);


// this.imageUri = null;

this.imageURIs = new ArrayList<>(3);

imageViews = new ArrayList<>();

this.imageViews.add(findViewById(R.id.ImageView1));
this.imageViews.add(findViewById(R.id.ImageView2));
this.imageViews.add(findViewById(R.id.ImageView3));

initActionListeners();
}

private void initActionListeners() {

uploadImageBackBtn.setOnClickListener(view -> {
if (imageURIs == null) {
setResult(RESULT_CANCELED);
finish();
}

Intent data = new Intent();
// data.putExtra("imageURIs", imageURIs.toArray());
Bundle args = new Bundle();
args.putSerializable("IMAGEURIS", (Serializable) imageURIs);
data.putExtra("BUNDLE", args);
setResult(RESULT_OK, data);
finish();
});


// pick from gallery
uploadGalleryImageBtn.setOnClickListener(view -> {
chooseGalleryImage();
});

// pick from camera
uploadCameraImageBtn.setOnClickListener(view -> {
// request camera permission if not granted already
if (ContextCompat.checkSelfPermission(ImageAttachForm.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(ImageAttachForm.this,
new String[]{
Manifest.permission.CAMERA
},
100);
}

chooseCameraImage();
});

imageViews.get(0).setOnClickListener(view -> {
imageURIs.remove(0);
updateImageViews();
});

imageViews.get(1).setOnClickListener(view -> {
imageURIs.remove(1);
updateImageViews();
});

imageViews.get(2).setOnClickListener(view -> {
imageURIs.remove(2);
updateImageViews();
});
}

private void chooseCameraImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, OPEN_CAMERA_REQUEST);
}


private void chooseGalleryImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, OPEN_GALLERY_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OPEN_GALLERY_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri newImageUri = data.getData();
//this.imageView.setImageURI(imageUri);
addImage(newImageUri);

// uploadPicture();
} else if (requestCode == OPEN_CAMERA_REQUEST && resultCode == RESULT_OK && data != null && data.getExtras() != null) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap, "Title", null);
// this.imageUri = Uri.parse(path);
Uri newImageUri = Uri.parse(path);
addImage(newImageUri);


// uploadPicture();
}
}

// private void uploadPicture() {
// final String randomKey = UUID.randomUUID().toString();
// StorageReference storageRef = storageReference.child("images/" + randomKey);
// storageRef.putFile(imageUri)
// .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
// @Override
// public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// System.out.println("SUCCESSS!!!");
// Task<Uri> downloadUri = taskSnapshot.getStorage().getDownloadUrl();
// System.out.println("downloadUri: " + downloadUri);
// }
// })
// .addOnFailureListener(new OnFailureListener() {
// @Override
// public void onFailure(@NonNull Exception e) {
// System.out.println("FAILEDDD");
// }
// });
// }

// adds image to imageURIs list and to the recycle view of displayed images
private void addImage(Uri newImageUri) {
System.out.println("Image URI HEREEE!!!: " + newImageUri);


if (imageURIs.size() == 3) {
// send message to remove 1
System.out.println("EARLY RETURN !!!!!");
return;
}

this.imageURIs.add(newImageUri);

System.out.println("ImageURIs:\n" + imageURIs);
updateImageViews();
}

private void updateImageViews() {
// set images to first views
int i = 0;
for (i = 0; i < imageURIs.size(); i++) {
imageViews.get(i).setImageURI(imageURIs.get(i));
}

// set the rest to invisible
while (i < 3) imageViews.get(i++).setImageURI(null);
}
}
Loading

0 comments on commit 31a59c6

Please sign in to comment.