android.util.TypedValue Java Examples

The following examples show how to use android.util.TypedValue. 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
Source File: EditPage.java    From Huochexing12306 with Apache License 2.0 6 votes vote down vote up
private LinearLayout getBodyBottom() {
	LinearLayout llBottom = new LinearLayout(getContext());
	llBottom.setLayoutParams(new LinearLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	String platform = String.valueOf(reqData.get("platform"));
	LinearLayout line = getAtLine(platform);
	if (line != null) {
		llBottom.addView(line);
	}

	// 字数统计
	tvCounter = new TextView(getContext());
	tvCounter.setText(String.valueOf(MAX_TEXT_COUNT));
	tvCounter.setTextColor(0xffcfcfcf);
	tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
	tvCounter.setTypeface(Typeface.DEFAULT_BOLD);
	LinearLayout.LayoutParams lpCounter = new LinearLayout.LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpCounter.gravity = Gravity.CENTER_VERTICAL;
	tvCounter.setLayoutParams(lpCounter);
	llBottom.addView(tvCounter);

	return llBottom;
}
 
Example #2
Source File: MessageActivity.java    From toktok-android with GNU General Public License v3.0 6 votes vote down vote up
private void startOverLayFriend() {
    SlideInContactsLayout overlayContactsLayout = (SlideInContactsLayout) getLayoutInflater().inflate(
            R.layout.overlay_contacts, null, false);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
                    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
            PixelFormat.TRANSLUCENT
    );
    getWindowManager().addView(overlayContactsLayout, params);

    TypedValue tv = new TypedValue();
    int actionBarHeight =
            getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true) ?
                    TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()) : 0;

    overlayContactsLayout.start(this, Friend.lorem, actionBarHeight);
}
 
Example #3
Source File: FragmentAccountCreate.java    From Ecommerce-Morningmist-Android with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@Override
public void formatUI() {
	// TODO Auto-generated method stub
	tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TITLE));

	tvEmail.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	editEmail.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	tvPassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	tvRepassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	editPassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	editRepassword.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));

	butSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, (int) (MainActivity.TEXT_SIZE_TILE));
	butSave.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.dark_shadow_background));
	butSave.setPadding(MainActivity.SPACING/2, MainActivity.SPACING/2, MainActivity.SPACING/2, MainActivity.SPACING/2);

	editPassword.setEnabled(false);
	editPassword.setBackgroundColor(getResources().getColor(R.color.light_gray));
	editRepassword.setEnabled(false);
	editRepassword.setBackgroundColor(getResources().getColor(R.color.light_gray));
}
 
Example #4
Source File: GifTextureView.java    From android-gif-drawable-eclipse-sample with MIT License 6 votes vote down vote up
private static InputSource findSource(final TypedArray textureViewAttributes) {
    final TypedValue value = new TypedValue();
    if (!textureViewAttributes.getValue(R.styleable.GifTextureView_gifSource, value)) {
        return null;
    }

    if (value.resourceId != 0) {
        final String type = textureViewAttributes.getResources().getResourceTypeName(value.resourceId);
        if ("drawable".equals(type) || "raw".equals(type)) {
            return new InputSource.ResourcesSource(textureViewAttributes.getResources(), value.resourceId);
        } else if (!"string".equals(type)) {
            throw new IllegalArgumentException("Expected string, drawable or raw resource, type " + type + " " +
                    "cannot be converted to GIF");
        }
    }
    return new InputSource.AssetSource(textureViewAttributes.getResources().getAssets(), value.string.toString());
}
 
Example #5
Source File: SearchView.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
/**
 * For a given suggestion and a given cursor row, get the action message. If
 * not provided by the specific row/column, also check for a single
 * definition (for the action key).
 *
 * @param c The cursor providing suggestions
 * @param actionKey The actionkey record being examined
 *
 * @return Returns a string, or null if no action key message for this
 *         suggestion
 */
// TODO private static String getActionKeyMessage(Cursor c, SearchableInfo.ActionKeyInfo actionKey) {
// TODO     String result = null;
// TODO     // check first in the cursor data, for a suggestion-specific message
// TODO     final String column = actionKey.getSuggestActionMsgColumn();
// TODO     if (column != null) {
// TODO         result = SuggestionsAdapter.getColumnString(c, column);
// TODO     }
// TODO     // If the cursor didn't give us a message, see if there's a single
// TODO     // message defined
// TODO     // for the actionkey (for all suggestions)
// TODO     if (result == null) {
// TODO         result = actionKey.getSuggestActionMsg();
// TODO     }
// TODO     return result;
// TODO }

