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:com.fivetrue.workout.timer.view.PagerSlidingTabStrip.java

private void addIconTab(final int position, Drawable drawable) {

    ImageView tab = new ImageView(getContext());
    tab.setFocusable(true);/*from w w  w . j a va 2 s.c  om*/
    tab.setImageDrawable(drawable);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
    tab.setSelected(currentPosition == position);
    LinearLayout.LayoutParams params = defaultTabLayoutParams;
    if (shouldExpand) {
        params = expandedTabLayoutParams;
    }
    tabsContainer.addView(tab, params);

}

From source file:org.arasthel.almeribus.fragments.InfoParadaFragment.java

@Override
public void onStart() {
    ImageView favorito = (ImageView) getView().findViewById(R.id.favorito);
    favorito.setOnClickListener(new OnClickListener() {

        @Override//  ww  w.  ja va 2  s  .com
        public void onClick(View arg0) {
            ImageView favorito = (ImageView) getView().findViewById(R.id.favorito);
            if (favorito.isSelected()) {
                DataStorage.DBHelper.removeFavorito(mNumParada);
                favorito.setImageResource(R.drawable.favorite_button);
            } else {
                DataStorage.DBHelper.addFavorito(mNumParada);
                favorito.setImageResource(R.drawable.ic_menu_favorite_on);
            }
            favorito.setSelected(!favorito.isSelected());
            Intent i = new Intent(ListaParadasFragment.UPDATE_FILTER);
            getActivity().sendBroadcast(i);
        }
    });
    boolean isFavorito = DataStorage.DBHelper.isFavorito(mNumParada);
    if (isFavorito) {
        favorito.setSelected(true);
        favorito.setImageResource(R.drawable.ic_menu_favorite_on);
    } else {
        favorito.setSelected(false);
        favorito.setImageResource(R.drawable.favorite_button);
    }

    ImageView verEnMapa = (ImageView) getView().findViewById(R.id.abrir_mapa);
    verEnMapa.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            double[] coord = DataStorage.paradas.get(mNumParada).getCoord();
            if (coord != null) {
                ((Principal) getActivity()).abrirMapaParadas(new LatLng(coord[1], coord[0]), true);
                ((MostrarInfoParada) getParentFragment()).dismiss();
            }
        }
    });

    LinearLayout listaTiempos = (LinearLayout) content.findViewById(R.id.tiemposEspera);
    listaTiempos.removeAllViews();
    if (mLineas.isEmpty()) {
        TextView tv = new TextView(getActivity());
        tv.setGravity(Gravity.CENTER);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        lp.rightMargin = 10;
        lp.leftMargin = 10;
        lp.topMargin = 20;
        tv.setLayoutParams(lp);
        tv.setText(
                "No hay conexin de internet.\n\nPor favor, compruebe que dispone de conexin y vuelva a intentarlo.");
        listaTiempos.addView(tv);
    } else {
        calcularTiempos();
    }
    super.onStart();
}

From source file:com.surinov.alexander.wallet2wallet.views.SlidingTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {
        ImageView tabView = crateDefaultImageView(getContext());

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;/*ww  w . j  av  a2  s .  co m*/
            lp.weight = 1;
        }

        tabView.setImageResource(((FragmentAdapter) adapter).getDrawableResource(i));
        tabView.setOnClickListener(tabClickListener);

        String desc = mContentDescriptions.get(i, null);

        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);

        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.rockerhieu.emojicon.slidingTab.SlidingTabLayout.java

/**
 * Method which populates tab strip with icon tabs, which represent each page with icons.
 *///  ww w. j  a  v  a  2 s.co  m
