Improved navigation & startup time

This commit is contained in:
Dominic Letz 2021-09-17 12:05:13 +02:00
parent b654e7c895
commit 30d4e3a5b0
8 changed files with 107 additions and 10 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.iml
.gradle
/app/release
/local.properties
/.idea/caches
/.idea/libraries
@ -15,4 +16,4 @@
local.properties
/app/elixir-app
/app/src/main/assets/app.zip
/app/src/main/assets/app.zip.xz
/app/src/main/assets/app.zip.xz

View file

@ -57,6 +57,11 @@ android {
buildFeatures {
viewBinding true
}
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
}
dependencies {

View file

@ -18,4 +18,16 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile
-dontskipnonpubliclibraryclasses
-dontobfuscate
-forceprocessing
-optimizationpasses 5
-keep class * extends android.app.Activity
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.elixirdesktop.example">
package="io.elixirdesktop.example"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.INTERNET" />
@ -13,6 +14,17 @@
android:supportsRtl="true"
android:theme="@style/Theme.Default"
android:extractNativeLibs="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="io.elixirdesktop.example.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity android:name="io.elixirdesktop.example.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -20,5 +32,4 @@
</intent-filter>
</activity>
</application>
</manifest>
</manifest>

View file

@ -110,8 +110,8 @@ const char* startErlang(std::string root_dir, std::string log_dir)
"enabled",
"--",
// "-heart",
"-pa",
update_dir.c_str(),
// "-pa",
// update_dir.c_str(),
"-start_epmd",
"false",
//"-kernel",
@ -125,7 +125,7 @@ const char* startErlang(std::string root_dir, std::string log_dir)
"elixir",
"start_cli",
"-mode",
"embedded",
"interactive",
"-config",
config_path.c_str(),
"-boot",

View file

@ -1,5 +1,6 @@
package io.elixirdesktop.example
import android.content.ActivityNotFoundException
import android.content.Context
import android.os.Build
import android.system.Os
@ -12,8 +13,18 @@ import java.net.ServerSocket
import java.net.Socket
import kotlin.concurrent.thread
import java.io.*
import java.net.URI
import java.util.*
import java.util.zip.ZipInputStream
import androidx.core.content.ContextCompat.startActivity
import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.content.ContextCompat.startActivity
import io.elixirdesktop.example.MainActivity
class Bridge(private val applicationContext : Context, private var webview : WebView) {
@ -225,6 +236,15 @@ class Bridge(private val applicationContext : Context, private var webview : Web
lastURL = args.getString(1)
webview.post { webview.loadUrl(lastURL) }
}
if (method == ":launchDefaultBrowser") {
val uri = Uri.parse(args.getString(0))
if (uri.scheme == "http") {
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
applicationContext.startActivity(browserIntent)
} else if (uri.scheme == "file") {
openFile(uri.path)
}
}
var response = ref
response += if (method == ":getOsDescription") {
@ -253,6 +273,33 @@ class Bridge(private val applicationContext : Context, private var webview : Web
}
}
fun openFile(filename: String?) {
// Get URI and MIME type of file
val file = File(filename)
val uri =
FileProvider.getUriForFile(applicationContext, applicationContext.packageName + ".fileprovider", File(filename))
val mime: String? = if (file.isDirectory) {
"resource/folder"
} else {
applicationContext.contentResolver.getType(uri)
}
// Open file with user selected app
var intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.setDataAndType(uri, mime)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
intent = Intent.createChooser(intent, "")
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
try {
applicationContext.startActivity(intent)
} catch (e : ActivityNotFoundException) {
Log.d("Exception", e.toString())
}
}
private fun stringToList(str : String): String {
val numbers = str.toByteArray().map { it.toInt().toString() }
return "[${numbers.joinToString(",")}]"

View file

@ -2,7 +2,8 @@ package io.elixirdesktop.example
import android.app.Activity
import android.os.Bundle
import android.util.Base64
import android.system.Os
import android.view.KeyEvent
import android.view.View
import io.elixirdesktop.example.databinding.ActivityMainBinding
import java.io.*
@ -40,7 +41,23 @@ class MainActivity : Activity() {
}
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (event.action == KeyEvent.ACTION_DOWN) {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
if (binding.browser.canGoBack()) {
binding.browser.goBack()
} else {
finish()
}
return true
}
}
}
return super.onKeyDown(keyCode, event)
}
companion object {
var bridge: Bridge? = null
}
}
}

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="home" path="/"/>
</paths>