JavaWidget: add css classes and default_stylesheet.css

This commit is contained in:
Daniel Panero
2024-11-18 14:08:07 +01:00
parent d6d2c94abd
commit be93b4c396
11 changed files with 202 additions and 4 deletions

View File

@@ -946,6 +946,11 @@ public class View implements Drawable.Callback {
if (a.hasValue(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();
}
onCreateDrawableState(0);
@@ -1063,6 +1068,12 @@ public class View implements Drawable.Callback {
protected native void native_requestLayout(long widget);
protected native void native_setBackgroundDrawable(long widget, long paintable);
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_drawContent(long widget, long snapshot);
@@ -1855,7 +1866,24 @@ public class View implements Drawable.Callback {
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) {}

View File

@@ -18,6 +18,10 @@ public class Button extends TextView {
if (a.hasValue(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();
}

View File

@@ -61,7 +61,18 @@ public class TextView extends View {
if (a.hasValue(com.android.internal.R.styleable.TextView_textSize)) {
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(); }
a.recycle();
haveCustomMeasure = false;
}
@@ -103,7 +114,25 @@ public class TextView extends View {
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 setLineSpacing(float add, float mult) {}
public final void setLinksClickable(boolean whether) {}
@@ -188,7 +217,14 @@ public class TextView extends View {
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) {}