Java Code Examples for android.widget.TextView#setTextSize()

The following examples show how to use android.widget.TextView#setTextSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public Object instantiateItem(ViewGroup container, final int position) {
	TextView text = new TextView(JazzyViewActivity.this);
	text.setGravity(Gravity.CENTER);
	text.setTextSize(30);
	text.setTextColor(Color.WHITE);
	text.setText("Page " + position);
	text.setPadding(30, 30, 30, 30);
	int bg = Color.rgb((int) Math.floor(Math.random()*128)+64, 
			(int) Math.floor(Math.random()*128)+64,
			(int) Math.floor(Math.random()*128)+64);
	text.setBackgroundColor(bg);
	container.addView(text, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
	mJazzy.setObjectForPosition(text, position);
	return text;
}
 
Example 2
@Override
protected void initWidgets() {
    super.initWidgets();
    mFeedsListView.setFooterDividersEnabled(false);
    // 隐藏发送跟设置按钮
    mPostBtn.setVisibility(View.GONE);
    mRootView.findViewById(ResFinder.getId("umeng_comm_title_setting_btn")).setVisibility(
            View.GONE);
    // 将标题改为朋友圈
    TextView titleTextView = (TextView) mRootView.findViewById(ResFinder
            .getId("umeng_comm_title_tv"));
    titleTextView.setText(ResFinder.getString("umeng_comm_recommend_friends"));
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);

    // 处理返回事件,显示发现页面
    mRootView.findViewById(ResFinder.getId("umeng_comm_title_back_btn")).setOnClickListener(
            new OnClickListener() {

                @Override
                public void onClick(View v) {
                    mListener.onResult(0);
                }
            });

    mBaseView = (BaseView) mRootView.findViewById(ResFinder.getId("umeng_comm_baseview"));
}
 
Example 3
Source Project: imsdk-android   File: SegmentTabLayout.java    License: MIT License 6 votes vote down vote up
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }
        }
    }
 
Example 4
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if (getArguments() != null) {
        mTitle = getArguments().getString(TITLE);
    }

    TextView tv = new TextView(getActivity());
    tv.setTextSize(50);
    tv.setTextColor(Color.parseColor("#ff000000"));
    tv.setBackgroundColor(Color.parseColor("#ffffffff"));
    tv.setText(mTitle);
    tv.setGravity(Gravity.CENTER);
    return tv;

}
 
Example 5
@Override
protected View onCreateDialogView() {

    LinearLayout.LayoutParams params;
    LinearLayout layout = new LinearLayout(mContext);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(6, 6, 6, 6);

    TextView mSplashText = new TextView(mContext);
    mSplashText.setPadding(72, 10, 30, 10);
    if (mDialogMessage != null)
        mSplashText.setText(mDialogMessage);
    layout.addView(mSplashText);

    mValueText = new TextView(mContext);
    mValueText.setGravity(Gravity.CENTER_HORIZONTAL);
    mValueText.setTextSize(32);
    params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.addView(mValueText, params);

    mSeekBar = new SeekBar(mContext);
    mSeekBar.setOnSeekBarChangeListener(this);
    layout.addView(mSeekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

    if (shouldPersist())
        mValue = getPersistedInt(mDefault);

    mSeekBar.setMax(mMax);
    mSeekBar.setProgress(mValue);

    return layout;
}
 
Example 6
Source Project: RunMap   File: ReviewActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void showEmptyView() {
    TextView textView = new TextView(ReviewActivity.this);
    textView.setText(R.string.string_empty_tips);
    textView.setTextSize(30);
    textView.setBackgroundColor(Color.WHITE);
    textView.setGravity(Gravity.CENTER);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    textView.setLayoutParams(lp);
    ((ViewGroup)(findViewById(android.R.id.content))).addView(textView);
}
 
Example 7
public View getView(int position, View convertView, ViewGroup parent) {
  LinearLayout ll = new LinearLayout(context);
  ll.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));
  ll.setMinimumHeight(50);
  ll.setOrientation(LinearLayout.HORIZONTAL);
  ll.setGravity(Gravity.CENTER_VERTICAL);

  ImageView iv = new ImageView(context);
  iv.setImageResource(attributes.get(position).getIconResId());
  iv.setAdjustViewBounds(true);
  iv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT,
      LayoutParams.WRAP_CONTENT));
  if (listView.getCheckedItemPosition() == position) {
    iv.setBackgroundResource(R.drawable.icon_hilight);
  }

  TextView tv = new TextView(context);
  tv.setText(attributes.get(position).getDescriptionShort());
  tv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
      LayoutParams.FILL_PARENT));
  tv.setGravity(Gravity.CENTER_VERTICAL);
  tv.setPadding(10, 0, 0, 0);
  tv.setTextSize(14.0f);
  tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
  tv.setTextColor(0xFFFFFFFF);
  tv.setMinHeight(46);

  ll.addView(iv);
  ll.addView(tv);

  return ll;
}
 
