Java Code Examples for android.content.res.Resources#getDimensionPixelSize()

The following examples show how to use android.content.res.Resources#getDimensionPixelSize() . 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: ModExpandedDesktop.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private static void updateNavbarDimensions() {
    try {
        Resources res = mContext.getResources();
        int resWidthId = res.getIdentifier(
                "navigation_bar_width", "dimen", "android");
        int resHeightId = res.getIdentifier(
                "navigation_bar_height", "dimen", "android");
        int resHeightLandscapeId = res.getIdentifier(
                "navigation_bar_height_landscape", "dimen", "android");
        mNavbarDimensions = new NavbarDimensions(
                (int) (res.getDimensionPixelSize(resWidthId) * mNavbarWidthScaleFactor),
                (int) (res.getDimensionPixelSize(resHeightId) * mNavbarHeightScaleFactor),
                (int) (res.getDimensionPixelSize(resHeightLandscapeId) * mNavbarHeightLandscapeScaleFactor));
        updateSettings();
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
Example 2
Source File: Config.java    From bottomsheets with Apache License 2.0 6 votes vote down vote up
public Builder(@NonNull Context context) {
    Preconditions.nonNull(context);

    final Resources resources = context.getResources();

    this.dimAmount = DEFAULT_DIM_AMOUNT;
    this.sheetCornerRadius = resources.getDimension(R.dimen.bottom_sheet_sheet_corner_radius);
    this.topGapSize = 0;
    this.extraPaddingTop = 0;
    this.extraPaddingBottom = 0;
    this.titleTextSize = resources.getDimensionPixelSize(R.dimen.action_picker_bottom_sheet_title_text_size);
    this.maxSheetWidth = resources.getDimension(R.dimen.bottom_sheet_max_sheet_width);
    this.dimColor = ContextCompat.getColor(context, R.color.bottom_sheet_dim_color);
    this.sheetBackgroundColor = ContextCompat.getColor(context, R.color.bottom_sheet_background_color);
    this.titleTextColor = ContextCompat.getColor(context, R.color.action_picker_bottom_sheet_title_color);
    this.title = "";
    this.animationDuration = DEFAULT_ANIMATION_DURATION;
    this.animationInterpolator = new DecelerateInterpolator(1.5f);
    this.isDismissableOnTouchOutside = true;
}
 
Example 3
Source File: ArrayRecyclerViewAdapter.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Adapts the padding of a list item.
 *
 * @param holder The view holder as an instance of the class {@link ViewHolder}. The view holder
 *               may not be null
 */
private void adaptPadding(@NonNull final ViewHolder holder) {
    View view = holder.itemView;
    Context context = view.getContext();
    Resources resources = context.getResources();
    int leftPadding = resources.getDimensionPixelSize(R.dimen.dialog_left_padding);
    int rightPadding = resources.getDimensionPixelSize(R.dimen.dialog_right_padding);
    view.setPadding(leftPadding, view.getPaddingTop(), rightPadding, view.getPaddingBottom());
}
 
Example 4
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the text and style properties for painting.
 */
private void initPaints(Resources res) {
    final String monthTypeface = res.getString(R.string.date_picker_month_typeface);
    final String dayOfWeekTypeface = res.getString(R.string.date_picker_day_of_week_typeface);
    final String dayTypeface = res.getString(R.string.date_picker_day_typeface);

    final int monthTextSize = res.getDimensionPixelSize(
            R.dimen.date_picker_month_text_size);
    final int dayOfWeekTextSize = res.getDimensionPixelSize(
            R.dimen.date_picker_day_of_week_text_size);
    final int dayTextSize = res.getDimensionPixelSize(
            R.dimen.date_picker_day_text_size);

    mMonthPaint.setAntiAlias(true);
    mMonthPaint.setTextSize(monthTextSize);
    mMonthPaint.setTypeface(Typeface.create(monthTypeface, 0));
    mMonthPaint.setTextAlign(Align.CENTER);
    mMonthPaint.setStyle(Style.FILL);

    mDayOfWeekPaint.setAntiAlias(true);
    mDayOfWeekPaint.setTextSize(dayOfWeekTextSize);
    mDayOfWeekPaint.setTypeface(Typeface.create(dayOfWeekTypeface, 0));
    mDayOfWeekPaint.setTextAlign(Align.CENTER);
    mDayOfWeekPaint.setStyle(Style.FILL);

    mDaySelectorPaint.setAntiAlias(true);
    mDaySelectorPaint.setStyle(Style.FILL);

    mDayHighlightPaint.setAntiAlias(true);
    mDayHighlightPaint.setStyle(Style.FILL);

    mDayHighlightSelectorPaint.setAntiAlias(true);
    mDayHighlightSelectorPaint.setStyle(Style.FILL);

    mDayPaint.setAntiAlias(true);
    mDayPaint.setTextSize(dayTextSize);
    mDayPaint.setTypeface(Typeface.create(dayTypeface, 0));
    mDayPaint.setTextAlign(Align.CENTER);
    mDayPaint.setStyle(Style.FILL);
}
 
Example 5
Source File: SystemBarTintManager.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }
    return result;
}
 
