private boolean clickRightClear(TextView tv, MotionEvent event){ Drawable drawableRight = tv.getCompoundDrawables()[2] ; if (drawableRight != null && event.getRawX() >= (tv.getRight() - drawableRight.getBounds().width())) { tv.setText(null); return true; } return false; }
@OnTouch(R.id.txt_new) boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Drawable drawableRight = mTxtNew.getCompoundDrawables()[2]; if (drawableRight != null && event.getRawX() >= (mTxtNew.getRight() - drawableRight.getBounds().width())) { mTxtNew.setVisibility(View.GONE); return true; } } return false; } }
if (x < mCurrText.getLeft() - mTabPadding) { mPager.setCurrentItem(mPager.getCurrentItem() - 1); } else if (x > mCurrText.getRight() + mTabPadding) { mPager.setCurrentItem(mPager.getCurrentItem() + 1);
@Override public void run() { tvLeft = textView.getLeft(); tvTop = textView.getTop(); tvRight = textView.getRight(); tvBottom = textView.getBottom(); first = false; textView.setText(tvLeft + "," + tvTop + "," + tvRight + "," + tvBottom); } });
TextView tv = (TextView)findViewById(R.id.textView1); Rect bounds = new Rect(tv.getLeft(), tv.getTop(), tv.getRight(), tv.getBottom());
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); } }
@Override void updateTextPositions(int position, float positionOffset, boolean force) { final Rect r = mTempRect; int bottom = getHeight(); int left = mCurrText.getLeft() - mTabPadding; int right = mCurrText.getRight() + mTabPadding; int top = bottom - mIndicatorHeight; r.set(left, top, right, bottom); super.updateTextPositions(position, positionOffset, force); mTabAlpha = (int) (Math.abs(positionOffset - 0.5f) * 2 * 0xFF); left = mCurrText.getLeft() - mTabPadding; right = mCurrText.getRight() + mTabPadding; r.union(left, top, right, bottom); invalidate(r); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (isInEditMode() || tabCount == 0) { return; } final int height = getHeight(); // draw indicator line rectPaint.setColor(indicatorColor); // default: line below current tab View currentTab = tabsContainer.getChildAt(currentPosition); float lineLeft = currentTab.getLeft(); float lineRight = currentTab.getRight(); // if there is an offset, start interpolating left and right coordinates between current and next tab if (currentPositionOffset > 0f && currentPosition < tabCount - 1) { TextView nextTab = (TextView) tabsContainer.getChildAt(currentPosition + 1); final float nextTabLeft = nextTab.getLeft(); final float nextTabRight = nextTab.getRight(); lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft); lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight); } if (textLengthVector == null) { canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint); } else { float pointC = (lineRight + lineLeft) / 2 - textLengthVector[currentPosition] / 2; float pointD = (lineRight + lineLeft) / 2 + textLengthVector[currentPosition] / 2; canvas.drawRect(pointC, height - indicatorHeight, pointD, height, rectPaint); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int height = getHeight(); final int bottom = height; final int left = mCurrText.getLeft() - mTabPadding; final int right = mCurrText.getRight() + mTabPadding; final int top = bottom - mIndicatorHeight; mTabPaint.setColor(mTabAlpha << 24 | (mIndicatorColor & 0xFFFFFF)); canvas.drawRect(left, top, right, bottom, mTabPaint); if (mDrawFullUnderline) { mTabPaint.setColor(0xFF << 24 | (mIndicatorColor & 0xFFFFFF)); canvas.drawRect(getPaddingLeft(), height - mFullUnderlineHeight, getWidth() - getPaddingRight(), height, mTabPaint); } }
private void invisible() { int cx = (ivMeinv.getLeft() + ivMeinv.getRight()) / 2; int cy = (ivMeinv.getTop() + ivMeinv.getBottom()) / 2; int initialRadius = ivMeinv.getWidth(); Animator anim = ViewAnimationUtils.createCircularReveal(ivMeinv, cx, cy, initialRadius, 0); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); ivMeinv.setVisibility(View.INVISIBLE); } }); anim.start(); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final int height = getHeight(); final int bottom = height; final int left = mCurrText.getLeft() - mTabPadding; final int right = mCurrText.getRight() + mTabPadding; final int top = bottom - mIndicatorHeight; mTabPaint.setColor(mTabAlpha << 24 | (mIndicatorColor & 0xFFFFFF)); canvas.drawRect(left, top, right, bottom, mTabPaint); if (mDrawFullUnderline) { mTabPaint.setColor(0xFF << 24 | (mIndicatorColor & 0xFFFFFF)); canvas.drawRect(getPaddingLeft(), height - mFullUnderlineHeight, getWidth() - getPaddingRight(), height, mTabPaint); } }
private void visible() { int cx = (ivMeinv.getLeft() + ivMeinv.getRight()) / 2; int cy = (ivMeinv.getTop() + ivMeinv.getBottom()) / 2; int initialRadius = ivMeinv.getWidth() + ivMeinv.getHeight(); Animator anim = ViewAnimationUtils.createCircularReveal(ivMeinv, cx, cy, 0, initialRadius); ivMeinv.setVisibility(View.VISIBLE); anim.start(); }
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) { view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom); view.setRight(view.getLeft() + data.width); view.setBottom(view.getTop() + data.height); view.setTextColor(data.textColor); int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY); view.measure(widthSpec, heightSpec); view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); }
private static void setTextViewData(TextView view, TextResizeData data, float fontSize) { view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); view.setPadding(data.paddingLeft, data.paddingTop, data.paddingRight, data.paddingBottom); view.setRight(view.getLeft() + data.width); view.setBottom(view.getTop() + data.height); view.setTextColor(data.textColor); int widthSpec = View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(view.getHeight(), View.MeasureSpec.EXACTLY); view.measure(widthSpec, heightSpec); view.layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); }
private boolean checkMargin() { if (!rectFAll.contains(localRectF2)) { return false; } for (TextView textView : tvs) { if (!rectFAll.contains(textView.getLeft(), textView.getTop(), textView.getRight(), textView.getBottom())) { return false; } } return true; }
int heightDiff = newHeight - oldHeight; textView.layout(textView.getLeft() - widthDiff / 2, textView.getTop() - heightDiff / 2, textView.getRight() + widthDiff / 2, textView.getBottom() + heightDiff / 2);
space = space / 2; assertThat(textView1.getLeft(), is(padding)); assertThat(flexboxLayout.getRight() - textView3.getRight(), is(padding)); assertTrue(space - 1 <= textView2.getLeft() - textView1.getRight() && textView2.getLeft() - textView1.getRight() <= space + 1); assertTrue(space - 1 <= textView3.getLeft() - textView2.getRight() && textView3.getLeft() - textView2.getRight() <= space + 1);
@Test @FlakyTest(tolerance = TOLERANCE) public void testAlignContent_flexEnd_flexDirection_column() throws Throwable { final FlexboxTestActivity activity = mActivityRule.getActivity(); mActivityRule.runOnUiThread(new Runnable() { @Override public void run() { activity.setContentView(R.layout.activity_align_content_test); FlexboxLayout flexboxLayout = (FlexboxLayout) activity .findViewById(R.id.flexbox_layout); flexboxLayout.setAlignContent(FlexboxLayout.ALIGN_CONTENT_FLEX_END); flexboxLayout.setFlexDirection(FlexboxLayout.FLEX_DIRECTION_COLUMN); } }); FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout); assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_FLEX_END)); assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_COLUMN)); onView(withId(R.id.text3)).check(isRightAlignedWith(withId(R.id.flexbox_layout))); onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout))); onView(withId(R.id.text1)).check(isLeftOf(withId(R.id.text3))); onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout))); onView(withId(R.id.text2)).check(isBelow(withId(R.id.text3))); TextView textView1 = (TextView) activity.findViewById(R.id.text1); TextView textView3 = (TextView) activity.findViewById(R.id.text3); assertThat(textView1.getRight(), is(flexboxLayout.getRight() - textView3.getWidth())); }