Example 8
public void updateCounter(int position, int count, boolean allMuted)
{
    RelativeLayout frame = (RelativeLayout) tabsContainer.getChildAt(position);
    if (frame != null && frame.getChildCount() > 1)
    {
        TextView tv = (TextView) frame.getChildAt(1);
        if (tv != null)
        {
            if (count > 0 && !FeaturedSettings.tabSettings.hideTabsCounters)
            {
                tv.setVisibility(VISIBLE);
                tv.setText(count >= 10000 && FeaturedSettings.tabSettings.limitTabsCounters ? "+9999" : String.format(Locale.getDefault(), "%d", count));
                tv.getBackground().setColorFilter(allMuted ?
                        Theme.getColor(Theme.key_chats_unreadCounterMuted) :
                        Theme.getColor(Theme.key_chats_unreadCounter), PorterDuff.Mode.SRC_IN);
            }
            else
            {
                tv.setVisibility(INVISIBLE);
            }

            tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
            tv.setTextColor(Theme.getColor(Theme.key_chats_unreadCounterText));
            tv.setPadding(AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0,
                    AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0);
        }
    }
}
 
Example 9
private View getItemView(int position){
    TextView textView = new TextView(mContext);
    textView.setTextAppearance(mContext, R.style.switcher_item_text_style);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            DensityUtil.dip2px(mContext,35));
    textView.setLayoutParams(layoutParams);
    textView.setSelected(position == mDefaultSelection);
    textView.setGravity(Gravity.CENTER);
    textView.setText(mAllItemArray.get(position));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12.0f);
    textView.setOnClickListener(mItemOnClickListener);
    textView.setTag(position);
    return textView;
}
 
Example 10
public AlbumView(Context context) {
    super(context);

    imageView = new BackupImageView(context);
    addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setBackgroundColor(0x7f000000);
    addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));

    nameTextView = new TextView(context);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setMaxLines(1);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 0));

    countTextView = new TextView(context);
    countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    countTextView.setTextColor(0xffaaaaaa);
    countTextView.setSingleLine(true);
    countTextView.setEllipsize(TextUtils.TruncateAt.END);
    countTextView.setMaxLines(1);
    countTextView.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(countTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 4, 0));

    selector = new View(context);
    selector.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
 
Example 11
public AlbumView(Context context) {
    super(context);

    imageView = new BackupImageView(context);
    addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setBackgroundResource(R.drawable.album_shadow);
    addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 60, Gravity.LEFT | Gravity.BOTTOM));

    nameTextView = new TextView(context);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    nameTextView.setTextColor(0xffffffff);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setMaxLines(1);
    nameTextView.setGravity(Gravity.BOTTOM);
    linearLayout.addView(nameTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 8, 0, 0, 5));

    countTextView = new TextView(context);
    countTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    countTextView.setTextColor(0xffffffff);
    countTextView.setSingleLine(true);
    countTextView.setEllipsize(TextUtils.TruncateAt.END);
    countTextView.setMaxLines(1);
    countTextView.setGravity(Gravity.BOTTOM);
    linearLayout.addView(countTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 4, 0, 7, 5));

    selector = new View(context);
    selector.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
 
Example 12
Source Project: box-android-sdk   File: BoxAvatarView.java    License: Apache License 2.0 5 votes vote down vote up
public BoxAvatarView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final LayoutInflater inflater = LayoutInflater.from(context);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BoxAvatarView,
            defStyleAttr, 0);
    View view = inflater.inflate(R.layout.boxsdk_avatar_item, this, true);
    mInitials = (TextView)view.findViewById(R.id.box_avatar_initials);
    int size = a.getInteger(R.styleable.BoxAvatarView_avatarTextSize, 0);
    if (size != 0) {
        mInitials.setTextSize(TypedValue.COMPLEX_UNIT_SP, size); //allow passing custom textSize in case user want to change textSize
    }
    mAvatar = (ImageView)view.findViewById(R.id.box_avatar_image);

}
 
Example 13
private void text(TextView view, String str) {
    if (null != view && !TextUtils.isEmpty(str)) {
        view.setText(str);
        view.setTextColor(mTextColor);
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
}
 
Example 14
Source Project: shift   File: SlidingTabLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    final float density = getResources().getDisplayMetrics().density;
    int padding = (int) (TAB_VIEW_PADDING_DIPS * density);
    textView.setPadding(padding, padding, padding, padding);
    textView.setWidth(widthPixels / 3);

    return textView;
}
 
