Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

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

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:SwipeListViewTouchListener.java

protected void handlerPendingDismisses(final int originalHeight) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override//  w w  w . j  av a 2  s  .  co m
        public void run() {
            removePendingDismisses(originalHeight);
        }
    }, animationTime + 100);
}

From source file:com.appstu.sattafestival.swipe_list.SwipeListViewTouchListener.java

public void handlerPendingDismisses(final int originalHeight) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*from   w w w .j  a  v a  2 s. c  om*/
        public void run() {
            removePendingDismisses(originalHeight);
        }
    }, animationTime + 100);
}

From source file:de.quist.app.maps.example.MarkerDemoActivity.java

@Override
public boolean onMarkerClick(final Marker marker) {
    if (marker.equals(mPerth)) {
        // This causes the marker at Perth to bounce into position when it is clicked.
        final Handler handler = new Handler();
        final long start = SystemClock.uptimeMillis();
        final long duration = 1500;

        final Interpolator interpolator = new BounceInterpolator();

        handler.post(new Runnable() {
            @Override//from   w  w w.  ja v a 2s  .co  m
            public void run() {
                long elapsed = SystemClock.uptimeMillis() - start;
                float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
                marker.setAnchor(0.5f, 1.0f + 2 * t);

                if (t > 0.0) {
                    // Post again 16ms later.
                    handler.postDelayed(this, 16);
                }
            }
        });
    } else if (marker.equals(mAdelaide)) {
        // This causes the marker at Adelaide to change color and alpha.
        marker.setIcon(
                BuildConfig.MAP_BINDING.bitmapDescriptorFactory().defaultMarker(mRandom.nextFloat() * 360));
        marker.setAlpha(mRandom.nextFloat());
    }

    mLastSelectedMarker = marker;
    // We return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

From source file:com.shonshampain.streamrecorder.util.StreamProxy.java

public void start() {
    Logger.logEvent("StreamProxy:start()");
    isRunning = true;//from  w ww  .j  ava2s . c  om
    init();
    EventBus.getDefault().register(this);
    thread = new Thread(this);
    thread.start();
    Handler handler = new Handler();
    Runnable postAcceptingConnectionsRunnable = new Runnable() {
        @Override
        public void run() {
            EventBus.getDefault().post(new ProxyAcceptingConnectionsEvent());
            Logger.logEvent("Proxy is accepting connections");
        }
    };
    // This is a bit of a hack.
    // We want to post the event after socket.accept,
    // but after socket.accept, we're in a wait state
    // This is good enough.
    handler.postDelayed(postAcceptingConnectionsRunnable, 1000);
}

From source file:lu.fisch.canze.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // always create an instance

    // needed to get strings from resources in non-Activity classes
    res = getResources();/*from  w  w w  .  j a  v a  2  s. c  o m*/

    // dataLogger = DataLogger.getInstance();
    dataLogger = new DataLogger();

    debug("MainActivity: onCreate");

    instance = this;

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // navigation bar
    AppSectionsPagerAdapter appSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());
    actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    viewPager = (ViewPager) findViewById(R.id.main);
    viewPager.setAdapter(appSectionsPagerAdapter);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            //actionBar.setSelectedNavigationItem(position);
            updateActionBar();
        }
    });
    updateActionBar();

    /*
    for (int i = 0; i < appSectionsPagerAdapter.getCount(); i++) {
    actionBar.addTab(
            actionBar.newTab()
                    .setText(appSectionsPagerAdapter.getPageTitle(i))
                    .setTabListener(MainActivity.this));
    }
    */

    // load the initial "main" fragment
    //loadFragement(new MainFragment());

    setTitle(TAG + " - not connected");
    setBluetoothState(BLUETOOTH_DISCONNECTED);

    // tabs
    //final ActionBar actionBar = getSupportActionBar();
    // Specify that tabs should be displayed in the action bar.

    // open the database
    CanzeDataSource.getInstance(getBaseContext()).open();
    // cleanup
    CanzeDataSource.getInstance().cleanUp();

    // setup cleaning (once every hour)
    Runnable cleanUpRunnable = new Runnable() {
        @Override
        public void run() {
            CanzeDataSource.getInstance().cleanUp();
        }
    };
    Handler handler = new Handler();
    handler.postDelayed(cleanUpRunnable, 60 * 1000);

    // register for bluetooth changes
    IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    this.registerReceiver(broadcastReceiver, intentFilter);

    // configure Bluetooth manager
    BluetoothManager.getInstance().setBluetoothEvent(new BluetoothEvent() {
        @Override
        public void onBeforeConnect() {
            setBluetoothState(BLUETOOTH_SEARCH);
        }

        @Override
        public void onAfterConnect(BluetoothSocket bluetoothSocket) {
            device.init(visible);
            device.registerFilters();

            // set title
            debug("MainActivity: onAfterConnect > set title");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    setTitle(TAG + " - connected to <" + bluetoothDeviceName + "@" + bluetoothDeviceAddress
                            + ">");
                    setBluetoothState(BLUETOOTH_CONNECTED);
                }
            });
        }

        @Override
        public void onBeforeDisconnect(BluetoothSocket bluetoothSocket) {
        }

        @Override
        public void onAfterDisconnect() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    setTitle(TAG + " - disconnected");
                }
            });
        }
    });
    // detect hardware status
    int BT_STATE = BluetoothManager.getInstance().getHardwareState();
    if (BT_STATE == BluetoothManager.STATE_BLUETOOTH_NOT_AVAILABLE)
        toast("Sorry, but your device doesn't seem to have Bluetooth support!");
    else if (BT_STATE == BluetoothManager.STATE_BLUETOOTH_NOT_ACTIVE) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, 1);
    }

    // load settings
    // - includes the reader
    // - includes the decoder
    //loadSettings(); --> done in onResume

    // load fields from static code
    debug("Loaded fields: " + fields.size());

    // load fields
    //final SharedPreferences settings = getSharedPreferences(PREFERENCES_FILE, 0);
    (new Thread(new Runnable() {
        @Override
        public void run() {
            debug("Loading fields last field values from database");
            for (int i = 0; i < fields.size(); i++) {
                Field field = fields.get(i);
                field.setCalculatedValue(CanzeDataSource.getInstance().getLast(field.getSID()));
                //debug("MainActivity: Setting "+field.getSID()+" = "+field.getValue());
                //f.setValue(settings.getFloat(f.getUniqueID(), 0));
            }
            debug("Loading fields last field values from database (done)");
        }
    })).start();
}

