Skip to content

verygoodgraphics/vgg_android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VGG container for Android

An android runtime library for VGG.

🔥 This project is participating OSPP 2024 Summer of Code! Please checkout it here.

Getting Started

  1. Build VggContainer.
  2. Open the VggRuntime in Android Studio.

Note

If you don't want to compile all architectures while developing, you can comment the unwanted arch in the line

ndk.abiFilters.addAll(listOf("x86_64", "arm64-v8a"))

in file VggRuntime/container/build.gradle.kts

Usage

Firstly, You should initialize the VggRuntime before any VggViews are created. For example, in your costume Application class:

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initVggRuntime();
        // any other initialization code
    }

}

Using in XML

Put your VGG model file in the res/raw directory, and use the app:model attribute to specify the model file.

<com.verygoodgraphics.android.container.view.VggView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:model="@raw/counter_with_js" />

Using programmatically

You can use Android Uri to specify the VGG model programmatically.

public class VggDemoViewActivity extends Activity {
    
    private VggView mVggView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
        mVggView = new VggView(this);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.addView(mVggView, params);
        vggView.vggModelUri = Uri.Builder()
                .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
                .authority(BuildConfig.APPLICATION_ID)
                .path(R.raw.counter_without_js.toString())
                .build();
        setContentView(frameLayout);
    }
}

Using in Compose

Refer to 在 Compose 中使用 View

API Reference

  • String getVggModelUri(): Get the Uri of the VGG model.
  • void setVggModelUri(Uri): Set the Uri of the VGG model.
  • ByteArray getVggModelBuffer(): Get the buffered VGG model.
  • void setVggModelBuffer(ByteArray): Set the buffered VGG model.
  • String getElements().get(String): Get the elements of the VGG model by ID.
  • void getElements().set(String, String): Set the elements of the VGG model by ID.
  • void addVggEventListener(EventListener): Add a listener to VGG events.

Example

You can run our Android example app in this repository, open the VggRuntime in Android Studio and select the demo module.

Contribution

By contributing to this project, you shall by default agree with the DCO document automatically, otherwise please don't send PR.

License

MIT License