remoteInterface: fix setResult

This commit is contained in:
imkiva 2019-01-09 23:10:07 +08:00
parent 3e15bbd2f7
commit 121130bf22
No known key found for this signature in database
GPG Key ID: A0A40A816B1689AA
41 changed files with 765 additions and 29 deletions

1
NeoTermBridge/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,71 @@
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com/NeoTerm/NeoTerm.git'
def gitUrl = 'https://github.com/NeoTerm/NeoTerm.git'
def libraryGroup = "io.neoterm.bridge"
def libraryRepoName = "neoterm-bridge"
def libraryDesc = "Communicate with NeoTerm in an elegant way."
def libraryVersionCode = 1
def libraryVersionName = "1.0"
def libraryLicences = ["MIT"]
group = libraryGroup
version = libraryVersionName + "-" + libraryVersionCode
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name libraryDesc
url siteUrl
licenses {
license {
name 'The MIT Software License'
url 'https://mit-license.org/'
}
}
developers {
developer {
id 'imkiva'
name 'imKiva'
email 'libkernelpanic@gmail.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.file('../local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
name = libraryRepoName
websiteUrl = siteUrl
vcsUrl = gitUrl
dryRun = false
licenses = libraryLicences
publish = true
publicDownloadNumbers = true
}
}

View File

@ -0,0 +1,36 @@
apply plugin: 'com.android.library'
def libraryVersionCode = 1
def libraryVersionName = "1.0"
android {
compileSdkVersion rootProject.ext.android.COMPILE_SDK_VERSION
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion rootProject.ext.android.MIN_SDK_VERSION
targetSdkVersion rootProject.ext.android.TARGET_SDK_VERSION
versionCode libraryVersionCode
versionName libraryVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation rootProject.ext.deps["junit"]
}
apply from: 'bintray.gradle'

21
NeoTermBridge/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,26 @@
package io.neoterm.bridge;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* 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() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("io.neoterm.bridge.test", appContext.getPackageName());
}
}

View File

@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.neoterm.bridge" />

View File

@ -0,0 +1,60 @@
package io.neoterm.bridge;
import android.content.ComponentName;
import android.content.Intent;
import java.util.Objects;
/**
* @author kiva
*/
public class Bridge {
public static final String ACTION_EXECUTE = "neoterm.action.remote.execute";
public static final String ACTION_SILENT_RUN = "neoterm.action.remote.silent-run";
public static final String EXTRA_COMMAND = "neoterm.extra.remote.execute.command";
public static final String EXTRA_SESSION_ID = "neoterm.extra.remote.execute.session";
public static final String EXTRA_FOREGROUND = "neoterm.extra.remote.execute.foreground";
private static final String NEOTERM_PACKAGE = "io.neoterm";
private static final String NEOTERM_REMOTE_INTERFACE = "io.neoterm.ui.term.NeoTermRemoteInterface";
private static final ComponentName NEOTERM_COMPONENT = new ComponentName(NEOTERM_PACKAGE, NEOTERM_REMOTE_INTERFACE);
private Bridge() throws IllegalAccessException {
throw new IllegalAccessException();
}
public static Intent createExecuteIntent(SessionId sessionId,
String command,
boolean foreground) {
Objects.requireNonNull(command, "command");
Objects.requireNonNull(sessionId, "session id");
Intent intent = new Intent(ACTION_EXECUTE);
intent.setComponent(NEOTERM_COMPONENT);
intent.putExtra(EXTRA_COMMAND, command);
intent.putExtra(EXTRA_SESSION_ID, sessionId.getSessionId());
intent.putExtra(EXTRA_FOREGROUND, foreground);
return intent;
}
public static Intent createExecuteIntent(SessionId sessionId, String command) {
return createExecuteIntent(sessionId, command, true);
}
public static Intent createExecuteIntent(String command) {
return createExecuteIntent(SessionId.NEW_SESSION, command);
}
public static Intent createExecuteIntent(String command, boolean foreground) {
return createExecuteIntent(SessionId.NEW_SESSION, command, foreground);
}
public static SessionId parseResult(Intent data) {
Objects.requireNonNull(data, "data");
if (data.hasExtra(EXTRA_SESSION_ID)) {
String handle = data.getStringExtra(EXTRA_SESSION_ID);
return SessionId.of(handle);
}
return null;
}
}

View File

