Example usage for android.widget ImageView setSelected

List of usage examples for android.widget ImageView setSelected

Introduction

In this page you can find the example usage for android.widget ImageView setSelected.

Prototype

@Override
    public void setSelected(boolean selected) 

Source Link

Usage

From source file:Main.java

public static void startVDAnimation(ImageView imageView, @DrawableRes int inactiveResId,
        @DrawableRes int activeResId, int duration) {
    int drawableResId = imageView.isSelected() ? activeResId : inactiveResId;
    Drawable drawable = ContextCompat.getDrawable(imageView.getContext(), drawableResId);
    imageView.setImageDrawable(drawable);

    if (drawable instanceof Animatable) {
        Animatable animatable = (Animatable) drawable;
        if (animatable.isRunning()) {
            animatable.stop();/*w  ww .  j  a  v  a2  s .c  o m*/
        }

        animatable.start();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            imageView.setSelected(!imageView.isSelected());
        } else {
            imageView.postDelayed(() -> {
                imageView.setSelected(!imageView.isSelected());
                int nextDrawableResId = imageView.isSelected() ? activeResId : inactiveResId;
                Drawable nextDrawable = ContextCompat.getDrawable(imageView.getContext(), nextDrawableResId);
                imageView.setImageDrawable(nextDrawable);
            }, duration);
        }
    }
}

From source file:j2w.team.common.widget.infiniteviewpager.iconindicator.IconPageIndicator.java

@Override
public void setCurrentItem(int item) {
    if (mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }/*w  w  w . j a  va  2  s.com*/
    mSelectedIndex = item;
    mViewPager.setCurrentItem(item);
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int tabCount = mIconsLayout.getChildCount();

    for (int i = 0; i < tabCount; i++) {
        ImageView child = (ImageView) mIconsLayout.getChildAt(i);
        boolean isSelected = (i == item);
        child.setSelected(isSelected);
        if (isSelected) {
            child.setImageResource(iconAdapter.getIconResId(i));
        } else {
            child.setImageResource(iconAdapter.getIconResIdDefault());
        }
    }
}

From source file:com.google.android.apps.forscience.whistlepunk.intro.TutorialActivity.java

private void setupDots(ArrayList<TutorialItem> items) {
    mDots.removeAllViews();// www  . j a v  a  2s  .co  m
    LayoutInflater inflater = getLayoutInflater();
    final int count = items.size() - 1; // Don't make a dot for the last item.
    for (int index = 0; index < count; index++) {
        ImageView view = (ImageView) inflater.inflate(R.layout.tutorial_dot_view, mDots, false);
        mDots.addView(view);
        view.setSelected(index == 0);
    }
}

From source file:com.b44t.ui.Components.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);// ww w.ja  v a2 s. c  o m
    tab.setImageResource(resId);
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}

From source file:info.androidhive.listviewfeed.data.SlidingTabLayout.java

private void populateTabStrip() {
    final TabsPagerAdapter adapter = (TabsPagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*  w w w.j  a v  a2 s .  c o  m*/
        ImageView tabIconView = null;
        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }
        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }
        tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawableId(i)));
        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        final int index_i = i;

        tabView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mViewPager.setCurrentItem(index_i);
            }
        });
        mTabStrip.addView(tabView);
        //tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
    }
}

From source file:info.androidhive.listviewfeed.SlidingTab.SlidingTabLayout.java

private void populateTabStrip() {
    final ViewpagerAdapter adapter = (ViewpagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from   w  w  w . ja va 2  s . c o m
        ImageView tabIconView = null;
        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }
        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }
        tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawableId(i)));
        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        //tabView.setOnClickListener(tabClickListener);
        final int index_i = i;

        tabView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mViewPager.setCurrentItem(index_i);
            }
        });
        mTabStrip.addView(tabView);
        //tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
    }
}

From source file:com.fivetrue.workout.timer.view.PagerSlidingTabStrip.java

private void selectTabTextColor(int position) {
    BasePagerAdapter adapter = (BasePagerAdapter) pager.getAdapter();
    for (int i = 0; i < tabsContainer.getChildCount(); i++) {
        PagerTabContent content = (PagerTabContent) adapter.getItem(i);

        if (content.isShowingIcon()) {
            ImageView tabImage = (ImageView) tabsContainer.getChildAt(i);
            if (i == position) {
                tabImage.setSelected(true);
            } else {
                tabImage.setSelected(false);
            }//from  w w w. ja  v a  2  s .  co  m
        } else {
            TextView tabText = (TextView) tabsContainer.getChildAt(i);
            if (i == position) {
                tabText.setTypeface(null, selectTabTypefaceStyle);
                tabText.setTextColor(selectTextColor);
            } else {
                tabText.setTypeface(null, tabTypefaceStyle);
                tabText.setTextColor(tabTextColor);
            }
        }
    }
}

From source file:com.example.facebook_volley.widget.SlidingTabLayout.java

private void populateTabStrip() {
    final ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from  w  w w .  j  a  v a  2  s . c o  m
        ImageView tabIconView = null;
        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }
        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }
        tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawableId(i)));
        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        // tabView.setOnClickListener(tabClickListener);

        final int index_i = i;

        tabView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mViewPager.setCurrentItem(index_i);
            }
        });
        mTabStrip.addView(tabView);
        //tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
    }
}

From source file:com.example.admin.viewpageexample.SlidingTab.SlidingTabLayout.java

private void populateTabStrip() {
    final ViewpagerAdapter adapter = (ViewpagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*  w w w. ja  v a 2  s  .com*/
        ImageView tabIconView = null;
        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }
        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawableId(i)));
        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        //            tabView.setOnClickListener(tabClickListener);
        final int index_i = i;

        tabView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mViewPager.setCurrentItem(index_i);

            }
        });

        mTabStrip.addView(tabView);
        //tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));

    }
}

From source file:org.vshgap.ui.Components.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);// ww w.  j a v a  2s. c o m
    paintTabIcons(position);
    //tab.setImageResource(resId);
    tab.setImageDrawable(getResources().getDrawable(resId));//Plus
    tab.setScaleType(ImageView.ScaleType.CENTER);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab);
    tab.setSelected(position == currentPosition);
}