Fix: Parcelable

This commit is contained in:
zt515 2017-07-12 23:46:09 +08:00
parent d7ea4352ac
commit ad96f39646
15 changed files with 203 additions and 43 deletions

1
NeoLang/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

32
NeoLang/build.gradle Normal file
View File

@ -0,0 +1,32 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
buildscript {
ext.kotlin_version = '1.1.3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

4
NeoLang/example/main.neo Normal file
View File

@ -0,0 +1,4 @@
NeoLang {
version : 1
x-letter : ${NeoLang@version} >= 2
}

View File

@ -0,0 +1,10 @@
package io.neolang
/**
* @author kiva
*/
object Version {
const val MAJOR = 0
const val MINOR = 1
const val PATCH = 0
}

View File

@ -0,0 +1,10 @@
package io.neolang.token
/**
* @author kiva
*/
class Token {
lateinit var type: TokenType
lateinit var value: Any
lateinit var nextToken: Token
}

View File

@ -0,0 +1,40 @@
package io.neolang.token
/**
* @author kiva
*/
enum class TokenType {
TYPE_IDENTIFIER,
TYPE_STRING,
TYPE_INTEGER,
TYPE_BOOLEAN,
KEYWORD_DOLLAR, /* $ */
KEYWORD_USE /* @ */,
OPERATOR_BEGIN,
OPT_ADD, /* + */
OPT_SUB, /* - */
OPT_NAV, /* - (负号) */
OPT_MUL, /* * */
OPT_DIV, /* / */
OPT_MOD, /* % */
OPT_XOR, /* ^ */
OPT_AND, /* & */
OPT_OR, /* | */
LEFT_SHIFT, /* << */
RIGHT_SHIFT, /* >> */
OPERATOR_END,
LOGICAL_OPERATOR_BEGIN,
OPT_LAND, /* && */
OPT_LOR, /* || */
OPT_LE, /* <= */
OPT_LT, /* < */
OPT_GE, /* >= */
OPT_GT, /* > */
OPT_EQ, /* == */
OPT_NEQ, /* != */
OPT_NOT, /* ! */
LOGICAL_OPERATOR_END,
}

View File

@ -17,8 +17,8 @@ android {
applicationId "io.neoterm" applicationId "io.neoterm"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 25 targetSdkVersion 25
versionCode 8 versionCode 9
versionName "1.1.6" versionName "1.1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "zh" resConfigs "zh"
externalNativeBuild { externalNativeBuild {

View File

@ -24,6 +24,10 @@
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
-dontpreverify
-printmapping proguardMapping.txt
-keep class io.neoterm.backend.JNI { -keep class io.neoterm.backend.JNI {
*; *;
} }
@ -51,14 +55,14 @@
# <init>(java.lang.Throwable); # <init>(java.lang.Throwable);
#} #}
#rxjava
-dontwarn rx.**
#-keep class rx.** { *; }
#skf4j #skf4j
-dontwarn org.slf4j.** -dontwarn org.slf4j.**
-dontwarn sun.misc.** -dontwarn sun.misc.**
# RxJava
#-keep class rx.** { *; }
-dontwarn rx.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex; long producerIndex;
long consumerIndex; long consumerIndex;
@ -69,3 +73,24 @@
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode; rx.internal.util.atomic.LinkedQueueNode consumerNode;
} }
# Parcelable
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class * implements android.os.Parcelable {
public <fields>;
private <fields>;
}
# Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

View File

@ -11,10 +11,9 @@ import android.util.Pair;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -24,8 +23,8 @@ import java.util.zip.ZipInputStream;
import io.neoterm.R; import io.neoterm.R;
import io.neoterm.backend.EmulatorDebug; import io.neoterm.backend.EmulatorDebug;
import io.neoterm.preference.NeoPreference;
import io.neoterm.preference.NeoTermPath; import io.neoterm.preference.NeoTermPath;
import io.neoterm.utils.FileUtils;
public final class BaseFileInstaller { public final class BaseFileInstaller {
public interface ResultListener { public interface ResultListener {
@ -64,8 +63,9 @@ public final class BaseFileInstaller {
final byte[] buffer = new byte[8096]; final byte[] buffer = new byte[8096];
final List<Pair<String, String>> symlinks = new ArrayList<>(50); final List<Pair<String, String>> symlinks = new ArrayList<>(50);
final URL zipUrl = determineZipUrl(); HttpURLConnection connection = openBaseFileConnection();
HttpURLConnection connection = (HttpURLConnection) zipUrl.openConnection(); connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
totalBytes = connection.getContentLength(); totalBytes = connection.getContentLength();
try (ZipInputStream zipInput = new ZipInputStream(connection.getInputStream())) { try (ZipInputStream zipInput = new ZipInputStream(connection.getInputStream())) {
@ -171,12 +171,22 @@ public final class BaseFileInstaller {
}.start(); }.start();
} }
private static URL determineZipUrl() throws MalformedURLException { private static HttpURLConnection openBaseFileConnection() throws IOException {
String archName = determineArchName(); String arch = determineArchName();
String baseUrl = NeoTermPath.INSTANCE.getSERVER_BOOT_URL(); String baseUrl = NeoTermPath.INSTANCE.getDEFAULT_SOURCE();
return new URL(baseUrl + "/" + archName + ".zip");
// Use the same source
NeoPreference.INSTANCE.store(R.string.key_package_source, baseUrl);
return (HttpURLConnection) new URL(baseUrl + "/boot/" + arch + ".zip").openConnection();
} }
// private static URL determineZipUrl() throws MalformedURLException {
// String archName = determineArchName();
// String baseUrl = NeoTermPath.INSTANCE.getSERVER_BOOT_URL();
// return new URL(baseUrl + "/" + archName + ".zip");
// }
private static String determineArchName() { private static String determineArchName() {
for (String androidArch : Build.SUPPORTED_ABIS) { for (String androidArch : Build.SUPPORTED_ABIS) {
switch (androidArch) { switch (androidArch) {
@ -186,8 +196,8 @@ public final class BaseFileInstaller {
return "arm"; return "arm";
case "x86_64": case "x86_64":
return "x86_64"; return "x86_64";
case "x86": // case "x86":
return "i686"; // return "i686";
} }
} }
throw new RuntimeException("Unable to determine arch from Build.SUPPORTED_ABIS = " + throw new RuntimeException("Unable to determine arch from Build.SUPPORTED_ABIS = " +

View File

@ -3,6 +3,7 @@ package io.neoterm.preference
import android.Manifest import android.Manifest
import android.app.Activity import android.app.Activity
import android.app.AlertDialog import android.app.AlertDialog
import android.content.ActivityNotFoundException
import android.content.DialogInterface import android.content.DialogInterface
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
@ -28,17 +29,23 @@ object NeoPermission {
Manifest.permission.READ_CONTACTS)) { Manifest.permission.READ_CONTACTS)) {
AlertDialog.Builder(context).setMessage("需要存储权限来访问存储设备上的文件") AlertDialog.Builder(context).setMessage("需要存储权限来访问存储设备上的文件")
.setPositiveButton(android.R.string.ok, { _: DialogInterface, _: Int -> .setPositiveButton(android.R.string.ok, { _: DialogInterface, _: Int ->
ActivityCompat.requestPermissions(context, doRequestPermission(context, requestCode)
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
requestCode)
}) })
.show() .show()
} else { } else {
ActivityCompat.requestPermissions(context, doRequestPermission(context, requestCode)
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
requestCode)
} }
} }
} }
private fun doRequestPermission(context: Activity, requestCode: Int) {
try {
ActivityCompat.requestPermissions(context,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
requestCode)
} catch (ignore: ActivityNotFoundException) {
// for MIUI, we ignore it.
}
}
} }

View File

@ -22,8 +22,8 @@ object NeoTermPath {
const val SOURCE_FILE = "$USR_PATH/etc/apt/sources.list" const val SOURCE_FILE = "$USR_PATH/etc/apt/sources.list"
const val PACKAGE_LIST_DIR = "$USR_PATH/var/lib/apt/lists" const val PACKAGE_LIST_DIR = "$USR_PATH/var/lib/apt/lists"
private const val RELEASE_SOURCE = "https://mirrors.geekpie.org/neoterm" const val RELEASE_SOURCE = "https://mirrors.geekpie.org/neoterm"
private const val DEBUG_SOURCE = "http://192.243.117.135" const val DEBUG_SOURCE = "http://neoterm.studio"
val DEFAULT_SOURCE: String val DEFAULT_SOURCE: String
val SERVER_BASE_URL: String val SERVER_BASE_URL: String
@ -32,6 +32,6 @@ object NeoTermPath {
init { init {
DEFAULT_SOURCE = if (BuildConfig.DEBUG) DEBUG_SOURCE else RELEASE_SOURCE DEFAULT_SOURCE = if (BuildConfig.DEBUG) DEBUG_SOURCE else RELEASE_SOURCE
SERVER_BASE_URL = DEFAULT_SOURCE SERVER_BASE_URL = DEFAULT_SOURCE
SERVER_BOOT_URL = "${SERVER_BASE_URL}/boot" SERVER_BOOT_URL = "$SERVER_BASE_URL/boot"
} }
} }

View File

@ -30,6 +30,7 @@ import io.neoterm.preference.NeoTermPath
import io.neoterm.ui.pm.adapter.PackageAdapter import io.neoterm.ui.pm.adapter.PackageAdapter
import io.neoterm.ui.pm.model.PackageModel import io.neoterm.ui.pm.model.PackageModel
import io.neoterm.utils.FileUtils import io.neoterm.utils.FileUtils
import io.neoterm.utils.PackageUtils
import io.neoterm.view.TerminalDialog import io.neoterm.view.TerminalDialog
import java.io.File import java.io.File
import java.net.URL import java.net.URL
@ -171,9 +172,7 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen
private fun changeSourceInternal(source: String) { private fun changeSourceInternal(source: String) {
NeoPreference.store(R.string.key_package_source, source) NeoPreference.store(R.string.key_package_source, source)
PackageUtils.syncSource()
val sourceFile = File(NeoTermPath.SOURCE_FILE)
FileUtils.writeFile(sourceFile, generateSourceFile(source).toByteArray())
executeAptUpdate() executeAptUpdate()
} }
@ -220,15 +219,6 @@ class PackageManagerActivity : AppCompatActivity(), SearchView.OnQueryTextListen
}.start() }.start()
} }
private fun generateSourceFile(source: String): String {
return StringBuilder().append("# Generated by NeoTerm-Preference\n")
.append("deb ")
.append(source)
.append(" stable main")
.append("\n")
.toString()
}
private fun filter(models: List<PackageModel>, query: String?): List<PackageModel> { private fun filter(models: List<PackageModel>, query: String?): List<PackageModel> {
val filteredModelList = ArrayList<PackageModel>() val filteredModelList = ArrayList<PackageModel>()
if (query != null) { if (query != null) {

View File

@ -21,6 +21,7 @@ import io.neoterm.customize.pm.NeoPackageManagerUtils
import io.neoterm.customize.setup.BaseFileInstaller import io.neoterm.customize.setup.BaseFileInstaller
import io.neoterm.preference.NeoPreference import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath import io.neoterm.preference.NeoTermPath
import io.neoterm.utils.PackageUtils
import io.neoterm.view.TerminalDialog import io.neoterm.view.TerminalDialog
import java.util.* import java.util.*
@ -92,6 +93,7 @@ class SetupActivity : AppCompatActivity() {
resultListener = BaseFileInstaller.ResultListener { error -> resultListener = BaseFileInstaller.ResultListener { error ->
if (error == null) { if (error == null) {
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
PackageUtils.syncSource()
executeAptUpdate() executeAptUpdate()
} else { } else {
AlertDialog.Builder(this@SetupActivity) AlertDialog.Builder(this@SetupActivity)
@ -100,6 +102,7 @@ class SetupActivity : AppCompatActivity() {
.setNegativeButton(R.string.use_system_shell, { _, _ -> .setNegativeButton(R.string.use_system_shell, { _, _ ->
setResult(Activity.RESULT_CANCELED) setResult(Activity.RESULT_CANCELED)
nextButton.visibility = View.VISIBLE nextButton.visibility = View.VISIBLE
finish()
}) })
.setPositiveButton(R.string.retry, { dialog, _ -> .setPositiveButton(R.string.retry, { dialog, _ ->
dialog.dismiss() dialog.dismiss()
@ -156,10 +159,12 @@ class SetupActivity : AppCompatActivity() {
val packageName = item.title val packageName = item.title
val pm = NeoPackageManager.get() val pm = NeoPackageManager.get()
val packageInfo = pm.getPackageInfo(packageName) val packageInfo = pm.getPackageInfo(packageName)
val packageDesc = packageInfo.description if (packageInfo != null) {
toast.cancel() val packageDesc = packageInfo.description
toast.setText(packageDesc) toast.cancel()
toast.show() toast.setText(packageDesc)
toast.show()
}
} }
override fun onBubbleDeselected(item: PickerItem) { override fun onBubbleDeselected(item: PickerItem) {

View File

@ -0,0 +1,26 @@
package io.neoterm.utils
import io.neoterm.R
import io.neoterm.preference.NeoPreference
import io.neoterm.preference.NeoTermPath
import java.io.File
/**
* @author kiva
*/
object PackageUtils {
fun syncSource() {
val source = NeoPreference.loadString(R.string.key_package_source, NeoTermPath.DEFAULT_SOURCE)
val sourceFile = File(NeoTermPath.SOURCE_FILE)
FileUtils.writeFile(sourceFile, generateSourceFile(source).toByteArray())
}
private fun generateSourceFile(source: String): String {
return StringBuilder().append("# Generated by NeoTerm-Preference\n")
.append("deb ")
.append(source)
.append(" stable main")
.append("\n")
.toString()
}
}

View File

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