本文整理汇总了Java中android.os.Handler.post方法的典型用法代码示例。如果您正苦于以下问题:Java Handler.post方法的具体用法?Java Handler.post怎么用?Java Handler.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Handler
的用法示例。
在下文中一共展示了Handler.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import android.os.Handler; //导入方法依赖的package包/类
@Override
protected void init(final String initialCommand) {
Handler uiHandler = new Handler(mContext.getMainLooper());
uiHandler.post(new Runnable() {
@Override
public void run() {
TermSettings settings = new TermSettings(mContext.getResources(), PreferenceManager.getDefaultSharedPreferences(mContext));
try {
mTermSession = new MyShellTermSession(settings, initialCommand);
mTermSession.initializeEmulator(1024, 40);
} catch (IOException e) {
mInitException = new UncheckedIOException(e);
}
}
});
}
示例2: getStringCallback
import android.os.Handler; //导入方法依赖的package包/类
private WebSocket.StringCallback getStringCallback() {
return new WebSocket.StringCallback(){
public void onStringAvailable(String s){
try {
final JSONObject row = new JSONObject(s);
Runnable dispatchState = new Runnable() {
@Override
public void run() {
processData(row);
}
};
Handler mainHandler = new Handler(context.getMainLooper());
mainHandler.post(dispatchState);
} catch (JSONException e) {}
}
};
}
示例3: ExecutorDelivery
import android.os.Handler; //导入方法依赖的package包/类
/**
* Creates a new response delivery interface.
* @param handler {@link Handler} to post responses on
*/
public ExecutorDelivery(final Handler handler) {
// Make an Executor that just wraps the handler.
mResponsePoster = new Executor() {
@Override
public void execute(Runnable command) {
handler.post(command);
}
};
}
示例4: runMainHanlder
import android.os.Handler; //导入方法依赖的package包/类
private void runMainHanlder(final Camera.Size previewSize) {
Handler mainHanlder = new Handler(Looper.getMainLooper());
mainHanlder.post(new Runnable() {
@Override
public void run() {
adjustViewSize(previewSize);
}
});
}
示例5: runTask
import android.os.Handler; //导入方法依赖的package包/类
static void runTask(Runnable r, boolean sync, Handler handler, ImageLoaderEngine engine) {
if (sync) {
r.run();
} else if (handler == null) {
engine.fireCallback(r);
} else {
handler.post(r);
}
}
示例6: runUI
import android.os.Handler; //导入方法依赖的package包/类
public void runUI(@NonNull Runnable runnable) {
if (Looper.myLooper() == Looper.getMainLooper()) {
runnable.run();
return;
}
Handler handler = ensureUiHandlerNotNull();
try {
handler.post(runnable);
} catch (Exception e) {
BoxingLog.d("update UI task fail. " + e.getMessage());
}
}
示例7: setProgressFromAnotherThread
import android.os.Handler; //导入方法依赖的package包/类
public void setProgressFromAnotherThread(final int progress) {
if (mProgress != progress) {
mProgress = progress;
// For some unknown reason, setProgress just does not work from a separate
// thread, although the code in ProgressBar looks like it should. Thus, we
// resort to a runnable posted to the handler of the view.
final Handler handler = getHandler();
// It's possible to come here before this view has been laid out. If so,
// just ignore the call - it will be updated again later.
if (null == handler) return;
handler.post(this);
}
}
示例8: DownloadStatusDeliveryImpl
import android.os.Handler; //导入方法依赖的package包/类
public DownloadStatusDeliveryImpl(final Handler handler) {
this.mDownloadStatusPoster = new Executor() {
public void execute(Runnable command) {
handler.post(command);
}
};
}
示例9: notifyListeners
import android.os.Handler; //导入方法依赖的package包/类
private void notifyListeners(int why, int deviceId) {
// the state of some device has changed
if (!mListeners.isEmpty()) {
// yes... this will cause an object to get created... hopefully
// it won't happen very often
for (InputDeviceListener listener : mListeners.keySet()) {
Handler handler = mListeners.get(listener);
DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
handler.post(odc);
}
}
}
示例10: openIME
import android.os.Handler; //导入方法依赖的package包/类
public void openIME(final EditText v) {
final boolean focus = v.requestFocus();
if (v.hasFocus()) {
final Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
InputMethodManager mgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
boolean result = mgr.showSoftInput(v, InputMethodManager.SHOW_FORCED);
log.debug("openIME " + focus + " " + result);
}
});
}
}
示例11: addPersonDataBool
import android.os.Handler; //导入方法依赖的package包/类
@ReactMethod
public void addPersonDataBool(final Boolean bool, final String key, final Promise promise)
{
if (!_initialised)
{
promise.reject(APPTENTIVE, "Apptentive is not initialised");
return;
}
if (bool == null)
{
promise.reject(APPTENTIVE, "Your bool is empty");
return;
}
if (key == null || key.isEmpty())
{
promise.reject(APPTENTIVE, "Your key is empty");
return;
}
Handler handler = new Handler(_application.getMainLooper());
Runnable runnable = new Runnable()
{
@Override
public void run()
{
Apptentive.addCustomPersonData(key, bool);
promise.resolve(true);
}
};
handler.post(runnable);
}
示例12: jumpPoint
import android.os.Handler; //导入方法依赖的package包/类
/**
* marker点击时跳动一下
*/
public void jumpPoint(final Marker marker) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
//获取地图投影坐标转换器
Projection proj = amap.getProjection();
final LatLng markerLatlng = marker.getPosition();
Point markerPoint = proj.toScreenLocation(markerLatlng);
markerPoint.offset(0, -50);
final LatLng startLatLng = proj.fromScreenLocation(markerPoint);
final long duration = 500;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * markerLatlng.longitude + (1 - t)
* startLatLng.longitude;
double lat = t * markerLatlng.latitude + (1 - t)
* startLatLng.latitude;
marker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
handler.postDelayed(this, 16);
}
}
});
}
示例13: record
import android.os.Handler; //导入方法依赖的package包/类
public void record(final HttpCall httpCall) throws IOException {
Handler handler = new Handler(context.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
AndroidSnooper.this.snooperRepo.save(HttpCallRecord.from(httpCall));
}
});
}
示例14: addDeviceDataNumber
import android.os.Handler; //导入方法依赖的package包/类
@ReactMethod
public void addDeviceDataNumber(final Number number, final String key, final Promise promise)
{
if (!_initialised)
{
promise.reject(APPTENTIVE, "Apptentive is not initialised");
return;
}
if (number == null)
{
promise.reject(APPTENTIVE, "Your number is empty");
return;
}
if (key == null || key.isEmpty())
{
promise.reject(APPTENTIVE, "Your key is empty");
return;
}
Handler handler = new Handler(_application.getMainLooper());
Runnable runnable = new Runnable()
{
@Override
public void run()
{
Apptentive.addCustomDeviceData(key, number);
promise.resolve(true);
}
};
handler.post(runnable);
}
示例15: update
import android.os.Handler; //导入方法依赖的package包/类
/**
* Update mobile map package with latest version
*/
@Override public void update() {
//Check for valid credentials
final String credentialString;
try {
credentialString = mCredentialCryptographer.decrypt();
if (credentialString != null && credentialString.length() > 0 ){
Log.i(TAG,"Downloading with cached credentials");
// Rehydrate the credential cache from the decrypted file
AuthenticationManager.CredentialCache.restoreFromJson(credentialString);
//Kick off a thread to handle mobile map package download
final Handler handler = new Handler() ;
handler.post(new Runnable() {
@Override public void run() {
// Download map book
downloadMapbook();
}
});
}else{
// If credentials are null, we'll prompt user for credentials
Log.i(TAG,"Credential cache cannot be reconstituted from null credentials, so asking using to provide credentials...");
signIn();
}
} catch (Exception e) {
Log.e(TAG, e.getClass().getSimpleName() + " " + e.getMessage());
if (e.getCause() != null){
Log.e(TAG, e.getCause().getMessage());
}
}
}