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

The following examples show how to use android.view.View#post() . 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: MyTargetNativeAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 6 votes vote down vote up
@Override
public void trackViews(final View containerView, final Map<String, View> clickables,
    Map<String, View> nonclickables) {
  final ArrayList<View> clickableViews = new ArrayList<>(clickables.values());
  containerView.post(new Runnable() {
    @Override
    public void run() {
      int mediaPosition = findMediaAdViewPosition(clickableViews, mediaAdView);
      if (mediaPosition >= 0) {
        clickableViews.remove(mediaPosition);
        clickableViews.add(mediaAdView);
      }
      nativeAd.registerView(containerView, clickableViews);
    }
  });
}
 
Example 2
Source File: ViewHelper.java    From DMusic with Apache License 2.0 6 votes vote down vote up
/**
 * 扩展点击区域的范围
 *
 * @param view       需要扩展的元素,此元素必需要有父级元素
 * @param expendSize 需要扩展的尺寸(以sp为单位的)
 */
public static void expendTouchArea(final View view, final int expendSize) {
    if (view != null) {
        final View parentView = (View) view.getParent();

        parentView.post(new Runnable() {
            @Override
            public void run() {
                Rect rect = new Rect();
                view.getHitRect(rect); //如果太早执行本函数,会获取rect失败,因为此时UI界面尚未开始绘制,无法获得正确的坐标
                rect.left -= expendSize;
                rect.top -= expendSize;
                rect.right += expendSize;
                rect.bottom += expendSize;
                parentView.setTouchDelegate(new TouchDelegate(rect, view));
            }
        });
    }
}
 
Example 3
Source File: JanitorLoginFragment.java    From United4 with GNU General Public License v3.0 6 votes vote down vote up
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View res = inflater.inflate(R.layout.janitor_login, container, false);
    res.post(new Runnable() {
        @Override
        public void run() {
            EditText username = res.findViewById(R.id.username);
            EditText password = res.findViewById(R.id.password);
            username.setText(P.get("username"));
            password.setText(P.get("password"));
            res.findViewById(R.id.button).setOnClickListener(new LoginButtonClickListener());
            updateLoggedInText();
            Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
            addOptions(toolbar);
        }
    });
    return res;
}
 
Example 4
Source File: AbstractPowerMenu.java    From PowerMenu with Apache License 2.0 6 votes vote down vote up
/**
 * showing the popup to the anchor.
 *
 * @param anchor anchor view.
 */
@MainThread
private void showPopup(final View anchor, final Function0 function) {
  if (!isShowing()) {
    this.isShowing = true;
    anchor.post(
        new Runnable() {
          @Override
          public void run() {
            if (showBackground) backgroundWindow.showAtLocation(anchor, Gravity.CENTER, 0, 0);
            doMenuEffect();
            function.invoke();
          }
        });
  } else if (this.dismissIfShowAgain) {
    dismiss();
  }
}
 
Example 5
Source File: FirstPageFragment.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void updateText(final View localView, final TextView tv, final String s) {
    Log.d("DrawStats", "updateText: " + s);
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {

            //Adrian: after screen rotation it might take some time to attach the view to the window
            //Wait up to 3 seconds for this to happen.
            int i = 0;
            while (localView.getHandler() == null && i < 10) {
                i++;
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                }

            }

            if (localView.getHandler() == null) {
                Log.d("DrawStats", "no Handler found - stopping to update view");
                return;
            }


            boolean success = localView.post(new Runnable() {
                @Override
                public void run() {
                    tv.setText(s);
                    Log.d("DrawStats", "setText actually called: " + s);

                }
            });
            Log.d("DrawStats", "updateText: " + s + " success: " + success);
        }
    });
    thread.start();

}
 
Example 6
Source File: ViewPropertyAnimatorCompat.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private void postStartMessage(ViewPropertyAnimatorCompat vpa, View view) {
    Runnable starter = null;
    if (mStarterMap != null) {
        starter = mStarterMap.get(view);
    }
    if (starter == null) {
        starter = new Starter(vpa, view);
        if (mStarterMap == null) {
            mStarterMap = new WeakHashMap<View, Runnable>();
        }
        mStarterMap.put(view, starter);
    }
    view.removeCallbacks(starter);
    view.post(starter);
}
 
