Example usage for android.os Looper getMainLooper

List of usage examples for android.os Looper getMainLooper

Introduction

In this page you can find the example usage for android.os Looper getMainLooper.

Prototype

public static Looper getMainLooper() 

Source Link

Document

Returns the application's main looper, which lives in the main thread of the application.

Usage

From source file:com.secupwn.aimsicd.ui.fragments.DeviceFragment.java

@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 {//from w  w  w  . j  ava 2s  .  c o  m
        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);
            }
        });
    }
}

From source file:com.appnexus.opensdk.ANNativeAdResponse.java

@Override
public void destroy() {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.removeCallbacks(expireRunnable);
    handler.post(expireRunnable);//from   w  w  w  . ja  va2  s.  c om
}

From source file:ca.ualberta.cmput301w14t08.geochan.managers.ThreadManager.java

/**
 * Private constructor due to singleton pattern.
 *//*from w  w  w  .j  a  v a 2 s. com*/
private ThreadManager() {
    commentListCache = new LruCache<String, CommentList>(MAXIMUM_CACHE_SIZE);
    getImageCache = new LruCache<String, Bitmap>(MAXIMUM_CACHE_SIZE);
    getPOICache = new LruCache<String, String>(MAXIMUM_CACHE_SIZE);

    getCommentListRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getCommentsRunnableQueue = new LinkedBlockingQueue<Runnable>();
    postImageRunnableQueue = new LinkedBlockingQueue<Runnable>();
    postRunnableQueue = new LinkedBlockingQueue<Runnable>();
    updateRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getImageRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getThreadCommentsRunnableQueue = new LinkedBlockingQueue<Runnable>();
    getPOIRunnableQueue = new LinkedBlockingQueue<Runnable>();

    getCommentsTaskQueue = new LinkedBlockingQueue<GetCommentsTask>();
    postTaskQueue = new LinkedBlockingQueue<PostTask>();
    getImageTaskQueue = new LinkedBlockingQueue<GetImageTask>();
    getThreadCommentsTaskQueue = new LinkedBlockingQueue<GetThreadCommentsTask>();
    getPOITaskQueue = new LinkedBlockingQueue<GetPOITask>();

    getCommentListPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getCommentListRunnableQueue);
    getCommentsPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getCommentsRunnableQueue);
    postImagePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, postImageRunnableQueue);
    postPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
            postRunnableQueue);
    updatePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, updateRunnableQueue);
    getImagePool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getImageRunnableQueue);
    getThreadCommentsPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getThreadCommentsRunnableQueue);
    getPOIPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT, getPOIRunnableQueue);

    handler = new Handler(Looper.getMainLooper()) {

        @Override
        public void handleMessage(Message inputMessage) {
            switch (inputMessage.what) {
            case POST_TASK_COMPLETE:
                PostTask postTaskComplete = (PostTask) inputMessage.obj;
                if (postTaskComplete.getDialog() != null) {
                    postTaskComplete.getDialog().dismiss();
                }
                ThreadComment threadComment = postTaskComplete.getThreadComment();
                if (threadComment != null) {
                    if (!postTaskComplete.isEdit()) {
                        // Update the model and sort accordingly
                        ThreadList.addThread(threadComment);
                        SortUtil.sortThreads(PreferencesManager.getInstance().getThreadSort(),
                                ThreadList.getThreads());
                    }
                    FragmentActivity activity = (FragmentActivity) context;
                    ThreadListFragment fragment = (ThreadListFragment) activity.getSupportFragmentManager()
                            .findFragmentByTag("threadListFrag");
                    if (fragment != null) {
                        fragment.finishReload();
                    }
                }
                break;

            case GET_THREADS_COMPLETE:
                GetThreadCommentsTask threadTask = (GetThreadCommentsTask) inputMessage.obj;
                threadTask.getFragment().finishReload();
                recycleGetThreadCommentsTask(threadTask);
                break;

            case GET_THREADS_FAILED:
                GetThreadCommentsTask threadTaskFail = (GetThreadCommentsTask) inputMessage.obj;
                threadTaskFail.getFragment().finishReload();
                recycleGetThreadCommentsTask(threadTaskFail);
                break;

            case GET_COMMENTS_COMPLETE:
                GetCommentsTask task = (GetCommentsTask) inputMessage.obj;
                task.getFragment().finishReload();
                recycleCommentsTask(task);
                break;

            case GET_COMMENTS_FAILED:
                GetCommentsTask taskFail = (GetCommentsTask) inputMessage.obj;
                taskFail.getFragment().finishReload();
                recycleCommentsTask(taskFail);
                break;

            case GET_COMMENT_LIST_RUNNING:
                break;

            case GET_COMMENT_LIST_FAILED:
                GetCommentsTask taskListFail = (GetCommentsTask) inputMessage.obj;
                taskListFail.getFragment().finishReload();
                recycleCommentsTask(taskListFail);
                break;

            case GET_IMAGE_RUNNING:
                GetImageTask imageTask = (GetImageTask) inputMessage.obj;
                if (imageTask.getDialog() != null) {
                    imageTask.getDialog().show();
                }
                break;

            case GET_IMAGE_FAILED:
                GetImageTask imageTaskFail = (GetImageTask) inputMessage.obj;
                if (imageTaskFail.getDialog() != null) {
                    imageTaskFail.getDialog().dismiss();
                }
                recycleGetImageTask(imageTaskFail);
                break;

            case GET_IMAGE_COMPLETE:
                GetImageTask imageTaskComplete = (GetImageTask) inputMessage.obj;
                if (imageTaskComplete.getDialog() != null) {
                    imageTaskComplete.getDialog().dismiss();
                }
                Bitmap bitmap = imageTaskComplete.getImageCache();
                String id = imageTaskComplete.getId();
                ImageView view = imageTaskComplete.getmImageWeakRef().get();
                if (view != null) {
                    view.setImageBitmap(bitmap);
                }
                CacheManager.getInstance().serializeImage(bitmap, id);
                recycleGetImageTask(imageTaskComplete);
                break;

            case GET_POI_RUNNING:
                GetPOITask poiTaskRunning = (GetPOITask) inputMessage.obj;
                if (poiTaskRunning.getDialog() != null) {
                    poiTaskRunning.getDialog().show();
                }
                break;

            case GET_POI_COMPLETE:
                GetPOITask poiTaskComplete = (GetPOITask) inputMessage.obj;
                if (poiTaskComplete.getDialog() != null) {
                    poiTaskComplete.getDialog().dismiss();
                }
                if (poiTaskComplete.getMarker() != null) {
                    poiTaskComplete.getMarker().setSubDescription((poiTaskComplete.getPOICache()));
                    poiTaskComplete.getMarker().showInfoWindow();

                }
                poiTaskComplete.getLocation().setLocationDescription(poiTaskComplete.getPOICache());
                recycleGetPOITask(poiTaskComplete);
                break;

            case GET_POI_FAILED:
                GetPOITask poiTaskFailed = (GetPOITask) inputMessage.obj;
                if (poiTaskFailed.getDialog() != null) {
                    poiTaskFailed.getDialog().dismiss();
                }
                if (poiTaskFailed.getMarker() != null) {
                    poiTaskFailed.getMarker().setSubDescription(("Unknown Location"));
                    poiTaskFailed.getMarker().showInfoWindow();
                }
                poiTaskFailed.getLocation().setLocationDescription("Unknown Location");
                recycleGetPOITask(poiTaskFailed);
                break;

            case POST_GET_POI_RUNNING:
                PostTask postPoiTaskRunning = (PostTask) inputMessage.obj;
                if (postPoiTaskRunning.getDialog() != null) {
                    postPoiTaskRunning.getDialog().show();
                }
                break;

            case POST_GET_POI_COMPLETE:
                PostTask postPoiTaskComplete = (PostTask) inputMessage.obj;
                if (postPoiTaskComplete.getDialog() != null) {
                    postPoiTaskComplete.getDialog().setMessage("Posting to Server");
                }
                break;

            case POST_GET_POI_FAILED:
                PostTask postPoiTaskFailed = (PostTask) inputMessage.obj;
                if (postPoiTaskFailed.getDialog() != null) {
                    postPoiTaskFailed.getDialog().dismiss();
                }
                break;

            case UPDATE_FAILED:
                PostTask postTaskUpdateFailed = (PostTask) inputMessage.obj;
                if (postTaskUpdateFailed.getDialog() != null) {
                    postTaskUpdateFailed.getDialog().dismiss();
                }
                break;

            case POST_FAILED:
                PostTask postTaskFailed = (PostTask) inputMessage.obj;
                if (postTaskFailed.getDialog() != null) {
                    postTaskFailed.getDialog().dismiss();
                }
                break;

            case POST_RUNNING:
                PostTask postTaskRun = (PostTask) inputMessage.obj;
                if (postTaskRun.getDialog() != null && !postTaskRun.getDialog().isShowing()) {
                    postTaskRun.getDialog().show();
                }
                break;

            case POST_IMAGE_FAILED:
                PostTask postTaskImageFailed = (PostTask) inputMessage.obj;
                if (postTaskImageFailed.getDialog() != null) {
                    postTaskImageFailed.getDialog().dismiss();
                }
                break;

            default:
                super.handleMessage(inputMessage);
                break;
            }
        }
    };
}

