Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gradle/7.0.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.0.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.0.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/jarAnalysis.bin
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/7.0.2/javaCompile/taskHistory.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified .gradle/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/checksums/sha1-checksums.bin
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules/app/mobilprog.app.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 38 additions & 93 deletions app/src/main/java/com/example/mobilprog/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
package com.example.mobilprog;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.CancellationTokenSource;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.ListResult;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageMetadata;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -83,6 +69,7 @@ public void onMap(View view) {
startActivity(i);
}

@SuppressWarnings("deprecation")
public void onImage(View view) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (i.resolveActivity(getPackageManager()) != null) {
Expand Down Expand Up @@ -110,61 +97,37 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
StorageReference ref = storageReference.child("Images/" + f.getName());

ref.putFile(Uri.fromFile(f))
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
double progress = (100.0 * snapshot.getBytesTransferred()) / snapshot.getTotalByteCount();
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress((int) progress);
}
.addOnProgressListener(snapshot -> {
double progress = (100.0 * snapshot.getBytesTransferred()) / snapshot.getTotalByteCount();
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress((int) progress);
})
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(MainActivity.this, "Image Uploaded!", Toast.LENGTH_SHORT).show();
loadImages();
createLocationMetadata(ref);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Failed " + e.getMessage(), Toast.LENGTH_LONG).show();
}
.addOnSuccessListener(taskSnapshot -> {
progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(MainActivity.this, "Image Uploaded!", Toast.LENGTH_SHORT).show();
loadImages();
createLocationMetadata(ref);
})
.addOnFailureListener(e -> Toast.makeText(MainActivity.this, "Failed " + e.getMessage(), Toast.LENGTH_LONG).show())
;
}
}

private void loadImages() {
gallery.removeAllViews();
listRef.listAll()
.addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for (StorageReference item : listResult.getItems()) {
ImageView imageView = new ImageView(getApplicationContext());
GlideApp.with(getApplicationContext()).load(item).into(imageView);

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openImage(item.getPath());
}
});

gallery.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT, 700);
}
.addOnSuccessListener(listResult -> {
for (StorageReference item : listResult.getItems()) {
ImageView imageView = new ImageView(getApplicationContext());
GlideApp.with(getApplicationContext()).load(item).into(imageView);

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setOnClickListener(v -> openImage(item.getPath()));

gallery.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT, 700);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Image load error!", Toast.LENGTH_SHORT).show();
}
});
.addOnFailureListener(e -> Toast.makeText(MainActivity.this, "Image load error!", Toast.LENGTH_SHORT).show());
}

private File createImageFile() throws IOException {
Expand All @@ -184,38 +147,20 @@ private void createLocationMetadata(StorageReference ref) {

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
fusedLocationClient.getCurrentLocation(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY, cancellationTokenSource.getToken())
.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
StorageMetadata metadata = new StorageMetadata.Builder()
.setCustomMetadata("Latitude", String.valueOf(location.getLatitude()))
.setCustomMetadata("Longitude", String.valueOf(location.getLongitude()))
.build();

ref.updateMetadata(metadata)
.addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
Toast.makeText(MainActivity.this, "Image Location is saved!", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Failed to save location for the image!", Toast.LENGTH_LONG).show();
}
})
;
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "The current location is not available!", Toast.LENGTH_SHORT).show();
.addOnSuccessListener(location -> {
if (location != null) {
StorageMetadata metadata = new StorageMetadata.Builder()
.setCustomMetadata("Latitude", String.valueOf(location.getLatitude()))
.setCustomMetadata("Longitude", String.valueOf(location.getLongitude()))
.build();

ref.updateMetadata(metadata)
.addOnSuccessListener(storageMetadata -> Toast.makeText(MainActivity.this, "Image Location is saved!", Toast.LENGTH_SHORT).show())
.addOnFailureListener(e -> Toast.makeText(MainActivity.this, "Failed to save location for the image!", Toast.LENGTH_LONG).show())
;
}
})
.addOnFailureListener(e -> Toast.makeText(MainActivity.this, "The current location is not available!", Toast.LENGTH_SHORT).show())

;
}
Expand Down
8 changes: 3 additions & 5 deletions local.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\bogna\\AppData\\Local\\Android\\Sdk
#Wed Oct 20 18:11:42 CEST 2021
sdk.dir=C\:\\Users\\ct4nk3r\\AppData\\Local\\Android\\Sdk