use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldQuitLooperAndThread.
@Test
public void shouldQuitLooperAndThread() throws Exception {
handlerThread = new HandlerThread("test");
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
handlerThread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
handlerThread.start();
assertTrue(handlerThread.isAlive());
assertTrue(handlerThread.quit());
handlerThread.join();
assertFalse(handlerThread.isAlive());
handlerThread = null;
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldCallOnLooperPrepared.
@Test
public void shouldCallOnLooperPrepared() throws Exception {
final Boolean[] wasCalled = new Boolean[] { false };
final CountDownLatch latch = new CountDownLatch(1);
handlerThread = new HandlerThread("test") {
@Override
protected void onLooperPrepared() {
wasCalled[0] = true;
latch.countDown();
}
};
handlerThread.start();
try {
assertNotNull(handlerThread.getLooper());
latch.await(1, TimeUnit.SECONDS);
assertTrue(wasCalled[0]);
} finally {
handlerThread.quit();
}
}
use of android.os.HandlerThread in project SimplifyReader by chentao0707.
the class FileCreateThread method run.
@Override
public void run() {
for (DownloadInfo info : download_temp_infos) {
if (download.existsDownloadInfo(info.videoid)) {
if (download.isDownloadFinished(info.videoid)) {
// 已下载完成
PlayerUtil.showTips(R.string.download_exist_finished);
} else {
PlayerUtil.showTips(R.string.download_exist_not_finished);
}
continue;
}
long time = System.currentTimeMillis();
info.createTime = time;
// 用时间戳做ID
info.taskId = String.valueOf(time).substring(5);
if (init(info)) {
Logger.d("DownloadFlow", "init() success");
download.addDownloadingInfo(info);
switch(info.format) {
case DownloadInfo.FORMAT_HD2:
break;
case DownloadInfo.FORMAT_MP4:
break;
default:
break;
}
successCount++;
YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_READY));
} else {
Logger.d("DownloadFlow", "init() fail");
failCount++;
YoukuPlayerApplication.context.sendBroadcast(new Intent(IDownload.ACTION_CREATE_DOWNLOAD_ONE_FAILED));
if (info.getExceptionId() == DownloadInfo.EXCEPTION_NO_SPACE) {
// 没有空间,提示切换空间
failCount = download_temp_infos.size() - successCount;
ArrayList<SDCardInfo> card = SDCardManager.getExternalStorageDirectory();
if (card != null && card.size() > 1) {
hasMaryPaths = true;
HandlerThread ht = new HandlerThread("handler_thread1");
ht.start();
new Handler(ht.getLooper()) {
public void handleMessage(Message msg) {
/* YoukuPlayerApplication.context
.startActivity(new Intent(
YoukuPlayerApplication.context,
EmptyActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));*/
Toast.makeText(YoukuPlayerApplication.context, "存储空间不足", Toast.LENGTH_SHORT).show();
}
;
}.sendEmptyMessageDelayed(0, 500L);
}
break;
}
continue;
}
}
for (DownloadInfo info : download_temp_infos) {
tempCreateData.remove(info.videoid);
}
showTips();
over();
HandlerThread ht = new HandlerThread("handler_thread2");
ht.start();
new Handler(ht.getLooper()) {
public void handleMessage(Message msg) {
Logger.d("DownloadFlow", "FileCreateThread: create task to download");
download.startNewTask();
}
;
}.sendEmptyMessageDelayed(0, 1000L);
super.run();
}
use of android.os.HandlerThread in project glide by bumptech.
the class FlickrSearchActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
backgroundThread = new HandlerThread("BackgroundThumbnailHandlerThread");
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
setContentView(R.layout.flickr_search_activity);
searching = findViewById(R.id.searching);
searchLoading = findViewById(R.id.search_loading);
searchTerm = (TextView) findViewById(R.id.search_term);
Resources res = getResources();
ViewPager pager = (ViewPager) findViewById(R.id.view_pager);
pager.setPageMargin(res.getDimensionPixelOffset(R.dimen.page_margin));
pager.setAdapter(new FlickrPagerAdapter(getSupportFragmentManager()));
Api.get(this).registerSearchListener(queryListener);
if (savedInstanceState != null) {
Query savedQuery = savedInstanceState.getParcelable(STATE_QUERY);
if (savedQuery != null) {
executeQuery(savedQuery);
}
} else {
executeQuery(RecentQuery.get());
}
int smallGridSize = res.getDimensionPixelSize(R.dimen.small_photo_side);
int mediumGridSize = res.getDimensionPixelSize(R.dimen.medium_photo_side);
int listHeightSize = res.getDimensionPixelSize(R.dimen.flickr_list_item_height);
int screenWidth = getScreenWidth();
if (savedInstanceState == null) {
// Weight values determined experimentally by measuring the number of incurred GCs while
// scrolling through the various photo grids/lists.
Glide.get(this).preFillBitmapPool(new PreFillType.Builder(smallGridSize).setWeight(1), new PreFillType.Builder(mediumGridSize).setWeight(1), new PreFillType.Builder(screenWidth / 2, listHeightSize).setWeight(6));
}
}
use of android.os.HandlerThread in project PlayerHater by chrisrhoden.
the class SongQueue method getHandler.
private static Handler getHandler() {
if (sHandler == null) {
HandlerThread thread = new HandlerThread("SongQueue");
thread.start();
sHandler = new Handler(thread.getLooper()) {
@Override
public void handleMessage(Message msg) {
SongMessage m = (SongMessage) msg.obj;
switch(msg.what) {
case CURRENT_SONG:
m.queue.sendSongChanged(m.song, m.oldSong);
break;
case NEXT_SONG:
m.queue.sendNextSongChanged(m.song, m.oldSong);
}
}
};
}
return sHandler;
}
Aggregations