Example 6
Source File: TitleBitmapFactory.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param context   The current Android's context.
 * @param incognito Whether the title are for incognito mode.
 * @param nullFaviconResourceId A drawable resource id of a default favicon.
 */
public TitleBitmapFactory(Context context, boolean incognito, int nullFaviconResourceId) {
    mNullFaviconResourceId = nullFaviconResourceId;

    Resources res = context.getResources();
    int textColor = ApiCompatibilityUtils.getColor(res, incognito
            ? R.color.compositor_tab_title_bar_text_incognito
            : R.color.compositor_tab_title_bar_text);
    float textSize = res.getDimension(R.dimen.compositor_tab_title_text_size);

    boolean fakeBoldText = res.getBoolean(R.bool.compositor_tab_title_fake_bold_text);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(textColor);

    mTextPaint.setTextSize(textSize);
    mTextPaint.setFakeBoldText(fakeBoldText);
    mTextPaint.density = res.getDisplayMetrics().density;

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;

    mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_title_favicon_size);
    mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight);

    int width = res.getDisplayMetrics().widthPixels;
    int height = res.getDisplayMetrics().heightPixels;
    mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height));

    // Set the favicon dimension here.
    mFaviconDimension = Math.min(mMaxWidth, mFaviconDimension);
}
 
Example 7
Source File: WPVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
    int flags = (
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH     |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL         |
            WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR      |
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN        |
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED        );
    WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, flags, PixelFormat.RGB_565);
    WPARAMS.windowAnimations = android.R.style.Animation_Dialog;
    WPARAMS.packageName = getContext().getPackageName();
    WPARAMS.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
    WPARAMS.setTitle(TAG);
    Resources res = getResources();
    final int panelWidth = getNotificationPanelWidth();
    final int maxWidth = ((panelWidth > 0) ? panelWidth : res.getDimensionPixelSize(R.dimen.notification_panel_width));
    final int menuWidth = res.getDimensionPixelSize(R.dimen.max_menu_width);
    final int screenWidth = getWindowWidth();
    if (stretch || (maxWidth <= 0) || (!res.getBoolean(R.bool.isTablet) && screenWidth < menuWidth)) {
        WPARAMS.gravity = (Gravity.FILL_HORIZONTAL | Gravity.TOP);
    } else {
        WPARAMS.gravity = (Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        WPARAMS.width = (maxWidth <= 0) ? menuWidth : maxWidth;
    }
    WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    return WPARAMS;
}
 
Example 8
Source File: KeyboardUtils.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
private static int getNavBarHeight() {
    Resources res = Resources.getSystem();
    int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId != 0) {
        return res.getDimensionPixelSize(resourceId);
    } else {
        return 0;
    }
}
 