From source file:com.appunite.list.FastScroller.java

boolean onTouchEvent(MotionEvent me) {
    if (mState == STATE_NONE) {
        return false;
    }/*from   ww w .j  a v a2s  .  c o m*/

    final int action = me.getAction();

    if (action == MotionEvent.ACTION_DOWN) {
        if (isPointInside(me.getX(), me.getY())) {
            if (!mList.isInScrollingContainerUnhide()) {
                beginDrag();
                return true;
            }
            mInitialTouchY = me.getY();
            startPendingDrag();
        }
    } else if (action == MotionEvent.ACTION_UP) { // don't add ACTION_CANCEL here
        if (mPendingDrag) {
            // Allow a tap to scroll.
            beginDrag();

            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            mThumbY = newThumbY;
            scrollTo((float) mThumbY / (viewHeight - mThumbH));

            cancelPendingDrag();
            // Will hit the STATE_DRAGGING check below
        }
        if (mState == STATE_DRAGGING) {
            if (mList != null) {
                // ViewGroup does the right thing already, but there might
                // be other classes that don't properly reset on touch-up,
                // so do this explicitly just in case.
                mList.requestDisallowInterceptTouchEvent(false);
                mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            }
            setState(STATE_VISIBLE);
            final Handler handler = mHandler;
            handler.removeCallbacks(mScrollFade);
            if (!mAlwaysShow) {
                handler.postDelayed(mScrollFade, 1000);
            }

            mList.invalidate();
            return true;
        }
    } else if (action == MotionEvent.ACTION_MOVE) {
        if (mPendingDrag) {
            final float y = me.getY();
            if (Math.abs(y - mInitialTouchY) > mScaledTouchSlop) {
                setState(STATE_DRAGGING);
                if (mListAdapter == null && mList != null) {
                    getSectionsFromIndexer();
                }
                if (mList != null) {
                    mList.requestDisallowInterceptTouchEvent(true);
                    mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                }

                cancelFling();
                cancelPendingDrag();
                // Will hit the STATE_DRAGGING check below
            }
        }
        if (mState == STATE_DRAGGING) {
            final int viewHeight = mList.getHeight();
            // Jitter
            int newThumbY = (int) me.getY() - mThumbH + 10;
            if (newThumbY < 0) {
                newThumbY = 0;
            } else if (newThumbY + mThumbH > viewHeight) {
                newThumbY = viewHeight - mThumbH;
            }
            if (Math.abs(mThumbY - newThumbY) < 2) {
                return true;
            }
            mThumbY = newThumbY;
            // If the previous scrollTo is still pending
            if (mScrollCompleted) {
                scrollTo((float) mThumbY / (viewHeight - mThumbH));
            }
            return true;
        }
    } else if (action == MotionEvent.ACTION_CANCEL) {
        cancelPendingDrag();
    }
    return false;
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

/**
 * Checks adapters sizes and/*from w  w  w  .ja  v a  2 s . c o  m*/
 * notifies user no items have been saved/added
 */
private void updateListViews() {
    if (mLogSnackAdapter.getCount() > 0)
        mNoSnacks.setVisibility(View.GONE);
    else
        mNoSnacks.setVisibility(View.VISIBLE);
    if (mLogBreakfastAdapter.getCount() > 0)
        mNoBreakfast.setVisibility(View.GONE);
    else
        mNoBreakfast.setVisibility(View.VISIBLE);
    if (mLogLunchAdapter.getCount() > 0)
        mNoLunch.setVisibility(View.GONE);
    else
        mNoLunch.setVisibility(View.VISIBLE);
    if (mLogDinnerAdapter.getCount() > 0)
        mNoDinner.setVisibility(View.GONE);
    else
        mNoDinner.setVisibility(View.VISIBLE);

    /**
     * Setting a post delay due to the progress bars not updating after an item is added through quick add.
     */
    Runnable mMyRunnable = new Runnable() {
        @Override
        public void run() {
            equations();
        }
    };
    Handler myHandler = new Handler();
    myHandler.postDelayed(mMyRunnable, 10);
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void morphToProgress() {
    setClickable(false);//w  w w .  j  a  v a  2  s  .  c o m

    int duration = 0;
    if (!mConfigurationChanged) {
        animateIdleStateButtonAfterClick();
        duration = IDLE_STATE_ANIMATION_DURATION_AFTER_CLICK;
    }

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            setWidth(getWidth());
            setText(mProgressText);

            MorphingAnimation animation = createProgressMorphing(mCornerRadius, getHeight(), getWidth(),
                    getHeight());

            animation.setFromColor(getNormalColor(mIdleColorState));
            animation.setToColor(mColorProgress);

            animation.setFromStrokeColor(
                    idleStateStrokeColor == -1 ? getNormalColor(mIdleColorState) : idleStateStrokeColor);
            animation.setToStrokeColor(mColorIndicatorBackground);

            animation.setListener(getProgressStateListener());
            animation.start();
        }
    }, duration);

}

From source file:com.pc.ui.fortysevendeg.swipelistview.SwipeListViewTouchListener.java

protected void handlerPendingDismisses(final int originalHeight) {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override//from ww w .  ja va  2 s .  co  m
        public void run() {
            removePendingDismisses(originalHeight);
        }
    }, animationTime + 100);
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Attach the navigation change listener
 * so that points of interest get updated
 * as the map's visible area is changed.
 */// ww  w .j a va 2 s.co m
private void setNavigationChangeListener() {
    mNavigationChangedListener = new NavigationChangedListener() {
        // This is a workaround for detecting when a fling
        // motion has completed on the map view. The
        // NavigationChangedListener listens for navigation changes,
        // not whether navigation has completed.  We wait
        // a small interval before checking if
        // map is view still navigating.
        @Override
        public void navigationChanged(final NavigationChangedEvent navigationChangedEvent) {
            if (!mMapView.isNavigating()) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        if (!mMapView.isNavigating()) {
                            onMapViewChange();
                        }
                    }
                }, 50);
            }
        }

    };
    mMapView.addNavigationChangedListener(mNavigationChangedListener);
}