Example 15
public PRTHeader(Context context) {
	super(context);
	setOrientation(VERTICAL);

	LinearLayout llInner = new LinearLayout(context);
	LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpInner.gravity = Gravity.CENTER_HORIZONTAL;
	addView(llInner, lpInner);

	ivArrow = new RotateImageView(context);
	int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr");
	if (resId > 0) {
		ivArrow.setImageResource(resId);
	}
	int dp_32 = dipToPx(context, 32);
	LayoutParams lpIv = new LayoutParams(dp_32, dp_32);
	lpIv.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(ivArrow, lpIv);

	pbRefreshing = new ProgressBar(context);
	llInner.addView(pbRefreshing, lpIv);
	pbRefreshing.setVisibility(View.GONE);

	tvHeader = new TextView(getContext());
	tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
	tvHeader.setGravity(Gravity.CENTER);
	int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
	tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10);
	tvHeader.setTextColor(0xff000000);
	LayoutParams lpTv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpTv.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(tvHeader, lpTv);
}
 
Example 16
public void showTable() {
    TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(
            TableRow.LayoutParams.MATCH_PARENT,
            TableRow.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;
    layoutParams.leftMargin = 30;
    layoutParams.bottomMargin = 10;
    layoutParams.topMargin = 10;

    for (int i = 0; i < 40; i++) {
        TableRow tableRow = new TableRow(this);
        TextView textView = new TextView(this);
        textView.setText("Test stretch scroll view " + i);
        textView.setTextSize(20);
        textView.setPadding(15, 15, 15, 15);

        tableRow.addView(textView, layoutParams);
        if (i % 2 != 0) {
            tableRow.setBackgroundColor(Color.LTGRAY);
        } else {
            tableRow.setBackgroundColor(Color.WHITE);
        }

        final int n = i;
        tableRow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(StretchViewActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show();
            }
        });

        mMainLayout.addView(tableRow);
    }
}
 
Example 17
public DialogsEmptyCell(Context context) {
    super(context);

    setGravity(Gravity.CENTER);
    setOrientation(VERTICAL);
    setOnTouchListener((v, event) -> true);

    imageView = new RLottieImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(imageView, LayoutHelper.createFrame(100, 100, Gravity.CENTER, 52, 4, 52, 0));
    imageView.setOnClickListener(v -> {
        if (!imageView.isPlaying()) {
            imageView.setProgress(0.0f);
            imageView.playAnimation();
        }
    });

    emptyTextView1 = new TextView(context);
    emptyTextView1.setTextColor(Theme.getColor(Theme.key_chats_nameMessage_threeLines));
    emptyTextView1.setText(LocaleController.getString("NoChats", R.string.NoChats));
    emptyTextView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    emptyTextView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    emptyTextView1.setGravity(Gravity.CENTER);
    addView(emptyTextView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 10, 52, 0));

    emptyTextView2 = new TextView(context);
    String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp);
    if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) {
        help = help.replace('\n', ' ');
    }
    emptyTextView2.setText(help);
    emptyTextView2.setTextColor(Theme.getColor(Theme.key_chats_message));
    emptyTextView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    emptyTextView2.setGravity(Gravity.CENTER);
    emptyTextView2.setLineSpacing(AndroidUtilities.dp(2), 1);
    addView(emptyTextView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 7, 52, 0));
}
 
Example 18
Source Project: BmapLite   File: SearchActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void initView(int layoutID) {
    super.initView(layoutID);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (null != getSupportActionBar()) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mCheckNearby = getView(R.id.check_nearby);
    mEditSearch = getView(R.id.edit_search);
    mGridHot = getView(R.id.grid_hot);
    mListResult = getView(R.id.list_result);
    mListHistory = getView(R.id.list_history);
    mLayMyCity = getView(R.id.lay_my_city);
    mTextCity = getView(R.id.text_city);
    mRecycleCity = getView(R.id.recycler_city);

    TextView textHeader = new TextView(this);
    textHeader.setText("历史记录");
    textHeader.setPadding(AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10));
    textHeader.setTextColor(Color.parseColor("#999999"));
    textHeader.setTextSize(12);
    Drawable drawable = getResources().getDrawable(R.drawable.ic_history_18dp);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    textHeader.setCompoundDrawables(drawable, null, null, null);
    textHeader.setCompoundDrawablePadding(AppUtils.dip2Px(this, 5));
    mListHistory.addHeaderView(textHeader, null, false);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecycleCity.setLayoutManager(layoutManager);

    mTextCity.setOnClickListener(this);
    mEditSearch.setOnEditorActionListener(this);
    mEditSearch.addTextChangedListener(this);
    mListResult.setOnLoadMoreListener(this);
    mListResult.setOnItemClickListener(this);
    mListHistory.setOnItemClickListener(this);
    mGridHot.setOnItemClickListener(this);
    mCheckNearby.setOnClickListener(this);
}
 
