mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-04-28 20:27:58 +03:00
JavaWidget: add css classes and default_stylesheet.css
This commit is contained in:
parent
d6d2c94abd
commit
be93b4c396
11 changed files with 202 additions and 4 deletions
|
@ -167,10 +167,14 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||||
'-D_LARGEFILE64_SOURCE',
|
'-D_LARGEFILE64_SOURCE',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
# atl.gresources.xml
|
||||||
|
resources = gnome.compile_resources('com.gitlab.android_translation_layer.android_translation_layer', files('src/main-executable/atl.gresource.xml'))
|
||||||
|
|
||||||
executable('android-translation-layer', [
|
executable('android-translation-layer', [
|
||||||
'src/main-executable/main.c',
|
'src/main-executable/main.c',
|
||||||
'src/main-executable/r_debug.c',
|
'src/main-executable/r_debug.c',
|
||||||
'src/main-executable/back_button.c'
|
'src/main-executable/back_button.c',
|
||||||
|
resources
|
||||||
],
|
],
|
||||||
install: true,
|
install: true,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
|
|
|
@ -295,6 +295,38 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable
|
||||||
JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate
|
JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate
|
||||||
(JNIEnv *, jobject, jlong);
|
(JNIEnv *, jobject, jlong);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_view_View
|
||||||
|
* Method: native_addClass
|
||||||
|
* Signature: (JLjava/lang/String;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1addClass
|
||||||
|
(JNIEnv *, jobject, jlong, jstring);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_view_View
|
||||||
|
* Method: native_removeClass
|
||||||
|
* Signature: (JLjava/lang/String;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1removeClass
|
||||||
|
(JNIEnv *, jobject, jlong, jstring);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_view_View
|
||||||
|
* Method: native_addClasses
|
||||||
|
* Signature: (J[Ljava/lang/String;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1addClasses
|
||||||
|
(JNIEnv *, jobject, jlong, jobjectArray);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_view_View
|
||||||
|
* Method: native_removeClasses
|
||||||
|
* Signature: (J[Ljava/lang/String;)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1removeClasses
|
||||||
|
(JNIEnv *, jobject, jlong, jobjectArray);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: android_view_View
|
* Class: android_view_View
|
||||||
* Method: native_drawBackground
|
* Method: native_drawBackground
|
||||||
|
|
|
@ -617,3 +617,52 @@ JNIEXPORT void JNICALL Java_android_view_View_nativeSetFullscreen(JNIEnv *env, j
|
||||||
gtk_window_unfullscreen(window);
|
gtk_window_unfullscreen(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1addClass(JNIEnv *env, jobject this, jlong widget_ptr, jstring class_name_jstr){
|
||||||
|
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||||
|
|
||||||
|
const char *class_name = (*env)->GetStringUTFChars(env, class_name_jstr, NULL);
|
||||||
|
gtk_widget_add_css_class(widget, class_name);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1removeClass(JNIEnv *env, jobject this, jlong widget_ptr, jstring class_name_jstr){
|
||||||
|
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||||
|
|
||||||
|
const char *class_name = (*env)->GetStringUTFChars(env, class_name_jstr, NULL);
|
||||||
|
gtk_widget_remove_css_class(widget, class_name);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1addClasses(JNIEnv *env, jobject this, jlong widget_ptr, jobjectArray class_names_jarray){
|
||||||
|
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||||
|
|
||||||
|
int length = (*env)->GetArrayLength(env, class_names_jarray);
|
||||||
|
|
||||||
|
for(int i = 0; i < length; i++){
|
||||||
|
jstring class_name_jstr = (jstring) ((*env)->GetObjectArrayElement(env, class_names_jarray, i));
|
||||||
|
|
||||||
|
const char *class_name = (*env)->GetStringUTFChars(env, class_name_jstr, NULL);
|
||||||
|
gtk_widget_add_css_class(widget, class_name);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1removeClasses(JNIEnv *env, jobject this, jlong widget_ptr, jobjectArray class_names_jarray){
|
||||||
|
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||||
|
|
||||||
|
int length = (*env)->GetArrayLength(env, class_names_jarray);
|
||||||
|
|
||||||
|
for(int i = 0; i < length; i++){
|
||||||
|
jstring class_name_jstr = (jstring) ((*env)->GetObjectArrayElement(env, class_names_jarray, i));
|
||||||
|
|
||||||
|
const char *class_name = (*env)->GetStringUTFChars(env, class_name_jstr, NULL);
|
||||||
|
gtk_widget_remove_css_class(widget, class_name);
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, class_name_jstr, class_name);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ JNIEXPORT jlong JNICALL Java_android_widget_Button_native_1constructor(JNIEnv *e
|
||||||
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), label);
|
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), label);
|
||||||
wrapper_widget_consume_touch_events(WRAPPER_WIDGET(wrapper)); // Android button consumes touch events
|
wrapper_widget_consume_touch_events(WRAPPER_WIDGET(wrapper)); // Android button consumes touch events
|
||||||
wrapper_widget_set_jobject(WRAPPER_WIDGET(wrapper), env, this);
|
wrapper_widget_set_jobject(WRAPPER_WIDGET(wrapper), env, this);
|
||||||
|
|
||||||
return _INTPTR(label);
|
return _INTPTR(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,4 +51,6 @@ JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setDrawable(JNIEn
|
||||||
GtkPicture *picture = GTK_PICTURE(gtk_button_get_child(GTK_BUTTON(button)));
|
GtkPicture *picture = GTK_PICTURE(gtk_button_get_child(GTK_BUTTON(button)));
|
||||||
GdkPaintable *paintable = _PTR(paintable_ptr);
|
GdkPaintable *paintable = _PTR(paintable_ptr);
|
||||||
gtk_picture_set_paintable(picture, paintable);
|
gtk_picture_set_paintable(picture, paintable);
|
||||||
|
|
||||||
|
gtk_widget_add_css_class(GTK_WIDGET(button), "ATL-no-border");
|
||||||
}
|
}
|
||||||
|
|
|
@ -946,6 +946,11 @@ public class View implements Drawable.Callback {
|
||||||
if (a.hasValue(com.android.internal.R.styleable.View_tag)) {
|
if (a.hasValue(com.android.internal.R.styleable.View_tag)) {
|
||||||
tag = a.getText(com.android.internal.R.styleable.View_tag);
|
tag = a.getText(com.android.internal.R.styleable.View_tag);
|
||||||
}
|
}
|
||||||
|
if(a.hasValue(com.android.internal.R.styleable.View_textAlignment)) {
|
||||||
|
int textAlignment = a.getInt(com.android.internal.R.styleable.View_textAlignment, 0);
|
||||||
|
setTextAlignment(textAlignment);
|
||||||
|
}
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
onCreateDrawableState(0);
|
onCreateDrawableState(0);
|
||||||
|
@ -1063,6 +1068,12 @@ public class View implements Drawable.Callback {
|
||||||
protected native void native_requestLayout(long widget);
|
protected native void native_requestLayout(long widget);
|
||||||
protected native void native_setBackgroundDrawable(long widget, long paintable);
|
protected native void native_setBackgroundDrawable(long widget, long paintable);
|
||||||
protected native void native_queueAllocate(long widget);
|
protected native void native_queueAllocate(long widget);
|
||||||
|
|
||||||
|
protected native void native_addClass(long widget, String className);
|
||||||
|
protected native void native_removeClass(long widget, String className);
|
||||||
|
|
||||||
|
protected native void native_addClasses(long widget, String[] classNames);
|
||||||
|
protected native void native_removeClasses(long widget, String[] classNames);
|
||||||
|
|
||||||
protected native void native_drawBackground(long widget, long snapshot);
|
protected native void native_drawBackground(long widget, long snapshot);
|
||||||
protected native void native_drawContent(long widget, long snapshot);
|
protected native void native_drawContent(long widget, long snapshot);
|
||||||
|
@ -1855,7 +1866,24 @@ public class View implements Drawable.Callback {
|
||||||
|
|
||||||
public boolean hasOnClickListeners() {return false;}
|
public boolean hasOnClickListeners() {return false;}
|
||||||
|
|
||||||
public void setTextAlignment(int textAlignment) {}
|
public void setTextAlignment(int textAlignment) {
|
||||||
|
String[] classesToRemove = {"ATL-text-align-left", "ATL-text-align-center", "ATL-text-align-right"};
|
||||||
|
native_removeClasses(widget, classesToRemove);
|
||||||
|
|
||||||
|
switch(textAlignment) {
|
||||||
|
case TEXT_ALIGNMENT_CENTER:
|
||||||
|
native_addClass(widget, "ATL-text-align-center");
|
||||||
|
break;
|
||||||
|
case TEXT_ALIGNMENT_TEXT_START:
|
||||||
|
case TEXT_ALIGNMENT_VIEW_START:
|
||||||
|
native_addClass(widget, "ATL-text-align-left");
|
||||||
|
break;
|
||||||
|
case TEXT_ALIGNMENT_TEXT_END:
|
||||||
|
case TEXT_ALIGNMENT_VIEW_END:
|
||||||
|
native_addClass(widget, "ATL-text-align-right");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) {}
|
public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) {}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ public class Button extends TextView {
|
||||||
if (a.hasValue(com.android.internal.R.styleable.TextView_text)) {
|
if (a.hasValue(com.android.internal.R.styleable.TextView_text)) {
|
||||||
setText(a.getText(com.android.internal.R.styleable.TextView_text));
|
setText(a.getText(com.android.internal.R.styleable.TextView_text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(getBackground() != null){
|
||||||
|
native_addClass(widget, "ATL-no-border");
|
||||||
|
}
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,18 @@ public class TextView extends View {
|
||||||
if (a.hasValue(com.android.internal.R.styleable.TextView_textSize)) {
|
if (a.hasValue(com.android.internal.R.styleable.TextView_textSize)) {
|
||||||
setTextSize(a.getDimensionPixelSize(com.android.internal.R.styleable.TextView_textSize, 10));
|
setTextSize(a.getDimensionPixelSize(com.android.internal.R.styleable.TextView_textSize, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(a.hasValue(com.android.internal.R.styleable.TextView_textStyle)) {
|
||||||
|
int textStyle = a.getInt(com.android.internal.R.styleable.TextView_textStyle, 0);
|
||||||
|
setTypeface(getTypeface(), textStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a.hasValue(com.android.internal.R.styleable.TextView_textAllCaps)) {
|
||||||
|
boolean allCaps = a.getBoolean(com.android.internal.R.styleable.TextView_textAllCaps, false);
|
||||||
|
setAllCaps(allCaps);
|
||||||
|
}
|
||||||
} catch(java.lang.Exception e) { System.out.println("exception while inflating TextView:"); e.printStackTrace(); }
|
} catch(java.lang.Exception e) { System.out.println("exception while inflating TextView:"); e.printStackTrace(); }
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
haveCustomMeasure = false;
|
haveCustomMeasure = false;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +114,25 @@ public class TextView extends View {
|
||||||
setTextColor(colors.getDefaultColor()); // TODO: do this properly
|
setTextColor(colors.getDefaultColor()); // TODO: do this properly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void setTypeface(Typeface tf, int style) {}
|
public void setTypeface(Typeface tf, int style) {
|
||||||
|
String[] classesToRemove = {"ATL-font-bold", "ATL-font-italic"};
|
||||||
|
native_removeClasses(widget, classesToRemove);
|
||||||
|
|
||||||
|
switch(style) {
|
||||||
|
case Typeface.BOLD:
|
||||||
|
native_addClass(widget, "ATL-font-bold");
|
||||||
|
break;
|
||||||
|
case Typeface.ITALIC:
|
||||||
|
native_addClass(widget, "ATL-font-italic");
|
||||||
|
break;
|
||||||
|
case Typeface.BOLD_ITALIC:
|
||||||
|
native_addClass(widget, "ATL-font-bold");
|
||||||
|
native_addClass(widget, "ATL-font-italic");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
public void setTypeface(Typeface tf) {}
|
public void setTypeface(Typeface tf) {}
|
||||||
public void setLineSpacing(float add, float mult) {}
|
public void setLineSpacing(float add, float mult) {}
|
||||||
public final void setLinksClickable(boolean whether) {}
|
public final void setLinksClickable(boolean whether) {}
|
||||||
|
@ -188,7 +217,14 @@ public class TextView extends View {
|
||||||
drawableBottom = bottom;
|
drawableBottom = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAllCaps(boolean allCaps) {}
|
public void setAllCaps(boolean allCaps) {
|
||||||
|
String[] classesToRemove = {"ATL-text-uppercase"};
|
||||||
|
native_removeClasses(widget, classesToRemove);
|
||||||
|
|
||||||
|
if(allCaps){
|
||||||
|
native_addClass(widget, "ATL-text-uppercase");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setSaveEnabled(boolean enabled) {}
|
public void setSaveEnabled(boolean enabled) {}
|
||||||
|
|
||||||
|
|
6
src/main-executable/atl.gresource.xml
Normal file
6
src/main-executable/atl.gresource.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/com/gitlab/android-translation-layer/android-translation-layer">
|
||||||
|
<file alias="default-stylesheet.css">src/main-executable/css/default-stylesheet.css</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
31
src/main-executable/css/default-stylesheet.css
Normal file
31
src/main-executable/css/default-stylesheet.css
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* Border Styling */
|
||||||
|
.ATL-no-border {
|
||||||
|
border: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Font styling */
|
||||||
|
.ATL-font-bold > * {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ATL-font-italic > * {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Text styling */
|
||||||
|
.ATL-text-uppercase > * {
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ATL-text-align-left > * {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ATL-text-align-center > * {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ATL-text-align-right > * {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
|
@ -417,6 +417,11 @@ static void open(GtkApplication *app, GFile **files, gint nfiles, const gchar *h
|
||||||
if (getenv("ATL_FORCE_FULLSCREEN"))
|
if (getenv("ATL_FORCE_FULLSCREEN"))
|
||||||
gtk_window_fullscreen(GTK_WINDOW(window));
|
gtk_window_fullscreen(GTK_WINDOW(window));
|
||||||
|
|
||||||
|
// Load default css stylesheet
|
||||||
|
GtkCssProvider * cssProvider = gtk_css_provider_new();
|
||||||
|
gtk_css_provider_load_from_resource(cssProvider, "/com/gitlab/android-translation-layer/android-translation-layer/default-stylesheet.css");
|
||||||
|
gtk_style_context_add_provider_for_display(gdk_display_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
|
|
||||||
prepare_main_looper(env);
|
prepare_main_looper(env);
|
||||||
|
|
||||||
// construct Application
|
// construct Application
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue