Example usage for android.content.res Resources getDimensionPixelSize

List of usage examples for android.content.res Resources getDimensionPixelSize

Introduction

In this page you can find the example usage for android.content.res Resources getDimensionPixelSize.

Prototype

public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID for use as a size in raw pixels.

Usage

From source file:com.android.adam.navigation.BottomNavigationMenuView.java

public BottomNavigationMenuView(Context context, AttributeSet attrs) {
    super(context, attrs);
    final Resources res = getResources();
    mInactiveItemMaxWidth = res
            .getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_item_max_width);
    mInactiveItemMinWidth = res//ww  w .ja  v a  2  s.c om
            .getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_item_min_width);
    mActiveItemMaxWidth = res.getDimensionPixelSize(
            android.support.design.R.dimen.design_bottom_navigation_active_item_max_width);
    mItemHeight = res.getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_height);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mAnimationHelper = new BottomNavigationAnimationHelperIcs();
    } else {
        mAnimationHelper = new BottomNavigationAnimationHelperBase();
    }

    mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            final BottomNavigationItemView itemView = (BottomNavigationItemView) v;
            MenuItem item = itemView.getItemData();
            if (!mMenu.performItemAction(item, mPresenter, 0)) {
                item.setChecked(true);
            }
        }
    };
    mTempChildWidths = new int[BottomNavigationMenu.MAX_ITEM_COUNT];
}

From source file:in.co.sdslabs.play.CustomGridPagerAdapter.java

private Fragment cardFragment(String title, String artist) {
    Resources res = mContext.getResources();
    customFragment = CardFragment.create(title, artist);
    // Add some extra bottom margin to leave room for the page indicator
    customFragment.setCardMarginBottom(res.getDimensionPixelSize(R.dimen.card_margin_bottom));
    return customFragment;
}

From source file:com.example.android.wearable.gridviewpager.SampleGridPagerAdapter.java

private Fragment cardFragment(int titleRes, int textRes) {
    Resources res = mContext.getResources();
    CardFragment fragment = CardFragment.create(res.getText(titleRes), res.getText(textRes));
    // Add some extra bottom margin to leave room for the page indicator
    fragment.setCardMarginBottom(res.getDimensionPixelSize(R.dimen.card_margin_bottom));
    return fragment;
}

From source file:org.mariotaku.twidere.fragment.ParcelableUsersFragment.java

@Nullable
@Override//  ww w .  j a  v a2 s. c  om
protected RecyclerView.ItemDecoration createItemDecoration(Context context, RecyclerView recyclerView,
        LinearLayoutManager layoutManager) {
    final ParcelableUsersAdapter adapter = getAdapter();
    final DividerItemDecoration itemDecoration = new DividerItemDecoration(context,
            ((LinearLayoutManager) recyclerView.getLayoutManager()).getOrientation());
    final Resources res = context.getResources();
    if (adapter.isProfileImageEnabled()) {
        final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 2
                + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
        itemDecoration.setPadding(new DividerItemDecoration.Padding() {
            @Override
            public boolean get(int position, Rect rect) {
                final int itemViewType = adapter.getItemViewType(position);
                boolean nextItemIsUser = false;
                if (position < adapter.getItemCount() - 1) {
                    nextItemIsUser = adapter
                            .getItemViewType(position + 1) == ParcelableUsersAdapter.ITEM_VIEW_TYPE_USER;
                }
                if (nextItemIsUser && itemViewType == ParcelableUsersAdapter.ITEM_VIEW_TYPE_USER) {
                    rect.left = decorPaddingLeft;
                } else {
                    rect.left = 0;
                }
                return true;
            }
        });
    }
    itemDecoration.setDecorationEndOffset(1);
    return itemDecoration;
}

From source file:org.chromium.chrome.browser.suggestions.TileGroup.java

