當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。