Methods Summary |
---|
public static android.view.PointerIcon | createCustomIcon(android.graphics.Bitmap bitmap, float hotSpotX, float hotSpotY)Creates a custom pointer from the given bitmap and hotspot information.
if (bitmap == null) {
throw new IllegalArgumentException("bitmap must not be null");
}
validateHotSpot(bitmap, hotSpotX, hotSpotY);
PointerIcon icon = new PointerIcon(STYLE_CUSTOM);
icon.mBitmap = bitmap;
icon.mHotSpotX = hotSpotX;
icon.mHotSpotY = hotSpotY;
return icon;
|
public int | describeContents()
return 0;
|
public boolean | equals(java.lang.Object other)
if (this == other) {
return true;
}
if (other == null || !(other instanceof PointerIcon)) {
return false;
}
PointerIcon otherIcon = (PointerIcon) other;
if (mStyle != otherIcon.mStyle
|| mSystemIconResourceId != otherIcon.mSystemIconResourceId) {
return false;
}
if (mSystemIconResourceId == 0 && (mBitmap != otherIcon.mBitmap
|| mHotSpotX != otherIcon.mHotSpotX
|| mHotSpotY != otherIcon.mHotSpotY)) {
return false;
}
return true;
|
public android.graphics.Bitmap | getBitmap()Gets the bitmap of the pointer icon.
throwIfIconIsNotLoaded();
return mBitmap;
|
public static android.view.PointerIcon | getDefaultIcon(android.content.Context context)Gets the default pointer icon.
return getSystemIcon(context, STYLE_DEFAULT);
|
public float | getHotSpotX()Gets the X offset of the pointer icon hotspot.
throwIfIconIsNotLoaded();
return mHotSpotX;
|
public float | getHotSpotY()Gets the Y offset of the pointer icon hotspot.
throwIfIconIsNotLoaded();
return mHotSpotY;
|
public static android.view.PointerIcon | getNullIcon()Gets a special pointer icon that has no bitmap.
return gNullIcon;
|
public int | getStyle()Gets the style of the pointer icon.
return mStyle;
|
public static android.view.PointerIcon | getSystemIcon(android.content.Context context, int style)Gets a system pointer icon for the given style.
If style is not recognized, returns the default pointer icon.
if (context == null) {
throw new IllegalArgumentException("context must not be null");
}
if (style == STYLE_NULL) {
return gNullIcon;
}
int styleIndex = getSystemIconStyleIndex(style);
if (styleIndex == 0) {
styleIndex = getSystemIconStyleIndex(STYLE_DEFAULT);
}
TypedArray a = context.obtainStyledAttributes(null,
com.android.internal.R.styleable.Pointer,
com.android.internal.R.attr.pointerStyle, 0);
int resourceId = a.getResourceId(styleIndex, -1);
a.recycle();
if (resourceId == -1) {
Log.w(TAG, "Missing theme resources for pointer icon style " + style);
return style == STYLE_DEFAULT ? gNullIcon : getSystemIcon(context, STYLE_DEFAULT);
}
PointerIcon icon = new PointerIcon(style);
if ((resourceId & 0xff000000) == 0x01000000) {
icon.mSystemIconResourceId = resourceId;
} else {
icon.loadResource(context, context.getResources(), resourceId);
}
return icon;
|
private static int | getSystemIconStyleIndex(int style)
switch (style) {
case STYLE_ARROW:
return com.android.internal.R.styleable.Pointer_pointerIconArrow;
case STYLE_SPOT_HOVER:
return com.android.internal.R.styleable.Pointer_pointerIconSpotHover;
case STYLE_SPOT_TOUCH:
return com.android.internal.R.styleable.Pointer_pointerIconSpotTouch;
case STYLE_SPOT_ANCHOR:
return com.android.internal.R.styleable.Pointer_pointerIconSpotAnchor;
default:
return 0;
}
|
public boolean | isLoaded()Returns true if the pointer icon has been loaded and its bitmap and hotspot
information are available.
return mBitmap != null || mStyle == STYLE_NULL;
|
public boolean | isNullIcon()Returns true if the pointer icon style is {@link #STYLE_NULL}.
return mStyle == STYLE_NULL;
|
public android.view.PointerIcon | load(android.content.Context context)Loads the bitmap and hotspot information for a pointer icon, if it is not already loaded.
Returns a pointer icon (not necessarily the same instance) with the information filled in.
if (context == null) {
throw new IllegalArgumentException("context must not be null");
}
if (mSystemIconResourceId == 0 || mBitmap != null) {
return this;
}
PointerIcon result = new PointerIcon(mStyle);
result.mSystemIconResourceId = mSystemIconResourceId;
result.loadResource(context, context.getResources(), mSystemIconResourceId);
return result;
|
public static android.view.PointerIcon | loadCustomIcon(android.content.res.Resources resources, int resourceId)Loads a custom pointer icon from an XML resource.
The XML resource should have the following form:
<?xml version="1.0" encoding="utf-8"?>
<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
android:bitmap="@drawable/my_pointer_bitmap"
android:hotSpotX="24"
android:hotSpotY="24" />
if (resources == null) {
throw new IllegalArgumentException("resources must not be null");
}
PointerIcon icon = new PointerIcon(STYLE_CUSTOM);
icon.loadResource(null, resources, resourceId);
return icon;
|
private void | loadResource(android.content.Context context, android.content.res.Resources resources, int resourceId)
final XmlResourceParser parser = resources.getXml(resourceId);
final int bitmapRes;
final float hotSpotX;
final float hotSpotY;
try {
XmlUtils.beginDocument(parser, "pointer-icon");
final TypedArray a = resources.obtainAttributes(
parser, com.android.internal.R.styleable.PointerIcon);
bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
a.recycle();
} catch (Exception ex) {
throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex);
} finally {
parser.close();
}
if (bitmapRes == 0) {
throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
}
Drawable drawable;
if (context == null) {
drawable = resources.getDrawable(bitmapRes);
} else {
drawable = context.getDrawable(bitmapRes);
}
if (!(drawable instanceof BitmapDrawable)) {
throw new IllegalArgumentException("<pointer-icon> bitmap attribute must "
+ "refer to a bitmap drawable.");
}
// Set the properties now that we have successfully loaded the icon.
mBitmap = ((BitmapDrawable)drawable).getBitmap();
mHotSpotX = hotSpotX;
mHotSpotY = hotSpotY;
|
private void | throwIfIconIsNotLoaded()
if (!isLoaded()) {
throw new IllegalStateException("The icon is not loaded.");
}
|
private static void | validateHotSpot(android.graphics.Bitmap bitmap, float hotSpotX, float hotSpotY)
if (hotSpotX < 0 || hotSpotX >= bitmap.getWidth()) {
throw new IllegalArgumentException("x hotspot lies outside of the bitmap area");
}
if (hotSpotY < 0 || hotSpotY >= bitmap.getHeight()) {
throw new IllegalArgumentException("y hotspot lies outside of the bitmap area");
}
|
public void | writeToParcel(android.os.Parcel out, int flags)
out.writeInt(mStyle);
if (mStyle != STYLE_NULL) {
out.writeInt(mSystemIconResourceId);
if (mSystemIconResourceId == 0) {
mBitmap.writeToParcel(out, flags);
out.writeFloat(mHotSpotX);
out.writeFloat(mHotSpotY);
}
}
|