public TileGroup(SuggestionsUiDelegate uiDelegate, ContextMenuManager contextMenuManager,
        Delegate tileGroupDelegate, Observer observer) {
    mContext = ContextUtils.getApplicationContext();
    mUiDelegate = uiDelegate;//from   w ww.j a  va2s.c om
    mContextMenuManager = contextMenuManager;
    mTileGroupDelegate = tileGroupDelegate;
    mObserver = observer;

    Resources resources = mContext.getResources();
    mDesiredIconSize = resources.getDimensionPixelSize(R.dimen.tile_view_icon_size);
    // On ldpi devices, mDesiredIconSize could be even smaller than ICON_MIN_SIZE_PX.
    mMinIconSize = Math.min(mDesiredIconSize, ICON_MIN_SIZE_PX);
    int desiredIconSizeDp = Math.round(mDesiredIconSize / resources.getDisplayMetrics().density);
    int iconColor = ApiCompatibilityUtils.getColor(resources, R.color.default_favicon_background_color);
    mIconGenerator = new RoundedIconGenerator(mContext, desiredIconSizeDp, desiredIconSizeDp,
            ICON_CORNER_RADIUS_DP, iconColor, ICON_TEXT_SIZE_DP);
}

From source file:com.hengtan.nanodegreeapp.stocount.ProductDetailGridPagerAdapter.java

private void CreateCardFragment(String titleRes, String textRes) {
    Resources res = mContext.getResources();
    cardFragment = CardFragment.create(titleRes, textRes);
    // Add some extra bottom margin to leave room for the page indicator
    cardFragment.setCardMarginBottom(res.getDimensionPixelSize(R.dimen.card_margin_bottom));
}

From source file:com.facebook.samples.musicdashboard.MusicGalleryFragment.java

int getColumnWidth() {
    if (null == gridView)
        return 0;

    Resources r = getActivity().getResources();
    int horizontalSpacing = r.getDimensionPixelSize(R.dimen.gridview_horizontal_spacing);
    int numColumns = r.getInteger(R.integer.gridview_num_columns);

    int spacing = horizontalSpacing * (numColumns - 1);
    int padding = gridView.getListPaddingLeft() + gridView.getListPaddingRight();

    return (gridView.getWidth() - padding - spacing) / numColumns;
}

From source file:com.sina.android.weibo.sdk.widget.LoginoutButton.java

/**
 * ??/*  w w w .jav  a2 s  .com*/
 * 
 * @param attrs XML ?
 */
private void loadDefaultStyle(AttributeSet attrs) {
    if (attrs != null && 0 == attrs.getStyleAttribute()) {
        Resources res = getResources();
        this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
        this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
        this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
        this.setCompoundDrawablePadding(
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_with_weibo_account);
    }
}

From source file:com.sina.weibo.sdk.widget.LoginButton1.java

/**
 * /*from   www .  jav a  2s.c o m*/
 *
 * @param attrs XML 
 */
private void loadDefaultStyle(AttributeSet attrs) {
    if (attrs != null && 0 == attrs.getStyleAttribute()) {
        Resources res = getResources();
        this.setBackgroundResource(R.drawable.com_sina_weibo_sdk_button_blue);
        this.setPadding(res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_left),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_top),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_right),
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_padding_bottom));
        this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_com_sina_weibo_sdk_logo, 0, 0, 0);
        this.setCompoundDrawablePadding(
                res.getDimensionPixelSize(R.dimen.com_sina_weibo_sdk_loginview_compound_drawable_padding));
        this.setTextColor(res.getColor(R.color.com_sina_weibo_sdk_loginview_text_color));
        this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                res.getDimension(R.dimen.com_sina_weibo_sdk_loginview_text_size));
        this.setTypeface(Typeface.DEFAULT_BOLD);
        this.setGravity(Gravity.CENTER);
        this.setText(R.string.com_sina_weibo_sdk_login_withweb);
    }
}

From source file:com.abhinavjhanwar.android.egg.neko.Cat.java

public Bitmap createLargeBitmap(Context context) {
    final Resources res = context.getResources();
    final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
    final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);

    Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(result);
    final Paint pt = new Paint();
    float[] hsv = new float[3];
    Color.colorToHSV(mBodyColor, hsv);
    hsv[2] = (hsv[2] > 0.5f) ? (hsv[2] - 0.25f) : (hsv[2] + 0.25f);
    pt.setColor(Color.HSVToColor(hsv));
    pt.setFlags(Paint.ANTI_ALIAS_FLAG);
    float r = w / 2;
    canvas.drawCircle(r, r, r, pt);//from  w  ww. j  ava2  s .  c o m
    int m = w / 10;

    slowDraw(canvas, m, m, w - m - m, h - m - m);

    return result;
}