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:com.facebook.GraphObjectPagingLoader.java

private void startLoading(Request request, boolean skipRoundtripIfCached, long afterDelay) {
    this.skipRoundtripIfCached = skipRoundtripIfCached;
    appendResults = false;//w w  w .  jav a2 s . co  m
    nextLink = null;
    currentRequest = request;
    currentRequest.setCallback(new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            requestCompleted(response);
        }
    });

    // We are considered loading even if we have a delay.
    loading = true;

    final RequestBatch batch = putRequestIntoBatch(request, skipRoundtripIfCached);
    Runnable r = new Runnable() {
        @Override
        public void run() {
            Request.executeBatchAsync(batch);
        }
    };
    if (afterDelay == 0) {
        r.run();
    } else {
        Handler handler = new Handler();
        handler.postDelayed(r, afterDelay);
    }
}

From source file:com.freshdigitable.udonroad.ffab.IndicatableFFAB.java

public IndicatableFFAB(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final View v = View.inflate(context, R.layout.view_indicatable_ffab, this);
    indicator = (ActionIndicatorView) v.findViewById(R.id.iffab_indicator);
    ffab = (FlingableFAB) v.findViewById(R.id.iffab_ffab);
    ViewCompat.setElevation(indicator, ffab.getCompatElevation());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IndicatableFFAB, defStyleAttr,
            R.style.Widget_FFAB_IndicatableFFAB);
    try {/* www .j  a  va 2s  .c  o m*/
        final Drawable fabIcon = a.getDrawable(R.styleable.IndicatableFFAB_fabIcon);
        ffab.setImageDrawable(fabIcon);
        final int fabTint = a.getColor(R.styleable.IndicatableFFAB_fabTint, NO_ID);
        if (fabTint != NO_ID) {
            ViewCompat.setBackgroundTintList(ffab, ColorStateList.valueOf(fabTint));
        }
        final int indicatorTint = a.getColor(R.styleable.IndicatableFFAB_indicatorTint, 0);
        indicator.setBackgroundColor(indicatorTint);
        indicatorMargin = a.getDimensionPixelSize(R.styleable.IndicatableFFAB_marginFabToIndicator, 0);
    } finally {
        a.recycle();
    }

    ffab.setOnTouchListener(new OnTouchListener() {
        private MotionEvent old;

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            final int action = motionEvent.getAction();
            if (action == MotionEvent.ACTION_DOWN) {
                old = MotionEvent.obtain(motionEvent);
                onStart();
                return false;
            }
            final Direction direction = Direction.getDirection(old, motionEvent);
            if (action == MotionEvent.ACTION_MOVE) {
                onMoving(direction);
            } else if (action == MotionEvent.ACTION_UP) {
                old.recycle();
                onFling(view.getHandler());
            }
            return false;
        }

        private Direction prevSelected = Direction.UNDEFINED;

        public void onStart() {
            indicator.onActionLeave(prevSelected);
            prevSelected = Direction.UNDEFINED;
            indicator.setVisibility(View.VISIBLE);
        }

        public void onMoving(Direction direction) {
            if (prevSelected == direction) {
                return;
            }
            indicator.onActionLeave(prevSelected);
            if (isDirectionEnabled(direction)) {
                indicator.onActionSelected(direction);
            }
            prevSelected = direction;
        }

        private boolean isDirectionEnabled(Direction direction) {
            for (Direction d : enableDirections) {
                if (d == direction) {
                    return true;
                }
            }
            return false;
        }

        public void onFling(Handler handler) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    indicator.setVisibility(View.INVISIBLE);
                }
            }, 200);
        }
    });

    if (isInEditMode()) {
        indicator.setVisibility(VISIBLE);
    }
}

From source file:com.shubhangrathore.xposed.xhover.MainActivity.java

/**
 * Posts a Test notification to status bar to be displayed through Hover.
 *///from  ww w . j  a  v a 2  s .  c  o m
