Search in sources :

Example 41 with HandlerThread

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;
}
Also used : HandlerThread(android.os.HandlerThread) Test(org.junit.Test)

Example 42 with HandlerThread

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();
    }
}
Also used : HandlerThread(android.os.HandlerThread) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 43 with HandlerThread

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();
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler) Intent(android.content.Intent) SDCardInfo(com.youku.service.download.SDCardManager.SDCardInfo)

Example 44 with HandlerThread

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));
    }
}
Also used : StrictMode(android.os.StrictMode) HandlerThread(android.os.HandlerThread) Query(com.bumptech.glide.samples.flickr.api.Query) SearchQuery(com.bumptech.glide.samples.flickr.api.SearchQuery) RecentQuery(com.bumptech.glide.samples.flickr.api.RecentQuery) Handler(android.os.Handler) Resources(android.content.res.Resources) ViewPager(android.support.v4.view.ViewPager)

Example 45 with HandlerThread

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;
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler)

Aggregations

HandlerThread (android.os.HandlerThread)313 Handler (android.os.Handler)149 IntentFilter (android.content.IntentFilter)34 Message (android.os.Message)26 PowerManager (android.os.PowerManager)26 Intent (android.content.Intent)25 Context (android.content.Context)22 Test (org.junit.Test)20 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 Looper (android.os.Looper)13 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Uri (android.net.Uri)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Bundle (android.os.Bundle)8