Tutorial: How To Import pluginlibrary into a New Project


#1

This was originally published on GitHub issues.

Some people have encountered problems with importimg the pluginlibrary into a new project.
If you import the library by selecting “File”-“New”-“Import Module…” in Android Studio 3.1.3, the folder may not show up in Android Studio. StackOverflow has a tip about this problem.

  1. Import “pluginlibrary” in the SDK by selecting “File”-“New”-“Import Module…”
  2. Add a text “include ‘:app’, ‘:pluginlibrary’” in “settings.gradle” file
  3. Sync by selecting “File”-“Sync Project with Gradle Files”.

You should now be able to import the pluginlibrary into your project.

Update 8/21/2018: I also needed to add implementation project(':pluginlibrary') in build.gradle


This tip and others will be included in an updated Plug-in Developer Community Guide.


Start New Project

image

image

Select API 25

image

Basic Activity

I’m using Basic Activity. You can use any template and work from there.

image

image

Import module

image

image

Edit Gradle Configuration Files

In build.gradle

image

image

In settings.gradle

image

image

image

import pluginlibrary into MainActivity.java

Build apk

image

Success.

image

Test in Camera

To verify that your application is controlling the camera, write a simple test will light up two LEDs on the camera when it is placed into plug-in mode.

Code Listing of Import Test

package guide.theta360.libraryimporttest;

import android.os.Bundle;
import android.view.KeyEvent;

import com.theta360.pluginlibrary.activity.PluginActivity;
import com.theta360.pluginlibrary.callback.KeyCallback;
import com.theta360.pluginlibrary.receiver.KeyReceiver;
import com.theta360.pluginlibrary.values.LedColor;
import com.theta360.pluginlibrary.values.LedTarget;

public class MainActivity extends PluginActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setKeyCallback(new KeyCallback() {
            @Override
            public void onKeyDown(int keyCode, KeyEvent event) {
                if (keyCode == KeyReceiver.KEYCODE_CAMERA) {
                    System.out.println("theta debug: pressed camera mode button down");
                }
            }

            @Override
            public void onKeyUp(int keyCode, KeyEvent event) {
                notificationLedShow(LedTarget.LED6);
                notificationLed3Show(LedColor.MAGENTA);
                System.out.println("theta debug: camera now in plug-in mode  :-)");
            }

            @Override
            public void onKeyLongPress(int keyCode, KeyEvent event) {

            }
        });
    }
}

Build apk and install into camera

image

Set Library Import Test as Active Plug-in

Use the THETA Desktop application.

Test Plug-in On Camera

Reboot camera. Press mode button for two seconds.

Verify that app is lighting the correct LEDs with the correct color.