private void makeStatusBarNotification() {
    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_hover_pressed_notification).setAutoCancel(true)
            .setContentTitle(getString(R.string.notification_xhover))
            .setContentText(getString(R.string.notification_text))
            .setTicker(getString(R.string.notification_text));

    final NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    final int mNotificationDelay = 3000; // 3 seconds
    Handler mHandler = new Handler();
    mHandler.postDelayed(new Runnable() {
        public void run() {
            mNotificationManager.notify(0, mBuilder.build());
        }
    }, mNotificationDelay);
}

From source file:org.exobel.routerkeygen.AutoConnectService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
        stopSelf();/*from   w w  w . j av a 2 s.co m*/
        return START_NOT_STICKY;
    }
    attempts = 0;
    currentNetworkId = -1;
    network = intent.getParcelableExtra(SCAN_RESULT);
    keys = intent.getStringArrayListExtra(KEY_LIST);
    final ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    final NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        if (wifi.disconnect()) {
            // besides disconnecting, we clean any previous configuration
            Wifi.cleanPreviousConfiguration(wifi, network, network.capabilities);
            mNotificationManager.notify(UNIQUE_ID, createProgressBar(getString(R.string.app_name),
                    getString(R.string.not_auto_connect_waiting), 0));
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    tryingConnection();
                }
            }, DISCONNECT_WAITING_TIME);
        } else {
            mNotificationManager.notify(UNIQUE_ID,
                    getSimple(getString(R.string.msg_error), getString(R.string.msg_error_key_testing))
                            .build());
            stopSelf();
            return START_NOT_STICKY;
        }
    } else {
        Wifi.cleanPreviousConfiguration(wifi, network, network.capabilities);
        tryingConnection();
    }
    return START_STICKY;
}

From source file:com.architjn.materialicons.ui.MainActivity.java

private void closeDrawerAfterSmallDelay() {
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override/*www.  j a  va2  s.co m*/
        public void run() {
            drawerLayout.closeDrawer(GravityCompat.START);
            navigationView.getMenu().findItem(R.id.navigation_home).setChecked(true);
        }
    }, 800);
}

From source file:com.bradzzz.dotdashdot.mytv_stream.activity.TvShowsActivity.java

/**
 * Initialize DraggableView.// w  ww .  jav a2  s  .c o  m
 */
private void initializeDraggableView() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            draggableView.setVisibility(View.GONE);
            draggableView.closeToRight();
        }
    }, DELAY_MILLIS);
}

From source file:it.flaviomascetti.posture.AccuracyTestFragment.java

@Override
public void onStart() {
    super.onStart();

    button = (Button) getActivity().findViewById(R.id.button_accuracy_test);

    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Showing the start snackbar
            Snackbar.make(getActivity().findViewById(R.id.fragment_accuracy_test), R.string.snack_begin_test,
                    Snackbar.LENGTH_LONG).show();

            testInProgress = false;/*from w w  w . j a v  a  2  s.  c  om*/

            // Delayed start of function testStart
            Handler handler = new Handler();
            handler.postDelayed(beginTest, delayTestStart);

            // Make the Begin Button unclickable
            button.setEnabled(false);
        }
    });

    // set reset button onClick
    getActivity().findViewById(R.id.button_accuracy_reset).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            getActivity().getSharedPreferences("saved_preferences", Context.MODE_PRIVATE).edit().clear()
                    .apply();
            updateOldResults();
        }
    });

    // set share button onClick
    getActivity().findViewById(R.id.button_accuracy_share).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,
                    String.format(android.os.Build.MODEL + "\n\nx: %f\ny: %f\nz: %f",
                            sp.getFloat("saved_x_values", 10), sp.getFloat("saved_y_values", 10),
                            sp.getFloat("saved_z_values", 10)));
            sendIntent.setType("text/plain");
            startActivity(sendIntent);
        }
    });
}