Example 7
Source File: LogicCalculatorActivity.java    From ncalc with GNU General Public License v3.0 5 votes vote down vote up
private void updateUI() {
    setSelectionButton(mMathEvaluator.getBaseEvaluator().getBase());
    for (int id : mBaseManager.getViewIds()) {
        final View view = findViewById(id);
        if (view != null) {
            final boolean isDisable = mBaseManager.isViewDisabled(id);
            view.post(new Runnable() {
                @Override
                public void run() {
                    view.setEnabled(!isDisable);
                }
            });
        }
    }
}
 
Example 8
Source File: FullScreenActivity.java    From NotchAdaptedTest with Apache License 2.0 5 votes vote down vote up
/**
 * 获得刘海区域信息
 */
@TargetApi(28)
public void getNotchParams() {
    final View decorView = getWindow().getDecorView();
    if (decorView != null) {
        decorView.post(new Runnable() {
            @Override
            public void run() {
                WindowInsets windowInsets = decorView.getRootWindowInsets();
                if (windowInsets != null) {
                    // 当全屏顶部显示黑边时,getDisplayCutout()返回为null
                    DisplayCutout displayCutout = windowInsets.getDisplayCutout();
                    Log.e("TAG", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
                    Log.e("TAG", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
                    Log.e("TAG", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
                    Log.e("TAG", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());
                    // 获得刘海区域
                    List<Rect> rects = displayCutout.getBoundingRects();
                    if (rects == null || rects.size() == 0) {
                        Log.e("TAG", "不是刘海屏");
                    } else {
                        Log.e("TAG", "刘海屏数量:" + rects.size());
                        for (Rect rect : rects) {
                            Log.e("TAG", "刘海屏区域:" + rect);
                        }
                    }
                }
            }
        });
    }
}
 
Example 9
Source File: ViewPropertyAnimatorPreHC.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function, called by animateProperty() and animatePropertyBy(), which handles the
 * details of adding a pending animation and posting the request to start the animation.
 *
 * @param constantName The specifier for the property being animated
 * @param startValue The starting value of the property
 * @param byValue The amount by which the property will change
 */
private void animatePropertyBy(int constantName, float startValue, float byValue) {
    // First, cancel any existing animations on this property
    if (mAnimatorMap.size() > 0) {
        Animator animatorToCancel = null;
        Set<Animator> animatorSet = mAnimatorMap.keySet();
        for (Animator runningAnim : animatorSet) {
            PropertyBundle bundle = mAnimatorMap.get(runningAnim);
            if (bundle.cancel(constantName)) {
                // property was canceled - cancel the animation if it's now empty
                // Note that it's safe to break out here because every new animation
                // on a property will cancel a previous animation on that property, so
                // there can only ever be one such animation running.
                if (bundle.mPropertyMask == NONE) {
                    // the animation is no longer changing anything - cancel it
                    animatorToCancel = runningAnim;
                    break;
                }
            }
        }
        if (animatorToCancel != null) {
            animatorToCancel.cancel();
        }
    }

    NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue);
    mPendingAnimations.add(nameValuePair);
    View v = mView.get();
    if (v != null) {
        v.removeCallbacks(mAnimationStarter);
        v.post(mAnimationStarter);
    }
}
 
Example 10
Source File: TouchAreaActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.second);
	refreshButton = (ImageButton) findViewById(R.id.refresh);
	View parent = findViewById(R.id.layout);
	parent.post(new Runnable() {
		public void run() {
			// Post in the parent's message queue to make sure the parent
			// lays out its children before we call getHitRect()
			Rect delegateArea = new Rect();
			ImageButton delegate = refreshButton;
			delegate.getHitRect(delegateArea);
			delegateArea.top -= 600;
			delegateArea.bottom += 600;
			delegateArea.left -= 600;
			delegateArea.right += 600;
			TouchDelegate expandedArea = new TouchDelegate(delegateArea,
					delegate);
			// give the delegate to an ancestor of the view we're
			// delegating the
			// area to
			if (View.class.isInstance(delegate.getParent())) {
				((View) delegate.getParent())
						.setTouchDelegate(expandedArea);
			}
		};
	});
}
 
