本文整理匯總了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();
}