diff options
author | Kunal <shindek@google.com> | 2020-05-06 16:48:48 -0700 |
---|---|---|
committer | Kunal <shindek@google.com> | 2020-05-07 17:18:33 -0700 |
commit | bf9a5fc5716fbce3bb7c1e496f9ad3ff00fd70d6 (patch) | |
tree | 50abfb7148dce41a7ee994340dd40d4eb6a5c546 | |
parent | 7ed1bd4ef7cb18503e4e3a77992b0bcf24038054 (diff) | |
download | teeui-bf9a5fc5716fbce3bb7c1e496f9ad3ff00fd70d6.tar.gz |
Add combo box for supported layout types in the framebufferizer
java application.
Bug: 156013568
Test: make -j TeeuiFramebufferizer &&
LD_LIBRARY_PATH=./out/host/linux-x86/lib64 TeeuiFramebufferizer
Change-Id: If9adb95297efc255e52d691cb9fa9419274c0023
6 files changed, 79 insertions, 27 deletions
diff --git a/libteeui/include/teeui/example/example.h b/libteeui/include/teeui/example/example.h index ef94651..07df995 100644 --- a/libteeui/include/teeui/example/example.h +++ b/libteeui/include/teeui/example/example.h @@ -59,6 +59,15 @@ enum class Examples : uint32_t { static constexpr const int8_t kFrameBufferError = -1; static constexpr const int8_t kLayoutExampleError = -2; +static constexpr const char* kPhysButtonLayout = "Physical button"; +static constexpr const char* kTouchButtonLayout = "Touch button"; + +static constexpr const char* kAvailableLayouts[] = { + kPhysButtonLayout, + kTouchButtonLayout, +}; + +#define NUM_LAYOUTS ((sizeof(kAvailableLayouts) / sizeof(kAvailableLayouts[0]))) std::unique_ptr<ITeeuiExample> createExample(Examples example); diff --git a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h index a24b826..b5bb08d 100644 --- a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h +++ b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h @@ -10,10 +10,10 @@ extern "C" { /* * Class: com_android_framebufferizer_NativeRenderer * Method: setDeviceInfo - * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;ZZ)I + * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;ZZLjava/lang/String;)I */ JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_setDeviceInfo( - JNIEnv*, jclass, jobject, jboolean, jboolean, jboolean); + JNIEnv*, jclass, jobject, jboolean, jboolean, jstring); /* * Class: com_android_framebufferizer_NativeRenderer @@ -41,6 +41,14 @@ Java_com_android_framebufferizer_NativeRenderer_getLanguageIdList(JNIEnv*, jclas /* * Class: com_android_framebufferizer_NativeRenderer + * Method: getAvailableLayouts + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL +Java_com_android_framebufferizer_NativeRenderer_getAvailableLayouts(JNIEnv*, jclass); + +/* + * Class: com_android_framebufferizer_NativeRenderer * Method: setConfimationMessage * Signature: (Ljava/lang/String;)V */ diff --git a/libteeui_jni/libteeui_jni.cpp b/libteeui_jni/libteeui_jni.cpp index 7f6e6fd..1beae12 100644 --- a/libteeui_jni/libteeui_jni.cpp +++ b/libteeui_jni/libteeui_jni.cpp @@ -129,11 +129,12 @@ static std::unique_ptr<teeui::example::ITeeuiExample> sCurrentExample; /* * Class: com_android_framebufferizer_NativeRenderer * Method: setDeviceInfo - * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;ZZ)I + * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;ZZLjava/lang/String;)I */ extern "C" JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_setDeviceInfo( JNIEnv* env, jclass, jobject jDeviceInfo, jboolean magnified, jboolean inverted, - jboolean touchLayout) { + jstring layout_type) { + JString layout(env, layout_type); using namespace teeui::example; jclass cDeviceInfo = env->FindClass("Lcom/android/framebufferizer/utils/DeviceInfo;"); jmethodID method = env->GetMethodID(cDeviceInfo, "getWidthPx", "()I"); @@ -153,7 +154,9 @@ extern "C" JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRendere device_info.volUpButtonTopMm_ = env->CallDoubleMethod(jDeviceInfo, method); method = env->GetMethodID(cDeviceInfo, "getVolUpButtonBottomMm", "()D"); device_info.volUpButtonBottomMm_ = env->CallDoubleMethod(jDeviceInfo, method); - sCurrentExample = createExample(touchLayout ? Examples::TouchButton : Examples::PhysButton); + sCurrentExample = + createExample((strcmp(layout.begin(), kTouchButtonLayout) == 0) ? Examples::TouchButton + : Examples::PhysButton); return sCurrentExample->setDeviceInfo(device_info, magnified, inverted); } @@ -173,6 +176,7 @@ extern "C" JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRendere (uint32_t)height, (uint32_t)lineStride, (uint32_t*)buffer.begin(), buffer.size()); } + /* * Class: com_android_confirmationui_Translation_selectLangID * Method: selectLangID @@ -203,6 +207,28 @@ Java_com_android_framebufferizer_NativeRenderer_getLanguageIdList(JNIEnv* env, j return language_ids; } + +/* + * Class: com_android_framebufferizer_NativeRenderer + * Method: getAvailableLayouts + * Signature: ()[Ljava/lang/String; + */ +extern "C" JNIEXPORT jobjectArray JNICALL +Java_com_android_framebufferizer_NativeRenderer_getAvailableLayouts(JNIEnv* env, jclass) { + using namespace teeui::example; + jobjectArray available_layouts; + const char* const* native_data = kAvailableLayouts; + size_t list_size = NUM_LAYOUTS; + + available_layouts = (jobjectArray)env->NewObjectArray( + list_size, env->FindClass("java/lang/String"), env->NewStringUTF("")); + + for (size_t i = 0; i < list_size; i++) + env->SetObjectArrayElement(available_layouts, i, env->NewStringUTF(native_data[i])); + + return available_layouts; +} + /* * Class: com_android_framebufferizer_NativeRenderer * Method: setConfimationMessage diff --git a/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java b/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java index 4a82bee..991e61b 100644 --- a/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java +++ b/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java @@ -23,10 +23,11 @@ public class NativeRenderer { System.loadLibrary("teeui_jni"); } - public static native int setDeviceInfo(DeviceInfo deviceInfo, boolean magnified, boolean inverted, boolean touchLayout); + public static native int setDeviceInfo(DeviceInfo deviceInfo, boolean magnified, boolean inverted, String touchLayout); public static native int renderBuffer(int x, int y, int width, int height, int lineStride, int[] buffer); public static native void setLanguage(String language_id); public static native String[] getLanguageIdList(); public static native void setConfimationMessage(String confimationMessage); public static native int onEvent(int x, int y, int event); + public static native String[] getAvailableLayouts(); } diff --git a/tools/framebufferizer/src/com/android/framebufferizer/utils/Config.java b/tools/framebufferizer/src/com/android/framebufferizer/utils/Config.java index 9e49bda..9e5baed 100644 --- a/tools/framebufferizer/src/com/android/framebufferizer/utils/Config.java +++ b/tools/framebufferizer/src/com/android/framebufferizer/utils/Config.java @@ -30,7 +30,7 @@ import org.json.JSONException; public class Config { public static final String KEY_MAGNIFIED = "magnified"; public static final String KEY_INVERTED = "inverted"; - public static final String KEY_TOUCH = "touch_layout"; + public static final String KEY_LAYOUT = "layout"; public static final String KEY_LOCALE = "locale"; public static final String KEY_DEVICE = "device"; public static final String KEY_MESSAGE = "message"; diff --git a/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java b/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java index 18991eb..a81e1db 100644 --- a/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java +++ b/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java @@ -104,14 +104,16 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous languages = NativeRenderer.getLanguageIdList(); } + private final String layouts[] = NativeRenderer.getAvailableLayouts(); private JComboBox<String> deviceSelector = new JComboBox(DeviceInfoDB.Device.values()); private JCheckBox magnifiedCheckbox = new JCheckBox("Magnified"); private JCheckBox invertedCheckbox = new JCheckBox("Inverted"); - private JCheckBox touchCheckbox = new JCheckBox("Touch layout"); private JComboBox<String> localeSelector = new JComboBox(languages); private JTextField confirmationMessage = new JTextField(); + private JComboBox<String> layoutSelector = new JComboBox(layouts); + protected ConfigSelector() { System.err.println("ConfigSelector"); this.setLayout(new GridBagLayout()); @@ -147,29 +149,36 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous c = new GridBagConstraints(); c.gridx = 0; c.gridy = 2; + this.add(new JLabel("Select Layout:"), c); + + layoutSelector.addActionListener(this); + c = new GridBagConstraints(); + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 2; + c.fill = GridBagConstraints.HORIZONTAL; + this.add(layoutSelector, c); + + c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 3; this.add(new JLabel("UIOptions:"), c); magnifiedCheckbox.addActionListener(this); c = new GridBagConstraints(); c.gridx = 1; - c.gridy = 2; + c.gridy = 3; this.add(magnifiedCheckbox, c); invertedCheckbox.addActionListener(this); c = new GridBagConstraints(); c.gridx = 2; - c.gridy = 2; + c.gridy = 3; this.add(invertedCheckbox, c); - touchCheckbox.addActionListener(this); - c = new GridBagConstraints(); - c.gridx = 3; - c.gridy = 2; - this.add(touchCheckbox, c); - c = new GridBagConstraints(); c.gridx = 0; - c.gridy = 3; + c.gridy = 4; this.add(new JLabel("Confirmation message:"), c); confirmationMessage.setText( @@ -177,7 +186,7 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous confirmationMessage.addActionListener(this); c = new GridBagConstraints(); c.gridx = 1; - c.gridy = 3; + c.gridy = 4; c.fill = GridBagConstraints.BOTH; c.gridwidth = 2; this.add(confirmationMessage, c); @@ -190,7 +199,7 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous config.setValue(Config.KEY_MAGNIFIED, getConfigSelector().magnified()); config.setValue(Config.KEY_INVERTED, getConfigSelector().inverted()); config.setValue(Config.KEY_MESSAGE, getConfigSelector().confirmationMessage()); - config.setValue(Config.KEY_TOUCH, getConfigSelector().touched()); + config.setValue(Config.KEY_LAYOUT, getConfigSelector().currentLayout()); } public void actionPerformed(ActionEvent e) { @@ -206,6 +215,10 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous return (String) localeSelector.getSelectedItem(); } + public String currentLayout() { + return (String) layoutSelector.getSelectedItem(); + } + public boolean magnified() { return magnifiedCheckbox.isSelected(); } @@ -214,10 +227,6 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous return invertedCheckbox.isSelected(); } - public boolean touched() { - return touchCheckbox.isSelected(); - } - public String confirmationMessage() { return confirmationMessage.getText(); } @@ -335,8 +344,8 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous case Config.KEY_MESSAGE: getConfigSelector().confirmationMessage.setText((String) element.getValue()); break; - case Config.KEY_TOUCH: - getConfigSelector().touchCheckbox.setSelected((Boolean) element.getValue()); + case Config.KEY_LAYOUT: + getConfigSelector().layoutSelector.setSelectedItem((String) element.getValue()); break; } } @@ -391,7 +400,6 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous DeviceInfo deviceInfo = DeviceInfoDB.getDeviceInfo(getConfigSelector().currentDevice()); boolean magnified = getConfigSelector().magnified(); boolean inverted = getConfigSelector().inverted(); - boolean touched = getConfigSelector().touched(); int w = deviceInfo.getWidthPx(); int h = deviceInfo.getHeightPx(); @@ -407,7 +415,7 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous new int[] { rMask, gMask, bMask }, null); ColorModel colorModel = new DirectColorModel(bpp, rMask, gMask, bMask); BufferedImage image = new BufferedImage(colorModel, raster, true, null); - NativeRenderer.setDeviceInfo(deviceInfo, magnified, inverted, touched); + NativeRenderer.setDeviceInfo(deviceInfo, magnified, inverted, getConfigSelector().currentLayout()); NativeRenderer.setLanguage(getConfigSelector().currentLocale()); NativeRenderer.setConfimationMessage(getConfigSelector().confirmationMessage()); error = NativeRenderer.renderBuffer(0, 0, w, h, linestride, mBuffer.getData()); |