Java Code Examples for android.view.View#postDelayed()

The following examples show how to use android.view.View#postDelayed() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void setUpSongListView() {
    setUpSongListPadding();
    songListView.setScrollViewCallbacks(observableScrollViewCallbacks);
    songListView.addHeaderView(songListHeader);

    songAdapter = new ArtistSongAdapter(this, getArtist().getSongs(), this);
    songListView.setAdapter(songAdapter);

    final View contentView = getWindow().getDecorView().findViewById(android.R.id.content);
    contentView.postDelayed(new Runnable() {
        @Override
        public void run() {
            songListBackground.getLayoutParams().height = contentView.getHeight();
            observableScrollViewCallbacks.onScrollChanged(-(artistImageViewHeight + titleViewHeight), false, false);
        }
    }, 1000);
}
 
Example 2
@Override
public SkinAnimator apply(@NonNull View view, @Nullable final Action action) {
    this.targetView = view;
    preAnimator = ObjectAnimator.ofPropertyValuesHolder(targetView,
            PropertyValuesHolder.ofFloat("scaleX",
                    1, 0.5f, 0.2f, 0.05f, 0.8f, 1),
            PropertyValuesHolder.ofFloat("scaleY",
                    1, 0.5f, 0.2f, 0.05f, 0.8f, 1),
            PropertyValuesHolder.ofFloat("rotationY", 0, 720))
            .setDuration(PRE_DURATION * 3);
    preAnimator.setInterpolator(new LinearInterpolator());

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            if(action != null){
                action.action();
            }
        }
    }, PRE_DURATION);

    preAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    return this;
}
 
Example 3
public static void startExitAnimation(MoveData moveData, TimeInterpolator interpolator, final Runnable endAction) {
    if (Build.VERSION.SDK_INT >= 21) {
        endAction.run();
        return;
    }
    View view = moveData.toView;
    int duration = moveData.duration;
    int leftDelta = moveData.leftDelta;
    int topDelta = moveData.topDelta;
    float widthScale = moveData.widthScale;
    float heightScale = moveData.heightScale;
    view.animate()
            .setDuration(duration)
            .scaleX(widthScale).scaleY(heightScale)
            .setInterpolator(interpolator).
            translationX(leftDelta).translationY(topDelta);
    view.postDelayed(endAction, duration);
}
 
Example 4
Source Project: smartcoins-wallet   File: LockableActivity.java    License: MIT License 6 votes vote down vote up
public void showKeyboard(View view) {
    InputMethodManager imm = (InputMethodManager)
            getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);

    if (imm.isAcceptingText()) {
        Log.d(TAG, "Software Keyboard was shown");
    } else {
        Log.d(TAG, "Software Keyboard was not shown.");
        //Sometimes the android doesn't show the keyboard at start up. Scheduling a new open solved for all tested cases
        if (view.getVisibility() == View.VISIBLE) {
            Log.d(TAG, "View is still visible. Scheduling a new input opening attempt...");
            final View runnableView = view;
            view.postDelayed(new Runnable() {
                public void run() {
                    // do work
                    showKeyboard(runnableView);
                }
            }, 100);
        }
    }
}
 
Example 5
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (Preferences.SHOW_COMPASS_NOTE.get()) {

        final ViewGroup root = (ViewGroup) (view.getRootView());
        final View toast = LayoutInflater.from(getActivity()).inflate(R.layout.compass_toast_menu, root, false);
        root.addView(toast);

        toast.setOnClickListener(v -> root.removeView(toast));
        toast.postDelayed(() -> {
            if (toast.getRootView() == root)
                root.removeView(toast);
        }, 10000);
    }
}
 
Example 6
Source Project: kimai-android   File: ActivityUtils.java    License: MIT License 6 votes vote down vote up
public ActivityUtils setSoftKeyboardVisibile(boolean visible, View... editView) {
    final Activity activity = _activity;
    if (activity != null) {
        final View v = (editView != null && editView.length > 0) ? (editView[0]) : (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null ? activity.getCurrentFocus() : null);
        final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (v != null && imm != null) {
            Runnable r = () -> {
                if (visible) {
                    v.requestFocus();
                    imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);
                } else {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            };
            r.run();
            for (int d : new int[]{100, 350}) {
                v.postDelayed(r, d);
            }
        }
    }
    return this;
}
 
Example 7
/**
 * 给View加上红边~~
 *
 * @param view the view to be bounded
 */
private static void addViewShape(final View view) {
    try {
        GradientDrawable gd = new GradientDrawable();
        gd.setStroke(4, Color.RED);
        final Drawable background = view.getBackground();
        view.setBackgroundDrawable(gd);
        //Then recover the background.
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                view.setBackgroundDrawable(background);
            }
        }, 800);
    } catch (Throwable ignored) {

    }
}
 
Example 8
Source Project: renderthread   File: MainActivity.java    License: MIT License 5 votes vote down vote up
private void startTest(final View button, TestView... testViews) {

        // start animation for 3s
        button.setEnabled(false);
        for (TestView testView : testViews) {
            testView.startAnimation(3000);
        }

        // after 1s -> pause UI thread (for 1s)
        button.postDelayed(
                new Runnable() {
                    @Override
                    public void run() {
                        pauseUiThread(1000);
                    }
                },
                1000);

        // after 3s -> re-enable button
        button.postDelayed(
                new Runnable() {
                    @Override
                    public void run() {
                        button.setEnabled(true);
                    }
                },
                3000);
    }
 
Example 9
Source Project: ParticleView   File: SpinnerActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    showLoading();
    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            hideLoading();
        }
    }, 4500);
}
 
Example 10
Source Project: PhotoDraweeView   File: Attacher.java    License: Apache License 2.0 5 votes vote down vote up
private void postOnAnimation(View view, Runnable runnable) {
    if (Build.VERSION.SDK_INT >= 16) {
        view.postOnAnimation(runnable);
    } else {
        view.postDelayed(runnable, 16L);
    }
}
 
Example 11
public static void postOnAnimation(View view, Runnable runnable) {
	if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
		SDK16.postOnAnimation(view, runnable);
	} else {
		view.postDelayed(runnable, 16);
	}
}
 
Example 12
Source Project: android-project-wo2b   File: Compat.java    License: Apache License 2.0 5 votes vote down vote up
public static void postOnAnimation(View view, Runnable runnable) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        postOnAnimationJellyBean(view, runnable);
    } else {
        view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
    }
}
 
Example 13
Source Project: Album   File: Compat.java    License: Apache License 2.0 5 votes vote down vote up
public static void postOnAnimation(View view, Runnable runnable) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        postOnAnimationJellyBean(view, runnable);
    } else {
        view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
    }
}
 
Example 14
public static void postOnAnimation(View view, Runnable runnable) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        postOnAnimationJellyBean(view, runnable);
    } else {
        view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
    }
}
 
Example 15
public static void postOnAnimation(View view, Runnable runnable) {
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        postOnAnimationJellyBean(view, runnable);
    } else {
        view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
    }
}
 
Example 16
Source Project: RefreashTabView   File: LinkMovement.java    License: Apache License 2.0 5 votes vote down vote up
private void checkForLongClick(View target, int delayOffset) {
    if (!target.isLongClickable()) {
        return;
    }
    if (longPress == null) {
        longPress = new CheckForLongPress(target);
    }
    target.postDelayed(longPress, ViewConfiguration.getLongPressTimeout() - delayOffset);
}
 
Example 17
Source Project: android-recipes-app   File: ViewCompat.java    License: Apache License 2.0 4 votes vote down vote up
public void postOnAnimation(View view, Runnable action) {
    view.postDelayed(action, getFrameTime());
}
 
Example 18
Source Project: ProjectX   File: Compat.java    License: Apache License 2.0 4 votes vote down vote up
public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
    view.postDelayed(action, getFrameTime() + delayMillis);
}
 
Example 19
Source Project: SmartSwipe   File: ShuttersConsumer.java    License: Apache License 2.0 4 votes vote down vote up
protected void refreshBitmap() {
    if (lastRefreshTime == 0) {
        lastRefreshTime = SystemClock.elapsedRealtime();
    }
    View v = mWrapper.getContentView();
    final int leavesCount = this.mLeavesCount;
    int width = (int) (mWidth * 1F / (mHorizontalSwiping ? leavesCount : 1) + 0.5F);
    int height = (int) (mHeight * 1F / (mHorizontalSwiping ? 1 : leavesCount) + 0.5F);
    int lastWidth = mHorizontalSwiping ? (mWidth - width * (leavesCount - 1)) : width;
    int lastHeight = mHorizontalSwiping ? height : (mHeight - height * (leavesCount - 1));
    //TODO reuse bitmap array. Tried to use buffer bitmap array, but a blink bug happens when refreshable enabled
    Bitmap[] array = new Bitmap[leavesCount];
    CountDownLatch latch = new CountDownLatch(leavesCount);
    int scrollX = 0, scrollY = 0;
    for (int i = 0; i < leavesCount; i++) {
        if (mHorizontalSwiping) {
            scrollX = width * i;
        } else {
            scrollY = height * i;
        }
        if (i == leavesCount - 1) {
            if (lastWidth <= 0 || lastHeight <= 0) {
                latch.countDown();
            } else {
                SwipeUtil.runInThreadPool(new ScreenshotCreateRunnable(lastWidth, lastHeight, i, array, latch, v, scrollX, scrollY));
            }
        } else {
            SwipeUtil.runInThreadPool(new ScreenshotCreateRunnable(width, height, i, array, latch, v, scrollX, scrollY));
        }
    }
    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    if (!mSwiping && (mProgress <= 0 || mProgress >= 1)) {
        setRefreshing(false);
    }
    if (!mRefreshing) {
        return;
    }
    boolean hasNull = false;
    for (Bitmap bitmap : array) {
        if (bitmap == null) {
            hasNull = true;
            break;
        }
    }
    if (!hasNull) {
        this.mScreenshots = array;
    }
    v.post(refreshWrapperRunnable);
    if (mRefreshable) {
        long timePass = SystemClock.elapsedRealtime() - lastRefreshTime;
        lastRefreshTime = SystemClock.elapsedRealtime();
        if (timePass < refreshDelay) {
            v.postDelayed(new Runnable() {
                @Override
                public void run() {
                    SwipeUtil.runInThreadPool(refreshBitmapRunnable);
                }
            }, refreshDelay - timePass);
        } else {
            SwipeUtil.runInThreadPool(refreshBitmapRunnable);
        }
    } else {
        setRefreshing(false);
    }
}
 
Example 20
Source Project: MiBandDecompiled   File: a.java    License: Apache License 2.0 4 votes vote down vote up
static void a(View view, Runnable runnable)
{
    view.postDelayed(runnable, 10L);
}