diff --git a/android/app/app.iml b/android/app/app.iml index 5eda7aaa..418506f8 100644 --- a/android/app/app.iml +++ b/android/app/app.iml @@ -42,7 +42,7 @@ @@ -149,31 +149,32 @@ + - + + + - - + - diff --git a/android/app/build.gradle b/android/app/build.gradle index b654a1b5..33631428 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -24,9 +24,9 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support.constraint:constraint-layout:1.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 838b119d..992e1612 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.mozilla.send.sendandroid"> + - - @@ -30,7 +29,6 @@ - \ No newline at end of file diff --git a/android/app/src/main/assets/index.html b/android/app/src/main/assets/index.html new file mode 100644 index 00000000..73434fe9 --- /dev/null +++ b/android/app/src/main/assets/index.html @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + Firefox Send + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + +
+
Private, Encrypted File Sharing
+
+
Send files through a safe, private, and encrypted link that automatically expires to ensure your stuff does not remain online forever.
+ + Learn more + +
+
+ +
+ Drop your file here to start uploading +
+ + For the most reliable operation, it’s best to keep your file under 1GB + + + +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/android/app/src/main/assets/intent-target.html b/android/app/src/main/assets/intent-target.html new file mode 100644 index 00000000..17a43f44 --- /dev/null +++ b/android/app/src/main/assets/intent-target.html @@ -0,0 +1,20 @@ + + + + + + Firefox Send + + + +
output
+ + + + \ No newline at end of file diff --git a/android/app/src/main/java/com/mozilla/send/sendandroid/IntentActivity.kt b/android/app/src/main/java/com/mozilla/send/sendandroid/IntentActivity.kt deleted file mode 100644 index f518da3b..00000000 --- a/android/app/src/main/java/com/mozilla/send/sendandroid/IntentActivity.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.mozilla.send.sendandroid - - -import android.support.v7.app.AppCompatActivity -import android.os.Bundle -import android.content.Intent -import android.util.Log -import android.net.Uri - -class IntentActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - val intent = getIntent() - val action = intent.getAction() - val type = intent.getType() - if (Intent.ACTION_SEND.equals(action) && type != null) { - if ("text/plain".equals(type)) { - val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT) - Log.w("INTENT", "text/plain " + sharedText); - } else if (type.startsWith("image/")) { - val imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM) as Uri - - Log.w("INTENT", "image/ " + imageUri); - } - } - } -} diff --git a/android/app/src/main/java/com/mozilla/send/sendandroid/MainActivity.kt b/android/app/src/main/java/com/mozilla/send/sendandroid/MainActivity.kt index e362501e..fc123456 100644 --- a/android/app/src/main/java/com/mozilla/send/sendandroid/MainActivity.kt +++ b/android/app/src/main/java/com/mozilla/send/sendandroid/MainActivity.kt @@ -7,11 +7,23 @@ import im.delight.android.webview.AdvancedWebView import android.graphics.Bitmap import android.content.Intent import android.annotation.SuppressLint +import android.net.Uri import android.webkit.WebView +import android.webkit.WebMessage import android.util.Log +import android.util.Base64 +import android.provider.MediaStore +import android.R.attr.data + + + + + + class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { private var mWebView: AdvancedWebView? = null + private var mToShare: String? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -23,7 +35,28 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { val webSettings = mWebView!!.getSettings() webSettings.setJavaScriptEnabled(true) - mWebView!!.loadUrl("https://send.firefox.com") + val intent = getIntent() + val action = intent.getAction() + val type = intent.getType() + if (Intent.ACTION_SEND.equals(action) && type != null) { + if (type.equals("text/plain")) { + val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT) + Log.w("INTENT", "text/plain " + sharedText) + mToShare = "data:text/plain;base64," + Base64.encodeToString(sharedText.toByteArray(), 16).trim() + } else if (type.startsWith("image/")) { + val imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM) as Uri + Log.w("INTENT", "image/ " + imageUri) + mToShare = "data:text/plain;base64," + Base64.encodeToString(imageUri.path.toByteArray(), 16).trim() + + // TODO Currently this causes a Permission Denied error + // val stream = contentResolver.openInputStream(imageUri) + } + mWebView!!.loadUrl("file:///android_asset/intent-target.html") + + } else { + mWebView!!.loadUrl("file:///android_asset/index.html") + } + } @SuppressLint("NewApi") @@ -66,6 +99,13 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { override fun onPageFinished(url: String) { Log.w("MAIN", "onPageFinished") + if (mToShare != null) { + Log.w("INTENT", mToShare) + + val webView = findViewById(R.id.webview) as AdvancedWebView + webView.postWebMessage(WebMessage(mToShare), Uri.EMPTY) + } + } override fun onPageError(errorCode: Int, description: String, failingUrl: String) { diff --git a/android/build.gradle b/android/build.gradle index 521fee58..7c715ccf 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.30' + ext.kotlin_version = '1.2.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.android.tools.build:gradle:3.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong