下面列出了android.os.Looper#getQueue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Creates a FrameMetricsObserver
*
* @param looper the looper to use when invoking callbacks
*/
FrameMetricsObserver(@NonNull Window window, @NonNull Looper looper,
@NonNull Window.OnFrameMetricsAvailableListener listener) {
if (looper == null) {
throw new NullPointerException("looper cannot be null");
}
mMessageQueue = looper.getQueue();
if (mMessageQueue == null) {
throw new IllegalStateException("invalid looper, null message queue\n");
}
mFrameMetrics = new FrameMetrics();
mWindow = new WeakReference<>(window);
mListener = listener;
}
/**
* Creates an input event sender bound to the specified input channel.
*
* @param inputChannel The input channel.
* @param looper The looper to use when invoking callbacks.
*/
public InputEventSender(InputChannel inputChannel, Looper looper) {
if (inputChannel == null) {
throw new IllegalArgumentException("inputChannel must not be null");
}
if (looper == null) {
throw new IllegalArgumentException("looper must not be null");
}
mInputChannel = inputChannel;
mMessageQueue = looper.getQueue();
mSenderPtr = nativeInit(new WeakReference<InputEventSender>(this),
inputChannel, mMessageQueue);
mCloseGuard.open("dispose");
}
/**
* Creates an input event receiver bound to the specified input channel.
*
* @param inputChannel The input channel.
* @param looper The looper to use when invoking callbacks.
*/
public InputEventReceiver(InputChannel inputChannel, Looper looper) {
if (inputChannel == null) {
throw new IllegalArgumentException("inputChannel must not be null");
}
if (looper == null) {
throw new IllegalArgumentException("looper must not be null");
}
mInputChannel = inputChannel;
mMessageQueue = looper.getQueue();
mReceiverPtr = nativeInit(new WeakReference<InputEventReceiver>(this),
inputChannel, mMessageQueue);
mCloseGuard.open("dispose");
}
/**
* Creates a display event receiver.
*
* @param looper The looper to use when invoking callbacks.
* @param vsyncSource The source of the vsync tick. Must be on of the VSYNC_SOURCE_* values.
*/
public DisplayEventReceiver(Looper looper, int vsyncSource) {
if (looper == null) {
throw new IllegalArgumentException("looper must not be null");
}
mMessageQueue = looper.getQueue();
mReceiverPtr = nativeInit(new WeakReference<DisplayEventReceiver>(this), mMessageQueue,
vsyncSource);
mCloseGuard.open("dispose");
}
@SuppressLint("NewApi") // Looper.getQueue is hidden before Android M.
private static MessageQueue getQueue(final Looper looper) {
return looper.getQueue();
}