WIP
This commit is contained in:
parent
0cb1cbb35d
commit
9102d6ef87
6 changed files with 64 additions and 50 deletions
|
@ -1,26 +0,0 @@
|
||||||
package com.getcapacitor.myapp;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instrumented test, which will execute on an Android device.
|
|
||||||
*
|
|
||||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
|
||||||
*/
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class ExampleInstrumentedTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void useAppContext() throws Exception {
|
|
||||||
// Context of the app under test.
|
|
||||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
|
||||||
|
|
||||||
assertEquals("com.getcapacitor.app", appContext.getPackageName());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,9 +33,7 @@
|
||||||
<!-- Include one or more domains that should be verified. -->
|
<!-- Include one or more domains that should be verified. -->
|
||||||
<data android:host="app.mapcomplete.org" />
|
<data android:host="app.mapcomplete.org" />
|
||||||
<data android:path="/land.html" />
|
<data android:path="/land.html" />
|
||||||
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
|
@ -52,5 +50,4 @@
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
51
app/src/main/java/org/mapcomplete/Databridge.java
Normal file
51
app/src/main/java/org/mapcomplete/Databridge.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package org.mapcomplete;
|
||||||
|
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.getcapacitor.JSObject;
|
||||||
|
import com.getcapacitor.Plugin;
|
||||||
|
import com.getcapacitor.PluginCall;
|
||||||
|
import com.getcapacitor.PluginMethod;
|
||||||
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@CapacitorPlugin(name = "Echo")
|
||||||
|
public class Databridge extends Plugin {
|
||||||
|
|
||||||
|
private final Map<String, Consumer<PluginCall>> responders;
|
||||||
|
|
||||||
|
private static Consumer<PluginCall> answer(String answer) {
|
||||||
|
JSObject ret = new JSObject();
|
||||||
|
ret.put("value", answer);
|
||||||
|
Log.i("databridge","Resolving call");
|
||||||
|
return (PluginCall call) -> call.resolve(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A responder will be activated if the native code asks for it.
|
||||||
|
* Use call.setKeepAlive(true) for multiple responses
|
||||||
|
* @param responders
|
||||||
|
*/
|
||||||
|
public Databridge(Map<String, Consumer<PluginCall>> responders) {
|
||||||
|
this.responders = responders;
|
||||||
|
responders.put("meta", Databridge.answer("capacitator-shell 0.0.1;"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PluginMethod()
|
||||||
|
public void request(PluginCall call) {
|
||||||
|
String key = call.getString("key");
|
||||||
|
Log.i("databridge","Got a call: "+key);
|
||||||
|
var c= this.responders.get(key);
|
||||||
|
if(c != null){
|
||||||
|
c.accept(call);
|
||||||
|
}else{
|
||||||
|
call.reject("ERROR: no responder installed for "+key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,15 @@
|
||||||
package org.mapcomplete;
|
package org.mapcomplete;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.getcapacitor.BridgeActivity;
|
import com.getcapacitor.BridgeActivity;
|
||||||
|
|
||||||
public class MainActivity extends BridgeActivity {}
|
public class MainActivity extends BridgeActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
registerPlugin(Databridge.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package com.getcapacitor.myapp;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Example local unit test, which will execute on the development machine (host).
|
|
||||||
*
|
|
||||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
|
||||||
*/
|
|
||||||
public class ExampleUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void addition_isCorrect() throws Exception {
|
|
||||||
assertEquals(4, 2 + 2);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
ext {
|
ext {
|
||||||
minSdkVersion = 22
|
minSdkVersion = 24
|
||||||
compileSdkVersion = 34
|
compileSdkVersion = 34
|
||||||
targetSdkVersion = 34
|
targetSdkVersion = 34
|
||||||
androidxActivityVersion = '1.8.0'
|
androidxActivityVersion = '1.8.0'
|
||||||
|
@ -13,4 +13,4 @@ ext {
|
||||||
androidxJunitVersion = '1.1.5'
|
androidxJunitVersion = '1.1.5'
|
||||||
androidxEspressoCoreVersion = '3.5.1'
|
androidxEspressoCoreVersion = '3.5.1'
|
||||||
cordovaAndroidVersion = '10.1.1'
|
cordovaAndroidVersion = '10.1.1'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue