Example usage for android.view View setSelected

List of usage examples for android.view View setSelected

Introduction

In this page you can find the example usage for android.view View setSelected.

Prototype

public void setSelected(boolean selected) 

Source Link

Document

Changes the selection state of this view.

Usage

From source file:android.support.v7.internal.widget.ScrollingTabContainerView.java

public void setTabSelected(int position) {
    mSelectedTabIndex = position;//ww w  . j  a  v a2  s  .  c o  m
    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final View child = mTabLayout.getChildAt(i);
        final boolean isSelected = i == position;
        child.setSelected(isSelected);
        if (isSelected) {
            animateToTab(position);
        }
    }
    if (mTabSpinner != null && position >= 0) {
        mTabSpinner.setSelection(position);
    }
}

From source file:com.hcy.suzhoubusquery.utils.PagerSlidingTabStrip.java

private void setTabsSelected(int position) {
    final int tabCount = tabsContainer.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final View child = tabsContainer.getChildAt(i);
        final boolean isSelected = (i == position);
        child.setSelected(isSelected);
    }/*  ww w  . ja  v  a  2 s . c  o m*/
}

From source file:com.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java

@Override
public void setCurrentItem(int item, boolean anim) {
    if (item < 0) {
        item = 0;/*from ww w.ja v  a2 s  .  co m*/
    } else if (item > mAdapter.getCount() - 1) {
        item = mAdapter.getCount() - 1;
    }
    if (mSelectedTabIndex != item) {
        int mPreSelectedTabIndex = mSelectedTabIndex;
        mSelectedTabIndex = item;
        final int tabCount = mAdapter.getCount();
        /*
         * ?tab
         */
        for (int i = 0; i < tabCount; i++) {
            final ViewGroup group = (ViewGroup) getChildAt(i);
            View child = group.getChildAt(0);
            final boolean isSelected = (i == item);
            child.setSelected(isSelected);
        }

        // ???,??
        if (!inRun.isFinished()) {
            inRun.stop();
        }
        // scrollBar?viewpager??
        if (scrollBar != null && mPositionOffset < 0.01f && mPreSelectedTabIndex >= 0
                && mPreSelectedTabIndex < getChildCount()) {
            // ?scrollBar?
            int sx = getChildAt(mPreSelectedTabIndex).getLeft();
            // ?scrollBar??
            int ex = getChildAt(item).getLeft();
            final float pageDelta = (float) Math.abs(ex - sx) / (getChildAt(item).getWidth());
            int duration = (int) ((pageDelta + 1) * 100);
            duration = Math.min(duration, 600);
            // scrollBar
            inRun.startScroll(sx, ex, duration);
        }
        // measureScrollBar(true);
    }
}

From source file:com.ryann10.pagerslidingtabstripsample.PagerSlidingTabStrip.java

private void updateSelectedState(int position) {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);

        //ryann10 fixed
        if (v instanceof TextView && i == position) {
            v.setSelected(true);
        } else {// w  w  w .j  a va 2  s. co m
            v.setSelected(false);
        }
    }
}

From source file:cn.ieclipse.af.view.AutoPlayView.java

/**
 * ??/*from   w w  w  . j ava  2  s  .c om*/
 *
 */
private void changePointView(int oldPosition, int newPosition) {
    if (mIndicatorLayout != null) {
        View old = null;
        View current = null;
        if (oldPosition < mIndicatorLayout.getChildCount()) {
            old = mIndicatorLayout.getChildAt(oldPosition);
        }
        if (newPosition < mIndicatorLayout.getChildCount()) {
            current = mIndicatorLayout.getChildAt(newPosition);
        }
        if (old != null) {
            old.setSelected(false);
        }
        if (current != null) {
            current.setSelected(true);
        }
    }
}

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessorTest.java

@MediumTest
public void testViewFocused_overridesViewSelected() {
    final View outerView = getViewForId(R.id.outer_view);
    final View middleView = getViewForId(R.id.middle_view);
    final View innerView = getViewForId(R.id.inner_view);

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_SELECTED;

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override/*from   w  w  w.  j a  va  2 s.  co  m*/
        public void run() {
            middleView.requestFocus();
            outerView.setSelected(true);
            innerView.setSelected(true);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertFalse(mMatched);
}

From source file:cn.edu.qzu.face.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*w  w  w  . j a v  a2s . c  o  m*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    for (int i = 0; i < tabsContainer.getChildCount(); ++i) {
        View tab = tabsContainer.getChildAt(i);
        tab.setSelected(i == selectedPosition);
    }

    // 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) {

        View nextTab = 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);
    }

    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    //Indicator
    /*View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();
    if (currentTab instanceof TextView) {
       TextView textView = (TextView) currentTab;
    bound.setEmpty();
       Paint textPaint = textView.getPaint();
       textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
       int padding = (textView.getWidth() - bound.width()) / 2;
       lineLeft = lineLeft + padding;
       lineRight = lineRight - padding;
    }
            
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
            
       View nextTab = tabsContainer.getChildAt(currentPosition + 1);
       float nextTabLeft = nextTab.getLeft();
       float nextTabRight = nextTab.getRight();
       if (nextTab instanceof TextView) {
    TextView textView = (TextView) nextTab;
    Rect bound = new Rect();
    Paint textPaint = textView.getPaint();
    textPaint.getTextBounds(textView.getText().toString(), 0, textView.getText().length(), bound);
    int padding = (textView.getWidth() - bound.width()) / 2;
    nextTabLeft = nextTabLeft + padding;
    nextTabRight = nextTabRight - padding;
       }
            
       lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
       lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
            
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);*/

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.xinwei.smallvideo.widget.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*from   ww  w  .j  ava 2s .c om*/
    }

    final int height = getHeight();

    // draw indicator line
    rectPaint.setColor(indicatorColor);

    // ??TAB
    View currentTab = tabsContainer.getChildAt(currentPosition);
    // ??TAB???
    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) {

        View nextTab = 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);
    }

    // 
    canvas.drawRect(lineLeft, 0, lineRight, indicatorHeight, rectPaint);

    // 
    // canvas.drawRect(lineLeft, height - indicatorHeight, lineRight,
    // height,
    // rectPaint);

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider
    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        boolean isSelected = (i == currentPosition);
        tab.setSelected(isSelected);

        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }
}

From source file:com.shawnway.nav.app.wtw.view.PagerSlidingTabStrip.java

private void updateTabStyles() {
    //Buttonselected?
    final int count = tabsContainer.getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = tabsContainer.getChildAt(i);

        child.setSelected(selectedPosition == i);
    }/* www  .  ja  v  a2 s .co m*/
    //
    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);
        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        }
    }

}

From source file:com.example.alvarpao.popularmovies.MovieGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // The adapter is initialized with an empty array if state wasn't restore on rotation, if
    // it was, the array of movies already has the saved data.
    //Toast.makeText(getActivity(), "mMovies size restored: " + mMovies.size(), Toast.LENGTH_SHORT).show();
    mMovieAdapter = new MovieAdapter(getActivity(), mMovies);
    mMoviesGridView = (GridView) rootView.findViewById(R.id.movies_grid);
    mMoviesGridView.setDrawSelectorOnTop(true);
    mMoviesGridView.setAdapter(mMovieAdapter);
    mMoviesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // This will force to draw the selector on top of the poster for the selected movie
            view.setSelected(true);
            mSelectedMovie = position;/*from w w w. j ava  2 s .c  o m*/
            // A selection occurred as opposed to selecting the first visible item by default
            // so the details fragment is not empty in the two-pane layout.
            mSelectionOccurred = true;
            //Toast.makeText(getActivity(), "Selected Movie: " +
            // ((Movie) mMoviesGridView.getItemAtPosition(position)).getOriginalTitle(),
            // Toast.LENGTH_SHORT).show();
            Movie movie = mMovieAdapter.getItem(position);
            // A movie has been selected so the MainActivity has to be notified to take
            // appropriate action
            ((Callback) getActivity()).onItemSelected(movie);
        }
    });

    // Handles pagination for movie grid, except in the case the sort option is "Favorites",
    // since we don't need pagination in that case
    mMoviesGridView.setOnScrollListener(this);

    // If a rotation occurred, restore the selected movie (either selected by the user or
    // "selected" by default (first visible movie before rotation))
    // The restore of the details fragment with this selected after rotation is handled in the
    // onCreateOptionsMenu() method which is called after onCreateView()
    if (savedInstanceState != null && savedInstanceState.containsKey((SELECTED_MOVIE)))
        mSelectedMovie = savedInstanceState.getInt(SELECTED_MOVIE);

    return rootView;
}