@ -0,0 +1,50 @@
package io.neoterm.bridge;
import java.util.Objects;
/**
* @author kiva
*/
public class SessionId {
/**
* Created a new session.
*/
public static final SessionId NEW_SESSION = SessionId.of("new");
/**
* Presents current session in NeoTerm.
*/
public static final SessionId CURRENT_SESSION = SessionId.of("current");
private final String sessionId;
SessionId(String sessionId) {
this.sessionId = sessionId;
}
public String getSessionId() {
return sessionId;
}
@Override
public String toString() {
return "TerminalSession { id = " + sessionId + " }";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SessionId sessionId1 = (SessionId) o;
return Objects.equals(sessionId, sessionId1.sessionId);
}
@Override
public int hashCode() {
return Objects.hash(sessionId);
}
public static SessionId of(String sessionId) {
return new SessionId(sessionId);
}
}

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">NeoTermBridge</string>
</resources>

View File

@ -0,0 +1,17 @@
package io.neoterm.bridge;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* 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() {
assertEquals(4, 2 + 2);
}
}

1
NeoTermBridgeExample/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,34 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "io.neoterm.bridge.example"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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'
implementation project(':NeoTermBridge')
}

21
NeoTermBridgeExample/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,26 @@
package io.neoterm.bridge.example;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* 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() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("io.neoterm.bridge.example", appContext.getPackageName());
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.neoterm.bridge.example">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,70 @@
package io.neoterm.bridge.example;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import io.neoterm.bridge.Bridge;
import io.neoterm.bridge.SessionId;
public class MainActivity extends Activity {
private static final int REQUEST_CODE_RUN = 1;
private static final int REQUEST_CODE_APPEND = 2;
private static final int REQUEST_CODE_APPEND_SILENTLY = 3;
private static final String COMMAND = "echo \"hello world\"";
private SessionId lastSessionId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onRunHelloWorld(View view) {
Intent intent = Bridge.createExecuteIntent(COMMAND);
startActivityForResult(intent, REQUEST_CODE_RUN);
}
public void onAppendHelloWorld(View view) {
if (lastSessionId == null) {
Toast.makeText(this, "Please run at least once",
Toast.LENGTH_SHORT).show();
}
Intent intent = Bridge.createExecuteIntent(lastSessionId, COMMAND);
startActivityForResult(intent, REQUEST_CODE_APPEND);
}
public void onAppendHelloWorldSilently(View view) {
if (lastSessionId == null) {
Toast.makeText(this, "Please run at least once",
Toast.LENGTH_SHORT).show();
}
Intent intent = Bridge.createExecuteIntent(lastSessionId, COMMAND, false);
startActivityForResult(intent, REQUEST_CODE_APPEND_SILENTLY);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
return;
}
switch (requestCode) {
case REQUEST_CODE_RUN:
lastSessionId = Bridge.parseResult(data);
break;
case REQUEST_CODE_APPEND:
Toast.makeText(this, "appended to " + lastSessionId.toString(), Toast.LENGTH_SHORT).show();
break;
case REQUEST_CODE_APPEND_SILENTLY:
Toast.makeText(this, "appended silently to " + lastSessionId.toString(), Toast.LENGTH_SHORT).show();
break;
}
}
}

View File

@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Run echo hello world"
android:onClick="onRunHelloWorld"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Append echo hello world"
android:onClick="onAppendHelloWorld"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Append echo hello world silently"
android:onClick="onAppendHelloWorldSilently"/>
</LinearLayout>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">NeoTermBridgeExample</string>
</resources>

View File

@ -0,0 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>

View File

@ -0,0 +1,17 @@
package io.neoterm.bridge.example;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* 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() {
assertEquals(4, 2 + 2);
}
}

View File