private int getSearchIconId() {
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.searchViewSearchIcon,
            outValue, true);
    return outValue.resourceId;
}
 
Example #6
Source File: Utils.java    From PersianDateRangePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the colorAccent from the current context, if possible/available
 *
 * @param context
 * @return -1 if accent color invalid, otherwise the accent color of the current context
 */
public static int getAccentColorFromThemeIfAvailable(Context context) {
  TypedValue typedValue = new TypedValue();
  //First, try the android:colorAccent
  if (Build.VERSION.SDK_INT >= 21) {
    context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true);
    return typedValue.data;
  }
  //Next, try colorAccent from support lib
  int colorAccentResId = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName());
  if (colorAccentResId == 0) {
    return -1;
  }

  if (!context.getTheme().resolveAttribute(colorAccentResId, typedValue, true)) {
    return -1;
  }
  return typedValue.data;
}
 
Example #7
Source File: CardFragment.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
            .getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.CENTER);
    v.setBackgroundResource(R.drawable.background_card);
    v.setText("CARD " + (position + 1));

    fl.addView(v);
    return fl;
}
 
Example #8
Source File: IRCColorUtils.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public static void loadColors(Resources.Theme theme, int resId) {
    TypedArray ta = theme.obtainStyledAttributes(resId, R.styleable.IRCColors);
    sColorValues = new int[R.styleable.IRCColors.length];
    for (int i = 0; i < sColorValues.length; i++) {
        try {
            int j = i;
            TypedValue tv;
            while ((tv = ta.peekValue(j)) != null && tv.type == TypedValue.TYPE_ATTRIBUTE)
                j = Arrays.binarySearch(R.styleable.IRCColors, tv.data);
            sColorValues[i] = ta.getColor(j, Color.RED);
        } catch (UnsupportedOperationException e) {
            e.printStackTrace();
            sColorValues[i] = Color.RED;
        }
    }
    ta.recycle();
}
 
Example #9
Source File: TypedArray.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the styled string value for the attribute at <var>index</var>.
 * <p>
 * If the attribute is not a string, this method will attempt to coerce
 * it to a string.
 *
 * @param index Index of attribute to retrieve.
 *
 * @return CharSequence holding string data. May be styled. Returns
 *         {@code null} if the attribute is not defined or could not be
 *         coerced to a string.
 * @throws RuntimeException if the TypedArray has already been recycled.
 */
public CharSequence getText(@StyleableRes int index) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }

    index *= STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return null;
    } else if (type == TypedValue.TYPE_STRING) {
        return loadStringValueAt(index);
    }

    final TypedValue v = mValue;
    if (getValueAt(index, v)) {
        return v.coerceToString();
    }

    // We already checked for TYPE_NULL. This should never happen.
    throw new RuntimeException("getText of bad type: 0x" + Integer.toHexString(type));
}
 
Example #10
Source File: SlidingTabLayout.java    From FancyPlaces with GNU General Public License v3.0 6 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);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
            outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}
 