private void populateTabStrip() {
    final EmojisPagerAdapter adapter = (EmojisPagerAdapter) mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    View tabView;

    for (int i = 0; i < adapter.getCount(); i++) {
        ImageView tabIconView = null;

        /// Initialize tab view, get ImageView
        tabView = createDefaultImageView(getContext());
        if (ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        //Drawable draw = res.getDrawable(adapter.getDrawableId(i)); --> Deprecated
        Drawable draw = ResourcesCompat.getDrawable(getResources(), adapter.getDrawableId(i), null);

        /// Set icon for the tab...
        if (null != tabIconView) {
            tabIconView.setImageDrawable(draw);
            if (mViewPager.getCurrentItem() == i) {
                tabIconView.setSelected(true);
            }
        }

        /// Create new layout parameters for this tab which is ImageView element...
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.MATCH_PARENT);
        /// Set width for the element if its defined...
        if (0 < mTabWidth) {
            lp.width = mTabWidth;
        } else {
            lp.width = 0;
            lp.weight = 1;
        }
        /// Set layout parameters for this tab.
        tabView.setLayoutParams(lp);

        /// Attach on click listener and add tab to view...
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    }
}

From source file:kr.wdream.ui.Components.PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {
    ImageView tab = new ImageView(getContext()) {
        @Override//  w w  w .ja va  2 s  .  com
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (pager.getAdapter() instanceof IconTabProvider) {
                ((IconTabProvider) pager.getAdapter()).customOnDraw(canvas, position);
            }
        }
    };
    tab.setFocusable(true);
    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:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java

private void populateTabStrip() {
    final TabAdapter adapter = (TabAdapter) viewPager.getAdapter();

    for (int i = 0; i < adapter.getCount(); i++) {

        ImageView tabIconView = null;

        final View tabView = (tabProvider == null) ? createDefaultTabView(adapter.getDrawableId(i))
                : tabProvider.createTabView(tabStrip, i, adapter);

        if (tabView == null) {
            throw new IllegalStateException("tabView is null.");
        }/*  w  w  w  .j a  v a 2 s.  co m*/

        if (distributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        if (tabIconView != null) {
            tabIconView.setImageResource(adapter.getDrawableId(i));
            if (viewPager.getCurrentItem() == i) {
                tabIconView.setSelected(true);
            }
        }

        if (internalTabClickListener != null) {
            tabView.setOnClickListener(internalTabClickListener);
        }

        if (i == 1) {
            View view = LayoutInflater.from(getContext()).inflate(R.layout.counter, tabStrip, false);
            FrameLayout counterLayout = (FrameLayout) view.findViewById(R.id.counter_layout);
            messageBackground = (ImageView) view.findViewById(R.id.message_background);
            counter = (TextView) view.findViewById(R.id.counter);
            counter.setText(String.valueOf(messageCount));
            ImageView imageView = new ImageView(getContext());
            imageView.setImageResource(adapter.getDrawableId(i));
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            counterLayout.addView(imageView, 0);
            if (internalTabClickListener != null) {
                view.setOnClickListener(internalTabClickListener);
            }
            if (messageCount > 0) {
                messageBackground.setVisibility(VISIBLE);
                counter.setVisibility(VISIBLE);
            } else {
                messageBackground.setVisibility(GONE);
                counter.setVisibility(GONE);
            }
            tabStrip.addView(view);
        } else {
            tabStrip.addView(tabView);
        }

        if (i == viewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

    }
}

From source file:com.materialdesign.view.tab.VerticalTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {

        View tabView = createDefaultTabView(getContext());

        TextView tabText = (TextView) tabView.findViewById(R.id.tv_tabText);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        if (mTabs.size() > i) {
            Tab tab = mTabs.get(i);//from w  w w  .j a v  a 2  s  .co m
            if (tab.icon != 0) {
                tabIcon.setImageResource(tab.icon);
            } else {
                tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextMediumSize);
                int padding = (int) (mTabViewCustomPadding * getResources().getDisplayMetrics().density);
                tabView.setPadding(0, padding, 0, padding);
            }

            if (tab.tabText != null) {
                tabText.setText(tab.tabText);
            }
        }

        tabText.setTextColor(mTabTextColorStateList);

        if (mTabViewTextCustomSize != 0) {
            tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextCustomSize);
        }

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 0, 1);
        if (i == 0) {
            tabText.setSelected(true);
            tabIcon.setSelected(true);
        }
        mTabStrip.addView(tabView, lp);
    }

    if (hasMiddleTabView) {
        View tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_layout, null);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText);

        textView.setVisibility(GONE);

        LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(
                (int) (36 * getResources().getDisplayMetrics().density),
                (int) (36 * getResources().getDisplayMetrics().density));
        tabIcon.setLayoutParams(iconParams);
        tabIcon.setImageResource(mMiddleIconResId);

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,
                1);

        mTabStrip.addView(tabView, 2, lp);
    }
}

