android.os.Handler.Callback Java Examples

The following examples show how to use android.os.Handler.Callback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: epoxy   Author: airbnb   File: EpoxyAsyncUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a Handler with the given Looper
 *
 * @param async If true the Handler will calls {@link Message#setAsynchronous(boolean)} for
 *              each {@link Message} that is sent to it or {@link Runnable} that is posted to it.
 */
public static Handler createHandler(Looper looper, boolean async) {
  if (!async) {
    return new Handler(looper);
  }

  // Standard way of exposing async handler on older api's from the support library
  // https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/core
  // /src/main/java/androidx/core/os/HandlerCompat.java#51
  if (Build.VERSION.SDK_INT >= 28) {
    return Handler.createAsync(looper);
  }
  if (Build.VERSION.SDK_INT >= 16) {
    try {
      //noinspection JavaReflectionMemberAccess
      return Handler.class.getDeclaredConstructor(Looper.class, Callback.class, boolean.class)
          .newInstance(looper, null, true);
    } catch (Throwable ignored) {
    }
  }

  return new Handler(looper);
}
 
Example #2
Source Project: sms-ticket   Author: SMSTicket   File: GlobalHandlerService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    // proces listeners for specified type of message what
    synchronized (mListenersSpecific) {
        List<BetterWeakReference<Callback>> whatListofListeners = mListenersSpecific.get(msg.what);
        if (whatListofListeners != null) {
            handleListeners(whatListofListeners, msg);
            if (whatListofListeners.size() == 0) {
                mListenersSpecific.remove(msg.what);
            }
        }
    }

    // process universal listeners
    handleListeners(mListenersUniversal, msg);

    return true;
}
 
Example #3
Source Project: darks-logs   Author: liulhdarks   File: AndroidConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register crash handler. It can catch ANR error automatically and use
 * logger to output message.
 * 
 * @param callback Call back object.When ANR error happened, it will use
 *            callback to notify developers. If it's null, it won't call
 *            back.
 */
public void registerCrashHandler(Callback callback)
{
    if (application == null)
    {
        return;
    }
    AndroidCrashHandler.getInstance().setup(application, callback);
}
 
Example #4
Source Project: POCenter   Author: ittianyu   File: FriendAdapter.java    License: MIT License 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #5
Source Project: POCenter   Author: ittianyu   File: OnekeyShareThemeImpl.java    License: MIT License 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #6
Source Project: YiZhi   Author: Horrarndoo   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #7
Source Project: YiZhi   Author: Horrarndoo   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #8
Source Project: ucar-weex-core   Author: weexext   File: WXThread.java    License: Apache License 2.0 5 votes vote down vote up
public static Callback secure(Callback callback){
  if(callback == null || callback instanceof SafeCallback){
    return callback;
  }

  return new SafeCallback(callback);
}
 
Example #9
Source Project: enjoyshop   Author: gaolhjy   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #10
Source Project: enjoyshop   Author: gaolhjy   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #11
Source Project: LiuAGeAndroid   Author: 6ag   File: FriendAdapter.java    License: MIT License 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #12
Source Project: LiuAGeAndroid   Author: 6ag   File: OnekeyShareThemeImpl.java    License: MIT License 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #13
Source Project: Social   Author: devallever   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #14
Source Project: Social   Author: devallever   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = R.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #15
Source Project: Mobike   Author: yiwent   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #16
Source Project: Mobike   Author: yiwent   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = R.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #17
Source Project: LQRWeChat   Author: GitLqr   File: FriendAdapter.java    License: MIT License 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #18
Source Project: LQRWeChat   Author: GitLqr   File: OnekeyShareThemeImpl.java    License: MIT License 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #19
Source Project: weex-uikit   Author: erguotou520   File: WXThread.java    License: MIT License 5 votes vote down vote up
public static Callback secure(Callback callback){
  if(callback == null || callback instanceof SafeCallback){
    return callback;
  }

  return new SafeCallback(callback);
}
 
Example #20
Source Project: BaoKanAndroid   Author: 6ag   File: OnekeyShareThemeImpl.java    License: MIT License 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #21
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: UIHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static void handleMessage(Message msg) {
	Object[] objs = (Object[]) msg.obj;
	Message inner = (Message) objs[0];
	Callback callback = (Callback) objs[1];
	if (callback != null) {
		callback.handleMessage(inner);
	}
}
 
Example #22
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: UIHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static void handleMessage(Message msg) {
    Object[] objs = (Object[]) msg.obj;
    Message inner = (Message) objs[0];
    Callback callback = (Callback) objs[1];
    if (callback != null) {
        callback.handleMessage(inner);
    }
}
 
Example #23
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: UIHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static Message getMessage(int msgWhat, Callback callback) {
    Message shell = new Message();
    Message inner = new Message();
    inner.what = msgWhat;
    shell.obj = new Object[]{inner, callback};
    return shell;
}
 
Example #24
Source Project: BigApp_Discuz_Android   Author: BigAppOS   File: UIHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发送消息
 *
 * @param callback
 * @return
 */
public static boolean sendMessage(Callback callback, int arg1, int arg2, Object obj, int what, Bundle bundle) {
    Message message = Message.obtain();
    message.arg1 = arg1;
    message.arg2 = arg2;
    message.obj = obj;
    message.what = what;
    message.setData(bundle);
    return  handler.sendMessage(getShellMessage(message,callback));
}
 
Example #25
Source Project: MyHearts   Author: wuyinlei   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #26
Source Project: MyHearts   Author: wuyinlei   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = R.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #27
Source Project: GithubApp   Author: mingjunli   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #28
Source Project: GithubApp   Author: mingjunli   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = R.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example #29
Source Project: fingerpoetry-android   Author: klisly   File: FriendAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public void onCancel(Platform plat, int action) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			activity.finish();
			return false;
		}
	});
}
 
Example #30
Source Project: fingerpoetry-android   Author: klisly   File: OnekeyShareThemeImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = R.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}