SurfaceHolder(二维码生成器时用到)

师:关于这个二维码生成器用到的API,你能看出多少来?
徒:类?方法,,接口
师:当然,还有呢,怎么用,需要什么条件?
徒:嗯,我能看到了。
师:进步了啊,还有呢?
徒:适用版本号?
师:嗯,入门了啊。还有呢?
徒:还有?
师:难道没了吗?哪些是要传入或者返回的参数值,哪些不用手动敲入代码,由上而下怎么介绍的这个类结构,这个类之外的联系结点有哪些......
徒:我知道了,这么说好像写指南的时候,每一个词都不是多余的啊,一定会认真阅读的,之后应该能熟用......
师:不是熟用,而是完成目标的同时不出错......人能做到不出错,就已经是完美人生了,执意追求什么虚无的成功,或许转身一看,又或者仅仅偏头一看,你会发现已经做了很多有成就的事,不过你只是只盯着前方这一个局部方向罢了,人的世界应该是360度六维空间体的......
public interface
SurfaceHolder
android.view.SurfaceHolder
Class Overview

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 SurfaceView class.

When using this interface from a thread other than the one running its SurfaceView, you will want to carefully read the methods lockCanvas() and Callback.surfaceCreated().
Summary
Nested Classes
class     SurfaceHolder.BadSurfaceTypeException     Exception that is thrown from lockCanvas() when called on a Surface whose type is SURFACE_TYPE_PUSH_BUFFERS.
interface     SurfaceHolder.Callback     A client may implement this interface to receive information about changes to the surface.
interface     SurfaceHolder.Callback2     Additional callbacks that can be received for SurfaceHolder.Callback.
Constants
int     SURFACE_TYPE_GPU     This constant was deprecated in API level 5. this is ignored, this value is set automatically when needed.
int     SURFACE_TYPE_HARDWARE     This constant was deprecated in API level 5. this is ignored, this value is set automatically when needed.
int     SURFACE_TYPE_NORMAL     This constant was deprecated in API level 11. this is ignored, this value is set automatically when needed.
int     SURFACE_TYPE_PUSH_BUFFERS     This constant was deprecated in API level 11. this is ignored, this value is set automatically when needed.
Public Methods
abstract void     addCallback(SurfaceHolder.Callback callback)
Add a Callback interface for this holder.
abstract Surface     getSurface()
Direct access to the surface object.
abstract Rect     getSurfaceFrame()
Retrieve the current size of the surface.
abstract boolean     isCreating()
Use this method to find out if the surface is in the process of being created from Callback methods.
abstract Canvas     lockCanvas(Rect dirty)
Just like lockCanvas() but allows specification of a dirty rectangle.
abstract Canvas     lockCanvas()
Start editing the pixels in the surface.
abstract void     removeCallback(SurfaceHolder.Callback callback)
Removes a previously added Callback interface from this holder.
abstract void     setFixedSize(int width, int height)
Make the surface a fixed size.
abstract void     setFormat(int format)
Set the desired PixelFormat of the surface.
abstract void     setKeepScreenOn(boolean screenOn)
Enable or disable option to keep the screen turned on while this surface is displayed.
abstract void     setSizeFromLayout()
Allow the surface to resized based on layout of its container (this is the default).
abstract void     setType(int type)
This method was deprecated in API level 11. this is ignored, this value is set automatically when needed.
abstract void     unlockCanvasAndPost(Canvas canvas)
Finish editing pixels in the surface.
Constants
public static final int SURFACE_TYPE_GPU
Added in API level 1

This constant was deprecated in API level 5.
this is ignored, this value is set automatically when needed.
Constant Value: 2 (0x00000002)
public static final int SURFACE_TYPE_HARDWARE
Added in API level 1

This constant was deprecated in API level 5.
this is ignored, this value is set automatically when needed.
Constant Value: 1 (0x00000001)
public static final int SURFACE_TYPE_NORMAL
Added in API level 1

This constant was deprecated in API level 11.
this is ignored, this value is set automatically when needed.
Constant Value: 0 (0x00000000)
public static final int SURFACE_TYPE_PUSH_BUFFERS
Added in API level 1

This constant was deprecated in API level 11.
this is ignored, this value is set automatically when needed.
Constant Value: 3 (0x00000003)
Public Methods
public abstract void addCallback (SurfaceHolder.Callback callback)
Added in API level 1

Add a Callback interface for this holder. There can several Callback interfaces associated with a holder.
Parameters
callback     The new Callback interface.
public abstract Surface getSurface ()
Added in API level 1

Direct access to the surface object. The Surface may not always be available -- for example when using a 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 Callback.surfaceCreated to find out when the Surface is available for use.

Note that if you directly access the Surface from another thread, it is critical that you correctly implement Callback.surfaceCreated and 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.

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).
Returns

    Surface The surface.

public abstract Rect getSurfaceFrame ()
Added in API level 1

Retrieve the current size of the surface. Note: do not modify the returned Rect. This is only safe to call from the thread of SurfaceView's window, or while inside of lockCanvas().
Returns

    Rect The surface's dimensions. The left and top are always 0.

public abstract boolean isCreating ()
Added in API level 1

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 surfaceChanged(SurfaceHolder, int, int, int).
Returns

    true if the surface is in the process of being created.

public abstract Canvas lockCanvas (Rect dirty)
Added in API level 1

Just like 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().
Parameters
dirty     Area of the Surface that will be modified.
Returns

    Canvas Use to draw into the surface.

See Also

    lockCanvas()

public abstract Canvas lockCanvas ()
Added in API level 1

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 Callback.surfaceCreated to find out when the Surface is available for use.

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.

If you call this repeatedly when the Surface is not ready (before Callback.surfaceCreated or after Callback.surfaceDestroyed), your calls will be throttled to a slow rate in order to avoid consuming CPU.

If null is not returned, this function internally holds a lock until the corresponding unlockCanvasAndPost(Canvas) call, preventing 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 Callback.surfaceDestroyed.
Returns

    Canvas Use to draw into the surface.

public abstract void removeCallback (SurfaceHolder.Callback callback)
Added in API level 1

Removes a previously added Callback interface from this holder.
Parameters
callback     The Callback interface to remove.
public abstract void setFixedSize (int width, int height)
Added in API level 1

Make the surface a fixed size. It will never change from this size. When working with a SurfaceView, this must be called from the same thread running the SurfaceView's window.
Parameters
width     The surface's width.
height     The surface's height.
public abstract void setFormat (int format)
Added in API level 1

Set the desired PixelFormat of the surface. The default is OPAQUE. When working with a SurfaceView, this must be called from the same thread running the SurfaceView's window.
Parameters
format     A constant from PixelFormat.
See Also

    PixelFormat

public abstract void setKeepScreenOn (boolean screenOn)
Added in API level 1

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.
Parameters
screenOn     Set to true to force the screen to stay on, false to allow it to turn off.
public abstract void setSizeFromLayout ()
Added in API level 1

Allow the surface to resized based on layout of its container (this is the default). When this is enabled, you should monitor surfaceChanged(SurfaceHolder, int, int, int) for changes to the size of the surface. When working with a SurfaceView, this must be called from the same thread running the SurfaceView's window.
public abstract void setType (int type)
Added in API level 1

This method was deprecated in API level 11.
this is ignored, this value is set automatically when needed.

Sets the surface's type.
public abstract void unlockCanvasAndPost (Canvas canvas)
Added in API level 1

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.
Parameters
canvas     The Canvas previously returned by lockCanvas().
See Also

    lockCanvas()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值