From source file:com.example.khaalijeb.newlistview_module.SlidingTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//  w w  w  .ja  v a  2s.  c o m
        TextView tabTitleView = null;
        ImageView tabIconView = null;
        /*  if (mTabViewLayoutId != 0 ) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
                false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
                
              tabIconView = (ImageView) tabView.findViewById(mTabViewImageViewId);
                
                
                    }
                
                    if (tabView == null) {
        tabView = createDefaultTabView(getContext());
                    }
                
                    if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
                    }*/

        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }

        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
            tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawable(i)));
        }

        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        /*       if (mDistributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
               }
                
        */

        //  tabTitleView.setText(adapter.getPageTitle(i));

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.yadadeya.yadadeya.widget.SlidingTabLayout.java

public void populateTabStrip(int frCount, int selectedFr) {
    // final ViewPagerAdapter adapter = (ViewPagerAdapter) mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < frCount; i++) {
        View tabView = null;/*  w  w  w  . j  av  a 2  s.com*/
        TextView tabTitleView = null;

        ImageView tabIconView = null;

        /*if (mTabViewLayoutId != 0) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
                false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }
                
        if (tabView == null) {
        tabView = createDefaultTabView(getContext());
        }
                
        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
        }*/

        /* if (mDistributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
         }*/

        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }

        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        tabIconView.setImageDrawable(getResources().getDrawable(getDrawableId(i)));
        if (selectedFr == i) {
            tabIconView.setSelected(true);
        }

        //tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        if (i == 2) {
            tabView.setEnabled(false);
            //tabView.setBackgroundColor(getResources().getColor(R.color.guillotine_background));

        }

        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == selectedFr) {
            tabView.setSelected(true);
            tabView.setBackgroundColor(Color.parseColor("#40000000"));
        }
    }
}

From source file:com.materialdesign.view.tab.TabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {

        View tabView = createDefaultTabView(getContext());

        TextView tabText = (TextView) tabView.findViewById(R.id.tv_tabText);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        if (mTabs.size() > i) {
            Tab tab = mTabs.get(i);//from w  ww  .  j a v  a  2s .  com
            if (tab.icon != 0) {
                tabIcon.setImageResource(tab.icon);
            } else {
                tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextMediumSize);
                int padding = (int) (mTabViewCustomPadding * getResources().getDisplayMetrics().density);
                tabView.setPadding(0, padding, 0, padding);
            }

            if (tab.tabText != null) {
                tabText.setText(tab.tabText);
            }
        }

        tabText.setTextColor(mTabTextColorStateList);

        if (mTabViewTextCustomSize != 0) {
            tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextCustomSize);
        }

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,
                1);
        if (i == 0) {
            tabText.setSelected(true);
            tabIcon.setSelected(true);
        }
        mTabStrip.addView(tabView, lp);
    }

    //tab,tab-?
    if (hasMiddleTabView) {
        View tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_layout, null);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText);

        textView.setVisibility(GONE);

        LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(
                (int) (36 * getResources().getDisplayMetrics().density),
                (int) (36 * getResources().getDisplayMetrics().density));
        tabIcon.setLayoutParams(iconParams);
        tabIcon.setImageResource(mMiddleIconResId);

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,
                1);

        mTabStrip.addView(tabView, 2, lp);
    }
}