Example usage for android.widget TextView setSelected

List of usage examples for android.widget TextView setSelected

Introduction

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

Prototype

@Override
    public void setSelected(boolean selected) 

Source Link

Usage

From source file:com.example.ngu.slidingtablayouticon.Fragment.SlidingTabLayout.java

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

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*w w w . j  av  a2s. co m*/
        TextView tabTitleView = 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;
        }

        //Set icon, that can be changeable instead setting text.
        //I think the text also can setting here from getPageTitle func.
        //But we interesting only in icon
        tabTitleView.setCompoundDrawablesWithIntrinsicBounds(adapter.getDrawableId(i), 0, 0, 0);
        //Select tab if it is current
        if (mViewPager.getCurrentItem() == i) {
            tabTitleView.setSelected(true);
        }
        tabView.setOnClickListener(tabClickListener);

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

}

From source file:com.applite.common.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        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));
                }//  www. ja  v  a  2s  . c o m
            }
            if (i == selectedPosition) {
                tab.setSelected(true);
            } else {
                tab.setSelected(false);
            }
        }
    }

}

From source file:com.example.testing.myapplication.module.pageSliding.PagerSlidingTabStrip.java

private void addTextTab(final int position, final String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);/*  w ww .  ja  v a 2s  . com*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setFocusable(true);
    //tab.setOnClickListener(new OnClickListener() {
    //    @Override public void onClick(View v) {
    //        pager.setCurrentItem(position);
    //        v.setSelected(true);
    //    }
    //});

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
            v.setSelected(true);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tab.setBackgroundResource(tabBackgroundResId);
    tab.setTextColor(mTabTextColor);
    tab.setTextSize(tabTextSize);
    //tab.setTypeface(tabTypeface, tabTypefaceStyle);

    tab.setSelected(position == 0);

    // 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));
        }
    }

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.giovanniterlingen.windesheim.view.Adapters.ScheduleAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final TextView lessonName = holder.lessonName;
    final TextView lessonTime = holder.lessonTime;
    final TextView lessonRoom = holder.lessonRoom;
    final TextView lessonComponent = holder.lessonComponent;
    final RelativeLayout menuButton = holder.menuButton;
    final ImageView menuButtonImage = holder.menuButtonImage;
    final View scheduleIdentifier = holder.scheduleIdentifier;

    Lesson lesson = this.lessons[position];
    long databaseDateStart = Long
            .parseLong(lesson.getDate().replaceAll("-", "") + lesson.getStartTime().replaceAll(":", ""));
    long databaseDateEnd = Long
            .parseLong(lesson.getDate().replaceAll("-", "") + lesson.getEndTime().replaceAll(":", ""));

    SimpleDateFormat yearMonthDayDateFormat = CalendarController.getInstance().getYearMonthDayDateTimeFormat();
    long currentDate = Long.parseLong(yearMonthDayDateFormat.format(new Date()));

    lessonName.setText(lesson.getSubject());
    lessonRoom.setText(lesson.getRoom());
    lessonComponent.setText(lesson.getScheduleType() == 2 ? lesson.getClassName() : lesson.getTeacher());
    lessonComponent.setSelected(true);

    if (databaseDateStart <= currentDate && databaseDateEnd >= currentDate) {
        lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent));
        lessonTime.setText(//w w  w  .  j ava 2s .c o  m
                ApplicationLoader.applicationContext.getResources().getString(R.string.lesson_started));
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()];
                if (!lessonTime.getText().toString().equals(ApplicationLoader.applicationContext.getResources()
                        .getString(R.string.lesson_started))) {
                    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f);
                    animation.setDuration(100);
                    lessonTime.setAnimation(animation);
                    lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent));
                    lessonTime.setText(ApplicationLoader.applicationContext.getResources()
                            .getString(R.string.lesson_started));
                } else {
                    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f);
                    animation.setDuration(100);
                    lessonTime.setAnimation(animation);
                    String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime();
                    lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText));
                    lessonTime.setText(lessonTimes);
                }
            }
        });
    } else if (databaseDateEnd < currentDate) {
        lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent));
        lessonTime.setText(ApplicationLoader.applicationContext.getResources().getString(R.string.finished));
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()];
                if (!lessonTime.getText().toString().equals(
                        ApplicationLoader.applicationContext.getResources().getString(R.string.finished))) {
                    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f);
                    animation.setDuration(100);
                    lessonTime.setAnimation(animation);
                    lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorAccent));
                    lessonTime.setText(
                            ApplicationLoader.applicationContext.getResources().getString(R.string.finished));
                } else {
                    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,
                            Animation.RELATIVE_TO_SELF, 0.0f);
                    animation.setDuration(100);
                    lessonTime.setAnimation(animation);
                    String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime();
                    lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText));
                    lessonTime.setText(lessonTimes);
                }
            }
        });
    } else {
        String lessonTimes = lesson.getStartTime() + " - " + lesson.getEndTime();
        lessonTime.setTextColor(ContextCompat.getColor(activity, R.color.colorSecondaryText));
        lessonTime.setText(lessonTimes);
        holder.cardView.setOnClickListener(null);
    }
    menuButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            menuButtonImage.setImageDrawable(
                    ResourcesCompat.getDrawable(activity.getResources(), R.drawable.overflow_open, null));
            PopupMenu popupMenu = new PopupMenu(activity, menuButton);
            popupMenu.inflate(R.menu.menu_schedule);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    Lesson lesson = ScheduleAdapter.this.lessons[holder.getAdapterPosition()];
                    if (item.getItemId() == R.id.hide_lesson) {
                        showPromptDialog(lesson.getSubject());
                        return true;
                    }
                    if (item.getItemId() == R.id.save_lesson) {
                        showCalendarDialog(lesson.getRowId());
                    }
                    return true;
                }
            });
            popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuButtonImage.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(),
                            R.drawable.overflow_normal, null));
                }
            });
            popupMenu.show();
        }
    });
    scheduleIdentifier.setBackgroundColor(ColorController.getInstance().getColorById(lesson.getScheduleId()));
}

From source file:com.android.messaging.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);//  w w w .j a  v  a 2  s  . c om
    textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.orangemoo.com.beta.widget.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*from   www  . j  a  v a  2  s .c o  m*/
    //        textView.setBackgroundResource(R.drawable.view_pager_tab_background);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    textView.setOnLongClickListener(new OnTabLongClickListener(position));

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    //        textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:com.example.capstone.view.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabSwitch && i != startTab ? tabDeactivateTextColor : 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));
                }//  w  ww  .  j  a  v  a 2 s.  c o  m
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            tab.setSelected(tabSwitch && i == startTab ? true : false);
        }
    }
}

