Giter VIP home page Giter VIP logo

onbon.bx05.mobiledemo's Introduction

onbon bx05 api for Android

Build Status Codacy Badge

English

本文件說明如何在 Android Studio 開發環境下,建立 onbon.bx05 api 的開發項目。

github source 測試對象為 BX-5E3 雙色控制器,資料顯示位置固定在 (448, 0),內容大小 為 (64, 32)。

Sample

相依檔案

JAR - onbon bx05 api Java 庫 (7/10)

  • bx05.message-x.x.x-SNAPSHOT.jar

  • bx05-x.x.x-SNAPSHOT.jar

  • log4j-1.2.14.jar

  • simple-xml-2.7.1.jar

  • uia.comm-x.x.x.jar

  • uia.message-x.x.x.jar

  • uia.utils-x.x.x.jar

AAR - onbon bx05 api on Android devcie 庫 (Android 專用)

  • java.awt4a-0.1-release.aar

Project 相關設定

build.gradle

  • flatDir - 設定相依 libs 的儲存位置。
allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

App 相關設定

build.gradle

  • project.ext.set - 設定輸出檔案名稱。

  • dexOptions - 允許掛載 Java AWT for Android。

  • dependencies - 定義 onbon.bx05 API 相關的 JAR & AAR 等八個檔案。檔案儲存在 libs 資料夾下。注意:檔名依使用版本調正。

android {
    ...
    defaultConfig {
        ...
        project.ext.set("archivesBaseName", "bx5g.mobiledemo-" + defaultConfig.versionName);
    }
    dexOptions {
        preDexLibraries = false
        additionalParameters =["--core-library"]
    }

}

dependencies {
    ...
    compile files('libs/bx05.message-0.5.0-SNAPSHOT.jar')
    compile files('libs/bx05-0.5.0-SNAPSHOT.jar')
    compile files('libs/log4j-1.2.14.jar')
    compile files('libs/simple-xml-2.7.1.jar')
    compile files('libs/uia.comm-0.2.1.jar')
    compile files('libs/uia.message-0.5.1.jar')
    compile files('libs/uia.utils-0.1.2.jar')
    compile(name:'java.awt4a-0.1-release', ext:'aar')
    ...
}

AndroidManifest.xml

  • android:name - 設定啟動應用程式類別,用來建立 BX5G API 運行環境。

  • android.permission.INTERNET - 設定允許 Socket 操作。

<application
    android:name="onbon.bx05.mobiledemo.MainApplication"
    ...>
</application>
<uses-permission android:name="android.permission.INTERNET" />

MainApplication.java

AndroidManifest.xml 中 android:name 設定類別的實作。

package onbon.bx05.mobiledemo;

import android.app.Application;

import j2a.awt.AwtEnv;
import onbon.bx05.Bx5GEnv;

public class MainApplication extends Application {

    private boolean initial;

    @Override
    public void onCreate() {
        super.onCreate();

        try {
            // java.awt for android 初始化
            AwtEnv.link(this);                          // 將 Application 與 AWT 連結
            AwtEnv.configPaintAntiAliasFlag(true);      // 設定圖案是要抗鋸齒。

            // 建立 BX5G API 運行環境。
            Bx5GEnv.initial();

            this.initial = true;
        }
        catch (Exception ex) {
            this.initial = false;
        }
    }
}

MainApplication.java

程式碼

開發注意事項

Screen (控制器) 操作

因為 Socket Client 不得執行於 UI 線程上,所以對 Screen 的操作都須在新的線程上,方能正確工作。

new Thread(new Runnable() {
    public void run() {
        // 操作 Screen
    }
}).start();

UI 更新

在非 UI 線程上操作 Screen 後,欲將結果回報至 UI 時,利用 runOnUiThread 方法。

runOnUiThread(new Runnable() {
    public void run() {
        // 更新 UI
    }
});

onbon.bx05.mobiledemo's People

Contributors

api2doc avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.