android progress
This commit is contained in:
parent
c2769cdf21
commit
9e31fb8058
@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.orastron.@NAME@">
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-sdk android:minSdkVersion="16" /> <!-- for miniaudio -->
|
||||
<uses-sdk android:minSdkVersion="26" /> <!-- for androidx core -->
|
||||
<uses-sdk android:targetSdkVersion="34" />
|
||||
<application android:label="@NAME@">
|
||||
<activity android:name=".MainActivity" android:label="@NAME@">
|
||||
<activity android:name=".MainActivity" android:label="@NAME@" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
@ -6,18 +6,44 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private WebView webView;
|
||||
|
||||
public class WebAppInterface {
|
||||
@JavascriptInterface
|
||||
public boolean hasAudioPermission() {
|
||||
return MainActivity.this.checkCallingOrSelfPermission(android.Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public boolean requestAudioPermission() {
|
||||
ActivityCompat.requestPermissions(MainActivity.this, new String[] { android.Manifest.permission.RECORD_AUDIO }, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
WebView webView = new WebView(this);
|
||||
webView = new WebView(this);
|
||||
setContentView(webView);
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webView.setWebChromeClient(new WebChromeClient());
|
||||
webView.setWebViewClient(new WebViewClient());
|
||||
webSettings.setDomStorageEnabled(true);
|
||||
webView.addJavascriptInterface(new WebAppInterface(), "Android");
|
||||
webView.loadUrl("file:///android_asset/index.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
if (grantResults.length > 0)
|
||||
webView.loadUrl("javascript:gotAudioPermission()");
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,14 @@
|
||||
COMMON_DIR := ${ROOT_DIR}/../../common/android
|
||||
BUILD_TOOLS_DIR := ${HOME}/Android/Sdk/build-tools/34.0.0
|
||||
ANDROIDX_DIR := ${HOME}/Android/androidx
|
||||
|
||||
JAR_FILE := ${HOME}/Android/Sdk/platforms/android-34/android.jar
|
||||
ANDROIDX_CORE_FILE := ${ANDROIDX_DIR}/core-1.10.1.jar
|
||||
ANDROIDX_LIFECYCLE_COMMON_FILE := ${ANDROIDX_DIR}/lifecycle-common-2.6.1.jar
|
||||
ANDROIDX_VERSIONEDPARCELABLE_FILE := ${ANDROIDX_DIR}/versionedparcelable-1.1.1.jar
|
||||
KOTLIN_STDLIB_FILE := ${HOME}/Android/kotlin/kotlin-stdlib-1.9.0.jar
|
||||
KOTLINX_COROUTINES_CORE_FILE := ${HOME}/Android/kotlin/kotlinx-coroutines-core-1.7.3.jar
|
||||
KOTLINX_COROUTINES_CORE_JVM_FILE := ${HOME}/Android/kotlin/kotlinx-coroutines-core-jvm-1.7.3.jar
|
||||
|
||||
JAVAC := javac
|
||||
KOTLINC := kotlinc
|
||||
@ -33,6 +41,15 @@ LDFLAGS := \
|
||||
SOURCES_COMMON := \
|
||||
${COMMON_DIR}/jni.cpp
|
||||
|
||||
JARS := \
|
||||
${JAR_FILE} \
|
||||
${ANDROIDX_CORE_FILE} \
|
||||
${ANDROIDX_LIFECYCLE_COMMON_FILE} \
|
||||
${ANDROIDX_VERSIONEDPARCELABLE_FILE} \
|
||||
${KOTLIN_STDLIB_FILE} \
|
||||
${KOTLINX_COROUTINES_CORE_FILE} \
|
||||
${KOTLINX_COROUTINES_CORE_JVM_FILE}
|
||||
|
||||
all: build/${NAME}.apk
|
||||
|
||||
build/${NAME}.apk: build/gen/${NAME}.aligned.apk build/apk/lib/armeabi-v7a/lib${NAME}.so build/gen/keystore.jks
|
||||
@ -45,22 +62,21 @@ build/gen/${NAME}.aligned.apk: build/gen/${NAME}.unsigned.apk
|
||||
${ZIPALIGN} -f -p 4 $^ $@
|
||||
|
||||
build/gen/${NAME}.unsigned.apk: build/apk/classes.dex build/gen/AndroidManifest.xml build/assets/index.html build/assets/config.js | build/gen
|
||||
#${AAPT} package -f -M build/gen/AndroidManifest.xml -I ${JAR_FILE} -F $@ build/apk
|
||||
#${AAPT} package -f -M build/gen/AndroidManifest.xml -S ${COMMON_DIR}/res -I ${JAR_FILE} -F $@ build/apk
|
||||
${AAPT} package -f -M build/gen/AndroidManifest.xml -A build/assets -I ${JAR_FILE} -F $@ build/apk
|
||||
${AAPT} package -f -M build/gen/AndroidManifest.xml -A build/assets -I ${JAR_FILE} -I ${ANDROIDX_CORE_FILE} -I ${ANDROIDX_LIFECYCLE_COMMON_FILE} -I ${ANDROIDX_VERSIONEDPARCELABLE_FILE} -I ${KOTLIN_STDLIB_FILE} -I ${KOTLINX_COROUTINES_CORE_FILE} -I ${KOTLINX_COROUTINES_CORE_JVM_FILE} -F $@ build/apk
|
||||
|
||||
build/apk/classes.dex: build/apk/my_classes.jar
|
||||
cd build/apk && ${BUILD_TOOLS_DIR}/d8 ../../$^ ${JAR_FILE} && cd ../..
|
||||
cd build/apk && ${BUILD_TOOLS_DIR}/d8 --min-api 21 ../../$^ ${JARS} && cd ../..
|
||||
|
||||
build/apk/my_classes.jar: build/obj/com/orastron/${NAME}/MainActivity.class | build/apk
|
||||
${D8} build/obj/com/orastron/${NAME}/MainActivity.class --output $@ --no-desugaring
|
||||
#${D8} $^ --output $@ --no-desugaring
|
||||
build/apk/my_classes.jar: build/obj/com/orastron/${NAME}/MainActivity.class build/obj/com/orastron/${NAME}/MainActivity$$WebAppInterface.class | build/apk
|
||||
${D8} build/obj/com/orastron/${NAME}/MainActivity.class 'build/obj/com/orastron/${NAME}/MainActivity$$WebAppInterface.class' --output $@ --no-desugaring
|
||||
|
||||
build/apk/lib/armeabi-v7a/lib${NAME}.so: ${SOURCES} | build/apk/lib/armeabi-v7a
|
||||
${CXX} $^ ${CXXFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
build/obj/com/orastron/${NAME}/MainActivity$$WebAppInterface.class: build/obj/com/orastron/${NAME}/MainActivity.class
|
||||
|
||||
build/obj/com/orastron/${NAME}/MainActivity.class: build/gen/com/orastron/${NAME}/MainActivity.java | build/obj
|
||||
${JAVAC} -classpath ${JAR_FILE} -d build/obj build/gen/com/orastron/${NAME}/MainActivity.java
|
||||
${JAVAC} -classpath "${JAR_FILE}:${ANDROIDX_CORE_FILE}:${ANDROIDX_LIFECYCLE_COMMON_FILE}:${ANDROIDX_VERSIONEDPARCELABLE_FILE}:${KOTLIN_STDLIB_FILE}:${KOTLINX_COROUTINES_CORE_FILE}:${KOTLINX_COROUTINES_CORE_JVM_FILE}" -d build/obj build/gen/com/orastron/${NAME}/MainActivity.java
|
||||
|
||||
build/gen/com/orastron/${NAME}/MainActivity.java: ${COMMON_DIR}/MainActivity.java | build/gen/com/orastron/${NAME}
|
||||
cat $^ | sed s:@NAME@:${NAME}:g > $@
|
||||
|
@ -2,13 +2,62 @@
|
||||
<head>
|
||||
<script type="text/javascript" src="config.js"></script>
|
||||
<script type="text/javascript">
|
||||
var hasAudioPermission = Android.hasAudioPermission();
|
||||
var topButtonElem;
|
||||
|
||||
window.onload = function () {
|
||||
var elemDiv = document.createElement('pre');
|
||||
elemDiv.innerText = JSON.stringify(parameters, null, 2);
|
||||
document.body.appendChild(elemDiv);
|
||||
topButtonElem = document.getElementById("topButton");
|
||||
topButtonElem.value = hasAudioPermission ? "START" : "INIT";
|
||||
topButtonElem.addEventListener("click", function () {
|
||||
if (hasAudioPermission) {
|
||||
for (var i = 0; i < parameters.length; i++) {
|
||||
var div = document.createElement("div");
|
||||
document.body.appendChild(div);
|
||||
|
||||
var label = document.createElement("label");
|
||||
label.innerText = parameters[i].name;
|
||||
div.appendChild(label);
|
||||
|
||||
div.appendChild(document.createElement("br"));
|
||||
|
||||
var range = document.createElement("input");
|
||||
range.classList.add("range");
|
||||
range.setAttribute("type", "range");
|
||||
range.setAttribute("id", "p" + i);
|
||||
range.setAttribute("min", 0);
|
||||
range.setAttribute("max", 1);
|
||||
range.setAttribute("step", parameters[i].step ? 1 / parameters[i].step : "any");
|
||||
range.value = parameters[i].defaultValue;
|
||||
if (parameters[i].output)
|
||||
range.setAttribute("readonly", true);
|
||||
div.appendChild(range);
|
||||
}
|
||||
}
|
||||
else
|
||||
Android.requestAudioPermission();
|
||||
});
|
||||
};
|
||||
|
||||
function gotAudioPermission() {
|
||||
hasAudioPermission = true;
|
||||
topButtonElem.value = "START";
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
#topButton {
|
||||
width: 100%;
|
||||
background-color: #04aa6d;
|
||||
color: white;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.range {
|
||||
width: 80%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<input id="topButton" type="button">
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user