add bunch of new java APIs: mostly stubs or copied from AOSP

Many of these classes are only needed to be subclassed by androidx
support library, which is used in many android apps
This commit is contained in:
Julian Winkler
2023-08-17 10:46:24 +02:00
parent a8e39cd613
commit 82744e9e5e
87 changed files with 2746 additions and 46 deletions

View File

@@ -4,4 +4,12 @@ public class Color {
public static int argb(int alpha, int red, int green, int blue) {
return (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
}
/**
* Return the alpha component of a color int. This is the same as saying
* color >>> 24
*/
public static int alpha(int color) {
return color >>> 24;
}
}

View File

@@ -220,7 +220,7 @@ public class Matrix {
if (src == null) {
reset();
} else {
native_set(native_instance, src.native_instance);
// native_set(native_instance, src.native_instance);
}
}
/**
@@ -739,7 +739,7 @@ public class Matrix {
@Override
protected void finalize() throws Throwable {
try {
finalizer(native_instance);
// finalizer(native_instance);
} finally {
super.finalize();
}
@@ -747,7 +747,9 @@ public class Matrix {
/*package*/ final int ni() {
return native_instance;
}
private static native int native_create(int native_src_or_zero);
private static /*native*/ int native_create(int native_src_or_zero) {
return 0;
}
private static native boolean native_isIdentity(int native_object);
private static native boolean native_rectStaysRect(int native_object);
private static native void native_reset(int native_object);

View File

@@ -3,6 +3,18 @@ package android.graphics;
public class Paint {
private int color = 0xFF000000;
public Paint() {
}
public Paint (int flags) {
this();
setFlags(flags);
}
public Paint(Paint paint) {
setColor(paint.getColor());
}
public void setColor(int color) {
this.color = color;
}

View File

@@ -662,7 +662,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
}
protected void finalize() throws Throwable {
try {
finalizer(mNativePath);
// finalizer(mNativePath);
} finally {
super.finalize();
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.graphics;
import android.os.Parcelable;
/**
* PointF holds two float coordinates
*/
public class PointF implements Parcelable {
public float x;
public float y;
public PointF() {}
public PointF(float x, float y) {
this.x = x;
this.y = y;
}
public PointF(Point p) {
this.x = p.x;
this.y = p.y;
}
/**
* Create a new PointF initialized with the values in the specified
* PointF (which is left unmodified).
*
* @param p The point whose values are copied into the new
* point.
*/
public PointF(PointF p) {
this.x = p.x;
this.y = p.y;
}
/**
* Set the point's x and y coordinates
*/
public final void set(float x, float y) {
this.x = x;
this.y = y;
}
/**
* Set the point's x and y coordinates to the coordinates of p
*/
public final void set(PointF p) {
this.x = p.x;
this.y = p.y;
}
public final void negate() {
x = -x;
y = -y;
}
public final void offset(float dx, float dy) {
x += dx;
y += dy;
}
/**
* Returns true if the point's coordinates equal (x,y)
*/
public final boolean equals(float x, float y) {
return this.x == x && this.y == y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PointF pointF = (PointF) o;
if (Float.compare(pointF.x, x) != 0) return false;
if (Float.compare(pointF.y, y) != 0) return false;
return true;
}
@Override
public int hashCode() {
int result = (x != +0.0f ? Float.floatToIntBits(x) : 0);
result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0);
return result;
}
@Override
public String toString() {
return "PointF(" + x + ", " + y + ")";
}
/**
* Return the euclidian distance from (0,0) to the point
*/
public final float length() {
return length(x, y);
}
/**
* Returns the euclidian distance from (0,0) to (x,y)
*/
public static float length(float x, float y) {
return (float) Math.hypot(x, y);
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.graphics;
/**
* A color filter that can be used to tint the source pixels using a single
* color and a specific {@link PorterDuff Porter-Duff composite mode}.
*/
public class PorterDuffColorFilter {
private int mColor;
private PorterDuff.Mode mMode;
/**
* Create a color filter that uses the specified color and Porter-Duff mode.
*
* @param color The ARGB source color used with the specified Porter-Duff mode
* @param mode The porter-duff mode that is applied
*
* @see Color
* @see #setColor(int)
* @see #setMode(android.graphics.PorterDuff.Mode)
*/
public PorterDuffColorFilter(int color, PorterDuff.Mode mode) {
mColor = color;
mMode = mode;
update();
}
/**
* Returns the ARGB color used to tint the source pixels when this filter
* is applied.
*
* @see Color
* @see #setColor(int)
*
* @hide
*/
public int getColor() {
return mColor;
}
/**
* Specifies the color to tint the source pixels with when this color
* filter is applied.
*
* @param color An ARGB {@link Color color}
*
* @see Color
* @see #getColor()
* @see #getMode()
*
* @hide
*/
public void setColor(int color) {
mColor = color;
update();
}
/**
* Returns the Porter-Duff mode used to composite this color filter's
* color with the source pixel when this filter is applied.
*
* @see PorterDuff
* @see #setMode(android.graphics.PorterDuff.Mode)
*
* @hide
*/
public PorterDuff.Mode getMode() {
return mMode;
}
/**
* Specifies the Porter-Duff mode to use when compositing this color
* filter's color with the source pixel at draw time.
*
* @see PorterDuff
* @see #getMode()
* @see #getColor()
*
* @hide
*/
public void setMode(PorterDuff.Mode mode) {
mMode = mode;
update();
}
private void update() {
// destroyFilter(native_instance);
// native_instance = native_CreatePorterDuffFilter(mColor, mMode.nativeInt);
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
final PorterDuffColorFilter other = (PorterDuffColorFilter) object;
if (mColor != other.mColor || mMode != other.mMode) {
return false;
}
return true;
}
@Override
public int hashCode() {
return 31 * mMode.hashCode() + mColor;
}
private static native long native_CreatePorterDuffFilter(int srcColor, int porterDuffMode);
}

View File

@@ -309,7 +309,7 @@ public class Region {
}
protected void finalize() throws Throwable {
try {
nativeDestructor(mNativeRegion);
// nativeDestructor(mNativeRegion);
} finally {
super.finalize();
}
@@ -330,7 +330,7 @@ public class Region {
return mNativeRegion;
}
private static native boolean nativeEquals(int native_r1, int native_r2);
private static native int nativeConstructor();
private static int nativeConstructor() {return -1;}
private static native void nativeDestructor(int native_region);
private static native void nativeSetRegion(int native_dst, int native_src);
private static native boolean nativeSetRect(int native_dst, int left,

View File

@@ -0,0 +1,5 @@
package android.graphics.drawable;
public interface Animatable {
}

View File

@@ -0,0 +1,13 @@
package android.graphics.drawable;
import android.graphics.Canvas;
public class ColorDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'draw'");
}
}

View File

@@ -1,11 +1,15 @@
package android.graphics.drawable;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.Rect;
public abstract class Drawable {
public static interface Callback {}
private Rect mBounds = new Rect();
private int[] mStateSet = new int[0];
public int getChangingConfigurations() {
return 0;
@@ -14,11 +18,12 @@ public abstract class Drawable {
public void setChangingConfigurations(int bitmap) {}
public ConstantState getConstantState() {
return new ConstantState();
return null;
}
public class ConstantState {
public abstract class ConstantState {
public abstract Drawable newDrawable(Resources res);
}
public void setBounds(int left, int top, int right, int bottom) {
@@ -30,4 +35,38 @@ public abstract class Drawable {
}
public abstract void draw(Canvas canvas);
public boolean setState(int[] stateSet) {
this.mStateSet = stateSet;
return false;
}
public int[] getState() {
return mStateSet;
}
public void invalidateSelf() {}
public void setCallback(Callback callback) {}
public boolean isVisible() {
return false;
}
public boolean setVisible (boolean visible, boolean restart) {
return false;
}
public void clearColorFilter() {}
public final int getLevel() {return 0;}
public final boolean setLevel(int level) {return false;}
public void setBounds(Rect bounds) {}
public void setColorFilter(int color, PorterDuff.Mode mode) {}
public Drawable mutate() {
return this;
}
}

View File

@@ -0,0 +1,17 @@
package android.graphics.drawable;
import android.graphics.Canvas;
public class GradientDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'draw'");
}
public void setColor(int color) {}
public void setCornerRadius(float cornerRadius) {}
}

View File

@@ -0,0 +1,14 @@
package android.graphics.drawable;
import android.graphics.Canvas;
public class LayerDrawable extends Drawable {
public LayerDrawable(Drawable[] drawables) {
}
@Override
public void draw(Canvas canvas) {
}
}