List of usage examples for android.view View post
public boolean post(Runnable action)
Causes the Runnable to be added to the message queue.
From source file:Main.java
/** * Hides the soft keyboard by clearing view's focus. * * @param view The view whose focus needs to be cleared. *///w w w.ja v a2 s . c o m public static void clearViewFocus(@NonNull final View view) { view.post(new Runnable() { @Override public void run() { view.clearFocus(); } }); }
From source file:Main.java
public static void softKeyboardDelayed(final View view) { view.post(new Runnable() { @Override/*from w w w .j a v a2s . c o m*/ public void run() { if (!isHardwareKeyboardAvailable(view.getContext())) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); } } } }); }
From source file:Main.java
/** * Performs a single touch on the center of the supplied view. * This is safe to call from the instrumentation thread and will invoke the touch * asynchronously./* ww w .j av a 2 s . c o m*/ * * @param view The view the coordinates are relative to. */ public static void simulateTouchCenterOfView(final View view) throws Throwable { view.post(new Runnable() { @Override public void run() { long eventTime = SystemClock.uptimeMillis(); float x = (float) (view.getRight() - view.getLeft()) / 2; float y = (float) (view.getBottom() - view.getTop()) / 2; view.onTouchEvent(MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0)); view.onTouchEvent(MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_UP, x, y, 0)); } }); }
From source file:Main.java
/** * @param top/*from w w w.ja va2 s .c om*/ * @param left * @param bottom * @param right * @param delegate */ public static void increaseHitRectBy(final int top, final int left, final int bottom, final int right, final View delegate) { final View parent = (View) delegate.getParent(); if (parent != null && delegate.getContext() != null) { parent.post(new Runnable() { // Post in the parent's message queue to make sure the parent // lays out its children before we call getHitRect() public void run() { final float densityDpi = delegate.getContext().getResources().getDisplayMetrics().densityDpi; final Rect r = new Rect(); delegate.getHitRect(r); r.top -= transformToDensityPixel(top, densityDpi); r.left -= transformToDensityPixel(left, densityDpi); r.bottom += transformToDensityPixel(bottom, densityDpi); r.right += transformToDensityPixel(right, densityDpi); parent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } }
From source file:slib.platform.android.ui.view.UiRefreshView.java
public static void _setRefreshing(final View view, final boolean flag) { if (!(UiThread.isUiThread())) { view.post(new Runnable() { public void run() { _setRefreshing(view, flag); }/*from w w w.ja v a 2 s . c om*/ }); return; } if (view instanceof SwipeRefreshLayout) { SwipeRefreshLayout rv = (SwipeRefreshLayout) view; rv.setRefreshing(flag); } }
From source file:Main.java
/** * Performs a drag between the given coordinates, specified relative to the given view. * This is safe to call from the instrumentation thread and will invoke the drag * asynchronously./* w w w.j a v a 2 s. c om*/ * * @param view The view the coordinates are relative to. * @param fromX The relative x-coordinate of the start point of the drag. * @param toX The relative x-coordinate of the end point of the drag. * @param fromY The relative y-coordinate of the start point of the drag. * @param toY The relative y-coordinate of the end point of the drag. * @param stepCount The total number of motion events that should be generated during the drag. * @param completionLatch The .countDown method is called on this latch once the drag finishes. */ public static void dragCompleteView(final View view, final int fromX, final int toX, final int fromY, final int toY, final int stepCount, final CountDownLatch completionLatch) { view.post(new Runnable() { @Override public void run() { long downTime = dragStart(view, fromX, fromY); dragTo(view, fromX, toX, fromY, toY, stepCount, downTime); dragEnd(view, toX, toY, downTime); if (completionLatch != null) { completionLatch.countDown(); } } }); }
From source file:Main.java
public static void runOnViewThread(View view, Runnable runnable) { if (view.getHandler() == null || view.getHandler().getLooper() == null || view.getHandler().getLooper().getThread() == Thread.currentThread()) { runnable.run();// w w w.j a v a 2s .c o m } else { view.post(runnable); } }
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter("increaseClickingArea") public static void increaseClickingArea(TextView textView, float size) { // fork from http://stackoverflow.com/a/1343796 View parent = (View) textView.getParent(); // post in the parent's message queue to make sure the parent // lays out its children before we call View#getHitRect() parent.post(() -> { final int halfSize = (int) (size / 2 + 0.5); Rect rect = new Rect(); textView.getHitRect(rect);/* w ww. j a v a2 s . c o m*/ rect.top -= halfSize; rect.right += halfSize; rect.bottom += halfSize; rect.left -= halfSize; // use TouchDelegate to increase count's clicking area parent.setTouchDelegate(new TouchDelegate(rect, textView)); }); }
From source file:Main.java
public static void startAnimationAfterNextDraw(final Animator animator, final View view) { view.getViewTreeObserver().addOnDrawListener(new ViewTreeObserver.OnDrawListener() { private boolean mStarted = false; public void onDraw() { if (mStarted) return; mStarted = true;/*from ww w.j a va 2 s . c o m*/ // Use this as a signal that the animation was cancelled if (animator.getDuration() == 0) { return; } animator.start(); final ViewTreeObserver.OnDrawListener listener = this; view.post(new Runnable() { public void run() { view.getViewTreeObserver().removeOnDrawListener(listener); } }); } }); }
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarColorizer.java
/** * Use this method to colorize toolbar icons to the desired target color * * @param toolbar toolbar view being colored * @param toolbarIconsColor the target color of toolbar icons *///from w ww .j ava2 s . c o m public static void colorizeToolbar(Toolbar toolbar, final int toolbarIconsColor) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN); for (int i = 0; i < toolbar.getChildCount(); i++) { final View v = toolbar.getChildAt(i); //Step 1 : Changing the color of back button (or open drawer button). if (v instanceof ImageButton) { //Action Bar back button ((ImageButton) v).getDrawable().setColorFilter(colorFilter); } if (v instanceof ActionMenuView) { for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) { //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon. //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu final View innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) { if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) { final int finalK = k; //Important to set the color filter in separate thread, by adding it to the message queue //Won't work otherwise. innerView.post(new Runnable() { @Override public void run() { ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK] .setColorFilter(colorFilter); } }); } } } } } } //Step 3: Changing the color of title and subtitle. toolbar.setTitleTextColor(toolbarIconsColor); toolbar.setSubtitleTextColor(toolbarIconsColor); }