Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Android CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Run tests
run: ./gradlew test

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: app-debug-apk
path: app/build/outputs/apk/debug/app-debug.apk
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

# Android Studio
*.iml
.idea/

# Build
build/
*/build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/
150 changes: 150 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,153 @@
> * Power users looking for customizable widget logic
> * Anyone who wishes Scriptable existed on Android

## Features

- **JavaScript Script Editor**: Write and edit JavaScript code with syntax highlighting
- **Script Execution**: Run JavaScript scripts with access to Android APIs
- **Battery Information**: Access battery level and charging state through JavaScript
- **Script Management**: Save, edit, and organize your scripts
- **System Integration**: Built-in APIs for device information and notifications

## Getting Started

### Prerequisites

- Android Studio Arctic Fox (2020.3.1) or later
- Android SDK API level 21 or higher
- Java 8 or higher

### Building the Project

1. Clone the repository:
```bash
git clone https://github.com/rushhiii/ScriptableDroid.git
cd ScriptableDroid
```

2. Set up Android SDK path:
- If using Android Studio: Open the project and let Android Studio configure it automatically
- If building from command line: Copy `local.properties.example` to `local.properties` and set your Android SDK path

3. Build the project:
```bash
# Using Gradle Wrapper (recommended)
./gradlew build

# Or on Windows
gradlew.bat build
```

4. Install on device/emulator:
```bash
./gradlew installDebug
```

**Note**: The Gradle Wrapper is included in the project, so you don't need to install Gradle separately. The wrapper will automatically download the correct version of Gradle.

### Project Structure

```
ScriptableDroid/
├── app/
│ ├── src/main/
│ │ ├── java/com/scriptabledroid/app/
│ │ │ ├── MainActivity.kt # Main activity with script list
│ │ │ ├── ScriptEditorActivity.kt # Script editor with code highlighting
│ │ │ ├── ScriptEngine.kt # JavaScript execution engine
│ │ │ ├── ScriptStorage.kt # Script persistence
│ │ │ ├── ScriptAdapter.kt # RecyclerView adapter for scripts
│ │ │ └── Script.kt # Script data model
│ │ ├── res/ # Android resources
│ │ └── AndroidManifest.xml
│ └── build.gradle # App-level Gradle config
├── build.gradle # Project-level Gradle config
└── settings.gradle # Gradle settings
```

## JavaScript API

ScriptableDroid provides several built-in JavaScript APIs:

### Device API
```javascript
// Get battery level (0-100)
const batteryLevel = Device.batteryLevel();

// Get battery state ("charging", "discharging", "full", "not_charging", "unknown")
const batteryState = Device.batteryState();
```

### Console API
```javascript
// Log messages
console.log("Hello from ScriptableDroid!");
```

### Notification API (Coming Soon)
```javascript
// Create notifications
Notification.create("Title", "Message body");
```

## Example Scripts

### Battery Monitor
```javascript
// Get battery information
const batteryLevel = Device.batteryLevel();
const batteryState = Device.batteryState();

console.log("Battery Level: " + batteryLevel + "%");
console.log("Battery State: " + batteryState);

"Battery: " + batteryLevel + "% (" + batteryState + ")";
```

## Contributing

We welcome contributions! Here's how to get started:

### Development Setup

1. Fork the repository
2. Clone your fork: `git clone https://github.com/yourusername/ScriptableDroid.git`
3. Open in Android Studio
4. Create a feature branch: `git checkout -b feature/amazing-feature`
5. Make your changes
6. Test thoroughly
7. Commit your changes: `git commit -m 'Add amazing feature'`
8. Push to your branch: `git push origin feature/amazing-feature`
9. Open a Pull Request

### Code Style

- Follow Kotlin coding conventions
- Use meaningful variable and function names
- Add comments for complex logic
- Maintain consistent formatting (use Android Studio's auto-formatter)

### Adding New JavaScript APIs

To add new JavaScript APIs:

1. Modify `ScriptEngine.kt` to add your API methods
2. Test the API with example scripts
3. Update the documentation in README.md
4. Add example scripts demonstrating the new API

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Roadmap

- [x] Basic JavaScript execution environment
- [x] Script editor with syntax highlighting
- [x] Device battery information API
- [ ] File system access
- [ ] Network requests support
- [ ] Home screen widgets
- [ ] More system APIs (contacts, calendar, etc.)
- [ ] Script sharing and import/export

58 changes: 58 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.scriptabledroid.app'
compileSdk 34

defaultConfig {
applicationId "com.scriptabledroid.app"
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
// viewBinding disabled for simplicity
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

// Duktape for JavaScript execution
implementation 'com.squareup.duktape:duktape-android:1.4.0'

// For code editor
implementation 'io.github.rosemoe.sora-editor:editor:0.23.4'
implementation 'io.github.rosemoe.sora-editor:language-javascript:0.23.4'

// JSON serialization
implementation 'com.google.code.gson:gson:2.10.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
28 changes: 28 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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

# Keep Duktape classes
-keep class com.squareup.duktape.** { *; }

# Keep Gson classes
-keep class com.google.gson.** { *; }
-keep class com.scriptabledroid.app.Script { *; }
36 changes: 36 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ScriptableDroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.ScriptableDroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".ScriptEditorActivity"
android:exported="false"
android:parentActivityName=".MainActivity" />
</application>

</manifest>
Loading
Loading