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
start implementing Drawable using underlying GdkPaintable
This commit is contained in:
@@ -80,6 +80,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
|||||||
'src/api-impl-jni/database/android_database_SQLiteCommon.c',
|
'src/api-impl-jni/database/android_database_SQLiteCommon.c',
|
||||||
'src/api-impl-jni/database/android_database_SQLiteConnection.c',
|
'src/api-impl-jni/database/android_database_SQLiteConnection.c',
|
||||||
'src/api-impl-jni/graphics/android_graphics_BitmapFactory.c',
|
'src/api-impl-jni/graphics/android_graphics_BitmapFactory.c',
|
||||||
|
'src/api-impl-jni/graphics/android_graphics_drawable_Drawable.c',
|
||||||
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
|
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
|
||||||
'src/api-impl-jni/media/android_media_MediaCodec.c',
|
'src/api-impl-jni/media/android_media_MediaCodec.c',
|
||||||
'src/api-impl-jni/android_content_res_AssetManager.c',
|
'src/api-impl-jni/android_content_res_AssetManager.c',
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||||
|
#include <jni.h>
|
||||||
|
/* Header for class android_graphics_drawable_Drawable */
|
||||||
|
|
||||||
|
#ifndef _Included_android_graphics_drawable_Drawable
|
||||||
|
#define _Included_android_graphics_drawable_Drawable
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Class: android_graphics_drawable_Drawable
|
||||||
|
* Method: native_paintable_from_path
|
||||||
|
* Signature: (Ljava/lang/String;)J
|
||||||
|
*/
|
||||||
|
JNIEXPORT jlong JNICALL Java_android_graphics_drawable_Drawable_native_1paintable_1from_1path
|
||||||
|
(JNIEnv *, jclass, jstring);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -279,6 +279,14 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1layout
|
|||||||
JNIEXPORT void JNICALL Java_android_view_View_native_1requestLayout
|
JNIEXPORT void JNICALL Java_android_view_View_native_1requestLayout
|
||||||
(JNIEnv *, jobject, jlong);
|
(JNIEnv *, jobject, jlong);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_view_View
|
||||||
|
* Method: native_setBackgroundDrawable
|
||||||
|
* Signature: (JJ)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable
|
||||||
|
(JNIEnv *, jobject, jlong, jlong);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: android_view_View
|
* Class: android_view_View
|
||||||
* Method: nativeInvalidate
|
* Method: nativeInvalidate
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include <gdk/gdk.h>
|
||||||
|
|
||||||
|
#include "../defines.h"
|
||||||
|
#include "../generated_headers/android_graphics_drawable_Drawable.h"
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL Java_android_graphics_drawable_Drawable_native_1paintable_1from_1path(JNIEnv *env, jclass class, jstring pathStr) {
|
||||||
|
const char *path = (*env)->GetStringUTFChars(env, pathStr, NULL);
|
||||||
|
|
||||||
|
GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_from_filename(path, NULL));
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars(env, pathStr, path);
|
||||||
|
return _INTPTR(paintable);
|
||||||
|
}
|
||||||
@@ -405,3 +405,9 @@ JNIEXPORT void JNICALL Java_android_view_View_setBackgroundColor(JNIEnv *env, jo
|
|||||||
|
|
||||||
gtk_style_context_add_provider(gtk_widget_get_style_context(gtk_widget_get_parent(widget)), GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk_style_context_add_provider(gtk_widget_get_style_context(gtk_widget_get_parent(widget)), GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr) {
|
||||||
|
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
|
||||||
|
GdkPaintable *paintable = GDK_PAINTABLE(_PTR(paintable_ptr));
|
||||||
|
wrapper_widget_set_background(WRAPPER_WIDGET(gtk_widget_get_parent(widget)), paintable);
|
||||||
|
}
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ void wrapper_widget_allocate(GtkWidget *widget, int width, int height, int basel
|
|||||||
gtk_widget_size_allocate(wrapper->child, &allocation, baseline);
|
gtk_widget_size_allocate(wrapper->child, &allocation, baseline);
|
||||||
if (wrapper->sk_area)
|
if (wrapper->sk_area)
|
||||||
gtk_widget_size_allocate(wrapper->sk_area, &allocation, baseline);
|
gtk_widget_size_allocate(wrapper->sk_area, &allocation, baseline);
|
||||||
|
if (wrapper->background)
|
||||||
|
gtk_widget_size_allocate(wrapper->background, &allocation, baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wrapper_widget_class_init(WrapperWidgetClass *class)
|
static void wrapper_widget_class_init(WrapperWidgetClass *class)
|
||||||
@@ -172,3 +174,12 @@ void wrapper_widget_set_layout_params(WrapperWidget *wrapper, int width, int hei
|
|||||||
wrapper->layout_width = width;
|
wrapper->layout_width = width;
|
||||||
wrapper->layout_height = height;
|
wrapper->layout_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wrapper_widget_set_background(WrapperWidget *wrapper, GdkPaintable *paintable)
|
||||||
|
{
|
||||||
|
if (!wrapper->background) {
|
||||||
|
wrapper->background = gtk_picture_new();
|
||||||
|
gtk_widget_insert_after(wrapper->background, GTK_WIDGET(wrapper), NULL);
|
||||||
|
}
|
||||||
|
gtk_picture_set_paintable(GTK_PICTURE(wrapper->background), paintable);
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct _WrapperWidget
|
|||||||
GtkWidget parent_instance;
|
GtkWidget parent_instance;
|
||||||
GtkWidget *child;
|
GtkWidget *child;
|
||||||
GtkWidget *sk_area;
|
GtkWidget *sk_area;
|
||||||
|
GtkWidget *background;
|
||||||
JavaVM *jvm;
|
JavaVM *jvm;
|
||||||
jobject jobj;
|
jobject jobj;
|
||||||
jobject canvas;
|
jobject canvas;
|
||||||
@@ -31,6 +32,7 @@ void wrapper_widget_set_child(WrapperWidget *parent, GtkWidget *child);
|
|||||||
void wrapper_widget_set_jobject(WrapperWidget *wrapper, JNIEnv *env, jobject jobj);
|
void wrapper_widget_set_jobject(WrapperWidget *wrapper, JNIEnv *env, jobject jobj);
|
||||||
void wrapper_widget_queue_draw(WrapperWidget *wrapper);
|
void wrapper_widget_queue_draw(WrapperWidget *wrapper);
|
||||||
void wrapper_widget_set_layout_params(WrapperWidget *wrapper, int width, int height);
|
void wrapper_widget_set_layout_params(WrapperWidget *wrapper, int width, int height);
|
||||||
|
void wrapper_widget_set_background(WrapperWidget *wrapper, GdkPaintable *paintable);
|
||||||
|
|
||||||
void _setOnTouchListener(JNIEnv *env, jobject this, GtkWidget *widget, jobject on_touch_listener);
|
void _setOnTouchListener(JNIEnv *env, jobject this, GtkWidget *widget, jobject on_touch_listener);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package android.content.res;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.icu.text.PluralRules;
|
import android.icu.text.PluralRules;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
// import android.graphics.Movie;
|
// import android.graphics.Movie;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
// import android.graphics.drawable.ColorDrawable;
|
// import android.graphics.drawable.ColorDrawable;
|
||||||
@@ -48,7 +49,6 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
class Movie {}
|
class Movie {}
|
||||||
class ColorDrawable {}
|
|
||||||
|
|
||||||
class ConstantState {}
|
class ConstantState {}
|
||||||
|
|
||||||
@@ -2017,7 +2017,7 @@ public class Resources {
|
|||||||
final String name = getResourceName(id);
|
final String name = getResourceName(id);
|
||||||
if (name != null) android.util.Log.d("PreloadDrawable", name);
|
if (name != null) android.util.Log.d("PreloadDrawable", name);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
boolean isColorDrawable = false;
|
boolean isColorDrawable = false;
|
||||||
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
|
if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
|
||||||
@@ -2027,6 +2027,8 @@ public class Resources {
|
|||||||
final long key = isColorDrawable ? value.data :
|
final long key = isColorDrawable ? value.data :
|
||||||
(((long) value.assetCookie) << 32) | value.data;
|
(((long) value.assetCookie) << 32) | value.data;
|
||||||
|
|
||||||
|
Drawable dr = null;
|
||||||
|
/*
|
||||||
Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key);
|
Drawable dr = getCachedDrawable(isColorDrawable ? mColorDrawableCache : mDrawableCache, key);
|
||||||
|
|
||||||
if (dr != null) {
|
if (dr != null) {
|
||||||
@@ -2040,7 +2042,7 @@ public class Resources {
|
|||||||
}
|
}
|
||||||
if (cs != null) {
|
if (cs != null) {
|
||||||
dr = cs.newDrawable(this);
|
dr = cs.newDrawable(this);
|
||||||
} else {
|
} else*/ {
|
||||||
if (isColorDrawable) {
|
if (isColorDrawable) {
|
||||||
dr = new ColorDrawable(value.data);
|
dr = new ColorDrawable(value.data);
|
||||||
}
|
}
|
||||||
@@ -2089,8 +2091,7 @@ public class Resources {
|
|||||||
InputStream is = mAssets.openNonAsset(
|
InputStream is = mAssets.openNonAsset(
|
||||||
value.assetCookie, file, AssetManager.ACCESS_STREAMING);
|
value.assetCookie, file, AssetManager.ACCESS_STREAMING);
|
||||||
// System.out.println("Opened file " + file + ": " + is);
|
// System.out.println("Opened file " + file + ": " + is);
|
||||||
dr = null/*Drawable.createFromResourceStream(this, value, is,
|
dr = Drawable.createFromResourceStream(this, value, is, file, null);
|
||||||
file, null)* /;
|
|
||||||
is.close();
|
is.close();
|
||||||
// System.out.println("Created stream: " + dr);
|
// System.out.println("Created stream: " + dr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -2108,7 +2109,7 @@ public class Resources {
|
|||||||
|
|
||||||
if (dr != null) {
|
if (dr != null) {
|
||||||
dr.setChangingConfigurations(value.changingConfigurations);
|
dr.setChangingConfigurations(value.changingConfigurations);
|
||||||
cs = dr.getConstantState();
|
/* cs = dr.getConstantState();
|
||||||
if (cs != null) {
|
if (cs != null) {
|
||||||
if (mPreloading) {
|
if (mPreloading) {
|
||||||
final int changingConfigs = cs.getChangingConfigurations();
|
final int changingConfigs = cs.getChangingConfigurations();
|
||||||
@@ -2145,12 +2146,10 @@ public class Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return dr;
|
return dr;
|
||||||
*/
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getCachedDrawable(
|
private Drawable getCachedDrawable(
|
||||||
|
|||||||
@@ -1,17 +1,35 @@
|
|||||||
package android.graphics.drawable;
|
package android.graphics.drawable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.content.res.XmlResourceParser;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
|
||||||
public abstract class Drawable {
|
public class Drawable {
|
||||||
public static interface Callback {}
|
public static interface Callback {}
|
||||||
|
|
||||||
private Rect mBounds = new Rect();
|
private Rect mBounds = new Rect();
|
||||||
private int[] mStateSet = new int[0];
|
private int[] mStateSet = new int[0];
|
||||||
|
public long paintable;
|
||||||
|
|
||||||
|
public Drawable() {}
|
||||||
|
|
||||||
|
public Drawable(long paintable) {
|
||||||
|
this.paintable = paintable;
|
||||||
|
}
|
||||||
|
|
||||||
public int getChangingConfigurations() {
|
public int getChangingConfigurations() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -38,7 +56,7 @@ public abstract class Drawable {
|
|||||||
return mBounds;
|
return mBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void draw(Canvas canvas);
|
public void draw(Canvas canvas) {}
|
||||||
|
|
||||||
public boolean setState(int[] stateSet) {
|
public boolean setState(int[] stateSet) {
|
||||||
this.mStateSet = stateSet;
|
this.mStateSet = stateSet;
|
||||||
@@ -89,4 +107,36 @@ public abstract class Drawable {
|
|||||||
public void setTintMode(PorterDuff.Mode tintMode) {}
|
public void setTintMode(PorterDuff.Mode tintMode) {}
|
||||||
|
|
||||||
public boolean isProjected () {return false;}
|
public boolean isProjected () {return false;}
|
||||||
|
|
||||||
|
public static Drawable createFromXml(Resources resources, XmlResourceParser parser) throws XmlPullParserException, IOException {
|
||||||
|
int type;
|
||||||
|
while ((type=parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
|
||||||
|
if (type != XmlPullParser.START_TAG)
|
||||||
|
throw new XmlPullParserException("No start tag found");
|
||||||
|
if ("selector".equals(parser.getName())) {
|
||||||
|
StateListDrawable drawable = new StateListDrawable();
|
||||||
|
drawable.inflate(resources, parser, parser, null);
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Drawable createFromResourceStream(Resources resources, TypedValue value, InputStream is, String file,
|
||||||
|
Object object) {
|
||||||
|
Path path = Paths.get(android.os.Environment.getExternalStorageDirectory().getPath(), file);
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(file)) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
Files.createDirectories(path.getParent());
|
||||||
|
Files.copy(inputStream, path);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
long paintable = native_paintable_from_path(path.toString());
|
||||||
|
return new Drawable(paintable);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static native long native_paintable_from_path(String path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
package android.graphics.drawable;
|
package android.graphics.drawable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.content.res.Resources.Theme;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Slog;
|
||||||
|
|
||||||
public class StateListDrawable extends Drawable {
|
public class StateListDrawable extends Drawable {
|
||||||
|
|
||||||
@@ -11,5 +20,16 @@ public class StateListDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addState(int[] stateSet, Drawable drawable) {}
|
public void addState(int[] stateSet, Drawable drawable) {}
|
||||||
|
|
||||||
|
public void inflate(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
|
||||||
|
while (parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||||
|
if ("item".equals(parser.getName())) {
|
||||||
|
int resid = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "drawable", -1);
|
||||||
|
Drawable drawable = resources.getDrawable(resid, theme);
|
||||||
|
this.paintable = drawable.paintable;
|
||||||
|
Slog.i("StateListDrawable", "item resid = " + resid + ", paintable = " + drawable.paintable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -930,6 +930,7 @@ public class View extends Object {
|
|||||||
protected native void native_measure(long widget, int widthMeasureSpec, int heightMeasureSpec, boolean isComplex);
|
protected native void native_measure(long widget, int widthMeasureSpec, int heightMeasureSpec, boolean isComplex);
|
||||||
protected native void native_layout(long widget, int l, int t, int r, int b);
|
protected native void native_layout(long widget, int l, int t, int r, int b);
|
||||||
protected native void native_requestLayout(long widget);
|
protected native void native_requestLayout(long widget);
|
||||||
|
protected native void native_setBackgroundDrawable(long widget, long paintable);
|
||||||
|
|
||||||
// --- stubs
|
// --- stubs
|
||||||
|
|
||||||
@@ -1005,8 +1006,8 @@ public class View extends Object {
|
|||||||
this.visibility = visibility;
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
public void setPadding(int left, int top, int right, int bottom) {}
|
public void setPadding(int left, int top, int right, int bottom) {}
|
||||||
public void setBackgroundResource(int resid) {
|
public void setBackgroundResource(int resid) throws Exception {
|
||||||
// Slog.w(TAG, "*** setBackgroundResource: " + getString(resid));
|
setBackgroundDrawable(getResources().getDrawable(resid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getHitRect(Rect outRect) {}
|
public void getHitRect(Rect outRect) {}
|
||||||
@@ -1243,7 +1244,9 @@ public class View extends Object {
|
|||||||
layout(left + offset, top, right + offset, bottom);
|
layout(left + offset, top, right + offset, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackgroundDrawable(Drawable backgroundDrawable) {}
|
public void setBackgroundDrawable(Drawable backgroundDrawable) {
|
||||||
|
native_setBackgroundDrawable(widget, backgroundDrawable != null ? backgroundDrawable.paintable : 0);
|
||||||
|
}
|
||||||
|
|
||||||
public int getOverScrollMode() {return 0;}
|
public int getOverScrollMode() {return 0;}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user