本文整理汇总了Java中android.os.Looper.getMainLooper方法的典型用法代码示例。如果您正苦于以下问题:Java Looper.getMainLooper方法的具体用法?Java Looper.getMainLooper怎么用?Java Looper.getMainLooper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Looper
的用法示例。
在下文中一共展示了Looper.getMainLooper方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearImageDiskCache
import android.os.Looper; //导入方法依赖的package包/类
/**
* 清除图片磁盘缓存
*/
public void clearImageDiskCache(final Context context) {
try {
if (Looper.myLooper() == Looper.getMainLooper()) {
new Thread(new Runnable() {
@Override
public void run() {
Glide.get(context).clearDiskCache();
}
}).start();
} else {
Glide.get(context).clearDiskCache();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: notifyChanged
import android.os.Looper; //导入方法依赖的package包/类
private void notifyChanged(final String key) {
if (Looper.myLooper() == Looper.getMainLooper()) {
for (OnSharedPreferenceChangeListener listener : listeners) {
if (listener != null) {
listener.onSharedPreferenceChanged(AccountPreferences.this, key);
}
}
} else {
mainHandler.post(new Runnable() {
@Override
public void run() {
notifyChanged(key);
}
});
}
}
示例3: getThreadPool
import android.os.Looper; //导入方法依赖的package包/类
/**
* 获取单例的线程池对象
*
* @return
*/
public static ThreadUtil.ThreadPool getThreadPool() {
if (mThreadPool == null) {
synchronized (ThreadUtil.class) {
if (mThreadPool == null) {
// cpu个数
int cpuNum = Runtime.getRuntime().availableProcessors();
int count = cpuNum * 2 + 1;
// int count = 15;
System.out.println("cpu个数:" + cpuNum);
mThreadPool = new ThreadPool(count, count, 0L);
mHandler = new Handler(Looper.getMainLooper());
}
}
}
return mThreadPool;
}
示例4: AndroidInflaterHandler
import android.os.Looper; //导入方法依赖的package包/类
public AndroidInflaterHandler(int threads, int priority) {
mMainHandlerFallback = new android.os.Handler(Looper.getMainLooper());
mLoopers = new LooperThread[8];
for (int i = 0; i < mLoopers.length; ++i) {
mLoopers[i] = new LooperThread("AndroidInflaterHandler " + i, priority);
mLoopers[i].start();
}
}
示例5: Loopers
import android.os.Looper; //导入方法依赖的package包/类
public Loopers(Timers timers) {
mTimers = timers;
if (Looper.myLooper() == Looper.getMainLooper()) {
waitWhenIdle = true;
}
Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
@Override
public boolean queueIdle() {
Looper l = Looper.myLooper();
if (l != null && shouldQuitLooper())
l.quit();
return true;
}
});
}
示例6: init
import android.os.Looper; //导入方法依赖的package包/类
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
injectMobileEngageConfig();
IamWebViewProvider.webView = null;
provider = new IamWebViewProvider();
listener = mock(MessageLoadedListener.class);
handler = new Handler(Looper.getMainLooper());
latch = new CountDownLatch(1);
dummyJsBridge = new IamJsBridge(mock(IamDialog.class), mock(InAppMessageHandlerProvider.class), mock(ButtonClickedRepository.class), "123", mock(Handler.class));
}
示例7: refreshCurrentAccessToken
import android.os.Looper; //导入方法依赖的package包/类
void refreshCurrentAccessToken() {
if (Looper.getMainLooper().equals(Looper.myLooper())) {
refreshCurrentAccessTokenImpl();
} else {
Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
refreshCurrentAccessTokenImpl();
}
});
}
}
示例8: onRefresh
import android.os.Looper; //导入方法依赖的package包/类
@Override
public void onRefresh() {
if (CellTracker.OCID_API_KEY != null && !CellTracker.OCID_API_KEY.equals("NA")) {
Request request = createOpenCellIdApiCall();
okHttpClient.newCall(request).enqueue(getOpenCellIdResponseCallback());
} else {
Handler refresh = new Handler(Looper.getMainLooper());
refresh.post(new Runnable() {
public void run() {
Helpers.sendMsg(getActivity(), getString(R.string.no_opencellid_key_detected));
swipeRefreshLayout.setRefreshing(false);
}
});
}
}
示例9: onCreate
import android.os.Looper; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = findById(this, R.id.toolbar);
setSupportActionBar(toolbar);
// Inject pragmatically
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.container, PlaceholderFragment.getInstance())
.commit();
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
// toolbar.setTitle("Calligraphy Added");
toolbar.setSubtitle("Added subtitle");
}
}, 1000);
handler.postDelayed(new Runnable() {
@Override public void run() {
toolbar.setTitle(null);
toolbar.setSubtitle("Added subtitle");
}
}, 2000);
handler.postDelayed(new Runnable() {
@Override public void run() {
toolbar.setTitle("Calligraphy added back");
toolbar.setSubtitle("Added subtitle");
}
}, 3000);
}
示例10: showMsg
import android.os.Looper; //导入方法依赖的package包/类
private void showMsg(final String msg) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
}
});
Log.e(TAG, msg);
}
示例11: runOnMainThread
import android.os.Looper; //导入方法依赖的package包/类
public static void runOnMainThread(Runnable r) {
if (Looper.myLooper() == Looper.getMainLooper()) {
r.run();
}
else {
scheduleOnMainThread(r);
}
}
示例12: OcrDetectorProcessor
import android.os.Looper; //导入方法依赖的package包/类
public OcrDetectorProcessor(GraphicOverlay<GraphicOverlay.Graphic> ocrGraphicOverlay,
Container maskViewContainer,
PreferenceManager preferenceManager,
SearchResultHandler searchResultHandler,
TextClassifierProvider textClassifierProvider) {
mOcrGraphicOverlay = ocrGraphicOverlay;
mMaskViewContainer = maskViewContainer;
mPreferenceManager = preferenceManager;
mSearchResultHandler = searchResultHandler;
mPinBitmap = BitmapFactory.decodeResource(mOcrGraphicOverlay.getResources(), R.drawable.pin);
mMainHandler = new Handler(Looper.getMainLooper());
mCurrentStatus = null;
mTextClassifierProvider = textClassifierProvider;
sendOnStatusChanged(Status.OFF);
}
示例13: ThreadHandler
import android.os.Looper; //导入方法依赖的package包/类
private ThreadHandler() {
super(Looper.getMainLooper());
sparseArray = new SparseArray<>();
}
示例14: isOnMainThread
import android.os.Looper; //导入方法依赖的package包/类
/**
* @return {@code true} if called on the main thread, {@code false} otherwise.
*/
private static boolean isOnMainThread() {
return Looper.myLooper() == Looper.getMainLooper();
}
示例15: checkMainThread
import android.os.Looper; //导入方法依赖的package包/类
private boolean checkMainThread() {
return Looper.myLooper() == Looper.getMainLooper();
}