├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── discord.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── openblocks │ │ └── moduleinterface │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── openblocks │ └── moduleinterface │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── openblocks │ │ └── moduleinterface │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── openblocks │ │ └── moduleinterface │ │ ├── OpenBlocksModule.java │ │ ├── api │ │ ├── OpenBlocksAPI.java │ │ └── ResourceManager.java │ │ ├── callbacks │ │ ├── Logger.java │ │ └── SaveCallback.java │ │ ├── exceptions │ │ ├── CompileException.java │ │ ├── NotSupportedException.java │ │ └── ParseException.java │ │ ├── models │ │ ├── OpenBlocksFile.java │ │ ├── OpenBlocksProjectMetadata.java │ │ ├── OpenBlocksRawProject.java │ │ ├── code │ │ │ ├── BlockCode.java │ │ │ ├── BlockCodeNest.java │ │ │ └── ParseBlockTask.java │ │ ├── compiler │ │ │ └── IncludedBinary.java │ │ ├── config │ │ │ ├── OpenBlocksConfig.java │ │ │ └── OpenBlocksConfigItem.java │ │ └── layout │ │ │ └── LayoutViewXMLAttribute.java │ │ └── projectfiles │ │ ├── OpenBlocksCode.java │ │ └── OpenBlocksLayout.java │ └── test │ └── java │ └── com │ └── openblocks │ └── moduleinterface │ └── ExampleUnitTest.java └── settings.gradle /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Java CI with Gradle 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | - name: Build with Gradle 26 | run: ./gradlew build 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | OpenBlocks Module Interface -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/discord.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, OpenBlocks 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenBlocks Module Interface 2 | An interface for developing OpenBlocks modules. To create your own OpenBlocks module, check [openblocks-module-template](https://github.com/OpenBlocksTeam/openblocks-module-template) 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdkVersion 30 7 | buildToolsVersion "30.0.3" 8 | 9 | defaultConfig { 10 | applicationId "com.openblocks.communicator" 11 | minSdkVersion 21 12 | targetSdkVersion 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | } 30 | 31 | dependencies { 32 | 33 | implementation 'androidx.appcompat:appcompat:1.2.0' 34 | implementation 'com.google.android.material:material:1.3.0' 35 | testImplementation 'junit:junit:4.+' 36 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 38 | } 39 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/openblocks/moduleinterface/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.openblocks.communicator", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OpenBlocks Module Communicator 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/openblocks/moduleinterface/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface; 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 Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:4.1.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | google() 18 | jcenter() 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Feb 20 14:02:51 WIB 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | } 4 | 5 | android { 6 | compileSdkVersion 30 7 | buildToolsVersion "30.0.3" 8 | 9 | defaultConfig { 10 | minSdkVersion 21 11 | targetSdkVersion 30 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles "consumer-rules.pro" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_7 27 | targetCompatibility JavaVersion.VERSION_1_7 28 | } 29 | } 30 | 31 | dependencies { 32 | 33 | implementation 'androidx.appcompat:appcompat:1.2.0' 34 | implementation 'com.google.android.material:material:1.3.0' 35 | testImplementation 'junit:junit:4.+' 36 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 38 | } 39 | -------------------------------------------------------------------------------- /lib/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenBlocksTeam/openblocks-module-interface/b7a303bd091d66560749f1918b715fb85b488f26/lib/consumer-rules.pro -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/openblocks/moduleinterface/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.openbloks.communicator.test", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/OpenBlocksModule.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | 6 | import androidx.annotation.NonNull; 7 | 8 | import com.openblocks.moduleinterface.callbacks.Logger; 9 | import com.openblocks.moduleinterface.callbacks.SaveCallback; 10 | import com.openblocks.moduleinterface.exceptions.CompileException; 11 | import com.openblocks.moduleinterface.exceptions.NotSupportedException; 12 | import com.openblocks.moduleinterface.exceptions.ParseException; 13 | import com.openblocks.moduleinterface.models.OpenBlocksFile; 14 | import com.openblocks.moduleinterface.models.OpenBlocksProjectMetadata; 15 | import com.openblocks.moduleinterface.models.OpenBlocksRawProject; 16 | import com.openblocks.moduleinterface.models.code.ParseBlockTask; 17 | import com.openblocks.moduleinterface.models.code.BlockCode; 18 | import com.openblocks.moduleinterface.models.compiler.IncludedBinary; 19 | import com.openblocks.moduleinterface.models.config.OpenBlocksConfig; 20 | import com.openblocks.moduleinterface.projectfiles.OpenBlocksCode; 21 | import com.openblocks.moduleinterface.projectfiles.OpenBlocksLayout; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | 26 | // TODO: 5/1/21 Make these to be abstract instead 27 | 28 | public interface OpenBlocksModule { 29 | 30 | /** 31 | * This function is used to indicate what type of module is this? 32 | * OpenBlocks need at least 1 module for each type for it to work 33 | * 34 | * NOTE: Do not return the wrong module type, as it can cause the app to be unstable 35 | * 36 | * @return This current module type 37 | */ 38 | Type getType(); 39 | 40 | 41 | /** 42 | * This function will be called everytime the module is loaded 43 | * 44 | * @param context The context of where the module is loaded 45 | * @param logger The logger where you can log stuff 46 | */ 47 | void initialize(Context context, Logger logger); 48 | 49 | 50 | 51 | /* OpenBlocksConfig is a set of Config Items, where you can create a configuration that can be 52 | Edited by the user */ 53 | 54 | /** 55 | * This function is called when the user requests this specific module's configuration 56 | * 57 | * @return This module's configuration 58 | */ 59 | OpenBlocksConfig setupConfig(); 60 | 61 | /** 62 | * This function is used to save / apply configuration that is retrieved from setupConfig() 63 | * and has been edited / configured by the user itself. 64 | * 65 | * @param config The new configuration 66 | */ 67 | void applyConfig(OpenBlocksConfig config); 68 | 69 | 70 | /** 71 | * This enum is used to identify what module is this? 72 | * one of this enums should be returned on OpenBlockModule.getType() 73 | */ 74 | enum Type { 75 | PROJECT_MANAGER, 76 | PROJECT_PARSER, 77 | PROJECT_LAYOUT_GUI, 78 | PROJECT_CODE_GUI, 79 | PROJECT_COMPILER, 80 | BLOCKS_COLLECTION 81 | } 82 | 83 | 84 | /** 85 | * Project Manager is used to manage on where the project is, how can it be accessed, how 86 | * to write to it, and how to list them. 87 | *
88 | * TL;DR This module manages the file access of the project (read, write, delete, etc) 89 | */ 90 | interface ProjectManager extends OpenBlocksModule { 91 | /* Self-explanatory */ 92 | void saveProject(OpenBlocksRawProject project); 93 | OpenBlocksRawProject getProject (String project_id); 94 | 95 | /** 96 | * This function is used to list every projects 97 | * @return A List of OpenBlocksProjects 98 | */ 99 | ArrayList listProjects(); 100 | 101 | /** 102 | * This function is used to check if a project with 103 | * the specified id exists 104 | * @param project_id The project id 105 | * @return Does the project with the project id exists? 106 | */ 107 | boolean projectExists(String project_id); 108 | 109 | /* 110 | * exportProject() should export the provided project into a single file 111 | * 112 | * importProject() should imports the provided input into a project 113 | */ 114 | 115 | /** 116 | * This function is used to export an OpenBlocksProject into a single file 117 | * 118 | * @param project The project 119 | * @return The exported file 120 | * @throws NotSupportedException Throw this if you don't support this function 121 | */ 122 | OpenBlocksFile exportProject(OpenBlocksRawProject project) throws NotSupportedException; 123 | 124 | /** 125 | * This function is used to import a file / data that has been exported on exportProject 126 | * into OpenBlocksProject 127 | * 128 | * @param input The file 129 | * @return The imported project 130 | * @throws NotSupportedException Throw this if you don't support this function 131 | */ 132 | OpenBlocksRawProject importProject(OpenBlocksFile input) throws NotSupportedException; 133 | } 134 | 135 | /** 136 | * Project Parser is used to parse a raw project (that you can get from using the ProjectManager) 137 | * into OpenBlocksLayout and OpenBlocksCode, that will later be displayed to the user 138 | *
139 | *
140 | *

TL;DR

141 | * This module manages: 142 | * 146 | */ 147 | interface ProjectParser extends OpenBlocksModule { 148 | 149 | /** 150 | * This function is used to generate a Free ID that will be used 151 | * to create a new project 152 | * @param existing_ids project IDs that already exists 153 | * @return The free ID 154 | */ 155 | String generateFreeId (ArrayList existing_ids); 156 | 157 | /** 158 | * This function is used to parse the raw project into a layout 159 | * 160 | * @param project The project 161 | * @return The parsed layout from the provided project 162 | * @throws ParseException When something goes wrong while parsing layout 163 | */ 164 | @NonNull 165 | OpenBlocksLayout parseLayout (OpenBlocksRawProject project) throws ParseException; 166 | 167 | /** 168 | * This function is used to parse the raw project into a code 169 | * @param project The project 170 | * @return The parsed code from the provided project 171 | * @throws ParseException When something goes wrong while parsing the code 172 | */ 173 | @NonNull 174 | OpenBlocksCode parseCode (OpenBlocksRawProject project) throws ParseException; 175 | 176 | /** 177 | * This function is used to parse the raw project to get it's metadata 178 | * @param project The project 179 | * @return The parsed code from the provided project 180 | * @throws ParseException When something goes wrong while parsing the metadata 181 | */ 182 | @NonNull 183 | OpenBlocksProjectMetadata parseMetadata (OpenBlocksRawProject project) throws ParseException; 184 | 185 | /** 186 | * This function is used to save a code, layout, and metadata into one 187 | * single raw project (list of files) 188 | * @param metadata The project's metadata 189 | * @param code The project's code 190 | * @param layout The project's layout 191 | * @return The raw project containing files representation of these metadata, code and layout 192 | */ 193 | @NonNull 194 | OpenBlocksRawProject saveProject (OpenBlocksProjectMetadata metadata, 195 | OpenBlocksCode code, 196 | OpenBlocksLayout layout); 197 | } 198 | 199 | /** 200 | * ProjectLayoutGUI is used to display / edit the layout, this module should inflate a layout 201 | * into the provided `View layout` 202 | *
203 | * TL;DR This module manages the layout editor 204 | */ 205 | interface ProjectLayoutGUI extends OpenBlocksModule { 206 | 207 | /** 208 | * This function is used to show the layout editor in the provided layout to inflate to. 209 | * 210 | * @param context The context 211 | * @param layout The layout where you should be putting / inflating your views 212 | * @param code_data The code of this project, used for reference 213 | * @param layout_data The layout data to be displayed 214 | * @param saveCallback The callback everytime this has to be saved 215 | */ 216 | void show(Context context, ViewGroup layout, OpenBlocksCode code_data, OpenBlocksLayout layout_data, OpenBlocksProjectMetadata metadata, SaveCallback saveCallback); 217 | 218 | /** 219 | * This function is used to initialize a new layout 220 | * @return An initialized {@link OpenBlocksLayout} 221 | */ 222 | OpenBlocksLayout initializeNewLayout(); 223 | } 224 | 225 | /** 226 | * ProjectCodeGUI is used to display / edit the Code, this module should inflate a layout 227 | * into the provided `View layout` 228 | */ 229 | interface ProjectCodeGUI extends OpenBlocksModule { 230 | 231 | /** 232 | * This function is used to show the code / block code editor in the provided layout to inflate to. 233 | * 234 | * @param context The context 235 | * @param layout The layout where you should be putting / inflating your views 236 | * @param code_data The code data to be displayed 237 | * @param layout_data The layout of this project, used for reference 238 | * @param saveCallback The callback everytime this has to be saved 239 | */ 240 | void show(Context context, ViewGroup layout, OpenBlocksCode code_data, OpenBlocksLayout layout_data, OpenBlocksProjectMetadata metadata, SaveCallback saveCallback); 241 | } 242 | 243 | /** 244 | * Collection of blocks, initialize(), getConfig(), saveConfig() are ignored, 245 | * see the example module for an easier understanding 246 | */ 247 | interface BlocksCollection extends OpenBlocksModule { 248 | 249 | /** 250 | * This function is used to initialize a new OpenBlocks code 251 | * @param blocks A list of blocks parsed from {@link #getBlocks()} 252 | * @return An initialized {@link OpenBlocksCode} 253 | */ 254 | OpenBlocksCode initializeNewCode(ArrayList blocks); 255 | 256 | /** 257 | * This function is used to fetch blocks that will be used and displayed using the {@link ProjectCodeGUI} 258 | * @return Simply put, this: Object[Object[Class block_type, int color, String opcode, String format, ParseBlockTask]] 259 | */ 260 | Object[] getBlocks(); 261 | } 262 | 263 | /** 264 | * ProjectCompiler is used to compile the code and the layout together into an APK at the 265 | * provided location 266 | *
267 | * TL;DR This project compiles the code and layout into an APK at the specified location 268 | */ 269 | interface ProjectCompiler extends OpenBlocksModule { 270 | 271 | /** 272 | * This function initializes the compiler module with included 273 | * essential build tools' binaries like aapt, aapt2, and zipalign 274 | * @param includedBinaries A list of binaries included within the app 275 | * @param blocks A HashMap of opcode and ParseBlockTask, used to parse blocks into java code by the compiler 276 | */ 277 | void initializeCompiler(ArrayList includedBinaries, HashMap blocks); 278 | 279 | /** 280 | * This function is used to compile the code and the layout into an APK file at the specified 281 | * location 282 | * @param metadata The project metadata, contains app name, app package, etc 283 | * @param code The code 284 | * @param layout The layout 285 | * @param location The location where the APK should be saved 286 | * @throws CompileException Exception when there is something wrong while compiling 287 | */ 288 | void compile(OpenBlocksProjectMetadata metadata, OpenBlocksCode code, OpenBlocksLayout layout, String location) throws CompileException; 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/api/OpenBlocksAPI.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.api; 2 | 3 | import android.content.Context; 4 | 5 | import java.lang.ref.WeakReference; 6 | 7 | public class OpenBlocksAPI { 8 | 9 | private static OpenBlocksAPI instance = null; 10 | 11 | private WeakReference context; 12 | 13 | //////////////////////////////////////////////////////// 14 | 15 | private ResourceManager resourceManager; 16 | 17 | //////////////////////////////////////////////////////// 18 | 19 | private OpenBlocksAPI(Context context, ResourceManager resourceManager) { 20 | this.context = new WeakReference<>(context); 21 | this.resourceManager = resourceManager; 22 | } 23 | 24 | // Just for modules 25 | public static OpenBlocksAPI getInstance() { 26 | if (instance == null) 27 | throw new IllegalStateException("OpenBlocksAPI hasn't been initialized yet"); 28 | 29 | return instance; 30 | } 31 | 32 | // For openblocks-app to initialize 33 | public static OpenBlocksAPI getInstance(Context context, ResourceManager resourceManager) { 34 | if (instance == null) 35 | instance = new OpenBlocksAPI(context, resourceManager); 36 | 37 | return instance; 38 | } 39 | 40 | public ResourceManager getResourceManager() { 41 | return resourceManager; 42 | } 43 | 44 | public Context getContext() { 45 | return context.get(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/api/ResourceManager.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.api; 2 | 3 | import android.graphics.Bitmap; 4 | import android.view.View; 5 | 6 | import com.openblocks.moduleinterface.OpenBlocksModule; 7 | 8 | public interface ResourceManager { 9 | /** 10 | * This function gets a in image resource for the specified module 11 | * @param module The module that is using this function 12 | * @param filename The filename of the image resource 13 | * @return The specified resource image bitmap 14 | */ 15 | Bitmap getImageResource(OpenBlocksModule module, String filename); 16 | 17 | /** 18 | * This function reads a resource in byte[] for the specified module 19 | * @param module The module that is using this function 20 | * @param filename The filename of the file resource 21 | * @return The contents of the file 22 | */ 23 | byte[] getRawResource(OpenBlocksModule module, String filename); 24 | 25 | /** 26 | * This function inflates an xml layout resource into a {@link View} 27 | * for the specified module 28 | * @param module The module that is using this function 29 | * @param xml_filename The filename of the xml layout 30 | * @return The inflated layout 31 | */ 32 | View inflateXmlLayout(OpenBlocksModule module, String xml_filename); 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/callbacks/Logger.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.callbacks; 2 | 3 | import com.openblocks.moduleinterface.OpenBlocksModule; 4 | 5 | /** 6 | * This interface is used by modules to log stuff, a class that implements this 7 | * interface will be provided on module initialize. 8 | * 9 | * The logs will be displayed on the Logs tab of OpenBlocks 10 | */ 11 | public interface Logger { 12 | void debug (Class module_class, String text); 13 | void trace (Class module_class, String text); 14 | void info (Class module_class, String text); 15 | void warn (Class module_class, String text); 16 | void err (Class module_class, String text); 17 | void fatal (Class module_class, String text); 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/callbacks/SaveCallback.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.callbacks; 2 | 3 | /** 4 | * Used for PROJECT_LAYOUT_GUI and PROJECT_CODE_GUI to save it's data 5 | * 6 | * Example Usage: 7 | * 8 | * EditGUI edit = new EditGUI(this); 9 | * edit.addOnSaveListener(new SaveCallback<\EditGUIData>() { 10 | * // When the user saved something on EditGUI 11 | * }) 12 | * 13 | * 14 | * @param The data type that is going to be saved 15 | */ 16 | public interface SaveCallback { 17 | void save(T data_to_be_saved); 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/exceptions/CompileException.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.exceptions; 2 | 3 | /* When something wrong happened during compiling on PROJECT_COMPILER module, throw this */ 4 | public class CompileException extends Exception { 5 | public String message; 6 | 7 | public CompileException(String title, String message) { 8 | super(title); 9 | this.message = message; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/exceptions/NotSupportedException.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.exceptions; 2 | 3 | /* When a module doesn't support the method in the interface, throw this instead of returning null */ 4 | public class NotSupportedException extends Exception { 5 | public NotSupportedException(String reason) { super(reason); } 6 | } 7 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/exceptions/ParseException.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.exceptions; 2 | 3 | /** 4 | * This exception is used when the Parser module failed 5 | * to parse something 6 | */ 7 | public class ParseException extends Exception { 8 | public ParseException(String error) { 9 | super(error); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/OpenBlocksFile.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * This class is basically used to store a file's data with the name on it, nothing special. 8 | */ 9 | public class OpenBlocksFile implements Parcelable { 10 | public byte[] data; 11 | public String name; 12 | 13 | public OpenBlocksFile() { } 14 | 15 | public OpenBlocksFile(byte[] data, String name) { 16 | this.data = data; 17 | this.name = name; 18 | } 19 | 20 | protected OpenBlocksFile(Parcel in) { 21 | data = in.createByteArray(); 22 | name = in.readString(); 23 | } 24 | 25 | public static final Creator CREATOR = new Creator() { 26 | @Override 27 | public OpenBlocksFile createFromParcel(Parcel in) { 28 | return new OpenBlocksFile(in); 29 | } 30 | 31 | @Override 32 | public OpenBlocksFile[] newArray(int size) { 33 | return new OpenBlocksFile[size]; 34 | } 35 | }; 36 | 37 | @Override 38 | public int describeContents() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void writeToParcel(Parcel dest, int flags) { 44 | dest.writeByteArray(data); 45 | dest.writeString(name); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/OpenBlocksProjectMetadata.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | public class OpenBlocksProjectMetadata implements Parcelable { 7 | String name; 8 | String package_name; 9 | String version_name; 10 | int version_code; 11 | 12 | public OpenBlocksProjectMetadata(String name, String package_name, String version_name, int version_code) { 13 | this.name = name; 14 | this.package_name = package_name; 15 | this.version_name = version_name; 16 | this.version_code = version_code; 17 | } 18 | 19 | protected OpenBlocksProjectMetadata(Parcel in) { 20 | name = in.readString(); 21 | package_name = in.readString(); 22 | version_name = in.readString(); 23 | version_code = in.readInt(); 24 | } 25 | 26 | public static final Creator CREATOR = new Creator() { 27 | @Override 28 | public OpenBlocksProjectMetadata createFromParcel(Parcel in) { 29 | return new OpenBlocksProjectMetadata(in); 30 | } 31 | 32 | @Override 33 | public OpenBlocksProjectMetadata[] newArray(int size) { 34 | return new OpenBlocksProjectMetadata[size]; 35 | } 36 | }; 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public String getPackageName() { 43 | return package_name; 44 | } 45 | 46 | public String getVersionName() { 47 | return version_name; 48 | } 49 | 50 | public int getVersionCode() { 51 | return version_code; 52 | } 53 | 54 | @Override 55 | public int describeContents() { 56 | return 0; 57 | } 58 | 59 | @Override 60 | public void writeToParcel(Parcel dest, int flags) { 61 | dest.writeString(name); 62 | dest.writeString(package_name); 63 | dest.writeString(version_name); 64 | dest.writeInt(version_code); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/OpenBlocksRawProject.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class OpenBlocksRawProject implements Parcelable { 9 | 10 | public String ID; 11 | public ArrayList files; 12 | 13 | public OpenBlocksRawProject() { } 14 | 15 | public OpenBlocksRawProject(String ID, ArrayList files) { 16 | this.ID = ID; 17 | this.files = files; 18 | } 19 | 20 | protected OpenBlocksRawProject(Parcel in) { 21 | ID = in.readString(); 22 | files = in.createTypedArrayList(OpenBlocksFile.CREATOR); 23 | } 24 | 25 | public static final Creator CREATOR = new Creator() { 26 | @Override 27 | public OpenBlocksRawProject createFromParcel(Parcel in) { 28 | return new OpenBlocksRawProject(in); 29 | } 30 | 31 | @Override 32 | public OpenBlocksRawProject[] newArray(int size) { 33 | return new OpenBlocksRawProject[size]; 34 | } 35 | }; 36 | 37 | @Override 38 | public int describeContents() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void writeToParcel(Parcel dest, int flags) { 44 | dest.writeString(ID); 45 | dest.writeTypedList(files); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/code/BlockCode.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.code; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * This class is used to store the properties of a block 7 | */ 8 | public class BlockCode { 9 | public String opcode; 10 | public String format; 11 | public int color; 12 | public ParseBlockTask parseBlockTask; 13 | public ArrayList parameters; 14 | 15 | public BlockCode(String opcode, String format, int color, ParseBlockTask parseBlockTask, ArrayList parameters) { 16 | this.opcode = opcode; 17 | this.format = format; 18 | this.color = color; 19 | this.parseBlockTask = parseBlockTask; 20 | this.parameters = parameters; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/code/BlockCodeNest.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.code; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * BlockCodeNest is a nest of {@link BlockCode}, which can be an: If statement, While loop, For loop, function, class, etc 7 | */ 8 | public class BlockCodeNest extends BlockCode { 9 | public ArrayList blocks; 10 | 11 | public BlockCodeNest(String opcode, String format, int color, ParseBlockTask parseBlockTask, ArrayList parameters, ArrayList blocks) { 12 | super(opcode, format, color, parseBlockTask, parameters); 13 | this.blocks = blocks; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/code/ParseBlockTask.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.code; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * This interface is used by the compiler to convert a block 7 | * opcode into java code 8 | */ 9 | public interface ParseBlockTask { 10 | /** 11 | * A function used to parse a block into code 12 | * TODO: An easier way to parse code to add stuff like imports 13 | * @param code The code 14 | * @param arguments The arguments given 15 | * @param childs_parsed_code Childs' parsed code if this block is a nested block 16 | */ 17 | void parseBlock(StringBuilder code, ArrayList arguments, String childs_parsed_code); 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/compiler/IncludedBinary.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.compiler; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | public class IncludedBinary { 7 | public String name; 8 | public int version; 9 | public String path; 10 | 11 | public IncludedBinary(String name, int version, String path) { 12 | this.name = name; 13 | this.version = version; 14 | this.path = path; 15 | } 16 | 17 | public Process executeWithParams(String params) throws IOException { 18 | return Runtime.getRuntime().exec("" + path + " " + params); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/config/OpenBlocksConfig.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Objects; 6 | 7 | /** 8 | * OpenBlocksConfig is a list of configuration that can be added, removed, and edited 9 | */ 10 | public class OpenBlocksConfig { 11 | public enum Type { 12 | SWITCH, 13 | INPUT_TEXT, 14 | INPUT_NUMBER, 15 | OPEN_FILE, 16 | DROPDOWN, 17 | MULTIPLE_CHOICE, 18 | } 19 | 20 | HashMap config = new HashMap<>(); 21 | 22 | public OpenBlocksConfig() { } 23 | 24 | public void addItem(String TAG, OpenBlocksConfigItem item) { 25 | config.put(TAG, item); 26 | } 27 | 28 | public void removeItem(String TAG) { 29 | config.remove(TAG); 30 | } 31 | 32 | public void clearItems() { 33 | config.clear(); 34 | } 35 | 36 | public String[] getTAGs() { 37 | return config.keySet().toArray(new String[0]); 38 | } 39 | 40 | public Object getConfigValue(String TAG) { 41 | if (!config.containsKey(TAG)) return null; 42 | 43 | return Objects.requireNonNull(config.get(TAG)).value; 44 | } 45 | 46 | public void setConfigValue(String TAG, Object value) { 47 | config.get(TAG).value = value; 48 | } 49 | 50 | public ArrayList getConfigs() { 51 | return (ArrayList) config.values(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/config/OpenBlocksConfigItem.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.config; 2 | 3 | /** 4 | * OpenBlocksConfigItem is an item of a list of configurations (on {@link OpenBlocksConfig}) 5 | * 6 | * {@link #text} is the informative text that will be displayed on the left of the edit specified 7 | * by {@link #config_type} 8 | * 9 | * {@link #value} is the value, when creating, you can use this as the default value 10 | */ 11 | public class OpenBlocksConfigItem { 12 | public String text; 13 | public Object value; 14 | public Object extra; 15 | 16 | public OpenBlocksConfig.Type config_type; 17 | 18 | /** 19 | * This constructor constructs this class to an object with the provided parameters 20 | * 21 | * @param text The informative text that will be displayed alongside the action / button / edit 22 | * @param value The default value 23 | * @param extra The extra, this can only be used to store ArrayList of objects that will be displayed on DROPDOWN, and MULTIPLE_CHOICE, otherwise, just put null 24 | * @param config_type The configuration type, value's type should match with the config_type 25 | */ 26 | public OpenBlocksConfigItem(String text, Object value, Object extra, OpenBlocksConfig.Type config_type) { 27 | this.text = text; 28 | this.value = value; 29 | this.extra = extra; 30 | this.config_type = config_type; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/models/layout/LayoutViewXMLAttribute.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.models.layout; 2 | 3 | public class LayoutViewXMLAttribute { 4 | public String prefix; 5 | public String attribute_name; 6 | public Object value; 7 | 8 | public LayoutViewXMLAttribute(String prefix, String attribute_name, Object value) { 9 | this.prefix = prefix; 10 | this.attribute_name = attribute_name; 11 | this.value = value; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/projectfiles/OpenBlocksCode.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.projectfiles; 2 | 3 | import com.openblocks.moduleinterface.models.code.BlockCode; 4 | import com.openblocks.moduleinterface.models.code.ParseBlockTask; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | // TODO: 3/18/21 Should be possible to make multiple collection of blocks / activity 10 | public class OpenBlocksCode { 11 | public String block_collection_name; 12 | // This HashMap is used by the code editor to display the blocks 13 | /** HashMap of opcode, format */ 14 | public HashMap blocks_formats; 15 | public ArrayList blocks = new ArrayList<>(); 16 | 17 | public OpenBlocksCode(String block_collection_name) { 18 | this.block_collection_name = block_collection_name; 19 | } 20 | 21 | public OpenBlocksCode(String block_collection_name, ArrayList blocks) { 22 | this.block_collection_name = block_collection_name; 23 | this.blocks = blocks; 24 | } 25 | 26 | public void setBlocksFormats(HashMap blocks_formats) { 27 | this.blocks_formats = blocks_formats; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/main/java/com/openblocks/moduleinterface/projectfiles/OpenBlocksLayout.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface.projectfiles; 2 | 3 | import com.openblocks.moduleinterface.models.layout.LayoutViewXMLAttribute; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * OpenBlocksLayout is a model that is used to represent a layout in XML 9 | */ 10 | public class OpenBlocksLayout { 11 | public ArrayList childs = new ArrayList<>(); 12 | public String view_name; 13 | public ArrayList xml_attributes; 14 | 15 | public OpenBlocksLayout(ArrayList childes, String view_name, ArrayList xml_attributes) { 16 | this.childs = childes; 17 | this.view_name = view_name; 18 | this.xml_attributes = xml_attributes; 19 | } 20 | 21 | public OpenBlocksLayout(String view_name, ArrayList xml_attributes) { 22 | this.view_name = view_name; 23 | this.xml_attributes = xml_attributes; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/test/java/com/openblocks/moduleinterface/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.openblocks.moduleinterface; 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 Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "OpenBlocks Module Interface" 2 | include ':lib' 3 | --------------------------------------------------------------------------------