How To: THETA Z1 Function Button Control

The RICOH THETA Z1 comes with a new side button with a label of Fn.

This button is mapped to keycode 119.

In the example below, I’m using the Fn button to control the OLED display.

As the Fn button is not in the pluginlibrary right now, I set up a constant at the top of my program to hold int 119.

    private final int KEYCODE_FUNCTION = 119;

How to define KeyCallback

Handle the key press with a KeyCallback. In onKeyDown, you’ll receive an int for the key pressed. Use an if statement to check if it is the function button.

    private KeyCallback keyCallback = new KeyCallback() {

        @Override
        public void onKeyDown(int keyCode, KeyEvent keyEvent) {
            if (keyCode == KEYCODE_FUNCTION) {
       ...

How to Set KeyCallback

I’m setting the KeyCallback in the Android onResume method.

    @Override
    protected void onResume() {
        super.onResume();
        setKeyCallback(keyCallback);
        if (isApConnected()) {
        }
    }

Cycle Through Messages

I’m using a Java switch statement to cycle through the three different messages.

        switch (messageTag) {
                case "compete":
                    middle = "color temperature";
                    bottom = "25K";
                    messageTag = "temperature";
                    break;
                case "temperature":
                    middle = "Play to win";
                    bottom = "Dream and Build";
                    messageTag = "win";
                    break;
                case "win":
                    middle = "Our objective is to win";
                    bottom = "Every day, every game";
                    messageTag = "compete";
                    break;

Text scrolling is handled automatically.

image

Related Articles

Dream and Build

If you want to learn more about plug-in development, join the RICOH THETA Dream and Build Contest.

Full Code Listing

package org.codecakes.oled;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

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

public class MainActivity extends PluginActivity {

    private final int KEYCODE_FUNCTION = 119;
    private Intent oledIntent = new Intent("com.theta360.plugin.ACTION_OLED_TEXT_SHOW");
    private String messageTag = "temperature";


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

        Intent oledIntentSet = new Intent("com.theta360.plugin.ACTION_OLED_DISPLAY_SET");
        oledIntentSet.putExtra("display", "plug-in");
        sendBroadcast(oledIntentSet);

        oledIntent.putExtra("text-middle", "Color Temperature");
        oledIntent.putExtra("text-bottom", "65K");
        sendBroadcast(oledIntent);

//        setKeyCallback(keyCallback);

    }

    @Override
    protected void onResume() {
        super.onResume();
        setKeyCallback(keyCallback);
        if (isApConnected()) {
        }
    }

    private KeyCallback keyCallback = new KeyCallback() {
        private String middle = "theta360.guide ";
        private String bottom = "developers rock";

        @Override
        public void onKeyDown(int keyCode, KeyEvent keyEvent) {
            if (keyCode == KEYCODE_FUNCTION) {
                switch (messageTag) {
                    case "compete":
                        middle = "color temperature";
                        bottom = "25K";
                        messageTag = "temperature";
                        break;
                    case "temperature":
                        middle = "Play to win";
                        bottom = "Dream and Build";
                        messageTag = "win";
                        break;
                    case "win":
                        middle = "Our objective is to win";
                        bottom = "Every day, every game";
                        messageTag = "compete";
                        break;

                }

                Log.d("PLUGIN", "pressed key");
                oledIntent.putExtra("text-middle", middle);
                oledIntent.putExtra("text-bottom", bottom);
                sendBroadcast(oledIntent);
            }
        }

        @Override
        public void onKeyUp(int keycode, KeyEvent keyEvent) {

        }

        @Override
        public void onKeyLongPress(int keycode, KeyEvent keyEvent) {

        }
    };
}
1 Like