Example 11
Source File: MainActivity.java    From zapp with MIT License 5 votes vote down vote up
private void onSearchQueryTextFocusChangeListener(View searchView, boolean hasFocus) {
	if (hasFocus && !searchView.isInTouchMode()) {
		searchView.post(() -> {
			InputMethodManager imm = (InputMethodManager) MainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.showSoftInput(searchView.findFocus(), InputMethodManager.SHOW_FORCED);
		});
	}
}
 
Example 12
Source File: ViewUtils.java    From Android-utils with Apache License 2.0 5 votes vote down vote up
public static void forceGetViewSize(final View view, final onGetSizeListener listener) {
    view.post(new Runnable() {
        @Override
        public void run() {
            if (listener != null) {
                listener.onGetSize(view);
            }
        }
    });
}
 
Example 13
Source File: FirstPageFragment.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
private void updateText(final View localView, final TextView tv, final String s) {
    Log.d("DrawStats", "updateText: " + s);
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {

            //Adrian: after screen rotation it might take some time to attach the view to the window
            //Wait up to 3 seconds for this to happen.
            int i = 0;
            while (localView.getHandler() == null && i < 10) {
                i++;
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                }

            }

            if (localView.getHandler() == null) {
                Log.d("DrawStats", "no Handler found - stopping to update view");
                return;
            }


            boolean success = localView.post(new Runnable() {
                @Override
                public void run() {
                    tv.setText(s);
                    Log.d("DrawStats", "setText actually called: " + s);

                }
            });
            Log.d("DrawStats", "updateText: " + s + " success: " + success);
        }
    });
    thread.start();

}
 
Example 14
Source File: NewPropertyFragment.java    From United4 with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    final View res = inflater.inflate(R.layout.property_editor, container, false);
    final View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            scrapeKey();
            Bundle args = new Bundle();
            args.putString("key", key);
            ((HiddenSettingsActivity) getActivity()).replace(HiddenSettingsActivity.FragmentType.PROPERTY_EDITOR, args);
        }
    };
    res.post(new Runnable() {
        @Override
        public void run() {
            ((TextView) res.findViewById(R.id.textView3)).setText("Create Property");
            ((TextView) res.findViewById(R.id.key_text)).setText(key);
            ((TextView) res.findViewById(R.id.key_text)).setInputType(InputType.TYPE_CLASS_TEXT);
            ((TextView) res.findViewById(R.id.value_text)).setInputType(InputType.TYPE_NULL);
            res.findViewById(R.id.value_text).setVisibility(View.GONE);
            res.findViewById(R.id.textView2).setVisibility(View.GONE);
            res.findViewById(R.id.save).setOnClickListener(listener);
            ((TextView) res.findViewById(R.id.save)).setText("Create");
            res.findViewById(R.id.save_back).setVisibility(View.INVISIBLE);
        }
    });
    return res;
}
 
Example 15
Source File: UDHorizontalScrollView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public UDView scrollTo(final int x, final int y) {
    final View view = getView();
    if (view != null) {
        view.post(new Runnable() {
            @Override
            public void run() {
                view.scrollTo(x, y);
            }
        });
    }
    return this;
}
 
Example 16
Source File: PhotoViewAttacher.java    From LLApp with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean onTouch(View v, MotionEvent ev) {
	boolean handled = false;

	if (mZoomEnabled) {
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			// First, disable the Parent from intercepting the touch
			// event
			v.getParent().requestDisallowInterceptTouchEvent(true);

			// If we're flinging, and the user presses down, cancel
			// fling
			cancelFling();
			break;

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			// If the user has zoomed less than min scale, zoom back
			// to min scale
			if (getScale() < mMinScale) {
				RectF rect = getDisplayRect();
				if (null != rect) {
					v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
					handled = true;
				}
			}
			break;
		}

		// Check to see if the user double tapped
		if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
			handled = true;
		}

		// Finally, try the Scale/Drag detector
		if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
			handled = true;
		}
	}

	return handled;
}
 
Example 17
Source File: PhotoViewAttacher.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
            case ACTION_DOWN:
                // First, disable the Parent from intercepting the touch
                // event
                if (null != parent)
                    parent.requestDisallowInterceptTouchEvent(true);
                else
                    Log.i(LOG_TAG, "onTouch getParent() returned null");

                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;

            case ACTION_CANCEL:
            case ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (null != rect) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector
                && mScaleDragDetector.onTouchEvent(ev)) {
            handled = true;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }
    }

    return handled;
}
 