From source file:com.gudong.appkit.ui.activity.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    Fragment fragment = null;/*from ww  w  .  ja va  2  s.  c  o  m*/
    switch (menuItem.getItemId()) {
    case R.id.nav_recent:
        fragment = AppListFragment.getInstance(0);
        break;
    case R.id.nav_installed:
        fragment = AppListFragment.getInstance(1);
        break;
    case R.id.nav_exported:
        fragment = new AppFileListFragment();
        break;
    case R.id.nav_donate:
        showDonateDialog();
        MobclickAgent.onEvent(this, "menu_donate");
        break;
    case R.id.nav_settings:
        mDrawerLayout.closeDrawers();
        Intent intentSetting = new Intent(MainActivity.this, SimpleContainerActivity.class);
        intentSetting.putExtra(SimpleContainerActivity.KEY_TYPE, SimpleContainerActivity.FragmentType.SETTING);
        startActivity(intentSetting);
        MobclickAgent.onEvent(this, "setting_entry");
        break;
    case R.id.nav_about:
        mDrawerLayout.closeDrawers();
        Intent intentAbout = new Intent(MainActivity.this, SimpleContainerActivity.class);
        intentAbout.putExtra(SimpleContainerActivity.KEY_TYPE, SimpleContainerActivity.FragmentType.ABOUT);
        startActivity(intentAbout);
        MobclickAgent.onEvent(this, "setting_about");
        break;
    case R.id.nav_opinion:
        mDrawerLayout.closeDrawers();
        NavigationManager.gotoSendOpinion(this);
        MobclickAgent.onEvent(this, "send_email");
        break;
    }

    if (fragment != null) {
        currentFragment = fragment;
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        FragmentManager fragmentManager = getSupportFragmentManager();
        final android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction()
                .replace(R.id.fl_container, fragment);
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                transaction.commit();
            }
        }, 350);
    }
}

From source file:com.appnexus.opensdk.mediatednativead.InMobiNativeAdResponse.java

public InMobiNativeAdResponse() {
    runnable = new Runnable() {
        @Override/*from   w ww.j ava2 s  .  co m*/
        public void run() {
            if (coverImage != null) {
                coverImage.recycle();
                ;
                coverImage = null;
            }
            if (icon != null) {
                icon.recycle();
                icon = null;
            }
            nativeAdEventlistener = null;
            expired = true;
            if (imNative != null) {
                InMobiNative.unbind(registeredView);
                imNative = null;
            }
            if (nativeElements != null && !nativeElements.isEmpty()) {
                nativeElements.clear();
            }
            registeredView = null;
            registeredClickables = null;
        }
    };
    Handler handler = new Handler(Looper.getMainLooper());
    handler.postDelayed(runnable, Settings.NATIVE_AD_RESPONSE_EXPIRATION_TIME);

}

From source file:com.ohso.omgubuntu.MainActivity.java

@Override
public void toggleSidebarFragment() {
    sidebarFragmentTransitionComplete = false;
    super.toggleSidebarFragment();
    if (sidebarFragmentLayout == null) {
        sidebarFragmentLayout = (LinearLayout) findViewById(R.id.sidebar_fragment_overlay);
    }/*ww w  .  j a v a2s.  co  m*/

    sidebarFragmentLayoutOffset = sidebarFragmentLayout.getChildAt(0).getWidth();
    if (sidebarFragmentActive)
        sidebarFragmentLayout.setVisibility(View.VISIBLE);
    if (Build.VERSION.SDK_INT >= 11) {
        ObjectAnimator sidebarAnimation = ObjectAnimator.ofFloat(articleFragmentContainer, "translationX",
                sidebarFragmentActive ? sidebarFragmentLayoutOffset : 0);
        sidebarAnimation.setDuration(250);
        sidebarAnimation.setStartDelay(100);
        sidebarAnimation.start();
        Handler handler = new Handler();
        // Need to timeout transitionComplete so that the transition...completes.
        handler.postDelayed(transitionComplete, 350);
    } else {
        LayoutParams relParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);
        relParams.leftMargin = sidebarFragmentActive ? sidebarFragmentLayoutOffset : 0;
        relParams.rightMargin = sidebarFragmentActive ? -sidebarFragmentLayoutOffset : 0;
        articleFragmentContainer.setLayoutParams(relParams);
        sidebarFragmentTransitionComplete = true;
        if (!sidebarFragmentActive)
            sidebarFragmentLayout.setVisibility(View.INVISIBLE);
    }
}