Skip to content

Commit 121130b

Browse files
committed
remoteInterface: fix setResult
1 parent 3e15bbd commit 121130b

File tree

41 files changed

+765
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+765
-29
lines changed

NeoTermBridge/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

NeoTermBridge/bintray.gradle

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apply plugin: 'com.github.dcendents.android-maven'
2+
apply plugin: 'com.jfrog.bintray'
3+
4+
def siteUrl = 'https://github.com/NeoTerm/NeoTerm.git'
5+
def gitUrl = 'https://github.com/NeoTerm/NeoTerm.git'
6+
def libraryGroup = "io.neoterm.bridge"
7+
def libraryRepoName = "neoterm-bridge"
8+
def libraryDesc = "Communicate with NeoTerm in an elegant way."
9+
def libraryVersionCode = 1
10+
def libraryVersionName = "1.0"
11+
def libraryLicences = ["MIT"]
12+
13+
group = libraryGroup
14+
version = libraryVersionName + "-" + libraryVersionCode
15+
16+
install {
17+
repositories.mavenInstaller {
18+
pom {
19+
project {
20+
packaging 'aar'
21+
name libraryDesc
22+
url siteUrl
23+
licenses {
24+
license {
25+
name 'The MIT Software License'
26+
url 'https://mit-license.org/'
27+
}
28+
}
29+
developers {
30+
developer {
31+
id 'imkiva'
32+
name 'imKiva'
33+
34+
}
35+
}
36+
scm {
37+
connection gitUrl
38+
developerConnection gitUrl
39+
url siteUrl
40+
}
41+
}
42+
}
43+
}
44+
}
45+
46+
task sourcesJar(type: Jar) {
47+
from android.sourceSets.main.java.srcDirs
48+
classifier = 'sources'
49+
}
50+
51+
artifacts {
52+
archives sourcesJar
53+
}
54+
55+
Properties properties = new Properties()
56+
properties.load(project.file('../local.properties').newDataInputStream())
57+
bintray {
58+
user = properties.getProperty("bintray.user")
59+
key = properties.getProperty("bintray.apikey")
60+
configurations = ['archives']
61+
pkg {
62+
repo = "maven"
63+
name = libraryRepoName
64+
websiteUrl = siteUrl
65+
vcsUrl = gitUrl
66+
dryRun = false
67+
licenses = libraryLicences
68+
publish = true
69+
publicDownloadNumbers = true
70+
}
71+
}

NeoTermBridge/build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'com.android.library'
2+
3+
def libraryVersionCode = 1
4+
def libraryVersionName = "1.0"
5+
6+
android {
7+
compileSdkVersion rootProject.ext.android.COMPILE_SDK_VERSION
8+
buildToolsVersion '28.0.3'
9+
10+
defaultConfig {
11+
minSdkVersion rootProject.ext.android.MIN_SDK_VERSION
12+
targetSdkVersion rootProject.ext.android.TARGET_SDK_VERSION
13+
versionCode libraryVersionCode
14+
versionName libraryVersionName
15+
16+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17+
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
}
27+
28+
dependencies {
29+
implementation fileTree(dir: 'libs', include: ['*.jar'])
30+
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
31+
exclude group: 'com.android.support', module: 'support-annotations'
32+
})
33+
testImplementation rootProject.ext.deps["junit"]
34+
}
35+
36+
apply from: 'bintray.gradle'

NeoTermBridge/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.neoterm.bridge;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("io.neoterm.bridge.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.neoterm.bridge" />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package io.neoterm.bridge;
2+
3+
import android.content.ComponentName;
4+
import android.content.Intent;
5+
6+
import java.util.Objects;
7+
8+
/**
9+
* @author kiva
10+
*/
11+
public class Bridge {
12+
public static final String ACTION_EXECUTE = "neoterm.action.remote.execute";
13+
public static final String ACTION_SILENT_RUN = "neoterm.action.remote.silent-run";
14+
public static final String EXTRA_COMMAND = "neoterm.extra.remote.execute.command";
15+
public static final String EXTRA_SESSION_ID = "neoterm.extra.remote.execute.session";
16+
public static final String EXTRA_FOREGROUND = "neoterm.extra.remote.execute.foreground";
17+
private static final String NEOTERM_PACKAGE = "io.neoterm";
18+
private static final String NEOTERM_REMOTE_INTERFACE = "io.neoterm.ui.term.NeoTermRemoteInterface";
19+
private static final ComponentName NEOTERM_COMPONENT = new ComponentName(NEOTERM_PACKAGE, NEOTERM_REMOTE_INTERFACE);
20+
21+
private Bridge() throws IllegalAccessException {
22+
throw new IllegalAccessException();
23+
}
24+
25+
public static Intent createExecuteIntent(SessionId sessionId,
26+
String command,
27+
boolean foreground) {
28+
Objects.requireNonNull(command, "command");
29+
Objects.requireNonNull(sessionId, "session id");
30+
31+
Intent intent = new Intent(ACTION_EXECUTE);
32+
intent.setComponent(NEOTERM_COMPONENT);
33+
intent.putExtra(EXTRA_COMMAND, command);
34+
intent.putExtra(EXTRA_SESSION_ID, sessionId.getSessionId());
35+
intent.putExtra(EXTRA_FOREGROUND, foreground);
36+
return intent;
37+
}
38+
39+
public static Intent createExecuteIntent(SessionId sessionId, String command) {
40+
return createExecuteIntent(sessionId, command, true);
41+
}
42+
43+
public static Intent createExecuteIntent(String command) {
44+
return createExecuteIntent(SessionId.NEW_SESSION, command);
45+
}
46+
47+
public static Intent createExecuteIntent(String command, boolean foreground) {
48+
return createExecuteIntent(SessionId.NEW_SESSION, command, foreground);
49+
}
50+
51+
public static SessionId parseResult(Intent data) {
52+
Objects.requireNonNull(data, "data");
53+
54+
if (data.hasExtra(EXTRA_SESSION_ID)) {
55+
String handle = data.getStringExtra(EXTRA_SESSION_ID);
56+
return SessionId.of(handle);
57+
}
58+
return null;
59+
}
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.neoterm.bridge;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* @author kiva
7+
*/
8+
public class SessionId {
9+
/**
10+
* Created a new session.
11+
*/
12+
public static final SessionId NEW_SESSION = SessionId.of("new");
13+
14+
/**
15+
* Presents current session in NeoTerm.
16+
*/
17+
public static final SessionId CURRENT_SESSION = SessionId.of("current");
18+
19+
private final String sessionId;
20+
21+
SessionId(String sessionId) {
22+
this.sessionId = sessionId;
23+
}
24+
25+
public String getSessionId() {
26+
return sessionId;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "TerminalSession { id = " + sessionId + " }";
32+
}
33+
34+
@Override
35+
public boolean equals(Object o) {
36+
if (this == o) return true;
37+
if (o == null || getClass() != o.getClass()) return false;
38+
SessionId sessionId1 = (SessionId) o;
39+
return Objects.equals(sessionId, sessionId1.sessionId);
40+
}
41+
42+
@Override
43+
public int hashCode() {
44+
return Objects.hash(sessionId);
45+
}
46+
47+
public static SessionId of(String sessionId) {
48+
return new SessionId(sessionId);
49+
}
50+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">NeoTermBridge</string>
3+
</resources>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.neoterm.bridge;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11+
*/
12+
public class ExampleUnitTest {
13+
@Test
14+
public void addition_isCorrect() {
15+
assertEquals(4, 2 + 2);
16+
}
17+
}

0 commit comments

Comments
 (0)