Example #11
Source File: PercentLayoutHelper.java    From android-percent-support-extend with Apache License 2.0 6 votes vote down vote up
private void supportTextSize(int widthHint, int heightHint, View view, PercentLayoutInfo info)
{
    //textsize percent support

    PercentLayoutInfo.PercentVal textSizePercent = info.textSizePercent;
    if (textSizePercent == null) return;

    int base = getBaseByModeAndVal(widthHint, heightHint, textSizePercent.basemode);
    float textSize = (int) (base * textSizePercent.percent);

    //Button 和 EditText 是TextView的子类
    if (view instanceof TextView)
    {
        ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
}
 
Example #12
Source File: Utils.java    From Emoji with Apache License 2.0 6 votes vote down vote up
@ColorInt static int resolveColor(final Context context, @AttrRes final int resource, @ColorRes final int fallback) {
  final TypedValue value = new TypedValue();
  context.getTheme().resolveAttribute(resource, value, true);
  final int resolvedColor;

  if (value.resourceId != 0) {
    resolvedColor = ContextCompat.getColor(context, value.resourceId);
  } else {
    resolvedColor = value.data;
  }

  if (resolvedColor != 0) {
    return resolvedColor;
  } else {
    return ContextCompat.getColor(context, fallback);
  }
}
 
Example #13
Source File: Bulletin.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public TwoLineLayout(@NonNull Context context) {
    super(context);

    final int undoInfoColor = Theme.getColor(Theme.key_undo_infoColor);

    addView(imageView = new BackupImageView(context), LayoutHelper.createFrameRelatively(29, 29, Gravity.START | Gravity.CENTER_VERTICAL, 12, 12, 12, 12));

    final LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    addView(linearLayout, LayoutHelper.createFrameRelatively(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 54, 8, 12, 8));

    titleTextView = new TextView(context);
    titleTextView.setSingleLine();
    titleTextView.setTextColor(undoInfoColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    linearLayout.addView(titleTextView);

    subtitleTextView = new TextView(context);
    subtitleTextView.setMaxLines(2);
    subtitleTextView.setTextColor(undoInfoColor);
    subtitleTextView.setTypeface(Typeface.SANS_SERIF);
    subtitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    linearLayout.addView(subtitleTextView);
}
 
Example #14
Source File: WebViewActivity.java    From FastLib with Apache License 2.0 6 votes vote down vote up
private void showDownDialog(String url) {
    UIActionSheetDialog actionSheetDialog = new UIActionSheetDialog.ListSheetBuilder(mContext)
            .addItem(Html.fromHtml(String.format(mFormat, mFilePath)))
            .setOnItemClickListener((dialog, itemView, i) -> {
                switch (i) {
                    case 0:
                        downImg(url);
                        break;
                }
            })
            .setCancel(com.aries.library.fast.R.string.fast_cancel)
            .setNavigationBarControl(this)
            .setTextSizeUnit(TypedValue.COMPLEX_UNIT_DIP)
            .create();
    actionSheetDialog.show();
}
 
Example #15
Source File: HintDialogCell.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public HintDialogCell(Context context) {
    super(context);

    imageView = new BackupImageView(context);
    imageView.setRoundRadius(AndroidUtilities.dp(27));
    addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));

    nameTextView = new TextView(context);
    nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    nameTextView.setMaxLines(2);
    nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    nameTextView.setLines(2);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));
}
 
Example #16
Source File: ThemeHelper.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr});
    try {
        final TypedValue value = a.peekValue(0);
        if (value == null) {
            return fallback;
        }
        if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            return getActionTextStateList(context, value.data);
        } else {
            final ColorStateList stateList = a.getColorStateList(0);
            if (stateList != null) {
                return stateList;
            } else {
                return fallback;
            }
        }
    } finally {
        a.recycle();
    }
}
 
Example #17
Source File: OutSideFrameTabLayout.java    From Collection-Android with MIT License 5 votes vote down vote up
private void updateTabStates() {

        for (int i = 0; i < mTabCount; i++) {
            View v = mTabsContainer.getChildAt(i);
            TextView tv_tab_title = v.findViewById(R.id.tv_tab_title);
            if (tv_tab_title != null) {
                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());
                }
            }
        }
    }
 
Example #18
Source File: WearListItemViews.java    From AndroidWear-OpenWear with MIT License 5 votes vote down vote up
private void initNameView() {
	mName = new TextView(getContext());
	mName.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
	mName.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
	mName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

	LayoutParams lp = new LayoutParams(
			LayoutParams.MATCH_PARENT,
			LayoutParams.MATCH_PARENT);
	lp.rightMargin = margin;
	lp.leftMargin = margin;
	lp.gravity = Gravity.CENTER_VERTICAL;
	mName.setLayoutParams(lp);
}
 
Example #19
Source File: XmlManifestReader.java    From AndroidPlugin with MIT License 5 votes vote down vote up
public int getAttributeResourceValue(int index, int defaultValue) {
    int offset = getAttributeOffset(index);
    int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
    if (valueType == TypedValue.TYPE_REFERENCE) {
        return m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
    }
    return defaultValue;
}
 
Example #20
Source File: BotSwitchCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public BotSwitchCell(Context context) {
    super(context);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setTextColor(Theme.getColor(Theme.key_chat_botSwitchToInlineText));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setMaxLines(1);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 14, 0, 14, 0));
}
 
