本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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);
}
}
}
示例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());
}
}
示例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;
}
}
示例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();
}
});
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例13: invaidateSelft
import android.os.Looper; //导入方法依赖的package包/类
private void invaidateSelft() {
if (Looper.myLooper() == Looper.getMainLooper()) {
invalidate();
} else {
postInvalidate();
}
}
示例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);
}
}
}
示例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());
}
}