fix warnings
parent
acb052382e
commit
0fe1de3869
|
|
@ -4,6 +4,8 @@
|
|||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.3353846153846154" />
|
||||
<entry key="app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml" value="0.3353846153846154" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -12,8 +12,13 @@
|
|||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="18" />
|
||||
|
||||
<queries>
|
||||
<!-- just to satisfy the warning from `resolveActivity()` -.- -->
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:fullBackupOnly="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
|
|
@ -38,7 +43,7 @@
|
|||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths"></meta-data>
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
package de.clkl.android.miniofotoapp;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -12,6 +8,15 @@ import android.provider.MediaStore;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -19,18 +24,13 @@ import java.security.InvalidKeyException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.minio.BucketExistsArgs;
|
||||
import io.minio.MakeBucketArgs;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.UploadObjectArgs;
|
||||
import io.minio.errors.ErrorResponseException;
|
||||
import io.minio.errors.InsufficientDataException;
|
||||
import io.minio.errors.InternalException;
|
||||
import io.minio.errors.InvalidResponseException;
|
||||
import io.minio.errors.MinioException;
|
||||
import io.minio.errors.ServerException;
|
||||
import io.minio.errors.XmlParserException;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
|
@ -40,6 +40,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
private String currentPhotoPath;
|
||||
private MinioClient minio;
|
||||
private String bucket;
|
||||
private ActivityResultLauncher<Intent> photoLauncher;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -54,26 +55,29 @@ public class MainActivity extends AppCompatActivity {
|
|||
bucket = getString(R.string.minio_bucket);
|
||||
|
||||
checkOrCreateBucket(minio, bucket);
|
||||
|
||||
photoLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> { // new ActivityResultCallback<ActivityResult>() {
|
||||
if (result.getResultCode() == RESULT_OK) {
|
||||
handlePhotoCallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void checkOrCreateBucket(MinioClient client, String bucket) {
|
||||
Runnable check = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
boolean isPresent = false;
|
||||
isPresent = client.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
|
||||
if (!isPresent) {
|
||||
System.out.println("Create Bucket '" + bucket + "'");
|
||||
client.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
||||
} else {
|
||||
System.out.println("Bucket '" + bucket + "' already present");
|
||||
}
|
||||
} catch (InvalidKeyException | IOException | NoSuchAlgorithmException | MinioException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "something went wrong with minio", e);
|
||||
Runnable check = () -> { // lambda syntax: short for `new Runnable{}`
|
||||
try {
|
||||
boolean isPresent = client.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
|
||||
if (!isPresent) {
|
||||
System.out.println("Create Bucket '" + bucket + "'");
|
||||
client.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
||||
} else {
|
||||
System.out.println("Bucket '" + bucket + "' already present");
|
||||
}
|
||||
} catch (InvalidKeyException | IOException | NoSuchAlgorithmException | MinioException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "something went wrong with minio", e);
|
||||
}
|
||||
};
|
||||
new Thread(check).start();
|
||||
|
|
@ -95,13 +99,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
"de.clkl.android.MinioPhotoApp.fileprovider",
|
||||
photoFile);
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
|
||||
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||
photoLauncher.launch(takePictureIntent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File createImageFile() throws IOException {
|
||||
String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
|
||||
String timeStamp = new SimpleDateFormat(
|
||||
"yyyy-MM-dd_HH-mm-ss",
|
||||
Locale.getDefault()
|
||||
).format(new Date());
|
||||
String fileName = "JPEG_" + timeStamp + "_";
|
||||
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
||||
File image = File.createTempFile(
|
||||
|
|
@ -110,6 +117,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
storageDir
|
||||
);
|
||||
currentPhotoPath = image.getAbsolutePath();
|
||||
Toast.makeText(this, currentPhotoPath, Toast.LENGTH_LONG).show();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
@ -119,25 +127,26 @@ public class MainActivity extends AppCompatActivity {
|
|||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
|
||||
thumb.setImageURI(Uri.fromFile(new File(currentPhotoPath)));
|
||||
Runnable upload = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
String filename = currentPhotoPath.substring(currentPhotoPath.lastIndexOf("/"));
|
||||
minio.uploadObject(UploadObjectArgs.builder().bucket(bucket).object(filename).filename(currentPhotoPath).build());
|
||||
} catch (InvalidKeyException | IOException | NoSuchAlgorithmException | MinioException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "something went wrong with minio", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
new Thread(upload).start();
|
||||
handlePhotoCallback();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handlePhotoCallback() {
|
||||
thumb.setImageURI(Uri.fromFile(new File(currentPhotoPath)));
|
||||
Runnable upload = () -> {
|
||||
|
||||
try {
|
||||
String filename = currentPhotoPath.substring(currentPhotoPath.lastIndexOf("/"));
|
||||
minio.uploadObject(UploadObjectArgs.builder().bucket(bucket).object(filename).filename(currentPhotoPath).build());
|
||||
} catch (InvalidKeyException | IOException | NoSuchAlgorithmException | MinioException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "something went wrong with minio", e);
|
||||
}
|
||||
};
|
||||
new Thread(upload).start();
|
||||
}
|
||||
|
||||
public void onButtonClick(View view) {
|
||||
Log.d(TAG, "button has been clicked");
|
||||
dispatchTakePictureIntent();
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="148dp"
|
||||
android:layout_marginTop="112dp"
|
||||
android:text="Button"
|
||||
android:text="@string/button"
|
||||
android:onClick="onButtonClick"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:contentDescription="@string/thumbnail"
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<string name="minio_access_key">demoAPI</string>
|
||||
<string name="minio_secret_key">952fa5f2-0965-11ec-b846-1756113babc3</string>
|
||||
<string name="minio_secret_key" tools:ignore="TypographyDashes">952fa5f2-0965-11ec-b846-1756113babc3</string>
|
||||
<string name="minio_host">http://192.168.2.53:9000</string>
|
||||
<string name="minio_bucket">android-demo</string>
|
||||
</resources>
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">MinioFotoApp</string>
|
||||
<string name="thumbnail">thumbnail</string>
|
||||
<string name="button">Tap to take a Photo</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue