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

The following examples show how to use android.view.View#postDelayed() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ArtistDetailActivity.java    From Orin with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: Hook.java    From fuckView with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 给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 3
Source File: ActivityUtils.java    From kimai-android with 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 4
Source File: MainFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: LockableActivity.java    From smartcoins-wallet with 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 6
Source File: TransitionAnimation.java    From candybar-library with Apache License 2.0 6 votes vote down vote up
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 7
Source File: SkinRotateAnimator3.java    From AndroidSkinAnimator with MIT License 6 votes vote down vote up
@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 8
Source File: SpinnerActivity.java    From ParticleView with 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 9
Source File: Attacher.java    From PhotoDraweeView with 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 10
Source File: MainActivity.java    From renderthread with 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 11
Source File: ViewCompat.java    From Favorite-Android-Client with 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) {
		SDK16.postOnAnimation(view, runnable);
	} else {
		view.postDelayed(runnable, 16);
	}
}
 
Example 12
Source File: Compat.java    From android-project-wo2b with 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 File: Compat.java    From Album with 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
Source File: Compat.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.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 15
Source File: Compat.java    From OmniList with GNU Affero General Public License v3.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 16
Source File: LinkMovement.java    From RefreashTabView with 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 File: Compat.java    From ProjectX with 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 18
Source File: ShuttersConsumer.java    From SmartSwipe with 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 19
Source File: a.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
static void a(View view, Runnable runnable)
{
    view.postDelayed(runnable, 10L);
}
 
Example 20
Source File: ViewCompat.java    From android-recipes-app with Apache License 2.0 4 votes vote down vote up
public void postOnAnimation(View view, Runnable action) {
    view.postDelayed(action, getFrameTime());
}