Example 9
Source File: SpringMenu.java    From JPSpringMenu with MIT License 5 votes vote down vote up
private int getStatusBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}
 
Example 10
Source File: DualControlLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new DualControlLayout.
 *
 * See {@link ViewGroup} for parameter details.  attrs may be null if constructed dynamically.
 */
public DualControlLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Cache dimensions.
    Resources resources = getContext().getResources();
    mHorizontalMarginBetweenViews =
            resources.getDimensionPixelSize(R.dimen.infobar_control_margin_between_items);

    if (attrs != null) parseAttributes(attrs);
}
 
Example 11
Source File: iOSVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected static Drawable makeBackground(Resources res, final int color) {
    int padding = res.getDimensionPixelSize(R.dimen.activity_horizontal_margin);
    float corners = (3 * padding) / 4;
    float[] radii = new float[] { corners, corners, corners, corners, corners, corners, corners, corners };
    ShapeDrawable rect = new ShapeDrawable(new RoundRectShape(radii, null, null));
    rect.setPadding(padding / 4, padding / 4, padding / 4, padding / 4);
    rect.getPaint().setColor(color);
    return rect;
}
 
Example 12
Source File: NavigationViewTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextAppearance() {
  // Open our drawer
  onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));

  final Resources res = activityTestRule.getActivity().getResources();
  final int defaultTextSize = res.getDimensionPixelSize(R.dimen.text_medium_size);

  // Check the default style of the menu items in our NavigationView
  for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
    onView(
            allOf(
                withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i])),
                isDescendantOfA(withId(R.id.start_drawer))))
        .check(matches(withTextSize(defaultTextSize)));
  }

  // Set a new text appearance on our NavigationView
  onView(withId(R.id.start_drawer)).perform(setItemTextAppearance(R.style.TextSmallStyle));

  // And check that all the menu items have the new style
  final int newTextSize = res.getDimensionPixelSize(R.dimen.text_small_size);
  for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
    onView(
            allOf(
                withText(menuStringContent.get(MENU_CONTENT_ITEM_IDS[i])),
                isDescendantOfA(withId(R.id.start_drawer))))
        .check(matches(withTextSize(newTextSize)));
  }
}
 
Example 13
Source File: SelectableListLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param res Resources used to retrieve drawables and dimensions.
 * @return The default list item lateral margin size in pixels. This value should be used in
 *         {@link HorizontalDisplayStyle#REGULAR} to hide the lateral shadow and rounded edges
 *         on items that use the list_item* 9-patches as a background.
 */
public static int getDefaultListItemLateralMarginPx(Resources res) {
    if (sDefaultListItemLateralMarginPx == -1) {
        int cardCornerRadius = res.getDimensionPixelSize(R.dimen.list_item_corner_radius);

        // A negative margin is used in HorizontalDisplayStyle#REGULAR to hide the lateral
        // shadow.
        sDefaultListItemLateralMarginPx =
                -(getDefaultListItemLateralShadowSizePx(res) + cardCornerRadius);
    }

    return sDefaultListItemLateralMarginPx;
}
 
Example 14
Source File: PresentationUtils.java    From Melophile with Apache License 2.0 5 votes vote down vote up
public static int getStatusBarHeight(Resources resources) {
  int result = 0;
  int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
    result = resources.getDimensionPixelSize(resourceId);
  }
  return result;
}
 
