List of usage examples for android.view View getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:com.devbrackets.android.recyclerext.decoration.ReorderDecoration.java
/** * Updates the horizontal view offsets if the dragging view has been moved around the <code>view</code>. * This happens when the dragging view starts before the <code>view</code> and has been dragged * after it, or vice versa./*from w ww .j a v a 2s . co m*/ * * @param view The view to compare with the dragging items current and original positions * @param itemPosition The position for the <code>view</code> * @param middle The center of the floating item * @param outRect The {@link Rect} to update the position in */ private void setHorizontalOffsets(View view, int itemPosition, PointF middle, Rect outRect) { if (orientation == LayoutOrientation.VERTICAL) { return; } if (itemPosition > selectedDragItemPosition && view.getLeft() < middle.x) { float amountRight = (middle.x - view.getLeft()) / (float) view.getWidth(); if (amountRight > 1) { amountRight = 1; } outRect.left = -(int) (floatingItemBounds.width() * amountRight); outRect.right = (int) (floatingItemBounds.width() * amountRight); } else if ((itemPosition < selectedDragItemPosition) && (view.getRight() > middle.x)) { float amountLeft = ((float) view.getRight() - middle.x) / (float) view.getWidth(); if (amountLeft > 1) { amountLeft = 1; } outRect.left = (int) (floatingItemBounds.width() * amountLeft); outRect.right = -(int) (floatingItemBounds.width() * amountLeft); } }
From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.RecyclerViewSwipeManager.java
private void handleActionUpOrCancelWhileSwiping(int action) { int result = RESULT_CANCELED; if (action == MotionEvent.ACTION_UP) { final boolean horizontal = mSwipeHorizontal; final View itemView = mSwipingItem.itemView; final int viewSize = (horizontal) ? itemView.getWidth() : itemView.getHeight(); final float distance = (horizontal) ? (mLastTouchX - mInitialTouchX) : (mLastTouchY - mInitialTouchY); final float absDistance = Math.abs(distance); mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); // 1000: pixels per second final float velocity = (horizontal) ? mVelocityTracker.getXVelocity() : mVelocityTracker.getYVelocity(); final float absVelocity = Math.abs(velocity); if ((absDistance > (mTouchSlop * MIN_DISTANCE_TOUCH_SLOP_MUL)) && ((distance * velocity) > 0.0f) && (absVelocity <= mMaxFlingVelocity) && ((absDistance > (viewSize / 2)) || (absVelocity >= mMinFlingVelocity))) { if (horizontal && (distance < 0) && SwipeReactionUtils.canSwipeLeft(mSwipingItemReactionType)) { result = RESULT_SWIPED_LEFT; } else if ((!horizontal) && (distance < 0) && SwipeReactionUtils.canSwipeUp(mSwipingItemReactionType)) { result = RESULT_SWIPED_UP; } else if (horizontal && (distance > 0) && SwipeReactionUtils.canSwipeRight(mSwipingItemReactionType)) { result = RESULT_SWIPED_RIGHT; } else if ((!horizontal) && (distance > 0) && SwipeReactionUtils.canSwipeDown(mSwipingItemReactionType)) { result = RESULT_SWIPED_DOWN; }/*from w ww .j av a 2 s .c o m*/ } } if (LOCAL_LOGD) { Log.d(TAG, "swping finished --- result = " + result); } finishSwiping(result); }
From source file:com.android.ex.photo.PhotoViewPager.java
private void initialize() { // Set the page transformer to perform the transition animation // for each page in the view. setPageTransformer(true, new PageTransformer() { @Override/* w ww .j a va 2s .com*/ public void transformPage(View page, float position) { // The >= 1 is needed so that the page // (page A) that transitions behind the newly visible // page (page B) that comes in from the left does not // get the touch events because it is still on screen // (page A is still technically on screen despite being // invisible). This makes sure that when the transition // has completely finished, we revert it to its default // behavior and move it off of the screen. if (position < 0 || position >= 1.f) { page.setTranslationX(0); page.setAlpha(1.f); page.setScaleX(1); page.setScaleY(1); } else { page.setTranslationX(-position * page.getWidth()); page.setAlpha(Math.max(0, 1.f - position)); final float scale = Math.max(0, 1.f - position * 0.3f); page.setScaleX(scale); page.setScaleY(scale); } } }); }
From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java
private void expand(final View v, Interpolator interpolator, int duration, int targetWidth) { int prevWidth = v.getWidth(); ValueAnimator valueAnimator = ValueAnimator.ofInt(prevWidth, targetWidth); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from www . j a v a 2s .c o m*/ public void onAnimationUpdate(ValueAnimator animation) { v.getLayoutParams().width = (int) animation.getAnimatedValue(); v.requestLayout(); } }); valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.start(); }
From source file:ch.uzh.supersede.feedbacklibrary.AnnotateImageActivity.java
private void removeOutOfBoundsAnnotations() { RelativeLayout relativeLayout = (RelativeLayout) findViewById( R.id.supersede_feedbacklibrary_annotate_image_layout); if (relativeLayout != null) { List<View> toRemove = new ArrayList<>(); int newBitmapWidth = annotateImageView.getBitmapWidth(); int newBitmapHeight = annotateImageView.getBitmapHeight(); float fraction = 0.5f; for (int i = 0; i < relativeLayout.getChildCount(); ++i) { View child = relativeLayout.getChildAt(i); if (child instanceof StickerAnnotationView || child instanceof TextAnnotationView) { // A fraction the sticker should be visible, if not the sticker will be removed float deleteThresholdX = child.getWidth() * fraction; float deleteThresholdY = child.getHeight() * fraction; float x = child.getX(); float y = child.getY(); boolean xOk = true; boolean yOk = true; if (x < 0) { xOk = Math.abs(x) < deleteThresholdX; } else if (x > 0 && !(x < 0)) { xOk = x + deleteThresholdX < newBitmapWidth; }/*ww w . j av a 2s .c om*/ if (y < 0) { yOk = Math.abs(y) < deleteThresholdY; } else if (y > 0 && !(y < 0)) { yOk = y + deleteThresholdY < newBitmapHeight; } if (!(xOk && yOk)) { toRemove.add(child); } } } for (int i = 0; i < toRemove.size(); ++i) { relativeLayout.removeView(toRemove.get(i)); } toRemove.clear(); textAnnotationCounter = 1; for (int i = 0; i < relativeLayout.getChildCount(); ++i) { View child = relativeLayout.getChildAt(i); if (child instanceof TextAnnotationView) { String newAnnotationNumber = Integer.toString(textAnnotationCounter); ((TextAnnotationImageView) child).getAnnotationNumberView().setText(newAnnotationNumber); textAnnotationCounter++; } if (textAnnotationCounter > textAnnotationCounterMaximum) { break; } } } }
From source file:com.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java
private void drawSlideBar(Canvas canvas) { if (mAdapter == null || scrollBar == null) { return;//from w ww. j a va 2s .c om } final int count = mAdapter.getCount(); if (count == 0) { return; } if (getCurrentItem() >= count) { setCurrentItem(count - 1); return; } float offsetX = 0; int offsetY = 0; switch (this.scrollBar.getGravity()) { case CENTENT_BACKGROUND: case CENTENT: offsetY = (getHeight() - scrollBar.getHeight(getHeight())) / 2; break; case TOP: case TOP_FLOAT: offsetY = 0; break; case BOTTOM: case BOTTOM_FLOAT: default: offsetY = getHeight() - scrollBar.getHeight(getHeight()); break; } View currentView = null; if (!inRun.isFinished() && inRun.computeScrollOffset()) { offsetX = inRun.getCurrentX(); int position = 0; for (int i = 0; i < count; i++) { currentView = getChildAt(i); if (currentView.getLeft() <= offsetX && offsetX < currentView.getRight()) { position = i; break; } } int width = currentView.getWidth(); int positionOffsetPixels = (int) (offsetX - currentView.getLeft()); float positionOffset = (offsetX - currentView.getLeft()) / width; notifyPageScrolled(position, positionOffset, positionOffsetPixels); } else if (mPositionOffset - 0.0f > 0.01) { currentView = getChildAt(mPosition); int width = currentView.getWidth(); offsetX = currentView.getLeft() + width * mPositionOffset; notifyPageScrolled(mPosition, mPositionOffset, mPositionOffsetPixels); } else { currentView = getChildAt(mSelectedTabIndex); if (currentView == null) { return; } offsetX = currentView.getLeft(); } int tabWidth = currentView.getWidth(); int width = scrollBar.getWidth(tabWidth); width = Math.min(tabWidth, width); offsetX += (tabWidth - width) / 2; int saveCount = canvas.save(); canvas.translate(offsetX, offsetY); canvas.clipRect(0, 0, width, scrollBar.getHeight(getHeight())); // needed int preHeight = scrollBar.getSlideView().getHeight(); int preWidth = scrollBar.getSlideView().getWidth(); if (preHeight != scrollBar.getHeight(getHeight()) || preWidth != scrollBar.getWidth(tabWidth)) { measureScrollBar(true); } scrollBar.getSlideView().draw(canvas); canvas.restoreToCount(saveCount); }
From source file:io.indy.seni.ui.EvolveGridFragment.java
@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Genotype genotype = mEvolveContainer.getGenotype((int) id); AstHolder astHolder = genotype.getAstHolder(); try {/*from ww w . ja va 2 s. co m*/ String script = astHolder.scribe(genotype); Intent intent = new Intent(getActivity(), RenderActivity.class); intent.putExtra(GENESIS_SCRIPT, script); // startActivity(intent); if (AppConfig.hasJellyBean()) { // makeThumbnailScaleUpAnimation() looks kind of ugly here as the loading spinner may // show plus the thumbnail image in GridView is cropped. so using // makeScaleUpAnimation() instead. ActivityOptions options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()); getActivity().startActivity(intent, options.toBundle()); } else { startActivity(intent); } } catch (Node.ScribeException e) { e.printStackTrace(); } }
From source file:com.cyanogenmod.eleven.ui.fragments.AudioPlayerFragment.java
/** * Initializes the header bar/*from w ww . ja v a2 s. c o m*/ */ private void initHeaderBar() { View headerBar = mRootView.findViewById(R.id.audio_player_header); final int bottomActionBarHeight = getResources().getDimensionPixelSize(R.dimen.bottom_action_bar_height); headerBar.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { // since we only want the top and bottom shadows, pad the horizontal width // to hide the shadows. Can't seem to find a better way to do this int padWidth = (int) (0.2f * view.getWidth()); outline.setRect(-padWidth, -bottomActionBarHeight, view.getWidth() + padWidth, view.getHeight()); } }); // Title text mSongTitle = (TextView) mRootView.findViewById(R.id.header_bar_song_title); mArtistName = (TextView) mRootView.findViewById(R.id.header_bar_artist_title); // Buttons // Search Button View v = mRootView.findViewById(R.id.header_bar_search_button); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { NavUtils.openSearch(getActivity(), ""); } }); // Add to Playlist Button // Setup the playlist button - add a click listener to show the context mAddToPlaylistButton = (ImageView) mRootView.findViewById(R.id.header_bar_add_button); // Create the context menu when requested mAddToPlaylistButton.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, menu); menu.setHeaderTitle(R.string.add_to_playlist); } }); // add a click listener to show the context mAddToPlaylistButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // save the current track id mSelectedId = MusicUtils.getCurrentAudioId(); mAddToPlaylistButton.showContextMenu(); } }); // Add the menu button // menu button mMenuButton = (ImageView) mRootView.findViewById(R.id.header_bar_menu_button); mMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showPopupMenu(); } }); }
From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java
private void internalHide(@NonNull final View container, @NonNull final InfoWindow toHideWindow, final boolean animated) { if (animated) { final Animation animation; if (hideAnimation == null) { final int containerWidth = container.getWidth(); final int containerHeight = container.getHeight(); final float pivotX = container.getX() + containerWidth / 2; final float pivotY = container.getY() + containerHeight; animation = new ScaleAnimation(1f, 0f, 1f, 0f, pivotX, pivotY); animation.setDuration(DURATION_WINDOW_ANIMATION); animation.setInterpolator(new DecelerateInterpolator()); } else {/* w w w . j av a 2 s .c om*/ animation = hideAnimation; } animation.setAnimationListener(new SimpleAnimationListener() { @Override public void onAnimationStart(Animation animation) { toHideWindow.setWindowState(InfoWindow.State.HIDING); propagateShowEvent(toHideWindow, InfoWindow.State.HIDING); } @Override public void onAnimationEnd(Animation animation) { removeWindow(toHideWindow, container); if (container.getId() != InfoWindowManager.this.currentContainer.getId()) { parent.removeView(container); } toHideWindow.setWindowState(InfoWindow.State.HIDDEN); propagateShowEvent(toHideWindow, InfoWindow.State.HIDDEN); } }); this.currentContainer.startAnimation(animation); } else { removeWindow(toHideWindow, container); propagateShowEvent(toHideWindow, InfoWindow.State.HIDDEN); } }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private Animator getRevealAnimator(View source, int revealColor) { final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/*from w w w . j ava 2 s . c o m*/ containerView.addView(revealView); final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f)); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS); animatorSet.playSequentially(revealAnimator, fadeAnimator); return revealAnimator; }