Example 19
Source Project: SprintNBA   File: NormalListDialog.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final DialogMenuItem item = mContents.get(position);

    LinearLayout llItem = new LinearLayout(mContext);
    llItem.setOrientation(LinearLayout.HORIZONTAL);
    llItem.setGravity(Gravity.CENTER_VERTICAL);

    ImageView ivItem = new ImageView(mContext);
    ivItem.setPadding(0, 0, dp2px(15), 0);
    llItem.addView(ivItem);

    TextView tvItem = new TextView(mContext);
    tvItem.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    tvItem.setSingleLine(true);
    tvItem.setTextColor(mItemTextColor);
    tvItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, mItemTextSize);

    llItem.addView(tvItem);
    float radius = dp2px(mCornerRadius);
    if (mIsTitleShow) {
        llItem.setBackgroundDrawable((CornerUtils.listItemSelector(radius, Color.TRANSPARENT, mItemPressColor,
                position == mContents.size() - 1)));
    } else {
        llItem.setBackgroundDrawable(CornerUtils.listItemSelector(radius, Color.TRANSPARENT, mItemPressColor,
                mContents.size(), position));
    }

    int left = item.mResId == 0 ? dp2px(18) : dp2px(16);
    int top = dp2px(10);
    int right = 0;
    int bottom = dp2px(10);
    llItem.setPadding(left + mItemExtraLeft, top + mItemExtraTop, right + mItemExtraRight, bottom + mItemExtraBottom);

    ivItem.setImageResource(item.mResId);
    tvItem.setText(item.mOperName);
    ivItem.setVisibility(item.mResId == 0 ? View.GONE : View.VISIBLE);

    return llItem;
}
 
Example 20
Source Project: settlers-remake   File: AndroidTextDrawer.java    License: MIT License 4 votes vote down vote up
private int findLineFor(String string) {
	int line = findExistingString(string);
	if (line >= 0) {
		return line;
	}

	int width = (int) Math.ceil(computeWidth(string) + 25);
	renderer = new TextView(context.getAndroidContext());
	renderer.setTextColor(Color.WHITE);
	renderer.setSingleLine(true);
	renderer.setTextSize(TypedValue.COMPLEX_UNIT_PX, getScaledSize());
	renderer.setText(string);

	int firstLine = findLineToUse();
	// System.out.println("string cache miss for " + string +
	// ", allocating new line: " + firstLine);
	int lastLine = firstLine;

	for (int x = 0; x < width; x += TEXTURE_WIDTH) {
		if (x == 0) {
			line = firstLine;
		} else {
			line = findLineToUse();
			nextTile[lastLine] = line;
			linestrings[line] = null;
			linewidths[line] = -1;
		}
		// important to not allow cycles.
		lastused[line] = Integer.MAX_VALUE;
		// just to be sure.
		nextTile[line] = -1;

		// render the new text to that line.
		Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, lineheight, Bitmap.Config.ALPHA_8);
		Canvas canvas = new Canvas(bitmap);
		renderer.layout(0, 0, width, lineheight);
		canvas.translate(-x, 0);
		renderer.draw(canvas);
		// canvas.translate(50, .8f * lineheight);
		int points = lineheight * TEXTURE_WIDTH;
		ByteBuffer alpha8 = ByteBuffer.allocateDirect(points);
		bitmap.copyPixelsToBuffer(alpha8);
		ByteBuffer updateBuffer;
		if(context instanceof GLES20DrawContext) {
			updateBuffer = ByteBuffer.allocateDirect(points*4);
			for(int i = 0;i != points;i++) {
				updateBuffer.putInt(0xFFFFFF00|alpha8.get(i));
			}
		} else {
			updateBuffer = alpha8;
		}
		updateBuffer.rewind();
		context.updateFontTexture(texture, 0, line*lineheight, TEXTURE_WIDTH, lineheight, updateBuffer);
		lastLine = line;
	}
	lastused[firstLine] = lastUsedCount++;
	linestrings[firstLine] = string;
	linewidths[firstLine] = width;

	checkInvariants();
	return firstLine;
}