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
refactor source tree organization, switch to meson
This commit is contained in:
20
src/api-impl/android/view/Display.java
Normal file
20
src/api-impl/android/view/Display.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package android.view;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
public final class Display {
|
||||
|
||||
public static int window_width = 960;
|
||||
public static int window_height = 540;
|
||||
|
||||
// FIXME: what do we return here?
|
||||
// we don't want to hardcode this stuff, but at the same time the apps can cache it
|
||||
public void getMetrics(DisplayMetrics outMetrics) {
|
||||
outMetrics.widthPixels = this.window_width;
|
||||
outMetrics.heightPixels = this.window_height;
|
||||
}
|
||||
|
||||
public int getRotation() {
|
||||
return 0/*ROTATION_0*/;
|
||||
}
|
||||
}
|
||||
443
src/api-impl/android/view/Gravity.java
Normal file
443
src/api-impl/android/view/Gravity.java
Normal file
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
* 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.view;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
* Standard constants and tools for placing an object within a potentially
|
||||
* larger container.
|
||||
*/
|
||||
public class Gravity
|
||||
{
|
||||
/** Constant indicating that no gravity has been set **/
|
||||
public static final int NO_GRAVITY = 0x0000;
|
||||
|
||||
/** Raw bit indicating the gravity for an axis has been specified. */
|
||||
public static final int AXIS_SPECIFIED = 0x0001;
|
||||
|
||||
/** Raw bit controlling how the left/top edge is placed. */
|
||||
public static final int AXIS_PULL_BEFORE = 0x0002;
|
||||
/** Raw bit controlling how the right/bottom edge is placed. */
|
||||
public static final int AXIS_PULL_AFTER = 0x0004;
|
||||
/** Raw bit controlling whether the right/bottom edge is clipped to its
|
||||
* container, based on the gravity direction being applied. */
|
||||
public static final int AXIS_CLIP = 0x0008;
|
||||
|
||||
/** Bits defining the horizontal axis. */
|
||||
public static final int AXIS_X_SHIFT = 0;
|
||||
/** Bits defining the vertical axis. */
|
||||
public static final int AXIS_Y_SHIFT = 4;
|
||||
|
||||
/** Push object to the top of its container, not changing its size. */
|
||||
public static final int TOP = (AXIS_PULL_BEFORE|AXIS_SPECIFIED)<<AXIS_Y_SHIFT;
|
||||
/** Push object to the bottom of its container, not changing its size. */
|
||||
public static final int BOTTOM = (AXIS_PULL_AFTER|AXIS_SPECIFIED)<<AXIS_Y_SHIFT;
|
||||
/** Push object to the left of its container, not changing its size. */
|
||||
public static final int LEFT = (AXIS_PULL_BEFORE|AXIS_SPECIFIED)<<AXIS_X_SHIFT;
|
||||
/** Push object to the right of its container, not changing its size. */
|
||||
public static final int RIGHT = (AXIS_PULL_AFTER|AXIS_SPECIFIED)<<AXIS_X_SHIFT;
|
||||
|
||||
/** Place object in the vertical center of its container, not changing its
|
||||
* size. */
|
||||
public static final int CENTER_VERTICAL = AXIS_SPECIFIED<<AXIS_Y_SHIFT;
|
||||
/** Grow the vertical size of the object if needed so it completely fills
|
||||
* its container. */
|
||||
public static final int FILL_VERTICAL = TOP|BOTTOM;
|
||||
|
||||
/** Place object in the horizontal center of its container, not changing its
|
||||
* size. */
|
||||
public static final int CENTER_HORIZONTAL = AXIS_SPECIFIED<<AXIS_X_SHIFT;
|
||||
/** Grow the horizontal size of the object if needed so it completely fills
|
||||
* its container. */
|
||||
public static final int FILL_HORIZONTAL = LEFT|RIGHT;
|
||||
|
||||
/** Place the object in the center of its container in both the vertical
|
||||
* and horizontal axis, not changing its size. */
|
||||
public static final int CENTER = CENTER_VERTICAL|CENTER_HORIZONTAL;
|
||||
|
||||
/** Grow the horizontal and vertical size of the object if needed so it
|
||||
* completely fills its container. */
|
||||
public static final int FILL = FILL_VERTICAL|FILL_HORIZONTAL;
|
||||
|
||||
/** Flag to clip the edges of the object to its container along the
|
||||
* vertical axis. */
|
||||
public static final int CLIP_VERTICAL = AXIS_CLIP<<AXIS_Y_SHIFT;
|
||||
|
||||
/** Flag to clip the edges of the object to its container along the
|
||||
* horizontal axis. */
|
||||
public static final int CLIP_HORIZONTAL = AXIS_CLIP<<AXIS_X_SHIFT;
|
||||
|
||||
/** Raw bit controlling whether the layout direction is relative or not (START/END instead of
|
||||
* absolute LEFT/RIGHT).
|
||||
*/
|
||||
public static final int RELATIVE_LAYOUT_DIRECTION = 0x00800000;
|
||||
|
||||
/**
|
||||
* Binary mask to get the absolute horizontal gravity of a gravity.
|
||||
*/
|
||||
public static final int HORIZONTAL_GRAVITY_MASK = (AXIS_SPECIFIED |
|
||||
AXIS_PULL_BEFORE | AXIS_PULL_AFTER) << AXIS_X_SHIFT;
|
||||
/**
|
||||
* Binary mask to get the vertical gravity of a gravity.
|
||||
*/
|
||||
public static final int VERTICAL_GRAVITY_MASK = (AXIS_SPECIFIED |
|
||||
AXIS_PULL_BEFORE | AXIS_PULL_AFTER) << AXIS_Y_SHIFT;
|
||||
|
||||
/** Special constant to enable clipping to an overall display along the
|
||||
* vertical dimension. This is not applied by default by
|
||||
* {@link #apply(int, int, int, Rect, int, int, Rect)}; you must do so
|
||||
* yourself by calling {@link #applyDisplay}.
|
||||
*/
|
||||
public static final int DISPLAY_CLIP_VERTICAL = 0x10000000;
|
||||
|
||||
/** Special constant to enable clipping to an overall display along the
|
||||
* horizontal dimension. This is not applied by default by
|
||||
* {@link #apply(int, int, int, Rect, int, int, Rect)}; you must do so
|
||||
* yourself by calling {@link #applyDisplay}.
|
||||
*/
|
||||
public static final int DISPLAY_CLIP_HORIZONTAL = 0x01000000;
|
||||
|
||||
/** Push object to x-axis position at the start of its container, not changing its size. */
|
||||
public static final int START = RELATIVE_LAYOUT_DIRECTION | LEFT;
|
||||
|
||||
/** Push object to x-axis position at the end of its container, not changing its size. */
|
||||
public static final int END = RELATIVE_LAYOUT_DIRECTION | RIGHT;
|
||||
|
||||
/**
|
||||
* Binary mask for the horizontal gravity and script specific direction bit.
|
||||
*/
|
||||
public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK = START | END;
|
||||
|
||||
/**
|
||||
* Apply a gravity constant to an object. This suppose that the layout direction is LTR.
|
||||
*
|
||||
* @param gravity The desired placement of the object, as defined by the
|
||||
* constants in this class.
|
||||
* @param w The horizontal size of the object.
|
||||
* @param h The vertical size of the object.
|
||||
* @param container The frame of the containing space, in which the object
|
||||
* will be placed. Should be large enough to contain the
|
||||
* width and height of the object.
|
||||
* @param outRect Receives the computed frame of the object in its
|
||||
* container.
|
||||
*/
|
||||
public static void apply(int gravity, int w, int h, Rect container, Rect outRect) {
|
||||
apply(gravity, w, h, container, 0, 0, outRect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a gravity constant to an object and take care if layout direction is RTL or not.
|
||||
*
|
||||
* @param gravity The desired placement of the object, as defined by the
|
||||
* constants in this class.
|
||||
* @param w The horizontal size of the object.
|
||||
* @param h The vertical size of the object.
|
||||
* @param container The frame of the containing space, in which the object
|
||||
* will be placed. Should be large enough to contain the
|
||||
* width and height of the object.
|
||||
* @param outRect Receives the computed frame of the object in its
|
||||
* container.
|
||||
* @param layoutDirection The layout direction.
|
||||
*
|
||||
* @see View#LAYOUT_DIRECTION_LTR
|
||||
* @see View#LAYOUT_DIRECTION_RTL
|
||||
*/
|
||||
public static void apply(int gravity, int w, int h, Rect container,
|
||||
Rect outRect, int layoutDirection) {
|
||||
int absGravity = getAbsoluteGravity(gravity, layoutDirection);
|
||||
apply(absGravity, w, h, container, 0, 0, outRect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a gravity constant to an object.
|
||||
*
|
||||
* @param gravity The desired placement of the object, as defined by the
|
||||
* constants in this class.
|
||||
* @param w The horizontal size of the object.
|
||||
* @param h The vertical size of the object.
|
||||
* @param container The frame of the containing space, in which the object
|
||||
* will be placed. Should be large enough to contain the
|
||||
* width and height of the object.
|
||||
* @param xAdj Offset to apply to the X axis. If gravity is LEFT this
|
||||
* pushes it to the right; if gravity is RIGHT it pushes it to
|
||||
* the left; if gravity is CENTER_HORIZONTAL it pushes it to the
|
||||
* right or left; otherwise it is ignored.
|
||||
* @param yAdj Offset to apply to the Y axis. If gravity is TOP this pushes
|
||||
* it down; if gravity is BOTTOM it pushes it up; if gravity is
|
||||
* CENTER_VERTICAL it pushes it down or up; otherwise it is
|
||||
* ignored.
|
||||
* @param outRect Receives the computed frame of the object in its
|
||||
* container.
|
||||
*/
|
||||
public static void apply(int gravity, int w, int h, Rect container,
|
||||
int xAdj, int yAdj, Rect outRect) {
|
||||
switch (gravity&((AXIS_PULL_BEFORE|AXIS_PULL_AFTER)<<AXIS_X_SHIFT)) {
|
||||
case 0:
|
||||
outRect.left = container.left
|
||||
+ ((container.right - container.left - w)/2) + xAdj;
|
||||
outRect.right = outRect.left + w;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_X_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_X_SHIFT)) {
|
||||
if (outRect.left < container.left) {
|
||||
outRect.left = container.left;
|
||||
}
|
||||
if (outRect.right > container.right) {
|
||||
outRect.right = container.right;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AXIS_PULL_BEFORE<<AXIS_X_SHIFT:
|
||||
outRect.left = container.left + xAdj;
|
||||
outRect.right = outRect.left + w;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_X_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_X_SHIFT)) {
|
||||
if (outRect.right > container.right) {
|
||||
outRect.right = container.right;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AXIS_PULL_AFTER<<AXIS_X_SHIFT:
|
||||
outRect.right = container.right - xAdj;
|
||||
outRect.left = outRect.right - w;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_X_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_X_SHIFT)) {
|
||||
if (outRect.left < container.left) {
|
||||
outRect.left = container.left;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
outRect.left = container.left + xAdj;
|
||||
outRect.right = container.right + xAdj;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gravity&((AXIS_PULL_BEFORE|AXIS_PULL_AFTER)<<AXIS_Y_SHIFT)) {
|
||||
case 0:
|
||||
outRect.top = container.top
|
||||
+ ((container.bottom - container.top - h)/2) + yAdj;
|
||||
outRect.bottom = outRect.top + h;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_Y_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_Y_SHIFT)) {
|
||||
if (outRect.top < container.top) {
|
||||
outRect.top = container.top;
|
||||
}
|
||||
if (outRect.bottom > container.bottom) {
|
||||
outRect.bottom = container.bottom;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AXIS_PULL_BEFORE<<AXIS_Y_SHIFT:
|
||||
outRect.top = container.top + yAdj;
|
||||
outRect.bottom = outRect.top + h;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_Y_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_Y_SHIFT)) {
|
||||
if (outRect.bottom > container.bottom) {
|
||||
outRect.bottom = container.bottom;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AXIS_PULL_AFTER<<AXIS_Y_SHIFT:
|
||||
outRect.bottom = container.bottom - yAdj;
|
||||
outRect.top = outRect.bottom - h;
|
||||
if ((gravity&(AXIS_CLIP<<AXIS_Y_SHIFT))
|
||||
== (AXIS_CLIP<<AXIS_Y_SHIFT)) {
|
||||
if (outRect.top < container.top) {
|
||||
outRect.top = container.top;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
outRect.top = container.top + yAdj;
|
||||
outRect.bottom = container.bottom + yAdj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a gravity constant to an object.
|
||||
*
|
||||
* @param gravity The desired placement of the object, as defined by the
|
||||
* constants in this class.
|
||||
* @param w The horizontal size of the object.
|
||||
* @param h The vertical size of the object.
|
||||
* @param container The frame of the containing space, in which the object
|
||||
* will be placed. Should be large enough to contain the
|
||||
* width and height of the object.
|
||||
* @param xAdj Offset to apply to the X axis. If gravity is LEFT this
|
||||
* pushes it to the right; if gravity is RIGHT it pushes it to
|
||||
* the left; if gravity is CENTER_HORIZONTAL it pushes it to the
|
||||
* right or left; otherwise it is ignored.
|
||||
* @param yAdj Offset to apply to the Y axis. If gravity is TOP this pushes
|
||||
* it down; if gravity is BOTTOM it pushes it up; if gravity is
|
||||
* CENTER_VERTICAL it pushes it down or up; otherwise it is
|
||||
* ignored.
|
||||
* @param outRect Receives the computed frame of the object in its
|
||||
* container.
|
||||
* @param layoutDirection The layout direction.
|
||||
*
|
||||
* @see View#LAYOUT_DIRECTION_LTR
|
||||
* @see View#LAYOUT_DIRECTION_RTL
|
||||
*/
|
||||
public static void apply(int gravity, int w, int h, Rect container,
|
||||
int xAdj, int yAdj, Rect outRect, int layoutDirection) {
|
||||
int absGravity = getAbsoluteGravity(gravity, layoutDirection);
|
||||
apply(absGravity, w, h, container, xAdj, yAdj, outRect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply additional gravity behavior based on the overall "display" that an
|
||||
* object exists in. This can be used after
|
||||
* {@link #apply(int, int, int, Rect, int, int, Rect)} to place the object
|
||||
* within a visible display. By default this moves or clips the object
|
||||
* to be visible in the display; the gravity flags
|
||||
* {@link #DISPLAY_CLIP_HORIZONTAL} and {@link #DISPLAY_CLIP_VERTICAL}
|
||||
* can be used to change this behavior.
|
||||
*
|
||||
* @param gravity Gravity constants to modify the placement within the
|
||||
* display.
|
||||
* @param display The rectangle of the display in which the object is
|
||||
* being placed.
|
||||
* @param inoutObj Supplies the current object position; returns with it
|
||||
* modified if needed to fit in the display.
|
||||
*/
|
||||
public static void applyDisplay(int gravity, Rect display, Rect inoutObj) {
|
||||
if ((gravity&DISPLAY_CLIP_VERTICAL) != 0) {
|
||||
if (inoutObj.top < display.top) inoutObj.top = display.top;
|
||||
if (inoutObj.bottom > display.bottom) inoutObj.bottom = display.bottom;
|
||||
} else {
|
||||
int off = 0;
|
||||
if (inoutObj.top < display.top) off = display.top-inoutObj.top;
|
||||
else if (inoutObj.bottom > display.bottom) off = display.bottom-inoutObj.bottom;
|
||||
if (off != 0) {
|
||||
if (inoutObj.height() > (display.bottom-display.top)) {
|
||||
inoutObj.top = display.top;
|
||||
inoutObj.bottom = display.bottom;
|
||||
} else {
|
||||
inoutObj.top += off;
|
||||
inoutObj.bottom += off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((gravity&DISPLAY_CLIP_HORIZONTAL) != 0) {
|
||||
if (inoutObj.left < display.left) inoutObj.left = display.left;
|
||||
if (inoutObj.right > display.right) inoutObj.right = display.right;
|
||||
} else {
|
||||
int off = 0;
|
||||
if (inoutObj.left < display.left) off = display.left-inoutObj.left;
|
||||
else if (inoutObj.right > display.right) off = display.right-inoutObj.right;
|
||||
if (off != 0) {
|
||||
if (inoutObj.width() > (display.right-display.left)) {
|
||||
inoutObj.left = display.left;
|
||||
inoutObj.right = display.right;
|
||||
} else {
|
||||
inoutObj.left += off;
|
||||
inoutObj.right += off;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply additional gravity behavior based on the overall "display" that an
|
||||
* object exists in. This can be used after
|
||||
* {@link #apply(int, int, int, Rect, int, int, Rect)} to place the object
|
||||
* within a visible display. By default this moves or clips the object
|
||||
* to be visible in the display; the gravity flags
|
||||
* {@link #DISPLAY_CLIP_HORIZONTAL} and {@link #DISPLAY_CLIP_VERTICAL}
|
||||
* can be used to change this behavior.
|
||||
*
|
||||
* @param gravity Gravity constants to modify the placement within the
|
||||
* display.
|
||||
* @param display The rectangle of the display in which the object is
|
||||
* being placed.
|
||||
* @param inoutObj Supplies the current object position; returns with it
|
||||
* modified if needed to fit in the display.
|
||||
* @param layoutDirection The layout direction.
|
||||
*
|
||||
* @see View#LAYOUT_DIRECTION_LTR
|
||||
* @see View#LAYOUT_DIRECTION_RTL
|
||||
*/
|
||||
public static void applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection) {
|
||||
int absGravity = getAbsoluteGravity(gravity, layoutDirection);
|
||||
applyDisplay(absGravity, display, inoutObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Indicate whether the supplied gravity has a vertical pull.</p>
|
||||
*
|
||||
* @param gravity the gravity to check for vertical pull
|
||||
* @return true if the supplied gravity has a vertical pull
|
||||
*/
|
||||
public static boolean isVertical(int gravity) {
|
||||
return gravity > 0 && (gravity & VERTICAL_GRAVITY_MASK) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Indicate whether the supplied gravity has an horizontal pull.</p>
|
||||
*
|
||||
* @param gravity the gravity to check for horizontal pull
|
||||
* @return true if the supplied gravity has an horizontal pull
|
||||
*/
|
||||
public static boolean isHorizontal(int gravity) {
|
||||
return gravity > 0 && (gravity & RELATIVE_HORIZONTAL_GRAVITY_MASK) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert script specific gravity to absolute horizontal value.</p>
|
||||
*
|
||||
* if horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
|
||||
* if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
|
||||
*
|
||||
*
|
||||
* @param gravity The gravity to convert to absolute (horizontal) values.
|
||||
* @param layoutDirection The layout direction.
|
||||
* @return gravity converted to absolute (horizontal) values.
|
||||
*/
|
||||
public static int getAbsoluteGravity(int gravity, int layoutDirection) {
|
||||
int result = gravity;
|
||||
// If layout is script specific and gravity is horizontal relative (START or END)
|
||||
if ((result & RELATIVE_LAYOUT_DIRECTION) > 0) {
|
||||
if ((result & Gravity.START) == Gravity.START) {
|
||||
// Remove the START bit
|
||||
result &= ~START;
|
||||
if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
|
||||
// Set the RIGHT bit
|
||||
result |= RIGHT;
|
||||
} else {
|
||||
// Set the LEFT bit
|
||||
result |= LEFT;
|
||||
}
|
||||
} else if ((result & Gravity.END) == Gravity.END) {
|
||||
// Remove the END bit
|
||||
result &= ~END;
|
||||
if (layoutDirection == View.LAYOUT_DIRECTION_RTL) {
|
||||
// Set the LEFT bit
|
||||
result |= LEFT;
|
||||
} else {
|
||||
// Set the RIGHT bit
|
||||
result |= RIGHT;
|
||||
}
|
||||
}
|
||||
// Don't need the script specific bit any more, so remove it as we are converting to
|
||||
// absolute values (LEFT or RIGHT)
|
||||
result &= ~RELATIVE_LAYOUT_DIRECTION;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
216
src/api-impl/android/view/InputEvent.java
Normal file
216
src/api-impl/android/view/InputEvent.java
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.view;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
class InputDevice {}
|
||||
|
||||
/**
|
||||
* Common base class for input events.
|
||||
*/
|
||||
public abstract class InputEvent {
|
||||
/** @hide */
|
||||
protected static final int PARCEL_TOKEN_MOTION_EVENT = 1;
|
||||
/** @hide */
|
||||
protected static final int PARCEL_TOKEN_KEY_EVENT = 2;
|
||||
|
||||
// Next sequence number.
|
||||
private static final AtomicInteger mNextSeq = new AtomicInteger();
|
||||
|
||||
/** @hide */
|
||||
protected int mSeq;
|
||||
|
||||
/** @hide */
|
||||
protected boolean mRecycled;
|
||||
|
||||
private static final boolean TRACK_RECYCLED_LOCATION = false;
|
||||
private RuntimeException mRecycledLocation;
|
||||
|
||||
/*package*/ InputEvent() {
|
||||
mSeq = mNextSeq.getAndIncrement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id for the device that this event came from. An id of
|
||||
* zero indicates that the event didn't come from a physical device
|
||||
* and maps to the default keymap. The other numbers are arbitrary and
|
||||
* you shouldn't depend on the values.
|
||||
*
|
||||
* @return The device id.
|
||||
* @see InputDevice#getDevice
|
||||
*/
|
||||
public abstract int getDeviceId();
|
||||
|
||||
/**
|
||||
* Gets the device that this event came from.
|
||||
*
|
||||
* @return The device, or null if unknown.
|
||||
*/
|
||||
public final InputDevice getDevice() {
|
||||
return null/*InputDevice.getDevice(getDeviceId())*/;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source of the event.
|
||||
*
|
||||
* @return The event source or {@link InputDevice#SOURCE_UNKNOWN} if unknown.
|
||||
* @see InputDevice#getSources
|
||||
*/
|
||||
public abstract int getSource();
|
||||
|
||||
/**
|
||||
* Modifies the source of the event.
|
||||
*
|
||||
* @param source The new source.
|
||||
* @hide
|
||||
*/
|
||||
public abstract void setSource(int source);
|
||||
|
||||
/**
|
||||
* Determines whether the event is from the given source.
|
||||
*
|
||||
* @param source The input source to check against. This can be a specific device type, such as
|
||||
* {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class, such as
|
||||
* {@link InputDevice#SOURCE_CLASS_POINTER}.
|
||||
* @return Whether the event is from the given source.
|
||||
*/
|
||||
public boolean isFromSource(int source) {
|
||||
return (getSource() & source) == source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the event.
|
||||
*
|
||||
* @return A deep copy of the event.
|
||||
* @hide
|
||||
*/
|
||||
public abstract InputEvent copy();
|
||||
|
||||
/**
|
||||
* Recycles the event.
|
||||
* This method should only be used by the system since applications do not
|
||||
* expect {@link KeyEvent} objects to be recycled, although {@link MotionEvent}
|
||||
* objects are fine. See {@link KeyEvent#recycle()} for details.
|
||||
* @hide
|
||||
*/
|
||||
public void recycle() {
|
||||
if (TRACK_RECYCLED_LOCATION) {
|
||||
if (mRecycledLocation != null) {
|
||||
throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
|
||||
}
|
||||
mRecycledLocation = new RuntimeException("Last recycled here");
|
||||
} else {
|
||||
if (mRecycled) {
|
||||
throw new RuntimeException(toString() + " recycled twice!");
|
||||
}
|
||||
mRecycled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally recycled the event if it is appropriate to do so after
|
||||
* dispatching the event to an application.
|
||||
*
|
||||
* If the event is a {@link MotionEvent} then it is recycled.
|
||||
*
|
||||
* If the event is a {@link KeyEvent} then it is NOT recycled, because applications
|
||||
* expect key events to be immutable so once the event has been dispatched to
|
||||
* the application we can no longer recycle it.
|
||||
* @hide
|
||||
*/
|
||||
public void recycleIfNeededAfterDispatch() {
|
||||
recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinitializes the event on reuse (after recycling).
|
||||
* @hide
|
||||
*/
|
||||
protected void prepareForReuse() {
|
||||
mRecycled = false;
|
||||
mRecycledLocation = null;
|
||||
mSeq = mNextSeq.getAndIncrement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a private flag that indicates when the system has detected that this input event
|
||||
* may be inconsistent with respect to the sequence of previously delivered input events,
|
||||
* such as when a key up event is sent but the key was not down or when a pointer
|
||||
* move event is sent but the pointer is not down.
|
||||
*
|
||||
* @return True if this event is tainted.
|
||||
* @hide
|
||||
*/
|
||||
public abstract boolean isTainted();
|
||||
|
||||
/**
|
||||
* Sets a private flag that indicates when the system has detected that this input event
|
||||
* may be inconsistent with respect to the sequence of previously delivered input events,
|
||||
* such as when a key up event is sent but the key was not down or when a pointer
|
||||
* move event is sent but the pointer is not down.
|
||||
*
|
||||
* @param tainted True if this event is tainted.
|
||||
* @hide
|
||||
*/
|
||||
public abstract void setTainted(boolean tainted);
|
||||
|
||||
/**
|
||||
* Retrieve the time this event occurred,
|
||||
* in the {@link android.os.SystemClock#uptimeMillis} time base.
|
||||
*
|
||||
* @return Returns the time this event occurred,
|
||||
* in the {@link android.os.SystemClock#uptimeMillis} time base.
|
||||
*/
|
||||
public abstract long getEventTime();
|
||||
|
||||
/**
|
||||
* Retrieve the time this event occurred,
|
||||
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
|
||||
* nanosecond (instead of millisecond) precision.
|
||||
* <p>
|
||||
* The value is in nanosecond precision but it may not have nanosecond accuracy.
|
||||
* </p>
|
||||
*
|
||||
* @return Returns the time this event occurred,
|
||||
* in the {@link android.os.SystemClock#uptimeMillis} time base but with
|
||||
* nanosecond (instead of millisecond) precision.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public abstract long getEventTimeNano();
|
||||
|
||||
/**
|
||||
* Gets the unique sequence number of this event.
|
||||
* Every input event that is created or received by a process has a
|
||||
* unique sequence number. Moreover, a new sequence number is obtained
|
||||
* each time an event object is recycled.
|
||||
*
|
||||
* Sequence numbers are only guaranteed to be locally unique within a process.
|
||||
* Sequence numbers are not preserved when events are parceled.
|
||||
*
|
||||
* @return The unique sequence number of this event.
|
||||
* @hide
|
||||
*/
|
||||
public int getSequenceNumber() {
|
||||
return mSeq;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
226
src/api-impl/android/view/LayoutInflater.java
Normal file
226
src/api-impl/android/view/LayoutInflater.java
Normal file
@@ -0,0 +1,226 @@
|
||||
package android.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import java.io.FileReader;
|
||||
|
||||
public class LayoutInflater {
|
||||
|
||||
public interface Factory {
|
||||
}
|
||||
|
||||
public interface Factory2 {
|
||||
}
|
||||
|
||||
private Factory2 factory2;
|
||||
|
||||
public final LayoutInflater.Factory getFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFactory2 (Factory2 factory) {
|
||||
this.factory2 = factory;
|
||||
}
|
||||
|
||||
public static LayoutInflater from (Context context) {
|
||||
return new LayoutInflater();
|
||||
}
|
||||
|
||||
public final View createView(String name, String prefix, AttributeSet attrs) throws Exception {
|
||||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>> createView("+name+", "+prefix+", "+attrs+");");
|
||||
|
||||
String view_class_name = prefix+name;
|
||||
Class view_class = Class.forName(view_class_name);
|
||||
|
||||
Constructor constructor = view_class.getConstructor(AttributeSet.class);
|
||||
|
||||
View view_instance = (View)constructor.newInstance(attrs);
|
||||
|
||||
return view_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* taken as-is
|
||||
*/
|
||||
protected View onCreateView(String name, AttributeSet attrs) throws Exception {
|
||||
try { // FIXME ugly
|
||||
return createView(name, "android.view.", attrs);
|
||||
} catch(java.lang.ClassNotFoundException e) {
|
||||
return createView(name, "android.widget.", attrs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* taken as-is
|
||||
*/
|
||||
protected View onCreateView(View parent, String name, AttributeSet attrs) throws Exception {
|
||||
return onCreateView(name, attrs);
|
||||
}
|
||||
|
||||
View createViewFromTag(View parent, String name, AttributeSet attrs) throws Exception {
|
||||
if (name.equals("view")) {
|
||||
name = attrs.getAttributeValue(null, "class");
|
||||
}
|
||||
|
||||
System.out.println("******** Creating view: " + name);
|
||||
|
||||
View view;
|
||||
|
||||
if (-1 == name.indexOf('.')) {
|
||||
view = onCreateView(parent, name, attrs);
|
||||
} else {
|
||||
view = createView(name, null, attrs);
|
||||
}
|
||||
|
||||
System.out.println("Created view is: " + view);
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
public View inflate(int resource, ViewGroup root) throws Exception {
|
||||
return inflate(resource, root, root != null);
|
||||
}
|
||||
|
||||
public View inflate(int layoutResID, ViewGroup root, boolean attachToRoot) throws Exception {
|
||||
|
||||
String layout_xml_file = "data/" + Context.this_application.getString(layoutResID);
|
||||
|
||||
System.out.println("loading layout from: " + layout_xml_file);
|
||||
|
||||
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
XmlPullParser xpp = factory.newPullParser();
|
||||
|
||||
xpp.setInput( new FileReader(layout_xml_file) );
|
||||
|
||||
return inflate(xpp, root, attachToRoot);
|
||||
}
|
||||
|
||||
public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot) throws Exception {
|
||||
|
||||
final AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
View result = root;
|
||||
|
||||
// Look for the root node.
|
||||
int type;
|
||||
while ((type = parser.next()) != XmlPullParser.START_TAG &&
|
||||
type != XmlPullParser.END_DOCUMENT) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
if (type != XmlPullParser.START_TAG) {
|
||||
throw new Exception(parser.getPositionDescription() + ": No start tag found!");
|
||||
}
|
||||
|
||||
final String name = parser.getName();
|
||||
|
||||
System.out.println("**************************");
|
||||
System.out.println("Creating root view: " + name);
|
||||
System.out.println("**************************");
|
||||
|
||||
if (name.equals("merge")) {
|
||||
if (root == null || !attachToRoot) {
|
||||
throw new Exception("<merge /> can be used only with a valid ViewGroup root and attachToRoot=true");
|
||||
}
|
||||
|
||||
rInflate(parser, root, attrs, false);
|
||||
} else {
|
||||
// Temp is the root view that was found in the xml
|
||||
View temp;
|
||||
if (name.equals("blink")) {
|
||||
throw new Exception("<blink> not supported atm");
|
||||
/*temp = new BlinkLayout(mContext, attrs);*/
|
||||
} else {
|
||||
temp = createViewFromTag(root, name, attrs);
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams params = null;
|
||||
|
||||
if (root != null) {
|
||||
System.out.println("Creating params from root: " + root);
|
||||
|
||||
// Create layout params that match root, if supplied
|
||||
params = root.generateLayoutParams(attrs);
|
||||
if (!attachToRoot) {
|
||||
// Set the layout params for temp if we are not
|
||||
// attaching. (If we are, we use addView, below)
|
||||
temp.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("-----> start inflating children");
|
||||
|
||||
// Inflate all children under temp
|
||||
rInflate(parser, temp, attrs, true);
|
||||
|
||||
System.out.println("-----> done inflating children");
|
||||
|
||||
// We are supposed to attach all the views we found (int temp)
|
||||
// to root. Do that now.
|
||||
if (root != null && attachToRoot) {
|
||||
root.addView(temp, params);
|
||||
}
|
||||
|
||||
// Decide whether to return the root that was passed in or the
|
||||
// top view found in xml.
|
||||
if (root == null || !attachToRoot) {
|
||||
result = temp;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void rInflate(XmlPullParser parser, View parent, final AttributeSet attrs, boolean finishInflate) throws Exception {
|
||||
|
||||
final int depth = parser.getDepth();
|
||||
int type;
|
||||
|
||||
while (((type = parser.next()) != XmlPullParser.END_TAG ||
|
||||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
|
||||
|
||||
if (type != XmlPullParser.START_TAG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String name = parser.getName();
|
||||
|
||||
if (name.equals("requestFocus")) {
|
||||
throw new Exception("<requestFocus /> not supported atm");
|
||||
//parseRequestFocus(parser, parent);
|
||||
} else if (name.equals("include")) {
|
||||
throw new Exception("<include /> not supported atm");
|
||||
/*if (parser.getDepth() == 0) {
|
||||
throw new Exception("<include /> cannot be the root element");
|
||||
}
|
||||
parseInclude(parser, parent, attrs);*/
|
||||
} else if (name.equals("merge")) {
|
||||
throw new Exception("<merge /> must be the root element");
|
||||
} else if (name.equals("blink")) {
|
||||
throw new Exception("<blink> not supported atm");
|
||||
/*final View view = new BlinkLayout(mContext, attrs);
|
||||
final ViewGroup viewGroup = (ViewGroup) parent;
|
||||
final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs);
|
||||
rInflate(parser, view, attrs, true);
|
||||
viewGroup.addView(view, params);*/
|
||||
} else {
|
||||
final View view = createViewFromTag(parent, name, attrs);
|
||||
final ViewGroup viewGroup = (ViewGroup) parent;
|
||||
final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs);
|
||||
rInflate(parser, view, attrs, true);
|
||||
viewGroup.addView(view, params);
|
||||
}
|
||||
}
|
||||
|
||||
if (finishInflate) parent.onFinishInflate();
|
||||
}
|
||||
}
|
||||
5
src/api-impl/android/view/Menu.java
Normal file
5
src/api-impl/android/view/Menu.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.view;
|
||||
|
||||
public interface Menu {
|
||||
|
||||
}
|
||||
3526
src/api-impl/android/view/MotionEvent.java
Normal file
3526
src/api-impl/android/view/MotionEvent.java
Normal file
File diff suppressed because it is too large
Load Diff
5
src/api-impl/android/view/Surface.java
Normal file
5
src/api-impl/android/view/Surface.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package android.view;
|
||||
|
||||
public class Surface {
|
||||
|
||||
}
|
||||
284
src/api-impl/android/view/SurfaceHolder.java
Normal file
284
src/api-impl/android/view/SurfaceHolder.java
Normal file
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* 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.view;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
* Abstract interface to someone holding a display surface. Allows you to
|
||||
* control the surface size and format, edit the pixels in the surface, and
|
||||
* monitor changes to the surface. This interface is typically available
|
||||
* through the {@link SurfaceView} class.
|
||||
*
|
||||
* <p>When using this interface from a thread other than the one running
|
||||
* its {@link SurfaceView}, you will want to carefully read the
|
||||
* methods
|
||||
* {@link #lockCanvas} and {@link Callback#surfaceCreated Callback.surfaceCreated()}.
|
||||
*/
|
||||
public interface SurfaceHolder {
|
||||
|
||||
/** @deprecated this is ignored, this value is set automatically when needed. */
|
||||
@Deprecated
|
||||
public static final int SURFACE_TYPE_NORMAL = 0;
|
||||
/** @deprecated this is ignored, this value is set automatically when needed. */
|
||||
@Deprecated
|
||||
public static final int SURFACE_TYPE_HARDWARE = 1;
|
||||
/** @deprecated this is ignored, this value is set automatically when needed. */
|
||||
@Deprecated
|
||||
public static final int SURFACE_TYPE_GPU = 2;
|
||||
/** @deprecated this is ignored, this value is set automatically when needed. */
|
||||
@Deprecated
|
||||
public static final int SURFACE_TYPE_PUSH_BUFFERS = 3;
|
||||
|
||||
/**
|
||||
* Exception that is thrown from {@link #lockCanvas} when called on a Surface
|
||||
* whose type is SURFACE_TYPE_PUSH_BUFFERS.
|
||||
*/
|
||||
public static class BadSurfaceTypeException extends RuntimeException {
|
||||
public BadSurfaceTypeException() {
|
||||
}
|
||||
|
||||
public BadSurfaceTypeException(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A client may implement this interface to receive information about
|
||||
* changes to the surface. When used with a {@link SurfaceView}, the
|
||||
* Surface being held is only available between calls to
|
||||
* {@link #surfaceCreated(SurfaceHolder)} and
|
||||
* {@link #surfaceDestroyed(SurfaceHolder)}. The Callback is set with
|
||||
* {@link SurfaceHolder#addCallback SurfaceHolder.addCallback} method.
|
||||
*/
|
||||
public interface Callback {
|
||||
/**
|
||||
* This is called immediately after the surface is first created.
|
||||
* Implementations of this should start up whatever rendering code
|
||||
* they desire. Note that only one thread can ever draw into
|
||||
* a {@link Surface}, so you should not draw into the Surface here
|
||||
* if your normal rendering will be in another thread.
|
||||
*
|
||||
* @param holder The SurfaceHolder whose surface is being created.
|
||||
*/
|
||||
public void surfaceCreated(SurfaceHolder holder);
|
||||
|
||||
/**
|
||||
* This is called immediately after any structural changes (format or
|
||||
* size) have been made to the surface. You should at this point update
|
||||
* the imagery in the surface. This method is always called at least
|
||||
* once, after {@link #surfaceCreated}.
|
||||
*
|
||||
* @param holder The SurfaceHolder whose surface has changed.
|
||||
* @param format The new PixelFormat of the surface.
|
||||
* @param width The new width of the surface.
|
||||
* @param height The new height of the surface.
|
||||
*/
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width,
|
||||
int height);
|
||||
|
||||
/**
|
||||
* This is called immediately before a surface is being destroyed. After
|
||||
* returning from this call, you should no longer try to access this
|
||||
* surface. If you have a rendering thread that directly accesses
|
||||
* the surface, you must ensure that thread is no longer touching the
|
||||
* Surface before returning from this function.
|
||||
*
|
||||
* @param holder The SurfaceHolder whose surface is being destroyed.
|
||||
*/
|
||||
public void surfaceDestroyed(SurfaceHolder holder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callbacks that can be received for {@link Callback}.
|
||||
*/
|
||||
public interface Callback2 extends Callback {
|
||||
/**
|
||||
* Called when the application needs to redraw the content of its
|
||||
* surface, after it is resized or for some other reason. By not
|
||||
* returning from here until the redraw is complete, you can ensure that
|
||||
* the user will not see your surface in a bad state (at its new
|
||||
* size before it has been correctly drawn that way). This will
|
||||
* typically be preceeded by a call to {@link #surfaceChanged}.
|
||||
*
|
||||
* @param holder The SurfaceHolder whose surface has changed.
|
||||
*/
|
||||
public void surfaceRedrawNeeded(SurfaceHolder holder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Callback interface for this holder. There can several Callback
|
||||
* interfaces associated with a holder.
|
||||
*
|
||||
* @param callback The new Callback interface.
|
||||
*/
|
||||
public void addCallback(Callback callback);
|
||||
|
||||
/**
|
||||
* Removes a previously added Callback interface from this holder.
|
||||
*
|
||||
* @param callback The Callback interface to remove.
|
||||
*/
|
||||
public void removeCallback(Callback callback);
|
||||
|
||||
/**
|
||||
* Use this method to find out if the surface is in the process of being
|
||||
* created from Callback methods. This is intended to be used with
|
||||
* {@link Callback#surfaceChanged}.
|
||||
*
|
||||
* @return true if the surface is in the process of being created.
|
||||
*/
|
||||
public boolean isCreating();
|
||||
|
||||
/**
|
||||
* Sets the surface's type.
|
||||
*
|
||||
* @deprecated this is ignored, this value is set automatically when needed.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setType(int type);
|
||||
|
||||
/**
|
||||
* Make the surface a fixed size. It will never change from this size.
|
||||
* When working with a {@link SurfaceView}, this must be called from the
|
||||
* same thread running the SurfaceView's window.
|
||||
*
|
||||
* @param width The surface's width.
|
||||
* @param height The surface's height.
|
||||
*/
|
||||
public void setFixedSize(int width, int height);
|
||||
|
||||
/**
|
||||
* Allow the surface to resized based on layout of its container (this is
|
||||
* the default). When this is enabled, you should monitor
|
||||
* {@link Callback#surfaceChanged} for changes to the size of the surface.
|
||||
* When working with a {@link SurfaceView}, this must be called from the
|
||||
* same thread running the SurfaceView's window.
|
||||
*/
|
||||
public void setSizeFromLayout();
|
||||
|
||||
/**
|
||||
* Set the desired PixelFormat of the surface. The default is OPAQUE.
|
||||
* When working with a {@link SurfaceView}, this must be called from the
|
||||
* same thread running the SurfaceView's window.
|
||||
*
|
||||
* @param format A constant from PixelFormat.
|
||||
*
|
||||
* @see android.graphics.PixelFormat
|
||||
*/
|
||||
public void setFormat(int format);
|
||||
|
||||
/**
|
||||
* Enable or disable option to keep the screen turned on while this
|
||||
* surface is displayed. The default is false, allowing it to turn off.
|
||||
* This is safe to call from any thread.
|
||||
*
|
||||
* @param screenOn Set to true to force the screen to stay on, false
|
||||
* to allow it to turn off.
|
||||
*/
|
||||
public void setKeepScreenOn(boolean screenOn);
|
||||
|
||||
/**
|
||||
* Start editing the pixels in the surface. The returned Canvas can be used
|
||||
* to draw into the surface's bitmap. A null is returned if the surface has
|
||||
* not been created or otherwise cannot be edited. You will usually need
|
||||
* to implement {@link Callback#surfaceCreated Callback.surfaceCreated}
|
||||
* to find out when the Surface is available for use.
|
||||
*
|
||||
* <p>The content of the Surface is never preserved between unlockCanvas() and
|
||||
* lockCanvas(), for this reason, every pixel within the Surface area
|
||||
* must be written. The only exception to this rule is when a dirty
|
||||
* rectangle is specified, in which case, non-dirty pixels will be
|
||||
* preserved.
|
||||
*
|
||||
* <p>If you call this repeatedly when the Surface is not ready (before
|
||||
* {@link Callback#surfaceCreated Callback.surfaceCreated} or after
|
||||
* {@link Callback#surfaceDestroyed Callback.surfaceDestroyed}), your calls
|
||||
* will be throttled to a slow rate in order to avoid consuming CPU.
|
||||
*
|
||||
* <p>If null is not returned, this function internally holds a lock until
|
||||
* the corresponding {@link #unlockCanvasAndPost} call, preventing
|
||||
* {@link SurfaceView} from creating, destroying, or modifying the surface
|
||||
* while it is being drawn. This can be more convenient than accessing
|
||||
* the Surface directly, as you do not need to do special synchronization
|
||||
* with a drawing thread in {@link Callback#surfaceDestroyed
|
||||
* Callback.surfaceDestroyed}.
|
||||
*
|
||||
* @return Canvas Use to draw into the surface.
|
||||
*/
|
||||
public Canvas lockCanvas();
|
||||
|
||||
|
||||
/**
|
||||
* Just like {@link #lockCanvas()} but allows specification of a dirty rectangle.
|
||||
* Every
|
||||
* pixel within that rectangle must be written; however pixels outside
|
||||
* the dirty rectangle will be preserved by the next call to lockCanvas().
|
||||
*
|
||||
* @see android.view.SurfaceHolder#lockCanvas
|
||||
*
|
||||
* @param dirty Area of the Surface that will be modified.
|
||||
* @return Canvas Use to draw into the surface.
|
||||
*/
|
||||
public Canvas lockCanvas(Rect dirty);
|
||||
|
||||
/**
|
||||
* Finish editing pixels in the surface. After this call, the surface's
|
||||
* current pixels will be shown on the screen, but its content is lost,
|
||||
* in particular there is no guarantee that the content of the Surface
|
||||
* will remain unchanged when lockCanvas() is called again.
|
||||
*
|
||||
* @see #lockCanvas()
|
||||
*
|
||||
* @param canvas The Canvas previously returned by lockCanvas().
|
||||
*/
|
||||
public void unlockCanvasAndPost(Canvas canvas);
|
||||
|
||||
/**
|
||||
* Retrieve the current size of the surface. Note: do not modify the
|
||||
* returned Rect. This is only safe to call from the thread of
|
||||
* {@link SurfaceView}'s window, or while inside of
|
||||
* {@link #lockCanvas()}.
|
||||
*
|
||||
* @return Rect The surface's dimensions. The left and top are always 0.
|
||||
*/
|
||||
public Rect getSurfaceFrame();
|
||||
|
||||
/**
|
||||
* Direct access to the surface object. The Surface may not always be
|
||||
* available -- for example when using a {@link SurfaceView} the holder's
|
||||
* Surface is not created until the view has been attached to the window
|
||||
* manager and performed a layout in order to determine the dimensions
|
||||
* and screen position of the Surface. You will thus usually need
|
||||
* to implement {@link Callback#surfaceCreated Callback.surfaceCreated}
|
||||
* to find out when the Surface is available for use.
|
||||
*
|
||||
* <p>Note that if you directly access the Surface from another thread,
|
||||
* it is critical that you correctly implement
|
||||
* {@link Callback#surfaceCreated Callback.surfaceCreated} and
|
||||
* {@link Callback#surfaceDestroyed Callback.surfaceDestroyed} to ensure
|
||||
* that thread only accesses the Surface while it is valid, and that the
|
||||
* Surface does not get destroyed while the thread is using it.
|
||||
*
|
||||
* <p>This method is intended to be used by frameworks which often need
|
||||
* direct access to the Surface object (usually to pass it to native code).
|
||||
*
|
||||
* @return Surface The surface.
|
||||
*/
|
||||
public Surface getSurface();
|
||||
}
|
||||
192
src/api-impl/android/view/SurfaceView.java
Normal file
192
src/api-impl/android/view/SurfaceView.java
Normal file
@@ -0,0 +1,192 @@
|
||||
package android.view;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class SurfaceView extends View {
|
||||
public SurfaceView(Context context) {
|
||||
super(context);
|
||||
|
||||
// native_constructor(context);
|
||||
}
|
||||
|
||||
public SurfaceHolder getHolder() {
|
||||
return mSurfaceHolder;
|
||||
}
|
||||
|
||||
final Surface mSurface = new Surface();
|
||||
|
||||
private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
|
||||
|
||||
private static final String LOG_TAG = "SurfaceHolder";
|
||||
|
||||
@Override
|
||||
public boolean isCreating() {
|
||||
// return mIsCreating;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
// This is a linear search, but in practice we'll
|
||||
// have only a couple callbacks, so it doesn't matter.
|
||||
if (mCallbacks.contains(callback) == false) {
|
||||
mCallbacks.add(callback);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallback(Callback callback) {
|
||||
/* synchronized (mCallbacks) {
|
||||
mCallbacks.remove(callback);
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixedSize(int width, int height) {
|
||||
/* if (mRequestedWidth != width || mRequestedHeight != height) {
|
||||
mRequestedWidth = width;
|
||||
mRequestedHeight = height;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSizeFromLayout() {
|
||||
/* if (mRequestedWidth != -1 || mRequestedHeight != -1) {
|
||||
mRequestedWidth = mRequestedHeight = -1;
|
||||
requestLayout();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFormat(int format) {
|
||||
/*
|
||||
// for backward compatibility reason, OPAQUE always
|
||||
// means 565 for SurfaceView
|
||||
if (format == PixelFormat.OPAQUE)
|
||||
format = PixelFormat.RGB_565;
|
||||
|
||||
mRequestedFormat = format;
|
||||
if (mWindow != null) {
|
||||
updateWindow(false, false);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated setType is now ignored.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setType(int type) { }
|
||||
|
||||
@Override
|
||||
public void setKeepScreenOn(boolean screenOn) {
|
||||
// Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG);
|
||||
// msg.arg1 = screenOn ? 1 : 0;
|
||||
// mHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* The caller must redraw the entire surface.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas() {
|
||||
// return internalLockCanvas(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
|
||||
*
|
||||
* After drawing into the provided {@link Canvas}, the caller must
|
||||
* invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
|
||||
*
|
||||
* @param inOutDirty A rectangle that represents the dirty region that the caller wants
|
||||
* to redraw. This function may choose to expand the dirty rectangle if for example
|
||||
* the surface has been resized or if the previous contents of the surface were
|
||||
* not available. The caller must redraw the entire dirty region as represented
|
||||
* by the contents of the inOutDirty rectangle upon return from this function.
|
||||
* The caller may also pass <code>null</code> instead, in the case where the
|
||||
* entire surface should be redrawn.
|
||||
* @return A canvas for drawing into the surface.
|
||||
*/
|
||||
@Override
|
||||
public Canvas lockCanvas(Rect inOutDirty) {
|
||||
// return internalLockCanvas(inOutDirty);
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Canvas internalLockCanvas(Rect dirty) {
|
||||
/* mSurfaceLock.lock();
|
||||
|
||||
if (DEBUG) Log.i(TAG, "Locking canvas... stopped="
|
||||
+ mDrawingStopped + ", win=" + mWindow);
|
||||
|
||||
Canvas c = null;
|
||||
if (!mDrawingStopped && mWindow != null) {
|
||||
try {
|
||||
c = mSurface.lockCanvas(dirty);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "Exception locking surface", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) Log.i(TAG, "Returned canvas: " + c);
|
||||
if (c != null) {
|
||||
mLastLockTime = SystemClock.uptimeMillis();
|
||||
return c;
|
||||
}
|
||||
|
||||
// If the Surface is not ready to be drawn, then return null,
|
||||
// but throttle calls to this function so it isn't called more
|
||||
// than every 100ms.
|
||||
long now = SystemClock.uptimeMillis();
|
||||
long nextTime = mLastLockTime + 100;
|
||||
if (nextTime > now) {
|
||||
try {
|
||||
Thread.sleep(nextTime-now);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
now = SystemClock.uptimeMillis();
|
||||
}
|
||||
mLastLockTime = now;
|
||||
mSurfaceLock.unlock();
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the new contents of the {@link Canvas} to the surface and
|
||||
* releases the {@link Canvas}.
|
||||
*
|
||||
* @param canvas The canvas previously obtained from {@link #lockCanvas}.
|
||||
*/
|
||||
@Override
|
||||
public void unlockCanvasAndPost(Canvas canvas) {
|
||||
// mSurface.unlockCanvasAndPost(canvas);
|
||||
// mSurfaceLock.unlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getSurface() {
|
||||
return mSurface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rect getSurfaceFrame() {
|
||||
// return mSurfaceFrame;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
839
src/api-impl/android/view/View.java
Normal file
839
src/api-impl/android/view/View.java
Normal file
File diff suppressed because it is too large
Load Diff
102
src/api-impl/android/view/ViewGroup.java
Normal file
102
src/api-impl/android/view/ViewGroup.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package android.view;
|
||||
|
||||
import android.util.AttributeSet;
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
public int id;
|
||||
public ArrayList<View> children;
|
||||
|
||||
public ViewGroup() {
|
||||
children = new ArrayList<View>();
|
||||
}
|
||||
|
||||
public ViewGroup(Context context) {
|
||||
super(context);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
}
|
||||
|
||||
public ViewGroup(AttributeSet attrs) {
|
||||
super(attrs);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
}
|
||||
|
||||
public ViewGroup(int _id) { // FIXME
|
||||
children = new ArrayList<View>();
|
||||
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public void addView(View child) {
|
||||
addView(child, -1, null);
|
||||
}
|
||||
|
||||
public void addView(View child, int index) {
|
||||
addView(child, index, null);
|
||||
}
|
||||
|
||||
public void addView(View child, LayoutParams params) {
|
||||
addView(child, -1, params);
|
||||
}
|
||||
|
||||
public void addView(View child, int width, int height) {
|
||||
addView(child, new LayoutParams(width, height));
|
||||
}
|
||||
|
||||
public native void addView(View child, int index, LayoutParams params);
|
||||
|
||||
public native void removeView(View view);/* {
|
||||
System.out.println("NOT_IMPLEMENTED: ViewGroup.removeView: Gtk4 doesn't have a generic function for removing a child of GtkView, so you must override this function in the actual widget's class");
|
||||
}*/
|
||||
public native void removeAllViews();/* {
|
||||
System.out.println("NOT_IMPLEMENTED: ViewGroup.removeAllViews: Gtk4 doesn't have a generic function for removing a child of GtkView, so you must override this function in the actual widget's class");
|
||||
new Exception().printStackTrace();
|
||||
}*/
|
||||
|
||||
public View getChildAt(int index) {
|
||||
return children.get(index);
|
||||
}
|
||||
|
||||
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {}
|
||||
|
||||
public LayoutParams generateLayoutParams(AttributeSet attrs) {
|
||||
return new LayoutParams(/*getContext(), attrs*/);
|
||||
}
|
||||
|
||||
public static class LayoutParams {
|
||||
public static final int FILL_PARENT = -1;
|
||||
public static final int MATCH_PARENT = -1;
|
||||
public static final int WRAP_CONTENT = -2;
|
||||
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public float weight = 1;
|
||||
public int gravity = -1;
|
||||
|
||||
public LayoutParams() {
|
||||
//FIXME
|
||||
}
|
||||
|
||||
public LayoutParams(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public LayoutParams(int width, int height, float weight) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public void setMargins(int left, int top, int right, int bottom) {}
|
||||
|
||||
/**
|
||||
* Used to animate layouts.
|
||||
*/
|
||||
// public LayoutAnimationController.AnimationParameters layoutAnimationParameters;
|
||||
}
|
||||
}
|
||||
37
src/api-impl/android/view/ViewManager.java
Normal file
37
src/api-impl/android/view/ViewManager.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.view;
|
||||
|
||||
/** Interface to let you add and remove child views to an Activity. To get an instance
|
||||
* of this class, call {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
|
||||
*/
|
||||
public interface ViewManager
|
||||
{
|
||||
/**
|
||||
* Assign the passed LayoutParams to the passed View and add the view to the window.
|
||||
* <p>Throws {@link android.view.WindowManager.BadTokenException} for certain programming
|
||||
* errors, such as adding a second view to a window without removing the first view.
|
||||
* <p>Throws {@link android.view.WindowManager.InvalidDisplayException} if the window is on a
|
||||
* secondary {@link Display} and the specified display can't be found
|
||||
* (see {@link android.app.Presentation}).
|
||||
* @param view The view to be added to this window.
|
||||
* @param params The LayoutParams to assign to view.
|
||||
*/
|
||||
public void addView(View view, ViewGroup.LayoutParams params);
|
||||
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
|
||||
public void removeView(View view);
|
||||
}
|
||||
7
src/api-impl/android/view/ViewParent.java
Normal file
7
src/api-impl/android/view/ViewParent.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package android.view;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
public interface ViewParent {
|
||||
|
||||
}
|
||||
1030
src/api-impl/android/view/ViewTreeObserver.java
Normal file
1030
src/api-impl/android/view/ViewTreeObserver.java
Normal file
File diff suppressed because it is too large
Load Diff
32
src/api-impl/android/view/Window.java
Normal file
32
src/api-impl/android/view/Window.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package android.view;
|
||||
|
||||
public class Window {
|
||||
public static interface Callback {}
|
||||
public static class fixme_callback implements Callback {}
|
||||
|
||||
// FIXME private
|
||||
public long native_window;
|
||||
|
||||
private Window.Callback callback;
|
||||
|
||||
public Window() {
|
||||
this.callback = new fixme_callback();
|
||||
}
|
||||
|
||||
public void addFlags(int flags) {}
|
||||
public void setFlags(int flags, int mask) {}
|
||||
public void clearFlags(int flags) {}
|
||||
|
||||
public final Callback getCallback() {
|
||||
return this.callback;
|
||||
}
|
||||
public void setCallback(Window.Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public void setContentView(View view) {
|
||||
set_widget_as_root(native_window, view.widget);
|
||||
}
|
||||
|
||||
private native void set_widget_as_root(long native_window, long widget);
|
||||
}
|
||||
8
src/api-impl/android/view/WindowManager.java
Normal file
8
src/api-impl/android/view/WindowManager.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package android.view;
|
||||
|
||||
public interface WindowManager {
|
||||
public android.view.Display getDefaultDisplay();
|
||||
|
||||
public class LayoutParams {
|
||||
}
|
||||
}
|
||||
10
src/api-impl/android/view/WindowManagerImpl.java
Normal file
10
src/api-impl/android/view/WindowManagerImpl.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package android.view;
|
||||
|
||||
public class WindowManagerImpl implements WindowManager {
|
||||
public android.view.Display getDefaultDisplay() {
|
||||
return new android.view.Display();
|
||||
}
|
||||
|
||||
public class LayoutParams {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user