diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index e0d5b93..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index c172c75..c723c86 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId "eu.dasancti.reversee"
minSdkVersion 21
targetSdkVersion 28
- versionCode 1
- versionName "1.0"
+ versionCode 2
+ versionName "ALPHA v0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8fd9108..4fc579a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -16,6 +16,11 @@
+
+
+
+
+
diff --git a/app/src/main/java/eu/dasancti/reversee/MainActivity.java b/app/src/main/java/eu/dasancti/reversee/MainActivity.java
index 42ace02..c85269c 100644
--- a/app/src/main/java/eu/dasancti/reversee/MainActivity.java
+++ b/app/src/main/java/eu/dasancti/reversee/MainActivity.java
@@ -31,6 +31,7 @@
public class MainActivity extends AppCompatActivity {
private static final String GOOGLE_REVERSE_IMAGE_SEARCH_URL = "https://www.google.com/searchbyimage/upload";
+ private static final String GOOGLE_REVERSE_IMAGE_SEARCH_URL_BY_URL = "https://www.google.com/searchbyimage?&image_url=";
private static final String FAKE_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11";
private static final String API_SCH_KEY = "sch";
private static final String API_SCH_VALUE = "sch";
@@ -49,38 +50,67 @@ protected void onCreate(Bundle savedInstanceState) {
progressStatus = findViewById(R.id.progressStatus);
Intent intent = getIntent();
+ if (intent == null) {
+ Toast.makeText(MainActivity.this, "No intent sent to application, closing.", Toast.LENGTH_SHORT).show();
+ this.finish();
+ return;
+ }
String action = intent.getAction();
if (action == null) {
Toast.makeText(MainActivity.this, "No action sent to application, closing.", Toast.LENGTH_SHORT).show();
this.finish();
return;
}
- if (isPermissionGranted()) {
- if (action.equals(Intent.ACTION_SEND)) {
- progressStatus.setText(getString(R.string.progress_status_recieved_intent));
- try {
- handleImageSearch(intent.getParcelableExtra(Intent.EXTRA_STREAM));
- } catch (FileNotFoundException e) {
- String err = "Failed to handle Share image intent:"+e.getMessage();
- Log.e("INTENT_HANDLE",err);
- Toast.makeText(getApplicationContext(), err, Toast.LENGTH_SHORT).show();
+ if (action.equals(Intent.ACTION_SEND)) {
+ if (intent.hasExtra(Intent.EXTRA_TEXT)) {
+ String intentExtraText = intent.getParcelableExtra(Intent.EXTRA_TEXT).toString();
+ progressStatus.setText(getString(R.string.progress_status_parsing_link));
+ if (intentExtraText.endsWith(".jpg") ||
+ intentExtraText.endsWith(".png") ||
+ intentExtraText.endsWith(".gif") ||
+ intentExtraText.endsWith(".webp")) {
+ progressStatus.setText(getString(R.string.progress_status_opening_from_url));
+ Toast.makeText(MainActivity.this, getString(R.string.progress_status_opening_from_url), Toast.LENGTH_SHORT).show();
+ Intent searchIntent = new Intent();
+ searchIntent.setAction(Intent.ACTION_VIEW);
+ searchIntent.setData(Uri.parse(GOOGLE_REVERSE_IMAGE_SEARCH_URL_BY_URL.concat(intentExtraText)));
+ startActivity(searchIntent);
+ MainActivity.this.finish();
+ } else {
+ progressStatus.setText(getString(R.string.progress_status_unsupported_format));
+ Toast.makeText(MainActivity.this, getString(R.string.progress_status_unsupported_format), Toast.LENGTH_SHORT).show();
+ this.finish();
+ }
+ } else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
+ if (isPermissionGranted()) {
+ progressStatus.setText(getString(R.string.progress_status_recieved_intent));
+ try {
+ handleImageSearch(intent.getParcelableExtra(Intent.EXTRA_STREAM));
+ } catch (FileNotFoundException e) {
+ String err = "Failed to handle Share image intent:" + e.getMessage();
+ Log.e("INTENT_HANDLE", err);
+ Toast.makeText(getApplicationContext(), err, Toast.LENGTH_SHORT).show();
+ }
+ } else {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Read storage permission required.");
+ builder.setMessage("This application requires READ_EXTERNAL_STORAGE permission in order to function properly.");
+ builder.setPositiveButton("Grant permission", (dialog, which) -> {
+ ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSION_EXTERNAL_STORAGE_STATE);
+ if (action.equals(Intent.ACTION_SEND)) {
+ requestPermissionsFallbackUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
+ }
+ });
+ builder.setNegativeButton("Deny permission", ((dialog, which) -> {
+ Toast.makeText(MainActivity.this, "Permission not granted, closing.", Toast.LENGTH_SHORT).show();
+ this.finish();
+ }));
+ builder.create().show();
}
}
} else {
- android.support.v7.app.AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle("Read storage permission required.");
- builder.setMessage("This application requires READ_EXTERNAL_STORAGE permission in order to function properly.");
- builder.setPositiveButton("Grant permission", (dialog, which) -> {
- ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_PERMISSION_EXTERNAL_STORAGE_STATE);
- if (action.equals(Intent.ACTION_SEND)) {
- requestPermissionsFallbackUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
- }
- });
- builder.setNegativeButton("Deny permission", ((dialog, which) -> {
- Toast.makeText(MainActivity.this, "Permission not granted, closing.", Toast.LENGTH_SHORT).show();
- this.finish();
- }));
- builder.create().show();
+ Toast.makeText(MainActivity.this, "Unhandled action sent to application, closing.", Toast.LENGTH_SHORT).show();
+ this.finish();
}
}
@@ -156,7 +186,6 @@ public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Thr
}
}
});
- // TODO: Display spinner until requestHandle.isFinished() is true
}
private boolean isPermissionGranted() {
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index c8fc93d..9515270 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -20,7 +20,7 @@
Reversee
- Recieved intent data (image share)
+ Received intent data (image share)
Handling google reverse image search.
Google request successful.
Found redirect URL, opening browser intent.
+ Parsing URL from share.
+ Unsupported file format from link.
+ Opening browser with shared URL