Example 18
Source File: PhotoViewAttacher.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
            case ACTION_DOWN:
                // First, disable the Parent from intercepting the touch
                // event
                if (null != parent)
                    parent.requestDisallowInterceptTouchEvent(true);
                else
                    Log.i(LOG_TAG, "onTouch getParent() returned null");

                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;

            case ACTION_CANCEL:
            case ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (null != rect) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector
                && mScaleDragDetector.onTouchEvent(ev)) {
            handled = true;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }
    }

    return handled;
}
 
Example 19
Source File: MediaFullscreenAnimationUtils.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void animateForward(final View transitionView, float bitmapWidth, float bitmapHeight,
                                  int transitionLeft, int transitionTop,
                                  int transitionWidth, int transitionHeight, final Animator.AnimatorListener listener) {
    transitionView.clearAnimation();

    float screenWidth = Screen.getWidth();
    float screenHeight = Screen.getHeight() + (Build.VERSION.SDK_INT >= 21 ? Screen.getNavbarHeight() : 0);

    if (bitmapHeight > screenHeight || bitmapWidth > screenWidth) {
        if (bitmapWidth / screenWidth < bitmapHeight / screenHeight) {
            bitmapWidth = bitmapWidth * (screenHeight / bitmapHeight);
            bitmapHeight = screenHeight;
        } else {
            bitmapHeight = bitmapHeight * (screenWidth / bitmapWidth);
            bitmapWidth = screenWidth;
        }
    }

    float startScaleWidth = (float) transitionWidth / bitmapWidth;
    float startScaleHeight = (float) transitionHeight / bitmapHeight;
    /*transitionView.setLeft((int) (transitionLeft + (bitmapWidth * (startScaleWidth - 1) / 2)));
    transitionView.setTop((int) (transitionTop + (bitmapHeight * (startScaleHeight - 1) / 2)));
    transitionView.setScaleX(startScaleWidth);
    transitionView.setScaleY(startScaleHeight);*/
    transitionView.animate().setInterpolator(new MaterialInterpolator())
            .setDuration(0)
            .setStartDelay(0)
            .alpha(1)
            .x(transitionLeft + (bitmapWidth * (startScaleWidth - 1) / 2))
            .y(transitionTop + (bitmapHeight * (startScaleHeight - 1) / 2))
            .scaleX(startScaleWidth)
            .scaleY(startScaleHeight)
            .setListener(null)
            .start();

    float endScale = 1;
    // float endScaleHeight = 1;
    float xPadding = 0;
    float yPadding = 0;
    if (bitmapWidth / screenWidth > bitmapHeight / screenHeight) {
        endScale = screenWidth / bitmapWidth;
        xPadding = (bitmapWidth * (endScale - 1) / 2);
        yPadding = screenHeight / 2 - (bitmapHeight / 2);
    } else {
        endScale = screenHeight / bitmapHeight;
        xPadding = screenWidth / 2 - (bitmapWidth / 2);
        yPadding = (bitmapHeight * (endScale - 1)) / 2;
    }
    final float finalXPadding = xPadding;
    final float finalEndScale = endScale;
    final float finalYPadding = yPadding;
    transitionView.post(new Runnable() {
        @Override
        public void run() {
            transitionView.animate()
                    .setInterpolator(new MaterialInterpolator())
                    .setStartDelay(startDelay)
                    .setDuration(300 * animationMultiplier)
                    .setInterpolator(new MaterialInterpolator())
                    .x(finalXPadding)
                    .y(finalYPadding)
                    .scaleX(finalEndScale)
                    .scaleY(finalEndScale)
                    .setListener(listener)
                    .start();
        }
    });

}
 
Example 20
Source File: PhotoViewAttacher.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
        ViewParent parent = v.getParent();
        switch (ev.getAction()) {
            case ACTION_DOWN:
                // First, disable the Parent from intercepting the touch
                // event
                if (null != parent) {
                    parent.requestDisallowInterceptTouchEvent(true);
                } else {
                    LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
                }

                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;

            case ACTION_CANCEL:
            case ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (null != rect) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                                rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }

        // Try the Scale/Drag detector
        if (null != mScaleDragDetector) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}