Example usage for android.widget TextView getTop

List of usage examples for android.widget TextView getTop

Introduction

In this page you can find the example usage for android.widget TextView getTop.

Prototype

@ViewDebug.CapturedViewProperty
public final int getTop() 

Source Link

Document

Top position of this view relative to its parent.

Usage

From source file:Main.java

public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) {
    final int compoundPaddingLeft = textView.getCompoundPaddingLeft();
    final int compoundPaddingTop = textView.getCompoundPaddingTop();
    final int compoundPaddingRight = textView.getCompoundPaddingRight();
    final int compoundPaddingBottom = textView.getCompoundPaddingBottom();

    final int scrollX = textView.getScrollX();
    final int scrollY = textView.getScrollY();

    final int right = textView.getRight();
    final int left = textView.getLeft();
    final int bottom = textView.getBottom();
    final int top = textView.getTop();

    final Drawable[] drawables = textView.getCompoundDrawables();
    if (drawables != null) {

        int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop;
        int hspace = right - left - compoundPaddingRight - compoundPaddingLeft;

        Drawable topDr = drawables[1];//from ww  w  . ja v  a2 s.  com
        // IMPORTANT: The coordinates computed are also used in invalidateDrawable()
        // Make sure to update invalidateDrawable() when changing this code.
        if (topDr != null) {
            canvas.save();
            canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2,
                    scrollY + textView.getPaddingTop() + vspace / 2);
            topDr.draw(canvas);
            canvas.restore();
            return true;
        }
    }

    return false;
}

From source file:com.timothy.android.api.fragment.LeftFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.left_list, null);
    title = (TextView) view.findViewById(R.id.indexTV);
    int branchIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_BRANCH_INDEX, sp);
    if (branchIndex != -1 && branchNames != null) {
        title.setText(branchNames[branchIndex - 1]);
    }/*from  w w  w .  j  av a 2  s  .c o m*/
    title.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            TextView tv = (TextView) arg0;
            if (view.getVisibility() == View.VISIBLE && tv.getVisibility() == View.VISIBLE) {
                if (branchNames != null && branchNames.length > 0) {
                    tv.getTop();
                    int y = tv.getBottom() * 3 / 2;
                    int x = tv.getLeft();
                    //                  int x = activity.getWindowManager().getDefaultDisplay().getWidth() / 4;
                    showPopupWindow(x, y);
                }
            }
        }
    });
    return view;
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Scrolls the scroll view of this {@link FormFragment} instance to specified question
 * so that it is visible to the user./*w  w w . j  av a  2  s  . com*/
 * @param questionToCheck question to scroll to
 */
private void scrollToQuestion(Question questionToCheck) {
    TextView textView = mQuestionTitleMappings.get(questionToCheck);
    // scroll to the top of the title
    mScrollView.smoothScrollTo(0, textView.getTop());
}

From source file:kankan.wheel.widget.WheelView.java

/**
 * Draws items/*from   w w w.  j a v a 2  s  .co m*/
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
    canvas.translate(PADDING, -top + scrollingOffset);

    //??
    AbstractWheelTextAdapter adapter = null;
    if (viewAdapter instanceof AbstractWheelTextAdapter) {
        adapter = (AbstractWheelTextAdapter) viewAdapter;
    }
    if (adapter != null && adapter.isEnableMultiTextColor()) {
        int targetIndex = -1;
        int minDis = Integer.MAX_VALUE;
        for (int i = 0; i < itemsLayout.getChildCount(); i++) {
            TextView child = (TextView) itemsLayout.getChildAt(i);
            int realTop = child.getTop() - top + scrollingOffset;
            int viewCenter = realTop + child.getHeight() / 2;
            Rect bounds = centerDrawable.getBounds();
            int dis = Math.abs(viewCenter - bounds.centerY());
            if (dis < minDis) {
                minDis = dis;
                targetIndex = i;
            }
        }

        for (int i = 0; i < itemsLayout.getChildCount(); i++) {
            TextView view = (TextView) itemsLayout.getChildAt(i);
            view.setAlpha(0.5f);
            view.setTextColor(adapter.getTextColor());
            view.setTextSize(adapter.getTextSize());
            adapter.setTextViewPadding(view, adapter.getTextPaddingTop(), adapter.getTextPaddingBottom());

        }

        if (targetIndex != -1) {
            TextView view = (TextView) itemsLayout.getChildAt(targetIndex);
            view.setAlpha(1);
            view.setTextColor(adapter.getTextSelectedColor());
            view.setTextSize(adapter.getTextSize() + 4);
            adapter.setTextViewPadding(view, adapter.getTextPaddingTop() - 2,
                    adapter.getTextPaddingBottom() - 2);
        }

        TextView view = (TextView) itemsLayout.getChildAt(targetIndex - 1);
        if (view != null)
            view.setAlpha(1);
        view = (TextView) itemsLayout.getChildAt(targetIndex + 1);
        if (view != null)
            view.setAlpha(1);
    }

    itemsLayout.draw(canvas);

    canvas.restore();
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private void setTempTitleView(TextView dest, TextView src) {
    dest.setVisibility(View.VISIBLE);
    dest.setText(src.getText());//from w w  w.  ja  v  a 2 s.co m
    dest.setTranslationY(0.0f);
    if (src.getVisibility() == View.VISIBLE) {
        dest.setAlpha(src.getAlpha());
        dest.setScaleX(src.getScaleX());
        dest.setScaleY(src.getScaleY());
    } else {
        dest.setAlpha(0.0f);
        dest.setScaleX(1.0f);
        dest.setScaleY(1.0f);
    }
    View parent = (View) src.getParent();
    dest.setLeft(src.getLeft() + parent.getLeft());
    dest.setRight(src.getRight() + parent.getLeft());
    dest.setTop(src.getTop() + parent.getTop());
    dest.setBottom(src.getBottom() + parent.getTop());
}

From source file:com.fastbootmobile.encore.app.fragments.ArtistFragment.java

/**
 * {@inheritDoc}//from   w w  w . ja  va2  s  .  co  m
 */
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mHandler = new Handler();

    // Setup the inside fragments
    mArtistTracksFragment = new ArtistTracksFragment();
    mArtistTracksFragment.setParentFragment(this);

    mArtistInfoFragment = new ArtistInfoFragment();
    mArtistInfoFragment.setArguments(mArtist);

    mArtistSimilarFragment = new ArtistSimilarFragment();
    mArtistSimilarFragment.setArguments(mArtist);

    // Inflate the main fragment view
    mRootView = (ParallaxScrollView) inflater.inflate(R.layout.fragment_artist, container, false);

    // Set the hero image and artist from arguments
    mHeroImageView = (ImageView) mRootView.findViewById(R.id.ivHero);
    if (mHeroImage != null) {
        mHeroImageView.setImageBitmap(mHeroImage);

        // The hero image that comes from a transition might be low in quality, so load
        // the higher quality and fade it in
        loadArt(false);
    } else {
        // Display placeholder and try to get the real art
        mHeroImageView.setImageResource(R.drawable.album_placeholder);
        loadArt(true);
    }

    final TextView tvArtist = (TextView) mRootView.findViewById(R.id.tvArtist);
    tvArtist.setBackgroundColor(mBackgroundColor);
    tvArtist.setText(mArtist.getName());

    final PagerTabStrip strip = (PagerTabStrip) mRootView.findViewById(R.id.pagerArtistStrip);
    strip.setDrawFullUnderline(false);
    strip.setAlpha(0.0f);
    strip.setTranslationY(-20);
    strip.animate().alpha(1.0f).setDuration(ANIMATION_DURATION).setStartDelay(500).translationY(0).start();

    if (!Utils.hasLollipop()) {
        tvArtist.setAlpha(0);
        tvArtist.animate().alpha(1).setDuration(ANIMATION_DURATION).setStartDelay(500).start();
    }

    // Setup the subfragments pager
    final WrapContentHeightViewPager pager = (WrapContentHeightViewPager) mRootView
            .findViewById(R.id.pagerArtist);
    pager.setAdapter(new ViewPagerAdapter(getChildFragmentManager()));
    pager.setOffscreenPageLimit(FRAGMENT_COUNT);

    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int i) {
            if (mRootView.getScrollY() > tvArtist.getTop()) {
                mRootView.smoothScrollTo(0, tvArtist.getTop());
            }
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    pager.setMinimumHeight(500);
                    pager.requestLayout();
                }
            });

            boolean hasRosetta = ProviderAggregator.getDefault().getRosettaStonePrefix().size() > 0;

            if (hasRosetta) {
                if (i == FRAGMENT_ID_BIOGRAPHY) {
                    mArtistInfoFragment.notifyActive();
                } else if (i == FRAGMENT_ID_SIMILAR) {
                    mArtistSimilarFragment.notifyActive();
                }
            } else {
                if (i == FRAGMENT_ID_SIMILAR) {
                    // This is actually BIOGRAPHY if rosetta is not available
                    mArtistInfoFragment.notifyActive();
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    mRootView.setOnScrollListener(new ObservableScrollView.ScrollViewListener() {
        @Override
        public void onScroll(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
            final ActionBar ab = ((AppActivity) getActivity()).getSupportActionBar();
            if (ab != null) {
                if (y >= tvArtist.getTop()) {
                    ab.hide();
                } else {
                    ab.show();
                }
            }
        }
    });

    // Setup the source logo
    final ImageView ivSource = (ImageView) mRootView.findViewById(R.id.ivSourceLogo);
    mLogoBitmap = PluginsLookup.getDefault().getCachedLogo(getResources(), mArtist);
    ivSource.setImageDrawable(mLogoBitmap);

    // Outline is required for the FAB shadow to be actually oval
    mFabPlay = (FloatingActionButton) mRootView.findViewById(R.id.fabPlay);
    showFab(false, false);

    // Set the FAB animated drawable
    mFabDrawable = new PlayPauseDrawable(getResources(), 1);
    mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY);
    mFabDrawable.setYOffset(6);

    final Song currentTrack = PlaybackProxy.getCurrentTrack();
    if (currentTrack != null && currentTrack.getArtist() != null
            && currentTrack.getArtist().equals(mArtist.getRef())) {
        int state = PlaybackProxy.getState();
        if (state == PlaybackService.STATE_PLAYING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
        } else if (state == PlaybackService.STATE_PAUSED) {
            mFabShouldResume = true;
        } else if (state == PlaybackService.STATE_BUFFERING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PLAY);
            mFabDrawable.setBuffering(true);
            mFabShouldResume = true;
        } else if (state == PlaybackService.STATE_PAUSING) {
            mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
            mFabDrawable.setBuffering(true);
            mFabShouldResume = true;
        }
    }

    mFabPlay.setImageDrawable(mFabDrawable);
    mFabPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mFabDrawable.getCurrentShape() == PlayPauseDrawable.SHAPE_PLAY) {
                if (mFabShouldResume) {
                    PlaybackProxy.play();
                } else {
                    mArtistTracksFragment.playRecommendation();
                }
            } else {
                mFabDrawable.setShape(PlayPauseDrawable.SHAPE_PAUSE);
                mFabShouldResume = true;
                PlaybackProxy.pause();
            }
        }
    });

    return mRootView;
}