From source file:pl.openrnd.connection.rest.ConnectionHandler.java

private void notifyTakingTooLong(final Request request) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override/*w  w  w.  j  a va  2s. c o m*/
        public void run() {
            if (mOnRequestConnectionListener != null) {
                mOnRequestConnectionListener.onRequestTakingTooLong(request);
            }
        }
    });
}

From source file:com.dspot.declex.actions.NotificationActionHolder.java

/**
 * Add a large icon to the notification content view.
 *
 * In the platform template, this image will be shown on the left of the notification view
 * in place of the {@link #smallIcon(Icon) small icon} (which will be placed in a small
 * badge atop the large icon).//from  www  .  j  av  a  2 s  .co m
 */
public NotificationActionHolder largeIcon(@FormattedExpression String icon) {
    if (icon == null || icon.isEmpty())
        return this;

    if (Looper.myLooper() == Looper.getMainLooper()) {
        //Call should not be in main thread
        pendingLargeIconLoad = icon;
        return this;
    }

    try {
        Bitmap bitmap = Picasso.with(context).load(icon).get();
        builder.setLargeIcon(bitmap);
    } catch (IOException ignored) {
    }

    return this;
}

From source file:com.secupwn.aimsicd.ui.fragments.DeviceFragment.java

@NonNull
private Callback getOpenCellIdResponseCallback() {
    return new Callback() {
        @Override//  www  .ja  va  2 s .  c o m
        public void onFailure(Request request, IOException e) {
            Handler refresh = new Handler(Looper.getMainLooper());
            refresh.post(new Runnable() {
                public void run() {
                    refreshFailed();
                }
            });
        }

        @Override
        public void onResponse(final Response response) throws IOException {
            Handler refresh = new Handler(Looper.getMainLooper());
            refresh.post(new Runnable() {
                public void run() {
                    Cell cell = responseToCell(response);
                    processFinish(cell);
                }
            });
        }
    };
}

