implement more APIs

This commit is contained in:
Julian Winkler
2024-03-20 23:05:17 +01:00
parent e8dc6e2f0d
commit 494605932c
18 changed files with 119 additions and 36 deletions

View File

@@ -170,12 +170,12 @@ JNIEXPORT jobjectArray JNICALL Java_android_content_res_AssetManager_getArrayStr
for (i = 0; i < bag_count; i++) {
struct Res_value value = bag[i].map.value;
ssize_t block = ResTable_resolveReference(res_table, &value, bag[i].stringBlock, NULL, NULL, NULL);
if (bag[i].map.value.dataType == TYPE_STRING) {
if (value.dataType == TYPE_STRING) {
const struct ResStringPool *string_pool = ResTable_getTableStringBlock(res_table, block);
if (string_pool == NULL)
continue;
size_t len;
const char16_t *string = ResStringPool_stringAt(string_pool, bag[i].map.value.data, &len);
const char16_t *string = ResStringPool_stringAt(string_pool, value.data, &len);
(*env)->SetObjectArrayElement(env, array, i, (*env)->NewString(env, string, len));
}
}

View File

@@ -231,6 +231,14 @@ JNIEXPORT void JNICALL Java_android_widget_EditText_native_1addTextChangedListen
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setOnEditorActionListener
(JNIEnv *, jobject, jlong, jobject);
/*
* Class: android_widget_EditText
* Method: native_setText
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setText
(JNIEnv *, jobject, jlong, jstring);
#ifdef __cplusplus
}
#endif

View File

@@ -77,3 +77,11 @@ JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setOnEditorActionLis
g_signal_connect(entry, "activate", G_CALLBACK(on_activate), callback_data);
}
JNIEXPORT void JNICALL Java_android_widget_EditText_native_1setText(JNIEnv *env, jobject this, jlong widget_ptr, jstring text_jstr)
{
const char *text = (*env)->GetStringUTFChars(env, text_jstr, NULL);
jsize length = (*env)->GetStringUTFLength(env, text_jstr);
gtk_entry_buffer_set_text(gtk_entry_get_buffer(GTK_ENTRY(_PTR(widget_ptr))), text, length);
(*env)->ReleaseStringUTFChars(env, text_jstr, text);
}

View File

@@ -3,7 +3,9 @@ package android.content;
import java.io.File;
import java.io.FileNotFoundException;
import android.database.AbstractCursor;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
@@ -23,4 +25,18 @@ public class ContentResolver {
public ParcelFileDescriptor openFileDescriptor(Uri uri, String mode) throws FileNotFoundException {
return ParcelFileDescriptor.open(new File(uri.uri), ParcelFileDescriptor.parseMode(mode));
}
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return new AbstractCursor() {
public int getCount() { return 0; }
public String[] getColumnNames() { return new String[0]; }
public String getString(int column) { throw new IndexOutOfBoundsException(); }
public short getShort(int column) { throw new IndexOutOfBoundsException(); }
public int getInt(int column) { throw new IndexOutOfBoundsException(); }
public long getLong(int column) { throw new IndexOutOfBoundsException(); }
public float getFloat(int column) { throw new IndexOutOfBoundsException(); }
public double getDouble(int column) { throw new IndexOutOfBoundsException(); }
public boolean isNull(int column) { throw new IndexOutOfBoundsException(); }
};
}
}

View File

@@ -419,7 +419,11 @@ public class Context extends Object {
if (intent.getComponent() == null) {
if(intent.getAction() != null && intent.getAction().equals("android.intent.action.SEND")) {
Slog.i(TAG, "starting extern activity with intent: " + intent);
ClipboardManager.native_set_clipboard(intent.getStringExtra("android.intent.extra.TEXT"));
String text = intent.getStringExtra("android.intent.extra.TEXT");
if (text == null)
text = String.valueOf(intent.getExtras().get("android.intent.extra.STREAM"));
if (text != null)
ClipboardManager.native_set_clipboard(text);
} else if (intent.getData() != null) {
Slog.i(TAG, "starting extern activity with intent: " + intent);
Activity.nativeOpenURI(String.valueOf(intent.getData()));

View File

@@ -294,4 +294,9 @@ public class Intent {
public String getType() {
return type;
}
public Intent setData(Uri uri) {
this.data = uri;
return this;
}
}

View File

@@ -156,4 +156,36 @@ public class BaseBundle {
public int size() {
return mMap.size();
}
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @param defaultValue Value to return if key does not exist
* @return an int value
*/
public int getInt(String key, int defaultValue) {
Object o = mMap.get(key);
if (o == null) {
return defaultValue;
}
try {
return (Integer)o;
} catch (ClassCastException e) {
typeWarning(key, o, "Integer", defaultValue, e);
return defaultValue;
}
}
/**
* Returns the value associated with the given key, or 0 if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @return an int value
*/
public int getInt(String key) {
return getInt(key, 0);
}
}

