You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
View: implement visibility and alpha properly
This commit is contained in:
@@ -298,10 +298,10 @@ JNIEXPORT void JNICALL Java_android_view_View_setBackgroundColor
|
||||
/*
|
||||
* Class: android_view_View
|
||||
* Method: native_setVisibility
|
||||
* Signature: (JI)V
|
||||
* Signature: (JIF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setVisibility
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
(JNIEnv *, jobject, jlong, jint, jfloat);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -251,19 +251,11 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *en
|
||||
wrapper_widget_set_layout_params(WRAPPER_WIDGET(widget), width, height);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setVisibility(JNIEnv *env, jobject this, jlong widget_ptr, jint visibility) {
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setVisibility(JNIEnv *env, jobject this, jlong widget_ptr, jint visibility, jfloat alpha) {
|
||||
GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr)));
|
||||
|
||||
switch (visibility) {
|
||||
case android_view_View_VISIBLE:
|
||||
gtk_widget_set_visible(widget, true);
|
||||
break;
|
||||
// TODO: View.INVISIBLE should still reserve layout space for the hidden view
|
||||
case android_view_View_INVISIBLE:
|
||||
case android_view_View_GONE:
|
||||
gtk_widget_set_visible(widget, false);
|
||||
break;
|
||||
}
|
||||
gtk_widget_set_visible(widget, visibility != android_view_View_GONE);
|
||||
gtk_widget_set_opacity(widget, (visibility != android_view_View_INVISIBLE) * alpha);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_view_View_native_1constructor(JNIEnv *env, jobject this, jobject context, jobject attrs)
|
||||
|
||||
@@ -815,6 +815,9 @@ public class View extends Object {
|
||||
private int oldHeight;
|
||||
private boolean haveCustomMeasure;
|
||||
|
||||
private int visibility = View.VISIBLE;
|
||||
private float alpha = 1.0f;
|
||||
|
||||
public View() {
|
||||
this(Context.this_application);
|
||||
} // FIXME
|
||||
@@ -996,10 +999,13 @@ public class View extends Object {
|
||||
private static native void nativeInvalidate(long widget);
|
||||
|
||||
public native void setBackgroundColor(int color);
|
||||
public native void native_setVisibility(long widget, int visibility);
|
||||
public native void native_setVisibility(long widget, int visibility, float alpha);
|
||||
public void setVisibility(int visibility) {
|
||||
native_setVisibility(widget, visibility);
|
||||
requestLayout();
|
||||
native_setVisibility(widget, visibility, alpha);
|
||||
if ((visibility == View.GONE) != (this.visibility == View.GONE)) {
|
||||
requestLayout();
|
||||
}
|
||||
this.visibility = visibility;
|
||||
}
|
||||
public void setPadding(int left, int top, int right, int bottom) {}
|
||||
public void setBackgroundResource(int resid) {
|
||||
@@ -1302,7 +1308,7 @@ public class View extends Object {
|
||||
|
||||
public void setActivated (boolean activated) {}
|
||||
|
||||
public int getVisibility() {return View.VISIBLE;}
|
||||
public int getVisibility() {return visibility;}
|
||||
|
||||
public boolean isInEditMode() {return false;}
|
||||
|
||||
@@ -1340,7 +1346,8 @@ public class View extends Object {
|
||||
public void setTranslationY(float translationY) {}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
setVisibility((alpha == 0.f) ? INVISIBLE : VISIBLE);
|
||||
native_setVisibility(widget, visibility, alpha);
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {return false;}
|
||||
@@ -1485,7 +1492,7 @@ public class View extends Object {
|
||||
|
||||
public int getWindowVisibility() {return VISIBLE;}
|
||||
|
||||
public float getAlpha() {return 1.f;}
|
||||
public float getAlpha() {return alpha;}
|
||||
|
||||
public View findFocus() {return this;}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user