本文整理了Java中android.os.Handler.hasMessages()
方法的一些代码示例,展示了Handler.hasMessages()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler.hasMessages()
方法的具体详情如下:
包路径:android.os.Handler
类名称:Handler
方法名:hasMessages
暂无
代码示例来源:origin: naman14/Timber
private static void releaseWakeLockIfHandlerIdle() {
if (mHandler.hasMessages(MSG_LONGPRESS_TIMEOUT)
|| mHandler.hasMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT)) {
if (DEBUG) Log.v(TAG, "Handler still has messages pending, not releasing wake lock");
return;
}
if (mWakeLock != null) {
if (DEBUG) Log.v(TAG, "Releasing wake lock");
mWakeLock.release();
mWakeLock = null;
}
}
代码示例来源:origin: aa112901/remusic
private static void releaseWakeLockIfHandlerIdle() {
if (mHandler.hasMessages(MSG_LONGPRESS_TIMEOUT)
|| mHandler.hasMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT)) {
if (DEBUG) Log.v(TAG, "Handler still has messages pending, not releasing wake lock");
return;
}
if (mWakeLock != null) {
if (DEBUG) Log.v(TAG, "Releasing wake lock");
mWakeLock.release();
mWakeLock = null;
}
}
代码示例来源:origin: aa112901/remusic
private void onProgressChanged() {
if (mProgressStyle == STYLE_HORIZONTAL) {
if (mViewUpdateHandler != null && !mViewUpdateHandler.hasMessages(0)) {
mViewUpdateHandler.sendEmptyMessage(0);
}
}
}
}
代码示例来源:origin: seven332/EhViewer
private void onProgressChanged() {
if (mProgressStyle == STYLE_HORIZONTAL) {
if (mViewUpdateHandler != null && !mViewUpdateHandler.hasMessages(0)) {
mViewUpdateHandler.sendEmptyMessage(0);
}
}
}
}
代码示例来源:origin: sunfusheng/StickyHeaderListView
public void removeBannerLoopMessage() {
if (mHandler.hasMessages(BANNER_TYPE)) {
mHandler.removeMessages(BANNER_TYPE);
}
}
代码示例来源:origin: journeyapps/zxing-android-embedded
private synchronized void autoFocusAgainLater() {
if (!stopped && !handler.hasMessages(MESSAGE_FOCUS)) {
handler.sendMessageDelayed(handler.obtainMessage(MESSAGE_FOCUS), AUTO_FOCUS_INTERVAL_MS);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeMessage_withSpecifiedObject() throws Exception {
ShadowLooper.pauseMainLooper();
Handler handler = new Handler();
Message.obtain(handler, 123, "foo").sendToTarget();
Message.obtain(handler, 123, "bar").sendToTarget();
assertThat(handler.hasMessages(123)).isTrue();
assertThat(handler.hasMessages(123, "foo")).isTrue();
assertThat(handler.hasMessages(123, "bar")).isTrue();
assertThat(handler.hasMessages(123, "baz")).isFalse();
handler.removeMessages(123, "foo");
assertThat(handler.hasMessages(123)).isTrue();
handler.removeMessages(123, "bar");
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void sendEmptyMessage_addMessageToQueue() {
ShadowLooper.pauseMainLooper();
Handler handler = new Handler();
assertThat(handler.hasMessages(123)).isFalse();
handler.sendEmptyMessage(123);
assertThat(handler.hasMessages(456)).isFalse();
assertThat(handler.hasMessages(123)).isTrue();
ShadowLooper.idleMainLooper(0);
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void resetThreadLoopers_clears_messages() {
HandlerThread backgroundThread = new HandlerThread("resetTest");
backgroundThread.start();
Looper backgroundLooper = backgroundThread.getLooper();
Handler handler = new Handler(backgroundLooper);
for (int i = 0; i < 5; i++) {
handler.sendEmptyMessageDelayed(1, 100);
ShadowLooper.resetThreadLoopers();
assertThat(handler.hasMessages(1)).isFalse();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testHasMessagesWithWhatAndObject() {
ShadowLooper.pauseMainLooper();
Object testObject = new Object();
Handler handler = new Handler();
Message message = handler.obtainMessage(123, testObject);
assertFalse(handler.hasMessages(123, testObject));
handler.sendMessage(message);
assertTrue(handler.hasMessages(123, testObject));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeMessages_takesMessageOutOfQueue() {
ShadowLooper.pauseMainLooper();
Handler handler = new Handler();
handler.sendEmptyMessageDelayed(123, 500);
handler.removeMessages(123);
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSendToTarget() throws Exception {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message.obtain(h, 123).sendToTarget();
assertThat(h.hasMessages(123)).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void sendEmptyMessageDelayed_sendsMessageAtCorrectTime() {
ShadowLooper.pauseMainLooper();
Handler handler = new Handler();
handler.sendEmptyMessageDelayed(123, 500);
assertThat(handler.hasMessages(123)).isTrue();
ShadowLooper.idleMainLooper(100);
assertThat(handler.hasMessages(123)).isTrue();
ShadowLooper.idleMainLooper(400);
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void sendMessageAtTime_sendsMessageAtCorrectTime() {
ShadowLooper.pauseMainLooper();
Handler handler = new Handler();
Message message = handler.obtainMessage(123);
handler.sendMessageAtTime(message, 500);
assertThat(handler.hasMessages(123)).isTrue();
ShadowLooper.idleMainLooper(100);
assertThat(handler.hasMessages(123)).isTrue();
ShadowLooper.idleMainLooper(400);
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSendToTarget() {
ShadowLooper.pauseMainLooper();
Object testObject = new Object();
Handler handler = new Handler();
Message message = handler.obtainMessage(123, testObject);
assertThat(handler).isEqualTo(message.getTarget());
message.sendToTarget();
assertTrue(handler.hasMessages(123, testObject));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testMessengerSend() throws Exception {
Handler handler = new Handler();
Messenger messenger = new Messenger(handler);
ShadowLooper.pauseMainLooper();
Message msg = Message.obtain(null, 123);
messenger.send(msg);
assertThat(handler.hasMessages(123)).isTrue();
Looper looper = Looper.myLooper();
shadowOf(looper).runOneTask();
assertThat(handler.hasMessages(123)).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSendMessageAtFrontOfQueueThenRunMainLooperOneMsgAtATime_shouldRunFrontOfQueueMsgFirst() throws Exception {
Handler handler = new Handler();
ShadowLooper.pauseMainLooper();
// Post two messages to handler. Handle first message and confirm that msg posted
// to front is removed.
handler.obtainMessage(123).sendToTarget();
Message frontMsg = handler.obtainMessage(345);
boolean result = handler.sendMessageAtFrontOfQueue(frontMsg);
assertTrue(result);
assertTrue(handler.hasMessages(123));
assertTrue(handler.hasMessages(345));
ShadowLooper.runMainLooperOneTask();
assertTrue(handler.hasMessages(123));
assertFalse(handler.hasMessages(345));
ShadowLooper.runMainLooperOneTask();
assertFalse(handler.hasMessages(123));
assertFalse(handler.hasMessages(345));
}
代码示例来源:origin: moagrius/TileView
private void updateViewportAndComputeTilesThrottled() {
if (!mRenderThrottle.hasMessages(RENDER_THROTTLE_ID)) {
mRenderThrottle.sendEmptyMessageDelayed(RENDER_THROTTLE_ID, RENDER_THROTTLE_INTERVAL);
}
}
代码示例来源:origin: iielse/ImageWatcher
@Override
public boolean onSingleTapUp(MotionEvent e) {
boolean hadTapMessage = mHandler.hasMessages(SINGLE_TAP_UP_CONFIRMED);
if (hadTapMessage) {
mHandler.removeMessages(SINGLE_TAP_UP_CONFIRMED);
handleDoubleTapTouchResult();
return true;
} else {
mHandler.sendEmptyMessageDelayed(SINGLE_TAP_UP_CONFIRMED, 350);
}
return false;
}
代码示例来源:origin: infinum/android_dbinspector
/**
* Posts a message to bind the preferences to the list view.
* <p/>
* Binding late is preferred as any custom preference types created in {@link #onCreate(Bundle)} are able to have their views recycled.
*/
private void postBindPreferences() {
if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) {
return;
}
mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget();
}
}
内容来源于网络,如有侵权,请联系作者删除!