Example #21
Source File: SystemBarConfig.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(14)
private int getActionBarHeight(Context context) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
        result = TypedValue.complexToDimensionPixelSize(tv.data,
            context.getResources().getDisplayMetrics());
    }
    return result;
}
 
Example #22
Source File: GridAutofitLayoutManager.java    From zapp with MIT License 5 votes vote down vote up
public GridAutofitLayoutManager(Context context, int columnWidth) {
	/* Initially set spanCount to 1, will be changed automatically later. */
	super(context, 1);
	// interprete as dip
	columnWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, columnWidth,
		context.getResources().getDisplayMetrics());
	setColumnWidth(checkedColumnWidth(context, columnWidth));
}
 
Example #23
Source File: SmartTabLayout.java    From imsdk-android with MIT License 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(CharSequence title) {
  TextView textView = new TextView(getContext());
  textView.setGravity(Gravity.CENTER);
  textView.setText(title);
  textView.setTextColor(tabViewTextColors);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
  textView.setTypeface(Typeface.DEFAULT_BOLD);
  textView.setLayoutParams(new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));

  if (tabViewBackgroundResId != NO_ID) {
    textView.setBackgroundResource(tabViewBackgroundResId);
  } else 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(tabViewTextAllCaps);
  }

  textView.setPadding(
      tabViewTextHorizontalPadding, 0,
      tabViewTextHorizontalPadding, 0);

  if (tabViewTextMinWidth > 0) {
    textView.setMinWidth(tabViewTextMinWidth);
  }

  return textView;
}
 
Example #24
Source File: FollowList.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
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 #25
Source File: SuggestionsAdapter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null),
            0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
 
Example #26
Source File: TestAdapter.java    From FlycoDialog_Master with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	final DialogMenuItem item = mMenuItems.get(position);

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

	ImageView iv_item = new ImageView(mContext);
	iv_item.setPadding(0, 0, (int) (15 * mDisplayMetrics.density), 0);
	ll_item.addView(iv_item);

	TextView tv_item = new TextView(mContext);
	tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT));
	tv_item.setSingleLine(true);
	tv_item.setTextColor(Color.parseColor("#303030"));
	tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

	ll_item.addView(tv_item);
	ll_item.setPadding(item.mResId == 0 ? (int) (18 * mDisplayMetrics.density) : (int) (16 * mDisplayMetrics.density), (int) (10 * mDisplayMetrics.density), 0,
			(int) (10 * mDisplayMetrics.density));

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

	return ll_item;
}
 
Example #27
Source File: ViewUtil.java    From android-dialer with Apache License 2.0 5 votes vote down vote up
public static void resizeText(TextView textView, int originalTextSize, int minTextSize) {
  final Paint paint = textView.getPaint();
  final int width = textView.getWidth();
  if (width == 0) {
    return;
  }
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize);
  float ratio = width / paint.measureText(textView.getText().toString());
  if (ratio <= 1.0f) {
    textView.setTextSize(
        TypedValue.COMPLEX_UNIT_PX, Math.max(minTextSize, originalTextSize * ratio));
  }
}
 
Example #28
Source File: BotSwitchCell.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public BotSwitchCell(Context context) {
    super(context);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setTextColor(Theme.getColor(Theme.key_chat_botSwitchToInlineText));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setMaxLines(1);
    textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 14, 0, 14, 0));
}
 
Example #29
Source File: HorizontalGridView.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void setRowHeight(TypedArray array) {
    TypedValue typedValue = array.peekValue(R.styleable.lbHorizontalGridView_rowHeight);
    int size;
    if (typedValue != null && typedValue.type == TypedValue.TYPE_DIMENSION) {
        size = array.getDimensionPixelSize(R.styleable.lbHorizontalGridView_rowHeight, 0);
    } else {
        size = array.getInt(R.styleable.lbHorizontalGridView_rowHeight, 0);
    }
    setRowHeight(size);
}
 
Example #30
Source File: ChatHeadUtils.java    From springy-heads with Apache License 2.0 5 votes vote down vote up
/**
 * Faster than {@link #dpToPx(Context, int)} since metrics is already present.
 * Use this is you are able to cache the reference to display metrics
 * @param metrics
 * @param dp
 * @return
 */
public static int dpToPx(DisplayMetrics metrics, int dp) {
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
    if (px < 1.0f) {
        px = 1;
    }
    return (int) px;
}