当前位置: 首页>>代码示例>>Java>>正文


Java Looper.myLooper方法代码示例

本文整理汇总了Java中android.os.Looper.myLooper方法的典型用法代码示例。如果您正苦于以下问题:Java Looper.myLooper方法的具体用法?Java Looper.myLooper怎么用?Java Looper.myLooper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.Looper的用法示例。


在下文中一共展示了Looper.myLooper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initPlayer

import android.os.Looper; //导入方法依赖的package包/类
private void initPlayer(IjkLibLoader libLoader) {
    loadLibrariesOnce(libLoader);
    initNativeOnce();

    Looper looper;
    if ((looper = Looper.myLooper()) != null) {
        mEventHandler = new EventHandler(this, looper);
    } else if ((looper = Looper.getMainLooper()) != null) {
        mEventHandler = new EventHandler(this, looper);
    } else {
        mEventHandler = null;
    }

    /*
     * Native setup requires a weak reference to our object. It's easier to
     * create it here than in C++.
     */
    native_setup(new WeakReference<IjkMediaPlayer>(this));
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:20,代码来源:IjkMediaPlayer.java

示例2: aroundJoinPoint

import android.os.Looper; //导入方法依赖的package包/类
@Around("methodAnnotated()")
public Object aroundJoinPoint(final ProceedingJoinPoint joinPoint) throws Throwable {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        result = joinPoint.proceed();
    } else {
        C.doBack(new Runnable() {
            @Override
            public void run() {
                try {
                    result = joinPoint.proceed();
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                }
            }
        });
    }
    return result;
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:19,代码来源:DoBackAspectj.java

示例3: loadBitmapFromHttp

import android.os.Looper; //导入方法依赖的package包/类
/**
 * 加载网络图片缓存到磁盘中
 * @param uri
 * @param reqWidth
 * @param reqHeight
 * @return
 */
private Bitmap loadBitmapFromHttp(String uri, int reqWidth, int reqHeight) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        throw new RuntimeException("can not visit network from UI thread.");
    }
    if (mDiskLruCache == null) {
        return null;
    }
    String key = hashKeyFromUri(uri);
    try {
        DiskLruCache.Editor editor = mDiskLruCache.edit(key);
        if (editor != null) {
            OutputStream outputStream = editor.newOutputStream(DISK_CACHE_INDEX);
            if (downloadBitmapToStream(uri, outputStream)){
                editor.commit();
            } else {
                editor.abort();
            }
            mDiskLruCache.flush();
            return loadBitmapFromDisCache(uri, reqWidth, reqHeight);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:33,代码来源:ImageLoader.java

示例4: getInstance

import android.os.Looper; //导入方法依赖的package包/类
public static LauncherAppState getInstance(final Context context) {
    if (INSTANCE == null) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            INSTANCE = new LauncherAppState(context.getApplicationContext());
        } else {
            try {
                return new MainThreadExecutor().submit(new Callable<LauncherAppState>() {
                    @Override
                    public LauncherAppState call() throws Exception {
                        return LauncherAppState.getInstance(context);
                    }
                }).get();
            } catch (InterruptedException|ExecutionException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return INSTANCE;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:20,代码来源:LauncherAppState.java

示例5: finish

import android.os.Looper; //导入方法依赖的package包/类
/**
 * Notifies the request queue that this request has finished (successfully or with error).
 *
 * <p>Also dumps all events from this request's event log; for debugging.</p>
 */
void finish(final String tag) {
    if (mRequestQueue != null) {
        mRequestQueue.finish(this);
    }
    if (MarkerLog.ENABLED) {
        final long threadId = Thread.currentThread().getId();
        if (Looper.myLooper() != Looper.getMainLooper()) {
            // If we finish marking off of the main thread, we need to
            // actually do it on the main thread to ensure correct ordering.
            Handler mainThread = new Handler(Looper.getMainLooper());
            mainThread.post(new Runnable() {
                @Override
                public void run() {
                    mEventLog.add(tag, threadId);
                    mEventLog.finish(this.toString());
                }
            });
            return;
        }

        mEventLog.add(tag, threadId);
        mEventLog.finish(this.toString());
    } else {
        long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
        if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
            VolleyLog.d("%d ms: %s", requestTime, this.toString());
        }
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:35,代码来源:Request.java

示例6: ensureInitialized

import android.os.Looper; //导入方法依赖的package包/类
/**
 * Ensure that native library is loaded and initialized. Can be called from
 * any thread, the load and initialization is performed on main thread.
 */
public static void ensureInitialized(
        final Context context, final CronetEngine.Builder builder) {
    synchronized (sLoadLock) {
        if (sInitStarted) {
            return;
        }
        sInitStarted = true;
        ContextUtils.initApplicationContext(context.getApplicationContext());
        if (builder.libraryLoader() != null) {
            builder.libraryLoader().loadLibrary(builder.libraryName());
        } else {
            System.loadLibrary(builder.libraryName());
        }
        ContextUtils.initApplicationContextForNative();
        if (!ImplVersion.CRONET_VERSION.equals(nativeGetCronetVersion())) {
            throw new RuntimeException(String.format("Expected Cronet version number %s, "
                            + "actual version number %s.",
                    ImplVersion.CRONET_VERSION, nativeGetCronetVersion()));
        }
        Log.i(TAG, "Cronet version: %s, arch: %s", ImplVersion.CRONET_VERSION,
                System.getProperty("os.arch"));
        // Init native Chromium CronetEngine on Main UI thread.
        Runnable task = new Runnable() {
            @Override
            public void run() {
                ensureInitializedOnMainThread(context);
            }
        };
        // Run task immediately or post it to the UI thread.
        if (Looper.getMainLooper() == Looper.myLooper()) {
            task.run();
        } else {
            // The initOnMainThread will complete on the main thread prior
            // to other tasks posted to the main thread.
            new Handler(Looper.getMainLooper()).post(task);
        }
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:43,代码来源:CronetLibraryLoader.java

示例7: setVoiceInteractor

import android.os.Looper; //导入方法依赖的package包/类
void setVoiceInteractor(IVoiceInteractor voiceInteractor) {
    if (mVoiceInteractor != null) {
        for (Request activeRequest: mVoiceInteractor.getActiveRequests()) {
            activeRequest.cancel();
            activeRequest.clear();
        }
    }
    if (voiceInteractor == null) {
        mVoiceInteractor = null;
    } else {
        mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this,
                Looper.myLooper());
    }
}
 
开发者ID:JessYanCoding,项目名称:ProgressManager,代码行数:15,代码来源:a.java

示例8: showAndGet

import android.os.Looper; //导入方法依赖的package包/类
public Object showAndGet() {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        super.show();
    } else {
        mUiHandler.post(Builder.super::show);
    }
    if (mResultBox != null) {
        return mResultBox.blockedGetOrThrow(ScriptInterruptedException.class);
    } else {
        return null;
    }
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:13,代码来源:BlockedMaterialDialog.java

示例9: unsubscribe

import android.os.Looper; //导入方法依赖的package包/类
public final void unsubscribe() {
    if (!this.unsubscribed.compareAndSet(false, true)) {
        return;
    }
    if (Looper.myLooper() == Looper.getMainLooper()) {
        onUnsubscribe();
    } else {
        AndroidSchedulers.mainThread().createWorker().schedule(new Action0() {
            public void call() {
                MainThreadSubscription.this.onUnsubscribe();
            }
        });
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:MainThreadSubscription.java

示例10: checkMainThread

import android.os.Looper; //导入方法依赖的package包/类
private boolean checkMainThread(Observer<? super CharSequence> observer) {
    if (Looper.myLooper() != Looper.getMainLooper()) {
        observer.onError(new IllegalStateException(
                "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
        return false;
    }
    return true;
}
 
开发者ID:Zackratos,项目名称:RxToast,代码行数:9,代码来源:ToastObservable.java

示例11: execute

import android.os.Looper; //导入方法依赖的package包/类
@Override
public void execute(@NonNull Runnable command) {
    if(Looper.myLooper() == Looper.getMainLooper()) {
        command.run();
    } else {
        handler.post(command);
    }
}
 
开发者ID:Zhuinden,项目名称:realm-helpers,代码行数:9,代码来源:RealmMainThreadExecutor.java

示例12: bundleChanged

import android.os.Looper; //导入方法依赖的package包/类
@SuppressLint("NewApi") @Override
public void bundleChanged(final BundleEvent event){
    switch (event.getType()) {
        case 0:/* LOADED */
            loaded(event.getBundle());
            break;
        case BundleEvent.INSTALLED:
            //todo 注意主dex bundle
            installed(event.getBundle());
            break;
        case BundleEvent.UPDATED:
            updated(event.getBundle());
            break;
        case BundleEvent.UNINSTALLED:
            uninstalled(event.getBundle());
            break;
        case BundleEvent.STARTED:
        	if(isLewaOS()){
        		if(Looper.myLooper() == null){
        			Looper.prepare();
        		}
                started(event.getBundle());
        	}else{
                started(event.getBundle());
        	}  
        	break;
        case BundleEvent.STOPPED:
            stopped(event.getBundle());
            break;
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:32,代码来源:BundleLifecycleHandler.java

示例13: invaidateSelft

import android.os.Looper; //导入方法依赖的package包/类
private void invaidateSelft() {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        invalidate();
    } else {
        postInvalidate();
    }
}
 
开发者ID:frank909zhao,项目名称:LoadButton,代码行数:8,代码来源:LoadButton.java

示例14: a

import android.os.Looper; //导入方法依赖的package包/类
private static void a(Runnable runnable) {
    if (runnable != null) {
        if ((Looper.getMainLooper() == Looper.myLooper() ? 1 : null) != null) {
            runnable.run();
        } else {
            new Handler(Looper.getMainLooper()).post(runnable);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:10,代码来源:d.java

示例15: runUI

import android.os.Looper; //导入方法依赖的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) {
        L.d("update UI task fail. " + e.getMessage());
    }
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:13,代码来源:RExecutor.java


注:本文中的android.os.Looper.myLooper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。