Example 15
Source File: TitleBar.java    From JPSpringMenu with MIT License 5 votes vote down vote up
private static int getInternalDimensionSize(Resources res, String key) {
    int result = 0;
    int resourceId = res.getIdentifier(key, "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }
    return result;
}
 
Example 16
Source File: OrnamentLayout.java    From Chandelier with MIT License 4 votes vote down vote up
public OrnamentLayout(final Context context, final AttributeSet attrs) {
  super(context);
  final Resources res = getResources();
  final TypedArray a = context.getTheme().obtainStyledAttributes(
      attrs,
      R.styleable.ChandelierLayout,
      0, 0);

  // Defaults
  final int defaultElevation = res.getDimensionPixelSize(R.dimen.default_elevation);
  final int defaultSelectorMargin = res.getDimensionPixelSize(R.dimen.default_selector_margin);
  final int defaultSelectorSize = res.getDimensionPixelSize(R.dimen.default_selector_size);
  final boolean defaultScaleEnabled = res.getBoolean(R.bool.default_scale_enabled);

  isScaleEnabled = a.getBoolean(R.styleable.ChandelierLayout_chandelier_scale_enabled,
      defaultScaleEnabled);
  actionItemLayoutHeight =
      a.getDimensionPixelSize(R.styleable.ChandelierLayout_ornament_layout_height,
          WRAP_CONTENT);
  actionItemLayoutWidth = a.getDimensionPixelSize(R.styleable.ChandelierLayout_ornament_layout_width,
      WRAP_CONTENT);

  // Action Layout
  container = new LinearLayout(context);
  container.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT, CENTER_VERTICAL));
  setBackground(a.getDrawable(R.styleable.ChandelierLayout_chandelier_background));

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    setElevation(
        a.getDimensionPixelSize(R.styleable.ChandelierLayout_chandelier_elevation, defaultElevation));
  }

  container.setOrientation(LinearLayout.HORIZONTAL);
  container.setGravity(CENTER_VERTICAL);

  // Action Item
  imageViewMargin =
      a.getDimensionPixelSize(R.styleable.ChandelierLayout_ornament_margin, defaultSelectorMargin);
  selectedSize = a.getDimensionPixelSize(R.styleable.ChandelierLayout_chandelier_selected_size,
      defaultSelectorSize);
  selectedImageView = new ImageView(context);
  final LayoutParams selectedLp = new LayoutParams(selectedSize, selectedSize, CENTER_VERTICAL);
  selectedLp.setMargins(0, imageViewMargin, 0, imageViewMargin);
  selectedImageView.setLayoutParams(selectedLp);

  Drawable selectorBackground = a.getDrawable(R.styleable.ChandelierLayout_chandelier_selector);
  if (selectorBackground != null) {
    selectedImageView.setBackground(selectorBackground);
  } else {
    selectedImageView.setBackground(res.getDrawable(R.drawable.default_selector));
  }

  Drawable layoutBackground = a.getDrawable(R.styleable.ChandelierLayout_chandelier_background);
  if (layoutBackground != null) {
    setBackground(layoutBackground);
  } else {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
    setBackgroundColor(typedValue.data);
  }

  a.recycle();

  addView(selectedImageView);
  addView(container);
}
 
Example 17
Source File: MonthView.java    From StyleableDateTimePicker with MIT License 4 votes vote down vote up
public MonthView(Context context) {
    super(context);

    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

    mDayTextColor = res.getColor(R.color.date_picker_text_normal);
    mTodayNumberColor = res.getColor(R.color.blue);

    TypedArray attrArray = getContext().getTheme().obtainStyledAttributes(R.styleable.DateTimePicker);
    int attrCount = attrArray.getIndexCount();
    for (int i = 0; i < attrCount; i++) {
        int attr = attrArray.getIndex(i);
        switch (attr) {
            case R.styleable.DateTimePicker_hightlightedTextColor:
                ColorStateList stateList = attrArray.getColorStateList(attr);
                mTodayNumberColor = stateList.getColorForState(new int[]{android.R.attr.state_selected}, stateList.getDefaultColor());
                break;
            case R.styleable.DateTimePicker_defaultTextColor:
                stateList = attrArray.getColorStateList(attr);
                mDayTextColor = stateList.getColorForState(new int[]{android.R.attr.state_selected}, stateList.getDefaultColor());
                break;
        }
    }
    mMonthTitleColor = res.getColor(R.color.white);
    mMonthTitleBGColor = res.getColor(R.color.circle_background);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res
            .getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height)
            - MONTH_HEADER_SIZE) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}
 