@ -9,8 +9,8 @@ android {
applicationId "io.neoterm"
minSdkVersion rootProject.ext.android.MIN_SDK_VERSION
targetSdkVersion rootProject.ext.android.TARGET_SDK_VERSION
versionCode 36
versionName "2.0.3"
versionCode 37
versionName "2.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "zh-rCN", "zh-rTW"
externalNativeBuild {
@ -74,6 +74,7 @@ dependencies {
implementation 'com.github.GrenderG:Color-O-Matic:1.1.5'
implementation project(':chrome-tabs')
implementation project(path: ':NeoLang')
implementation project(':NeoLang')
implementation project(':NeoTermBridge')
implementation project(':Xorg')
}

View File

@ -1,12 +1,13 @@
package io.neoterm.frontend.session.shell
import io.neoterm.backend.TerminalSession
import io.neoterm.bridge.SessionId
/**
* @author kiva
*/
class ShellParameter {
var sessionId: String? = null;
var sessionId: SessionId? = null
var executablePath: String? = null
var arguments: Array<String>? = null
var cwd: String? = null
@ -56,12 +57,12 @@ class ShellParameter {
return this
}
fun session(sessionId: String?): ShellParameter {
fun session(sessionId: SessionId?): ShellParameter {
this.sessionId = sessionId
return this
}
fun willCreateNewSession(): Boolean {
return sessionId == null
return sessionId?.equals(SessionId.NEW_SESSION) ?: true
}
}

View File

@ -13,6 +13,7 @@ import android.support.v4.app.NotificationCompat
import io.neoterm.R
import io.neoterm.backend.EmulatorDebug
import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.logging.NLog
import io.neoterm.frontend.session.shell.ShellParameter
import io.neoterm.frontend.session.xorg.XParameter
import io.neoterm.frontend.session.xorg.XSession
@ -109,14 +110,16 @@ class NeoTermService : Service() {
private fun createOrFindSession(parameter: ShellParameter): TerminalSession {
if (parameter.willCreateNewSession()) {
NLog.d("createOrFindSession: creating new session")
val session = TerminalUtils.createSession(this, parameter)
mTerminalSessions.add(session)
return session
}
// TODO: find session by id
val sessionId = parameter.sessionId!!
val session = mTerminalSessions.find { it.mHandle == sessionId }
NLog.d("createOrFindSession: find session by id $sessionId")
val session = mTerminalSessions.find { it.mHandle == sessionId.sessionId }
?: throw IllegalArgumentException("cannot find session by given id")
session.write(parameter.initialCommand + "\n")

View File

@ -13,6 +13,8 @@ import android.widget.ArrayAdapter
import android.widget.ListView
import io.neoterm.App
import io.neoterm.R
import io.neoterm.bridge.Bridge.*
import io.neoterm.bridge.SessionId
import io.neoterm.component.userscript.UserScript
import io.neoterm.component.userscript.UserScriptComponent
import io.neoterm.frontend.component.ComponentManager
@ -24,7 +26,6 @@ import io.neoterm.utils.MediaUtils
import io.neoterm.utils.TerminalUtils
import java.io.File
/**
* @author kiva
*/
@ -80,17 +81,15 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
when (intent.action) {
ACTION_EXECUTE -> {
if (!intent.hasExtra(EXTRA_COMMAND)) {
App.get().errorDialog(this, R.string.no_command_extra, { finish() })
App.get().errorDialog(this, R.string.no_command_extra)
{ finish() }
return
}
val command = intent.getStringExtra(EXTRA_COMMAND)
val foreground = intent.getBooleanExtra(EXTRA_FOREGROUND, true)
val session = if (intent.hasExtra(EXTRA_SESSION_ID)) {
intent.getStringExtra(EXTRA_SESSION_ID)
} else {
null
}
openTerm(command, session, foreground)
val session = intent.getStringExtra(EXTRA_SESSION_ID)
openTerm(command, SessionId.of(session), foreground)
}
else -> openTerm(null, null)
@ -199,6 +198,10 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
foreground: Boolean = true) {
val session = termService!!.createTermSession(parameter)
val data = Intent()
data.putExtra(EXTRA_SESSION_ID, session.mHandle)
setResult(Activity.RESULT_OK, data)
if (foreground) {
// Set current session to our new one
// In order to switch to it when entering NeoTermActivity
@ -209,14 +212,10 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
val data = Intent()
data.putExtra(EXTRA_SESSION_ID, session.mHandle)
setResult(Activity.RESULT_OK, data)
}
private fun openTerm(initialCommand: String?,
sessionId: String? = null,
sessionId: SessionId? = null,
foreground: Boolean = true) {
val parameter = ShellParameter()
.initialCommand(initialCommand)
@ -239,11 +238,4 @@ class NeoTermRemoteInterface : AppCompatActivity(), ServiceConnection {
private fun detectSystemShell(): Boolean {
return false
}
companion object {
const val ACTION_EXECUTE = "neoterm.action.remote.execute"
const val EXTRA_COMMAND = "neoterm.extra.remote.execute.command"
const val EXTRA_SESSION_ID = "neoterm.extra.remote.execute.session"
const val EXTRA_FOREGROUND = "neoterm.extra.remote.execute.foreground"
}
}

View File

@ -57,6 +57,9 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath rootProject.ext.deps["kotlin-gradle-plugin"]
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

View File

@ -1 +1 @@
include ':app', ':chrome-tabs', ':NeoLang', ':Xorg'
include ':app', ':chrome-tabs', ':NeoLang', ':Xorg', ':NeoTermBridge', ':NeoTermBridgeExample'