From source file:com.hdezninirola.fantasywithdrawer.custom_views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(!tabSwitch ? tabBackgroundResId : transparentColorId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabSwitch ? tabDeactivateTextColor : 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));
                }/*from  w  w  w .  j a v a 2s  .c o m*/
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            tab.setSelected(tabSwitch ? true : false);
        }
    }
}

From source file:com.leigo.qsbk.app.widget.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(!tabSwitch ? tabBackgroundResId : transparentColorId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabSwitch && i != 0 ? tabDeactivateTextColor : 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));
                }/*  w w w.jav  a 2 s . c  o m*/
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            tab.setSelected(tabSwitch && i == 0 ? true : false);
        }
    }
}

From source file:com.appybite.customer.AllowedHotels.java

private void updateHotelList() {
    llHotelList.removeAllViews();//from ww w  .  j a  va  2 s .c o  m

    for (int i = 0; i < aryHotelList.size(); i++) {

        final HotelInfo value = aryHotelList.get(i);

        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View item = null;
        if (DeviceUtil.isTabletByRes(this))
            item = vi.inflate(R.layout.item_hotel_tab, llHotelList, false);
        else
            item = vi.inflate(R.layout.item_hotel, llHotelList, false);

        ImageView ivThumb = (ImageView) item.findViewById(R.id.ivThumb);
        if (value.id == -1) {
            ivThumb.setImageResource(R.drawable.home_hotel_bg);
        } else {
            ImageLoader.getInstance().displayImage(value.hotel_logo, ivThumb, options, animateFirstListener);
        }

        TextView tvTitle = (TextView) item.findViewById(R.id.tvTitle);
        tvTitle.setText(value.hotel_name);
        tvTitle.setSelected(true);
        if (i == 0)
            tvTitle.setTextColor(getResources().getColor(R.color.Goldenrod));

        item.setTag(tvTitle);

        item.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                unselectHotels();

                ((TextView) arg0.getTag()).setTextColor(getResources().getColor(R.color.Goldenrod));

                if (value.id == -1) {
                    PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_id, "-1");
                    if (DeviceUtil.isTabletByRes(AllowedHotels.this))
                        goHome_Tab();
                    else
                        goHome();
                } else {
                    PrefValue.setString(AllowedHotels.this, R.string.pref_hotel_id,
                            String.valueOf(value.hotel_id));
                    goHotel(value);
                }
            }
        });

        if (!PRJFUNC.DEFAULT_SCREEN) {

            PRJFUNC.mGrp.relayoutView(item, LayoutLib.LP_LinearLayout);
            PRJFUNC.mGrp.setTextViewFontScale(tvTitle);
            PRJFUNC.mGrp.repaddingView(tvTitle);
            PRJFUNC.mGrp.relayoutView(item.findViewById(R.id.ivShadowTop), LayoutLib.LP_RelativeLayout);
            PRJFUNC.mGrp.relayoutView(item.findViewById(R.id.ivShadowBottom), LayoutLib.LP_RelativeLayout);
        }
        llHotelList.addView(item);
    }
}