android.content.res.Resources#getDimensionPixelSize()源码实例Demo

下面列出了android.content.res.Resources#getDimensionPixelSize() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bottomsheets   文件: Config.java
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;
}
 
源代码2 项目: GravityBox   文件: ModExpandedDesktop.java
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);
    }
}
 
源代码3 项目: tysq-android   文件: KeyboardUtils.java
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;
    }
}
 
源代码4 项目: JPSpringMenu   文件: TitleBar.java
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;
}
 
源代码5 项目: Melophile   文件: PresentationUtils.java
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;
}
 
源代码6 项目: 365browser   文件: SelectableListLayout.java
/**
 * @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;
}
 
@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)));
  }
}
 
源代码8 项目: Noyze   文件: iOSVolumePanel.java
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;
}
 
源代码9 项目: AndroidChromium   文件: DualControlLayout.java
/**
 * 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);
}
 
源代码10 项目: JPSpringMenu   文件: SpringMenu.java
private int getStatusBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}
 
/**
 * 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());
}
 
源代码12 项目: Noyze   文件: WPVolumePanel.java
@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;
}
 
源代码13 项目: 365browser   文件: TitleBitmapFactory.java
/**
 * @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);
}
 
源代码14 项目: FireFiles   文件: SystemBarTintManager.java
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;
}
 
源代码15 项目: android_9.0.0_r45   文件: SimpleMonthView.java
/**
 * 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);
}
 
源代码16 项目: deltachat-android   文件: CropAreaRenderer.java
@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();
}
 
源代码17 项目: UETool   文件: DimenUtil.java
public static int getStatusBarHeight() {
    Resources resources = CONTEXT.getResources();
    int resId = resources.getIdentifier("status_bar_height", "dimen", "android");
    return resId > 0 ? resources.getDimensionPixelSize(resId) : 0;
}
 
源代码18 项目: Chandelier   文件: OrnamentLayout.java
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);
}
 
源代码19 项目: StyleableDateTimePicker   文件: MonthView.java
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();
}
 
源代码20 项目: TiCrouton   文件: Crouton.java
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;
}