add more APIs needed for NewPipe

This commit is contained in:
Julian Winkler
2024-03-16 12:49:28 +01:00
parent b3c0023a45
commit 276b5ca7ef
40 changed files with 768 additions and 50 deletions

View File

@@ -2,4 +2,19 @@ package android.animation;
public class AnimatorSet extends Animator {
public class Builder {
public Builder with(Animator animator) {
return this;
}
}
public Builder play(Animator animator) {
return new Builder();
}
public void setInterpolator(TimeInterpolator value) {}
public void playSequentially(Animator[] animators) {}
}

View File

@@ -254,7 +254,7 @@ public class Activity extends ContextWrapper implements Window.Callback {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {}
public void startActivityForResult(Intent intent, int requestCode) {
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
System.out.println("startActivityForResult(" + intent + ", " + requestCode + ") called, but we don't currently support multiple activities");
if (intent.getComponent() != null) {
try {
@@ -276,9 +276,13 @@ public class Activity extends ContextWrapper implements Window.Callback {
}
}
else {
System.out.println("startActivityForResult: intent was not handled. Calling onActivityResult(RESULT_CANCELED).");
onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent()); // RESULT_CANCELED is the only pre-defined return value, so hopefully it works out for us
}
}
public void startActivityForResult(Intent intent, int requestCode) {
startActivityForResult(intent, requestCode, null);
}
public void setResult(int resultCode, Intent data) {
if (resultActivity != null) {
@@ -422,5 +426,4 @@ public class Activity extends ContextWrapper implements Window.Callback {
public static native void nativeRecreateActivity(Activity activity);
public static native void nativeStartActivity(Activity activity);
public static native void nativeOpenURI(String uri);
public static native void nativeShare(String text);
}

View File

@@ -143,4 +143,13 @@ public class Notification {
public MediaStyle setMediaSession(MediaSession.Token token) {return this;}
}
public static class BigTextStyle extends Style {
public BigTextStyle(Notification.Builder builder) {}
public BigTextStyle setBigContentTitle(CharSequence title) {return this;}
public BigTextStyle bigText(CharSequence text) {return this;}
}
}

View File

@@ -6,4 +6,8 @@ public class NotificationManager {
public void notify(String tag, int id, Notification notification) {
System.out.println("notify(" + tag + ", " + id + ", " + notification + ") called");
}
public void notify(int id, Notification notification) {
System.out.println("notify(" + id + ", " + notification + ") called");
}
}

View File

@@ -19,6 +19,10 @@ public class PendingIntent {
return new PendingIntent();
}
public static PendingIntent getService(Context context, int requestCode, Intent intent, int flags) {
return new PendingIntent();
}
public class CanceledException extends Exception {
}
}

View File

@@ -6,7 +6,9 @@ import android.os.IBinder;
public abstract class Service extends Context {
public abstract void onCreate();
public void onCreate() {
System.out.println("Service.onCreate() called");
}
public abstract IBinder onBind(Intent intent);
@@ -16,4 +18,8 @@ public abstract class Service extends Context {
System.out.println("startForeground(" + id + ", " + notification + ") called");
}
public void stopForeground(boolean remove) {
System.out.println("stopForeground(" + remove + ") called");
}
}

View File

@@ -0,0 +1,12 @@
package android.content;
public class ClipData {
String text;
public static ClipData newPlainText(CharSequence label, CharSequence text) {
ClipData clip = new ClipData();
clip.text = text.toString();
return clip;
}
}

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
package android.content;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
@@ -22,7 +23,6 @@ import android.os.RemoteException;
import android.util.Log;
import java.util.ArrayList;
class ClipData {}
class ClipDescription {}
/**
@@ -79,6 +79,8 @@ public class ClipboardManager extends android.text.ClipboardManager {
* @param clip The clipped data item to set.
*/
public void setPrimaryClip(ClipData clip) {
// this is not the primary clipboard in UNIX sense (not middle click paste)
native_set_clipboard(clip.text);
}
/**
* Returns the current primary clip on the clipboard.
@@ -125,4 +127,6 @@ public class ClipboardManager extends android.text.ClipboardManager {
}
void reportPrimaryClipChanged() {
}
public static native void native_set_clipboard(String text);
}

View File

@@ -24,6 +24,10 @@ import android.location.LocationManager;
import android.media.AudioManager;
import android.media.MediaRouter;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Vibrator;
@@ -86,6 +90,7 @@ public class Context extends Object {
r = new Resources(assets, dm, config);
theme = r.newTheme();
application_info = new ApplicationInfo();
application_info.dataDir = Environment.getExternalStorageDirectory().getAbsolutePath();
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml");
try {
manifest = AndroidManifestBlock.load(inStream);
@@ -188,6 +193,8 @@ public class Context extends Object {
return new AccessibilityManager();
case "layout_inflater":
return new LayoutInflater();
case "wifi":
return new WifiManager();
default:
Slog.e(TAG, "!!!!!!! getSystemService: case >" + name + "< is not implemented yet");
return null;
@@ -374,24 +381,29 @@ public class Context extends Object {
public void registerComponentCallbacks(ComponentCallbacks callbacks) {}
public boolean bindService(Intent intent, ServiceConnection serviceConnection, int dummy3) {
try {
if(intent.getComponent() == null) {
Slog.w(TAG, "Context.bindService: intent.getComponent() is null");
return false; // maybe?
}
Class<? extends Service> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Service.class);
if (!runningServices.containsKey(cls)) {
Service service = cls.getConstructor().newInstance();
service.onCreate();
runningServices.put(cls, service);
}
serviceConnection.onServiceConnected(intent.getComponent(), runningServices.get(cls).onBind(intent));
} catch (ReflectiveOperationException e) {
e.printStackTrace();
public boolean bindService(final Intent intent, final ServiceConnection serviceConnection, int dummy3) {
if(intent.getComponent() == null) {
Slog.w(TAG, "Context.bindService: intent.getComponent() is null");
return false;
}
return false; // maybe?
new Handler().post(new Runnable() { // run this asynchron so the caller can finish its setup before onServiceConnected is called
@Override
public void run() {
try {
Class<? extends Service> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Service.class);
if (!runningServices.containsKey(cls)) {
Service service = cls.getConstructor().newInstance();
service.onCreate();
runningServices.put(cls, service);
}
serviceConnection.onServiceConnected(intent.getComponent(), runningServices.get(cls).onBind(intent));
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
}
});
return true;
}
public void startActivity(Intent intent) {
@@ -402,7 +414,7 @@ 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);
Activity.nativeShare((String) intent.getExtras().get("android.intent.extra.TEXT"));
ClipboardManager.native_set_clipboard(intent.getStringExtra("android.intent.extra.TEXT"));
} else if (intent.getData() != null) {
Slog.i(TAG, "starting extern activity with intent: " + intent);
Activity.nativeOpenURI(String.valueOf(intent.getData()));
@@ -466,4 +478,8 @@ public class Context extends Object {
public Context createPackageContext(String dummy, int dummy2) {
return this; // FIXME?
}
public void grantUriPermission(String dummy, Uri dummy2, int dummy3) {
System.out.println("grantUriPermission(" + dummy + ", " + dummy2 + ", " + dummy3 + ") called");
}
}

View File

@@ -278,4 +278,16 @@ public class Intent {
this.type = type;
return this;
}
public long getLongExtra(String name, long def) {
return extras.getLong(name, def);
}
public char getCharExtra(String name, char def) {
return extras.getChar(name, def);
}
public Parcelable[] getParcelableArrayExtra(String name) {
return extras.getParcelableArray(name);
}
}

View File

@@ -127,4 +127,31 @@ public class Color {
sColorNameMap.put("silver", 0xC0C0C0);
sColorNameMap.put("teal", 0x008080);
}
public static void colorToHSV(int color, float[] hsv) {
float red = ((color >> 16) & 0xFF) / 255.0f;
float green = ((color >> 8) & 0xFF) / 255.0f;
float blue = (color & 0xFF) / 255.0f;
float min = Math.min(red, Math.min(green, blue));
float max = Math.max(red, Math.max(green, blue));
float delta = max - min;
if (delta == 0) {
hsv[0] = 6;
} else if (max == red) {
hsv[0] = (green - blue) / delta % 6;
} else if (max == green) {
hsv[0] = 2 + (blue - red) / delta + 2;
} else {
hsv[0] = 4 + (red - green) / delta + 4;
}
hsv[0] *= 60;
if (max == 0) {
hsv[1] = 0;
} else {
hsv[1] = delta / max;
}
hsv[2] = max;
}
}

View File

@@ -9,6 +9,12 @@ public class ConnectivityManager {
}
public NetworkInfo getActiveNetworkInfo() {
return null; // there is no active network, because there isn't any network at all
return new NetworkInfo();
}
public void registerNetworkCallback(NetworkRequest request, NetworkCallback callback) {}
public boolean isActiveNetworkMetered() {
return false;
}
}

View File

@@ -17,4 +17,8 @@ public class NetworkInfo {
public int getType() {
return 0x8; // where did you even get a NetworkInfo object... there is no network
}
public boolean isConnected() {
return true;
}
}

View File

@@ -0,0 +1,11 @@
package android.net;
public class NetworkRequest {
public class Builder {
public NetworkRequest build() {
return new NetworkRequest();
}
}
}

View File

@@ -7,7 +7,9 @@ import java.io.File;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
public class Uri {
import android.os.Parcelable;
public class Uri implements Parcelable {
public static final Uri EMPTY = new Uri();

View File

@@ -1,5 +1,19 @@
package android.net.wifi;
public class WifiManager {
public class WifiLock {
public void setReferenceCounted(boolean referenceCounted) {}
public void release() {}
public void acquire() {}
public boolean isHeld() { return false; }
}
public WifiLock createWifiLock(int lockType, String tag) {
return new WifiLock();
}
}

View File

@@ -7,6 +7,8 @@ public final class PowerManager {
public void acquire() {}
public void release() {}
public boolean isHeld() { return false; }
}
public WakeLock newWakeLock(int levelAndFlags, String tag) {

View File

@@ -17,4 +17,10 @@ public class Layout {
public TextPaint getPaint() {return new TextPaint();}
public int getEllipsisCount(int line) {return 0;}
public CharSequence getText() {return "FIXME Layout.getText";}
public int getWidth() {return 10;}
public int getHeight() {return 10;}
}

View File

@@ -1,8 +1,12 @@
package android.view;
import android.graphics.drawable.Drawable;
public interface MenuItem {
public interface OnMenuItemClickListener {}
public interface OnMenuItemClickListener {
public boolean onMenuItemClick(MenuItem item);
}
public MenuItem setIcon(int iconRes);
@@ -30,4 +34,10 @@ public interface MenuItem {
public MenuItem setTitle(int resId);
public boolean isVisible();
public Drawable getIcon();
public SubMenu getSubMenu();
}

View File

@@ -18,6 +18,7 @@ import android.os.Looper;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.LayoutDirection;
import android.util.Property;
import android.util.Slog;
import android.util.SparseArray;
import android.view.animation.Animation;
@@ -823,6 +824,13 @@ public class View extends Object {
private int minWidth = 0;
private int minHeight = 0;
public static final Property<View, Float> TRANSLATION_Z = new Property<View, Float>(Float.class, "translationZ") {
@Override
public Float get(View object) {
return 0.f;
}
};
public View(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -1641,4 +1649,8 @@ public class View extends Object {
}
public boolean onCheckIsTextEditor() {return false;}
public boolean hasOnClickListeners() {return false;}
public void setTextAlignment(int textAlignment) {}
}

Some files were not shown because too many files have changed in this diff Show More