List of usage examples for android.widget TextView setSingleLine
public void setSingleLine()
From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java
/** * Create or recreate the limiter breadcrumbs. *///from w ww.ja va2s. c o m public void updateLimiterViews() { mLimiterViews.removeAllViews(); Limiter limiterData = mPagerAdapter.getCurrentLimiter(); if (limiterData != null) { String[] limiter = limiterData.names; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.leftMargin = 5; for (int i = 0; i != limiter.length; ++i) { PaintDrawable background = new PaintDrawable(Color.GRAY); background.setCornerRadius(5); TextView view = new TextView(this); view.setSingleLine(); view.setEllipsize(TextUtils.TruncateAt.MARQUEE); view.setText(limiter[i] + " | X"); view.setTextColor(Color.WHITE); view.setBackgroundDrawable(background); view.setLayoutParams(params); view.setPadding(5, 2, 5, 2); view.setTag(i); view.setOnClickListener(this); mLimiterViews.addView(view); } mLimiterScroller.setVisibility(View.VISIBLE); } else { mLimiterScroller.setVisibility(View.GONE); } }
From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java
/** * Create or recreate the limiter breadcrumbs. *//*w w w. ja v a 2 s.c om*/ public void updateLimiterViews() { mLimiterViews.removeAllViews(); Limiter limiterData = mPagerAdapter.getCurrentLimiter(); if (limiterData != null) { String[] limiter = limiterData.names; LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.leftMargin = 5; for (int i = 0; i != limiter.length; ++i) { int color = (i + 1 == limiter.length ? 0xFFA0A0A0 : 0xFFC0C0C0); PaintDrawable background = new PaintDrawable(color); background.setCornerRadius(0); TextView view = new TextView(this); view.setSingleLine(); view.setEllipsize(TextUtils.TruncateAt.MARQUEE); view.setText(limiter[i]); view.setTextColor(Color.WHITE); view.setBackgroundDrawable(background); view.setLayoutParams(params); view.setPadding(14, 6, 14, 6); view.setTag(i); view.setOnClickListener(this); mLimiterViews.addView(view); } mLimiterScroller.setVisibility(View.VISIBLE); } else { mLimiterScroller.setVisibility(View.GONE); } }
From source file:com.example.appdetail_optimization.PagerSlidingTabStrip.java
@SuppressWarnings("deprecation") private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/*w w w. jav a 2s . c o m*/ tab.setGravity(Gravity.CENTER); tab.setPadding(0, 0, 0, 0); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); tab.setMaxWidth(width / tabCount - tabPadding * 2); tab.setEllipsize(TruncateAt.END); tab.setSingleLine(); addTab(position, tab); }
From source file:net.ibaixin.chat.view.PagerSlidingTabStrip.java
/** * tab/* w w w. j a v a 2 s.co m*/ * @update 2015128 ?9:58:54 * @param position * @param title */ private void addTextTab(final int position, CharSequence title) { //layout RelativeLayout tabLayout = new RelativeLayout(getContext()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); tabLayout.setLayoutParams(layoutParams); RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); textParams.addRule(RelativeLayout.CENTER_IN_PARENT); //tab TextView tab = new TextView(getContext()); tab.setId(100 + position); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tabLayout.addView(tab, textParams); //??? RelativeLayout.LayoutParams viewParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); viewParams.addRule(RelativeLayout.RIGHT_OF, tab.getId()); viewParams.addRule(RelativeLayout.CENTER_VERTICAL); View view = new View(getContext()); ViewGroup.LayoutParams vParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(vParams); tabLayout.addView(view, viewParams); addTab(position, tabLayout); }
From source file:com.example.wechatsample.utils.widget.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); // final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm); // params.setMargins(0, 255, 0, 255); tab.setLayoutParams(params);//from w w w. j a va 2 s . com tab.setLayoutParams(params); tab.setPadding(tabPadding, 0, tabPadding, 0); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); addTab(position, tab); }
From source file:org.nla.tarotdroid.lib.ui.GameSetSynthesisFragment.java
/** * Refreshes the stats rows on the synthesis view. *//* ww w . ja v a 2 s.co m*/ protected void refreshPlayerStatsRows() { // sort players List<Player> sortedPlayers = this.getGameSet().getPlayers().getPlayers(); Collections.sort(sortedPlayers, new PlayerScoreComparator()); // get general data sources IGameSetStatisticsComputer gameSetStatisticsComputer = GameSetStatisticsComputerFactory .GetGameSetStatisticsComputer(this.getGameSet(), "guava"); MapPlayersScores lastScores = this.getGameSet().getGameSetScores().getResultsAtLastGame(); Map<Player, Integer> leadingCount = gameSetStatisticsComputer.getLeadingCount(); Map<Player, Integer> leadingSuccesses = gameSetStatisticsComputer.getLeadingSuccessCount(); Map<Player, Integer> calledCount = gameSetStatisticsComputer.getCalledCount(); int minScoreEver = gameSetStatisticsComputer.getMinScoreEver(); int maxScoreEver = gameSetStatisticsComputer.getMaxScoreEver(); // format statistics lines for (int rank = 0; rank < sortedPlayers.size(); ++rank) { // get player specific data sources Player player = sortedPlayers.get(rank); int lastScore = lastScores == null ? 0 : lastScores.get(player); int successfulLeadingGamesCount = leadingSuccesses.get(player) == null ? 0 : leadingSuccesses.get(player).intValue(); int leadingGamesCount = leadingCount.get(player) == null ? 0 : leadingCount.get(player); int successRate = (int) (((double) successfulLeadingGamesCount) / ((double) leadingGamesCount) * 100.0); int minScoreForPlayer = gameSetStatisticsComputer.getMinScoreEverForPlayer(player); int maxScoreForPlayer = gameSetStatisticsComputer.getMaxScoreEverForPlayer(player); // get line widgets LinearLayout statRow = this.statsRows.get(rank + 1); //TextView statPlayerName = (TextView)statRow.findViewById(R.id.statPlayerName); TextView statScore = (TextView) statRow.findViewById(R.id.statScore); TextView statLeadingGamesCount = (TextView) statRow.findViewById(R.id.statLeadingGamesCount); TextView statSuccessfulGamesCount = (TextView) statRow.findViewById(R.id.statSuccessfulGamesCount); TextView statMinScore = (TextView) statRow.findViewById(R.id.statMinScore); TextView statMaxScore = (TextView) statRow.findViewById(R.id.statMaxScore); // Bitmap playerImage = null; // if (player.getPictureUri() != null && !player.getPictureUri().equals("")) { // playerImage = UIHelper.getPlayerImage(this.getActivity(), player); // } // // // // assign values to widgets // if (player.getFacebookId() != null) { // // player facebook image // ProfilePictureView pictureView = new ProfilePictureView(this.getActivity()); // pictureView.setProfileId(player.getFacebookId()); // pictureView.setPresetSize(ProfilePictureView.SMALL); // //pictureView.setOnClickListener(playerClickListener); // pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); // statRow.removeViewAt(0); // statRow.addView(pictureView, 0); // } // else { // // WARNING: The properties below reference the style ScoreTextStyle, but we can't set a style at runtime. // TextView playerName = new TextView(this.getActivity()); // playerName.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1)); // playerName.setGravity(Gravity.CENTER); // playerName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); // playerName.setEllipsize(TruncateAt.END); // playerName.setSingleLine(); // playerName.setTextColor(Color.WHITE); // playerName.setTypeface(null, Typeface.BOLD); // playerName.setText(player.getName()); // //playerName.setBackgroundResource(R.drawable.border_player_white); // statRow.removeViewAt(0); // statRow.addView(playerName, 0); // } OnClickListener playerClickListener = new PlayerClickListener(player); // facebook picture if (player.getFacebookId() != null) { ProfilePictureView pictureView = new ProfilePictureView(this.getActivity()); pictureView.setProfileId(player.getFacebookId()); pictureView.setPresetSize(ProfilePictureView.SMALL); pictureView.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); pictureView.setOnClickListener(playerClickListener); //this.addView(pictureView); statRow.removeViewAt(0); statRow.addView(pictureView, 0); } // contact picture else if (player.getPictureUri() != null && player.getPictureUri().toString().contains("content://com.android.contacts/contacts")) { Bitmap playerImage = UIHelper.getContactPicture(this.getActivity(), Uri.parse(player.getPictureUri()).getLastPathSegment()); ImageView imgPlayer = new ImageView(this.getActivity()); imgPlayer.setImageBitmap(playerImage); imgPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); imgPlayer.setOnClickListener(playerClickListener); //this.addView(imgPlayer); statRow.removeViewAt(0); statRow.addView(imgPlayer, 0); } // no picture, only name else { TextView txtPlayer = new TextView(this.getActivity()); txtPlayer.setText(player.getName()); txtPlayer.setGravity(Gravity.CENTER); txtPlayer.setLayoutParams(UIConstants.PLAYERS_LAYOUT_PARAMS); txtPlayer.setMinWidth(UIConstants.PLAYER_VIEW_WIDTH); txtPlayer.setHeight(UIConstants.PLAYER_VIEW_HEIGHT); txtPlayer.setBackgroundColor(Color.TRANSPARENT); txtPlayer.setTypeface(null, Typeface.BOLD); txtPlayer.setTextColor(Color.WHITE); txtPlayer.setSingleLine(); txtPlayer.setEllipsize(TruncateAt.END); txtPlayer.setOnClickListener(playerClickListener); //this.addView(txtPlayer); statRow.removeViewAt(0); statRow.addView(txtPlayer, 0); } statScore.setText(Integer.toString(lastScore)); statLeadingGamesCount.setText(Integer.toString(leadingGamesCount)); statSuccessfulGamesCount.setText( Integer.toString(successfulLeadingGamesCount) + " (" + Integer.toString(successRate) + "%)"); // display called game count if necessary if (this.getGameSet().getGameStyleType() == GameStyleType.Tarot5) { TextView statCalledGamesCount = (TextView) statRow.findViewById(R.id.statCalledGamesCount); statCalledGamesCount .setText(Integer.toString(calledCount.get(player) == null ? 0 : calledCount.get(player))); } statMinScore.setText(Integer.toString(minScoreForPlayer)); statMaxScore.setText(Integer.toString(maxScoreForPlayer)); statMinScore.setTextColor(Color.WHITE); statMaxScore.setTextColor(Color.WHITE); // color min score if lowest if (minScoreEver == minScoreForPlayer) { statMinScore.setTextColor(Color.YELLOW); } // color max score if highest if (maxScoreEver == maxScoreForPlayer) { statMaxScore.setTextColor(Color.GREEN); } } }
From source file:com.example.fragmentdemo.views.PagerSlidingTabStrip.java
private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId, int iIconLocation) { // final View tabView = ((Activity) getContext()).getLayoutInflater() // .inflate(iLayoutResId, null); // TextView tab_text_textview = (TextView) // tabView.findViewById(iTextId); // tab_text_textview.setText(title); LinearLayout tabView = new LinearLayout(getContext()); tabView.setGravity(Gravity.CENTER);//www . j ava 2 s . c o m TextView tab_text_textview = new TextView(getContext()); tab_text_textview.setId(position); tab_text_textview.setText(title); tab_text_textview.setGravity(Gravity.CENTER_VERTICAL); tab_text_textview.setSingleLine(); // tab_text_textview.setTextColor(tabTextColor); // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color)); XmlPullParser xrp = getResources().getXml(tabTextColor); try { ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp); if (tab_text_textview != null) { tab_text_textview.setTextColor(csl); } } catch (Exception e) { } tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle); LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (iconResId != 0) { // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds( // iconResId, 0, 0, 0); // Drawable mDrawable = ((Activity) getContext()).getResources() // .getDrawable(iconResId); // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(), // mDrawable.getMinimumHeight()); int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding); ImageView icon = new ImageView(getContext()); icon.setImageResource(iconResId); icon.setScaleType(ScaleType.CENTER_INSIDE); LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, iIconHeight); switch (iIconLocation) { case 1: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 2: // tab_text_textview.setCompoundDrawables(null, mDrawable, null, // null); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(icon, lpImage); lpText.topMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 3: // tab_text_textview.setCompoundDrawables(null, null, mDrawable, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(tab_text_textview, lpText); lpImage.leftMargin = iPandding; tabView.addView(icon, lpImage); break; case 4: // tab_text_textview.setCompoundDrawables(null, null, null, // mDrawable); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(tab_text_textview, lpText); lpImage.topMargin = iPandding; tabView.addView(icon, lpImage); break; default: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; } // tab_text_textview // .setCompoundDrawablePadding((int) ((Activity) getContext()) // .getResources() // .getDimension(R.dimen.common_padding)); } else { tabView.addView(tab_text_textview, lpText); } tabView.setFocusable(true); tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0); tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:com.wangbb.naruto.app.view.PagerSlidingTabStrip.java
private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId, int iIconLocation) { // final View tabView = ((Activity) getContext()).getLayoutInflater() // .inflate(iLayoutResId, null); // TextView tab_text_textview = (TextView) // tabView.findViewById(iTextId); // tab_text_textview.setText(title); LinearLayout tabView = new LinearLayout(getContext()); tabView.setGravity(Gravity.CENTER);//from w ww . j a va2 s .com TextView tab_text_textview = new TextView(getContext()); tab_text_textview.setId(position); tab_text_textview.setText(title); tab_text_textview.setGravity(Gravity.CENTER_VERTICAL); tab_text_textview.setSingleLine(); // tab_text_textview.setTextColor(tabTextColor); // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color)); // XmlPullParser xrp = getResources().getXml(tabTextColor); // try { // ColorStateList csl = ColorStateList.createFromXml(getResources(), // xrp); // if (tab_text_textview != null) { tab_text_textview.setTextColor(tabTextColor); // } // } catch (Exception e) { // // } tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle); LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (iconResId != 0) { // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds( // iconResId, 0, 0, 0); // Drawable mDrawable = ((Activity) getContext()).getResources() // .getDrawable(iconResId); // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(), // mDrawable.getMinimumHeight()); int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding); ImageView icon = new ImageView(getContext()); icon.setImageResource(iconResId); icon.setScaleType(ScaleType.CENTER_INSIDE); LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, iIconHeight); switch (iIconLocation) { case 1: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 2: // tab_text_textview.setCompoundDrawables(null, mDrawable, null, // null); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(icon, lpImage); lpText.topMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; case 3: // tab_text_textview.setCompoundDrawables(null, null, mDrawable, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(tab_text_textview, lpText); lpImage.leftMargin = iPandding; tabView.addView(icon, lpImage); break; case 4: // tab_text_textview.setCompoundDrawables(null, null, null, // mDrawable); tabView.setOrientation(LinearLayout.VERTICAL); // tabView.setGravity(Gravity.CENTER_HORIZONTAL); tabView.addView(tab_text_textview, lpText); lpImage.topMargin = iPandding; tabView.addView(icon, lpImage); break; default: // tab_text_textview.setCompoundDrawables(mDrawable, null, null, // null); tabView.setOrientation(LinearLayout.HORIZONTAL); // tabView.setGravity(Gravity.CENTER_VERTICAL); tabView.addView(icon, lpImage); lpText.leftMargin = iPandding; tabView.addView(tab_text_textview, lpText); break; } // tab_text_textview // .setCompoundDrawablePadding((int) ((Activity) getContext()) // .getResources() // .getDimension(R.dimen.common_padding)); } else { tabView.addView(tab_text_textview, lpText); } tabView.setFocusable(true); tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); } }); // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0); tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:com.xda.one.ui.widget.TabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set * via/*from w w w. j av a 2 s . c o m*/ * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); // Modified for XDA One final TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.textAppearanceSmallInverse, typedValue, true); textView.setTextAppearance(getContext(), typedValue.resourceId); getContext().getTheme().resolveAttribute(android.R.attr.textColorPrimaryInverse, typedValue, true); textView.setTextColor(getResources().getColor(typedValue.resourceId)); textView.setTypeface(null, Typeface.BOLD); // Customized for app textView.setLayoutParams( new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f / mViewPager.getAdapter().getCount())); textView.setSingleLine(); AutofitHelper.create(textView); // Modified for XDA One getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true); textView.setBackgroundResource(typedValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.yktx.check.widget.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = null; if (position == 3) {//? view2 = LayoutInflater.from(getContext()).inflate(R.layout.pagerslidingtabstip_text, null); text2 = (TextView) view2.findViewById(R.id.text); image2 = (ImageView) view2.findViewById(R.id.image); // badgeView = new BadgeView(getContext(), text2); addTab(position, view2);/* www .j a va 2 s . c o m*/ } else { tab = new TextView(getContext()); tab.setText(title); tab.setSingleLine(); tab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); tab.setGravity(Gravity.CENTER); addTab(position, tab); } }