Example usage for android.os Handler post

List of usage examples for android.os Handler post

Introduction

In this page you can find the example usage for android.os Handler post.

Prototype

public final boolean post(Runnable r) 

Source Link

Document

Causes the Runnable r to be added to the message queue.

Usage

From source file:com.mobilesolutionworks.android.http.WorksHttpFutureTask.java

protected Result postResult(Handler handler, final WorksHttpResponse<Result> response) {
    handler.post(new Runnable() {
        @Override/*  w  w w  . j  av a2  s .c  o m*/
        public void run() {
            if (mFuture.isCancelled()) {
                response.errorCode = WorksHttpResponse.ErrorCode.ERR_CANCELLED;
            }

            switch (response.errorCode) {
            case OK: {
                try {
                    if (response.request.returnTransfer) {
                        onLoadFinished(response.request, response.statusCode, (Result) response.text);
                    } else {
                        onLoadFinished(response.request, response.statusCode, (Result) response.data);
                    }
                } catch (Exception e) {
                    onProcessError(response.request, response.exception);
                }
                break;
            }

            case ERR_CANCELLED: {
                onCancelled(response.request);
                break;
            }

            case ERR_EXCEPTION: {
                onProcessError(response.request, response.exception);
                break;
            }

            case ERR_INVALID_HTTP_STATUS: {
                onNetError(response.request, response.statusCode);
                break;
            }
            }
        }
    });

    if (response.request.returnTransfer) {
        return (Result) response.text;
    } else {
        return response.data;
    }

}

From source file:com.frostwire.android.gui.activities.internal.NavigationMenu.java

private void refreshMenuRemoveAdsItem() {
    // only visible for basic or debug build and if ads have not been disabled.
    int visibility = ((Constants.IS_GOOGLE_PLAY_DISTRIBUTION || Constants.IS_BASIC_AND_DEBUG)
            && !Offers.disabledAds()) ? View.VISIBLE : View.GONE;
    Handler handler = new Handler(Looper.getMainLooper());
    // TODO: review why calling this directly was causing ANR
    // there is some lifecycle issue here
    handler.post(() -> menuRemoveAdsItem.setVisibility(visibility));
}

From source file:org.schabi.newpipe.VideoItemListActivity.java

private void postNewErrorToast(Handler h, final int stringResource) {
    h.post(new Runnable() {
        @Override//from  w w  w.  ja v  a2s  .  c om
        public void run() {
            Toast.makeText(VideoItemListActivity.this, getString(stringResource), Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:fr.cph.chicago.fragment.drawer.NavigationDrawerFragment.java

/**
 * Users of this fragment must call this method to set up the navigation drawer interactions.
 * //from   ww  w  .  ja v  a  2 s . co m
 * @param fragmentId
 *            The android:id of this fragment in its activity's layout.
 * @param drawerLayout
 *            The DrawerLayout containing this fragment's UI.
 */
public final void setUp(final int fragmentId, final DrawerLayout drawerLayout) {
    mFragmentContainerView = getActivity().findViewById(fragmentId);
    mDrawerLayout = drawerLayout;

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the navigation drawer and the action bar app icon.
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
            R.string.navigation_drawer_close /* "close drawer" description for accessibility */
    ) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (!isAdded()) {
                return;
            }

            if (mPendingRunnable != null) {
                Handler mHandler = new Handler();
                mHandler.post(mPendingRunnable);
                mPendingRunnable = null;
            }

            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (!isAdded()) {
                return;
            }

            if (!mUserLearnedDrawer) {
                // The user manually opened the drawer; store this flag to prevent auto-showing
                // the navigation drawer automatically in the future.
                mUserLearnedDrawer = true;
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
            }
            getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
        }
    };

    // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
    // per the navigation drawer design guidelines.
    if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
        mDrawerLayout.openDrawer(mFragmentContainerView);
    }

    // Defer code dependent on restoration of previous instance state.
    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:org.dodgybits.shuffle.android.core.listener.CursorLoader.java

private void onViewUpdated(@Observes LocationUpdatedEvent event) {
    Log.d(TAG, "Received view update event " + event);
    mLocation = event.getLocation();//from  w w w. j  a va 2 s  .co m
    mTaskSelector = TaskSelector.fromLocation(mActivity, mLocation);

    // delay call so that when list is reloaded straight away,
    // other location update handlers have all been called
    final Handler handler = new Handler();
    handler.post(new Runnable() {
        @Override
        public void run() {
            startListLoading(mLocation);
            startCountLoading(mLocation);
        }
    });
}

From source file:com.libreteam.taxi.Customer_Boarding.java

public void didGetPosition(final LatLng driver) {
    driverLatLng = driver;//from   w ww.  ja va2 s  .c om
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {

        }
    });
}