From source file:com.chen.mail.browse.ConversationCursor.java

public ConversationCursor(Activity activity, Uri uri, boolean initialConversationLimit, String name) {
    mInitialConversationLimit = initialConversationLimit;
    mResolver = activity.getApplicationContext().getContentResolver();
    qUri = uri;//from  w  w  w.j  a va 2  s .  c om
    mName = name;
    qProjection = UIProvider.CONVERSATION_PROJECTION;
    mCursorObserver = new CursorObserver(new Handler(Looper.getMainLooper()));
}

From source file:com.sveder.cardboardpassthrough.MainActivity.java

/**
 * Sets the view to our CardboardView and initializes the transformation matrices we will use
 * to render our scene.//from   w  w  w . j a v a 2  s . com
 * @param savedInstanceState
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);

    setContentView(R.layout.common_ui);
    cardboardView = (CardboardView) findViewById(R.id.cardboard_view);
    cardboardView.setRenderer(this);
    setCardboardView(cardboardView);

    //        mModelCube = new float[16];
    mCamera = new float[16];
    mView = new float[16];
    resultadoTV = (TextView) findViewById(R.id.TVresult);
    //        mModelViewProjection = new float[16];
    //        mModelView = new float[16];
    //        mModelFloor = new float[16];
    //        mHeadView = new float[16];
    //        mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    //
    //
    mOverlayView = (CardboardOverlayView) findViewById(R.id.overlay);
    mOverlayView.show3DToast("Hola, bienvenido a New Hearing :D");

    voiceRecognizer = new listener();
    handler = new Handler(Looper.getMainLooper());

    callMessageTask();

    // Funciona
    //startRecognitionActivity();
    // Funciona
}

From source file:cn.com.hgh.view.SlideSwitch.java

/**
 * draw again/*from ww  w  .j  a  v a2  s .com*/
 */
private void invalidateView() {
    if (Looper.getMainLooper() == Looper.myLooper()) {
        invalidate();
    } else {
        postInvalidate();
    }
}

From source file:com.android.contacts.ContactSaveService.java

public ContactSaveService() {
    super(TAG);
    setIntentRedelivery(true);
    mMainHandler = new Handler(Looper.getMainLooper());
}