View File

@@ -3,4 +3,6 @@ package android.os;
public class Binder extends IBinder {
public void attachInterface(IInterface owner, String descriptor) {}
public static void flushPendingCommands() {}
}

View File

@@ -752,38 +752,6 @@ public final class Bundle extends BaseBundle implements Cloneable {
}
}
/**
* Returns the value associated with the given key, or 0 if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @return an int value
*/
public int getInt(String key) {
return getInt(key, 0);
}
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @param defaultValue Value to return if key does not exist
* @return an int value
*/
public int getInt(String key, int defaultValue) {
Object o = mMap.get(key);
if (o == null) {
return defaultValue;
}
try {
return (Integer)o;
} catch (ClassCastException e) {
typeWarning(key, o, "Integer", defaultValue, e);
return defaultValue;
}
}
/**
* Returns the value associated with the given key, or 0L if
* no mapping of the desired type exists for the given key.

View File

@@ -0,0 +1,11 @@
package android.os;
public class FileObserver {
public FileObserver(String path, int mask) {}
public void startWatching() {}
public void stopWatching() {}
}

View File

@@ -2,4 +2,8 @@ package android.text.method;
public class LinkMovementMethod extends MovementMethod {
public static MovementMethod getInstance() {
return new LinkMovementMethod();
}
}

View File

@@ -0,0 +1,7 @@
package android.text.style;
public class StyleSpan {
public StyleSpan(int style) {}
}

View File

@@ -1,4 +1,6 @@
package android.text.style;
public class URLSpan {
public URLSpan(String url) {}
}

View File

@@ -4,6 +4,11 @@ import android.text.Spannable;
import android.widget.TextView;
public class Linkify {
public static MatchFilter sUrlMatchFilter = null;
public static final boolean addLinks(Spannable text, int mask) { return true; }
public static final boolean addLinks(TextView text, int mask) { return true; }
public class MatchFilter {}
}

View File

@@ -1661,4 +1661,8 @@ public class View extends Object {
public boolean hasOnClickListeners() {return false;}
public void setTextAlignment(int textAlignment) {}
public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) {}
public StateListAnimator getStateListAnimator() {return null;}
}

View File

@@ -20,6 +20,7 @@ public class EditText extends TextView {
protected native String native_getText(long widget);
protected native void native_addTextChangedListener(long widget, TextWatcher watcher);
protected native void native_setOnEditorActionListener(long widget, OnEditorActionListener l);
protected native void native_setText(long widget, String text);
public Editable getText() {
return new SpannableStringBuilder(native_getText(widget));
@@ -30,7 +31,9 @@ public class EditText extends TextView {
}
@Override
public void setText(CharSequence text) {}
public void setText(CharSequence text) {
native_setText(widget, String.valueOf(text));
}
@Override
public void setTextSize(float size) {}

View File

@@ -231,4 +231,6 @@ public class TextView extends View {
public float getLetterSpacing() {return 0.f;}
public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end, int bottom) {}
public boolean getLinksClickable() {return true;}
}

View File

@@ -247,6 +247,7 @@ hax_jar = jar('hax', [
'android/os/Debug.java',
'android/os/DropBoxManager.java',
'android/os/Environment.java',
'android/os/FileObserver.java',
'android/os/Handler.java',
'android/os/HandlerThread.java',
'android/os/IBinder.java',
@@ -309,6 +310,7 @@ hax_jar = jar('hax', [
'android/text/method/TransformationMethod.java',
'android/text/style/CharacterStyle.java',
'android/text/style/ClickableSpan.java',
'android/text/style/StyleSpan.java',
'android/text/style/URLSpan.java',
'android/text/util/Linkify.java',
'android/util/AndroidException.java',