From source file:com.jungle.widgets.view.JungleLanternView.java

private void scheduleLanternSwitch() {
    if (mLanternSwitchRunnable != null) {
        final Handler handler = ThreadManager.getInstance().getUIHandler();
        handler.removeCallbacks(mLanternSwitchRunnable);
        handler.post(new Runnable() {
            @Override/*from ww  w .ja  v  a 2 s .c  o  m*/
            public void run() {
                handler.postDelayed(mLanternSwitchRunnable, mSwitchIntervalMs);
            }
        });
    }
}

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 source file:com.licubeclub.zionhs.MealActivity.java

private void loadMealTask() {
    final MealCacheManager manager = new MealCacheManager(MealActivity.this);
    SRL.setRefreshing(false);//w w w . j  a  v  a2  s. c o  m
    SRL.setRefreshing(true);
    if (NetCheck.isNetworkConnected()) {
        final Handler mHandler = new Handler();
        new Thread() {

            public void run() {
                mHandler.post(new Runnable() {

                    public void run() {
                        // SRL.setRefreshing(true);
                    }
                });
                try {
                    LunchArray = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date
                    LunchKcalArray = MealLoadHelper.getKcal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Kcal Value
                    DinnerArray = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date
                    DinnerKcalArray = MealLoadHelper.getKcal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Kcal Value
                } catch (Exception e) {
                }

                mHandler.post(new Runnable() {
                    public void run() {
                        mViewPager.setAdapter(new SamplePagerAdapter());
                        mSlidingTabLayout.setViewPager(mViewPager);
                        manager.updateCache(LunchArray, LunchKcalArray, DinnerArray, DinnerKcalArray);
                        Log.d("MealLoadTadk", "Data Loading Done");
                        if (mShareActionProvider != null) {
                            mShareActionProvider.setShareIntent(createShareIntent(1));
                        } else {
                        }
                        SRL.setRefreshing(false);
                        handler.sendEmptyMessage(0);
                    }
                });

            }
        }.start();

    } else {
        Toast.makeText(MealActivity.this, getResources().getString(R.string.network_connection_warning),
                Toast.LENGTH_LONG).show();
        //Load from Cache
        Log.d("MealLoadTask", "Loading from Cache");
        LunchArray = manager.loadLunchCache();
        LunchKcalArray = manager.loadLunchKcalcache();
        DinnerArray = manager.loadDinnerCache();
        DinnerKcalArray = manager.loadDinnerKcalCache();
        mViewPager.setAdapter(new SamplePagerAdapter());
        mSlidingTabLayout.setViewPager(mViewPager);
        if (mShareActionProvider != null) {
            mShareActionProvider.setShareIntent(createShareIntent(1));
        } else {
        }
        SRL.setRefreshing(false);
    }
}

From source file:com.libreteam.taxi.Customer_Boarding.java

public void didUpdatePosition() {
    if (timer == null)
        timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override//from w  ww .j a  v  a  2  s.  co m
        public void run() {

            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    //                   startTracking(driverLatLng);
                    setUpMapView();
                }
            });
        }
    }, 0, 6000);
}