Adding translation rendering am: d179091ba1 am: f64d257c3e
Change-Id: Ibe1dc76ed6930153c64587008f878d48669bbf4a
diff --git a/libteeui/example/layout.h b/libteeui/example/layout.h
index 0c4a183..1bfd50a 100644
--- a/libteeui/example/layout.h
+++ b/libteeui/example/layout.h
@@ -71,6 +71,7 @@
VerticallyCentered;
TextColor(DefaultTextColor);
Font(DefaultFont);
+TextID(1424834532030812203);
END_ELEMENT();
BEGIN_ELEMENT(IconPower, teeui::Button, ConvexObjectCount(2))
@@ -95,6 +96,7 @@
VerticallyCentered;
TextColor(DefaultTextColor);
Font(DefaultFont);
+TextID(1796282799666106567);
END_ELEMENT();
BEGIN_ELEMENT(IconVolUp, teeui::Button, ConvexObjectCount(2))
@@ -127,6 +129,7 @@
Font(DefaultFont);
VerticallyCentered;
TextColor(DefaultTextColor);
+TextID(6973195374358399966);
END_ELEMENT();
BEGIN_ELEMENT(LabelHint, teeui::Label)
@@ -140,6 +143,7 @@
VerticallyCentered;
TextColor(DefaultTextColor);
Font(DefaultFont);
+TextID(217688588483778177);
END_ELEMENT();
BEGIN_ELEMENT(LabelBody, teeui::Label)
@@ -148,12 +152,7 @@
NumberOfLines(20);
Position(BorderWidth, BOTTOM_EDGE_OF(LabelTitle) + 24_dp);
Dimension(LabelWidth, LabelHint::pos_y - pos_y - 24_dp);
-DefaultText(
- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut "
- "labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco "
- "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in "
- "voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat "
- "cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
+DefaultText("Confirmation Message");
TextColor(DefaultTextColor);
Font(DefaultFont);
END_ELEMENT();
@@ -161,6 +160,7 @@
NEW_LAYOUT(ConfUILayout, LabelOK, IconPower, LabelCancel, IconVolUp, IconShield, LabelTitle,
LabelHint, LabelBody);
+// LABELS(ConfUILabels, LabelOK, LabelCancel, LabelTitle, LabelHint, LabelBody);
} // namespace teeui
#endif // TEEUI_LIBTEEUI_EXAMPLE_LAYOUT_H_
diff --git a/libteeui/example/teeui.cpp b/libteeui/example/teeui.cpp
index 58b6aad..1ee7718 100644
--- a/libteeui/example/teeui.cpp
+++ b/libteeui/example/teeui.cpp
@@ -14,9 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include "layout.h"
+#include <cassert>
+#include <iostream>
+#include <localization/ConfirmationUITranslations.h>
#include <teeui/example/teeui.h>
+#include <typeinfo>
using namespace teeui;
@@ -39,18 +42,6 @@
return e.bounds_.drawPoint(Point<pxs>(x, y));
}
-template <typename... Elements>
-uint32_t renderPixel(uint32_t x, uint32_t y, const std::tuple<Elements...>& layout) {
- uint32_t intensity = (x * 256) / device_width_px;
- uint32_t acc = (intensity & 0xff) << 16 | (intensity & 0xff) << 8 | (intensity & 0xff);
- for (uint32_t value : {renderPixel(x, y, std::get<Elements>(layout))...}) {
- double alfa = (value & 0xff000000) >> 24;
- alfa /= 255.0;
- acc = alfaCombineChannel(0, alfa, value, acc) | alfaCombineChannel(8, alfa, value, acc) |
- alfaCombineChannel(16, alfa, value, acc);
- }
- return acc;
-}
struct FrameBuffer {
uint32_t left_;
@@ -90,6 +81,23 @@
return 0;
}
+void selectLanguage(const char* language_id) {
+ ConfirmationUITranslations_select_lang_id(language_id);
+}
+
+void translate(LabelImpl* label) {
+ uint64_t textId = label->textId();
+ const char* translation = ConfirmationUITranslations_lookup(textId);
+ label->setText({&translation[0], &translation[strlen(translation)]});
+}
+
+template <typename... Elements> void translateLabels(std::tuple<Elements...>& layout) {
+ translate(&std::get<LabelOK>(layout));
+ translate(&std::get<LabelCancel>(layout));
+ translate(&std::get<LabelTitle>(layout));
+ translate(&std::get<LabelHint>(layout));
+}
+
uint32_t renderUIIntoBuffer(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t lineStride,
uint32_t* buffer, size_t buffer_size_in_elements_not_bytes) {
uint32_t afterLastPixelIndex = 0;
@@ -118,6 +126,8 @@
auto layoutInstance = instantiateLayout(ConfUILayout(), conv);
+ translateLabels(layoutInstance);
+
uint32_t* begin = buffer + (y * lineStride + x);
for (uint32_t yi = 0; yi < h; ++yi) {
for (uint32_t xi = 0; xi < w; ++xi) {
diff --git a/libteeui/include/teeui/example/teeui.h b/libteeui/include/teeui/example/teeui.h
index 058ad01..2e456e7 100644
--- a/libteeui/include/teeui/example/teeui.h
+++ b/libteeui/include/teeui/example/teeui.h
@@ -36,4 +36,6 @@
uint32_t renderUIIntoBuffer(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t lineStride,
uint32_t* buffer, size_t buffer_size_in_elements_not_bytes);
+void selectLanguage(const char* language_id);
+
#endif // TEEUI_LIBTEEUI_INCLUDE_TEEUI_H_
diff --git a/libteeui/include/teeui/label.h b/libteeui/include/teeui/label.h
index a952081..97a47e6 100644
--- a/libteeui/include/teeui/label.h
+++ b/libteeui/include/teeui/label.h
@@ -65,12 +65,12 @@
LabelImpl()
: fontSize_(10_px), lineHeight_(12_px), text_{}, rightJustified_(false),
- verticallyCentered_(false), textColor_(0), font_{} {}
+ verticallyCentered_(false), textColor_(0), font_{}, textId_(0) {}
LabelImpl(pxs fontSize, pxs lineHeight, text_t text, bool rightJustified,
- bool verticallyCentered, Color textColor, FontBuffer font)
+ bool verticallyCentered, Color textColor, FontBuffer font, uint64_t textId)
: fontSize_(fontSize), lineHeight_(lineHeight), text_(text),
rightJustified_(rightJustified), verticallyCentered_(verticallyCentered),
- textColor_(textColor), font_(font) {}
+ textColor_(textColor), font_(font), textId_(textId) {}
pxs fontSize() const { return fontSize_; }
@@ -78,6 +78,7 @@
void setTextColor(Color color) { textColor_ = color; }
text_t text() const { return text_; }
+ uint64_t textId() const { return textId_; }
Error draw(const PixelDrawer& drawPixel, const Box<pxs>& bounds, LineInfo* lineInfo);
@@ -89,6 +90,7 @@
bool verticallyCentered_;
Color textColor_;
FontBuffer font_;
+ uint64_t textId_;
};
/**
@@ -102,6 +104,7 @@
static const constexpr bool label_vertically_centered = false;
static const constexpr Color label_text_color = 0xff000000;
static const constexpr int label_font = 0;
+ static const constexpr uint64_t text_id = 0;
Label() = default;
template <typename Context>
@@ -111,7 +114,7 @@
context = Derived::label_font_size, context = Derived::label_line_height,
{&Derived::label_text[0], &Derived::label_text[sizeof(Derived::label_text) - 1]},
Derived::label_right_justified, Derived::label_vertically_centered,
- Derived::label_text_color, getFont(Derived::label_font)) {}
+ Derived::label_text_color, getFont(Derived::label_font), Derived::text_id) {}
Error draw(const PixelDrawer& drawPixel) {
LabelImpl::LineInfo::info_t lines[Derived::label_number_of_lines];
@@ -146,4 +149,6 @@
#define Font(fontbuffer) static const constexpr auto label_font = fontbuffer
+#define TextID(tid) static const constexpr uint64_t text_id = tid
+
#endif // LIBTEEUI_LABEL_H_
diff --git a/libteeui/include/teeui/utils.h b/libteeui/include/teeui/utils.h
index 7e1b908..f9f318c 100644
--- a/libteeui/include/teeui/utils.h
+++ b/libteeui/include/teeui/utils.h
@@ -917,4 +917,6 @@
#define NEW_PARAMETER_SET(name, ...) using name = ::teeui::MetaList<__VA_ARGS__>
+#define LABELS(name, ...) using ::teeui::MetaList<__VA_ARGS__>
+
#endif // TEEUI_LIBTEEUI_UTILS_H_
diff --git a/libteeui_jni/Android.bp b/libteeui_jni/Android.bp
index c3d53fc..8c69e16 100644
--- a/libteeui_jni/Android.bp
+++ b/libteeui_jni/Android.bp
@@ -9,5 +9,6 @@
"libft2.nodep",
"libteeui",
"libteeui_example_layout",
+ "libteeui_localization",
],
}
diff --git a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
index 0eb1625..774200c 100644
--- a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
+++ b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
@@ -25,6 +25,20 @@
JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_renderBuffer(
JNIEnv*, jclass, jint, jint, jint, jint, jint, jintArray);
+/*
+ * Class: com_android_framebufferizer_NativeRenderer_setLanguage
+ * Method: setLanguage
+ * Signature: (Ljava/lang/String;)Ljava/lang/String;
+ */
+JNIEXPORT void JNICALL Java_com_android_framebufferizer_NativeRenderer_setLanguage(JNIEnv*, jclass,
+ jstring);
+/*
+ * Class: com_android_framebufferizer_NativeRenderer_getLanguageIdList
+ * Method: getLanguageIdList
+ */
+JNIEXPORT jobjectArray JNICALL
+Java_com_android_framebufferizer_NativeRenderer_getLanguageIdList(JNIEnv*, jclass);
+
#ifdef __cplusplus
}
#endif
diff --git a/libteeui_jni/libteeui_jni.cpp b/libteeui_jni/libteeui_jni.cpp
index bf51080..ee08859 100644
--- a/libteeui_jni/libteeui_jni.cpp
+++ b/libteeui_jni/libteeui_jni.cpp
@@ -16,6 +16,7 @@
*/
#include <jni.h>
+#include <localization/ConfirmationUITranslations.h>
#include <teeui/example/teeui.h>
/*
@@ -163,3 +164,33 @@
return renderUIIntoBuffer((uint32_t)x, (uint32_t)y, (uint32_t)width, (uint32_t)height,
(uint32_t)lineStride, (uint32_t*)buffer.begin(), buffer.size());
}
+/*
+ * Class: com_android_framebufferizer_NativeRenderer_setLanguage
+ * Method: setLanguage
+ */
+extern "C" JNIEXPORT void JNICALL
+Java_com_android_framebufferizer_NativeRenderer_setLanguage(JNIEnv* env, jclass, jstring jlang_id) {
+ jboolean isCopy = false;
+ const char* lang_id = (env)->GetStringUTFChars(jlang_id, &isCopy);
+ selectLanguage(lang_id);
+ (env)->ReleaseStringUTFChars(jlang_id, lang_id);
+}
+/*
+ * Class: com_android_framebufferizer_NativeRenderer_getLanguageIdList
+ * Method: getLanguageIdList
+ */
+extern "C" JNIEXPORT jobjectArray JNICALL
+Java_com_android_framebufferizer_NativeRenderer_getLanguageIdList(JNIEnv* env, jclass) {
+ jobjectArray language_ids;
+ languages lang_list = ConfirmationUITranslations_get_languages();
+ const char* const* native_data = lang_list.list;
+ size_t list_size = lang_list.size;
+
+ language_ids = (jobjectArray)env->NewObjectArray(list_size, env->FindClass("java/lang/String"),
+ env->NewStringUTF(""));
+
+ for (size_t i = 0; i < list_size; i++)
+ env->SetObjectArrayElement(language_ids, i, env->NewStringUTF(native_data[i]));
+
+ return language_ids;
+}