Example 18
Source File: DimenUtil.java    From UETool with MIT License 4 votes vote down vote up
public static int getStatusBarHeight() {
    Resources resources = CONTEXT.getResources();
    int resId = resources.getIdentifier("status_bar_height", "dimen", "android");
    return resId > 0 ? resources.getDimensionPixelSize(resId) : 0;
}
 
Example 19
Source File: CropAreaRenderer.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void render(@NonNull RendererContext rendererContext) {
  rendererContext.save();

  Canvas    canvas    = rendererContext.canvas;
  Resources resources = rendererContext.context.getResources();

  canvas.clipPath(cropClipPath);
  canvas.drawColor(ResourcesCompat.getColor(resources, color, null));

  rendererContext.mapRect(dst, Bounds.FULL_BOUNDS);

  final int thickness = resources.getDimensionPixelSize(R.dimen.crop_area_renderer_edge_thickness);
  final int size      = (int) Math.min(resources.getDimensionPixelSize(R.dimen.crop_area_renderer_edge_size), Math.min(dst.width(), dst.height()) / 3f - 10);

  paint.setColor(ResourcesCompat.getColor(resources, R.color.crop_area_renderer_edge_color, null));

  rendererContext.canvasMatrix.setToIdentity();
  screenClipPath.reset();
  screenClipPath.moveTo(dst.left, dst.top);
  screenClipPath.lineTo(dst.right, dst.top);
  screenClipPath.lineTo(dst.right, dst.bottom);
  screenClipPath.lineTo(dst.left, dst.bottom);
  screenClipPath.close();
  canvas.clipPath(screenClipPath);
  canvas.translate(dst.left, dst.top);

  float halfDx = (dst.right - dst.left - size + thickness) / 2;
  float halfDy = (dst.bottom - dst.top - size + thickness) / 2;

  canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(0, halfDy);
  if (renderCenterThumbs) canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(0, halfDy);
  canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(halfDx, 0);
  if (renderCenterThumbs) canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(halfDx, 0);
  canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(0, -halfDy);
  if (renderCenterThumbs) canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(0, -halfDy);
  canvas.drawRect(-thickness, -thickness, size, size, paint);

  canvas.translate(-halfDx, 0);
  if (renderCenterThumbs) canvas.drawRect(-thickness, -thickness, size, size, paint);

  rendererContext.restore();
}
 
Example 20
Source File: Crouton.java    From TiCrouton with MIT License 4 votes vote down vote up
private RelativeLayout initializeContentView(final Resources resources) {
  RelativeLayout contentView = new RelativeLayout(this.activity);
  contentView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
      RelativeLayout.LayoutParams.MATCH_PARENT));

  // set padding
  int padding = this.style.paddingInPixels;

  // if a padding dimension has been set, this will overwrite any padding
  // in pixels
  if (this.style.paddingDimensionResId > 0) {
    padding = resources.getDimensionPixelSize(this.style.paddingDimensionResId);
  }
  contentView.setPadding(padding, padding, padding, padding);

  // only setup image if one is requested
  ImageView image = null;
  if ((null != this.style.imageDrawable) || (0 != this.style.imageResId)) {
    image = initializeImageView();
    contentView.addView(image, image.getLayoutParams());
  }

  TextView text = initializeTextView(resources);

  RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
      RelativeLayout.LayoutParams.WRAP_CONTENT);
  if (null != image) {
    textParams.addRule(RelativeLayout.RIGHT_OF, image.getId());
  }

  if ((this.style.gravity & Gravity.CENTER) != 0) {
    textParams.addRule(RelativeLayout.CENTER_IN_PARENT);
  } else if ((this.style.gravity & Gravity.CENTER_VERTICAL) != 0) {
    textParams.addRule(RelativeLayout.CENTER_VERTICAL);
  } else if ((this.style.gravity & Gravity.CENTER_HORIZONTAL) != 0) {
    textParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
  }

  contentView.addView(text, textParams);
  return contentView;
}