-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenGalleryActivity.java
70 lines (56 loc) · 2.35 KB
/
OpenGalleryActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.soumio.inceptiontutorial;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
public class OpenGalleryActivity extends AppCompatActivity {
public ImageView imageView;
public static final int PICK_IMAGE = 100;
private Uri imageUri;
ContentValues values = new ContentValues();
private String lang;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
imageView = findViewById(R.id.image);
if(getIntent().getExtras() != null) lang = getIntent().getExtras().getString("lang");
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
imageView.setImageBitmap(bitmap);
imageUri = data.getData();
try {
Intent intent = new Intent(this, Classify.class);
intent.putExtra("lang", lang);
intent.putExtra("resID_uri", imageUri);
String chosen = "inception_quant.tflite";
intent.putExtra("chosen", chosen);
boolean quant = true;
intent.putExtra("quant", quant);
startActivity(intent);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}