下面列出了android.view.View#postDelayed ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@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;
}
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);
}
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);
}
}
}
@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);
}
}
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;
}
/**
* 给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) {
}
}
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);
}
@Override
public void onClick(View view) {
showLoading();
view.postDelayed(new Runnable() {
@Override
public void run() {
hideLoading();
}
}, 4500);
}
private void postOnAnimation(View view, Runnable runnable) {
if (Build.VERSION.SDK_INT >= 16) {
view.postOnAnimation(runnable);
} else {
view.postDelayed(runnable, 16L);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
private void checkForLongClick(View target, int delayOffset) {
if (!target.isLongClickable()) {
return;
}
if (longPress == null) {
longPress = new CheckForLongPress(target);
}
target.postDelayed(longPress, ViewConfiguration.getLongPressTimeout() - delayOffset);
}
public void postOnAnimation(View view, Runnable action) {
view.postDelayed(action, getFrameTime());
}
public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
view.postDelayed(action, getFrameTime() + delayMillis);
}
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);
}
}
static void a(View view, Runnable runnable)
{
view.postDelayed(runnable, 10L);
}