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.andryr.musicplayer.fragments.AlbumListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_album_list, container, false);
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.list_view);
    WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Resources res = getActivity().getResources();
    float screenWidth = display.getWidth();
    float itemWidth = res.getDimension(R.dimen.album_grid_item_width);
    mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), Math.round(screenWidth / itemWidth)));

    int artworkSize = res.getDimensionPixelSize(R.dimen.art_size);
    mAdapter = new AlbumListAdapter(getActivity(), artworkSize, artworkSize);
    mAdapter.setOnItemClickListener(mOnItemClickListener);
    mRecyclerView.setAdapter(mAdapter);/*w  ww . j  a  va 2 s  .  c  o m*/

    mFastScroller = (FastScroller) rootView.findViewById(R.id.fastscroller);
    mFastScroller.setShowBubble(mShowScrollerBubble);
    mFastScroller.setSectionIndexer(mAdapter);
    mFastScroller.setRecyclerView(mRecyclerView);

    return rootView;
}

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

private int getStatusBarHeight() {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }//ww w . j av  a  2s . c o  m
    return 0;
}

From source file:com.android.launcher3.allapps.AllAppsRecyclerView.java

public AllAppsRecyclerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr);
    Resources res = getResources();
    addOnItemTouchListener(this);
    mScrollbar.setDetachThumbOnFastScroll();
    mEmptySearchBackgroundTopOffset = res.getDimensionPixelSize(R.dimen.all_apps_empty_search_bg_top_offset);

    if (Utilities.isAllowNightModePrefEnabled(context)) {
        setBackgroundColor(ContextCompat.getColor(getContext(), R.color.night_color));
    } else {/* w  ww . j  av  a2  s  . co  m*/
        if (Utilities.getDrawerBackgroundPrefEnabled(getContext()) != -1) {
            setBackgroundColor(Utilities.getDrawerBackgroundPrefEnabled(getContext()));
        } else {
            setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.white));
        }
    }
}

From source file:com.gruporaido.tasker_library.util.Helper.java

/**
 * Gets Navigation bar height if there is one, 0 otherwise
 *
 * @return/*from w  ww . j a  v a  2  s  . c  o  m*/
 */
public int navigationBarSize() {
    Resources resources = mContext.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

From source file:org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView.java

/**
 * Constructor needed to inflate from XML.
 *///from ww w .  j a  v a 2 s . c  o m
public NewTabPageRecyclerView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            boolean retVal = super.onSingleTapUp(e);
            requestFocus();
            return retVal;
        }
    });
    mLayoutManager = new LinearLayoutManager(getContext());
    setLayoutManager(mLayoutManager);

    Resources res = context.getResources();
    mToolbarHeight = res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow)
            + res.getDimensionPixelSize(R.dimen.toolbar_progress_bar_height);
    mMaxHeaderHeight = res.getDimensionPixelSize(R.dimen.snippets_article_header_height);
}

From source file:com.indeema.mail.utils.NotificationUtils.java

private static Bitmap getContactIcon(final Context context, final String displayName,
        final String senderAddress, final Folder folder) {
    if (senderAddress == null) {
        return null;
    }/*from  w ww . j  a va  2  s . c  o  m*/

    Bitmap icon = null;

    final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress }));

    // Get the ideal size for this icon.
    final Resources res = context.getResources();
    final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);

    if (contactIds != null) {
        for (final long id : contactIds) {
            final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
            final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
            final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO },
                    null, null, null);

            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        final byte[] data = cursor.getBlob(0);
                        if (data != null) {
                            icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
                            if (icon != null && icon.getHeight() < idealIconHeight) {
                                // We should scale this image to fit the intended size
                                icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true);
                            }
                            if (icon != null) {
                                break;
                            }
                        }
                    }
                } finally {
                    cursor.close();
                }
            }
        }
    }

    if (icon == null) {
        // Make a colorful tile!
        final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE);

        icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress);
    }

    if (icon == null) {
        // Icon should be the default mail icon.
        icon = getDefaultNotificationIcon(context, folder, false /* single new message */);
    }
    return icon;
}

From source file:com.smartcodeunited.demo.bluetooth.activity.BaseActivity.java

public int getNavigationBarHeight() {
    Resources resources = getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0 && hasNavigationBar()) {
        return resources.getDimensionPixelSize(resourceId);
    }//from w  w w . java 2  s  .  c  om
    return 0;
}

From source file:com.chen.mail.utils.NotificationUtils.java

private static Bitmap getContactIcon(final Context context, final String displayName,
        final String senderAddress, final Folder folder) {
    if (senderAddress == null) {
        return null;
    }/*from  w ww  . j  av  a2  s . co m*/

    Bitmap icon = null;

    final List<Long> contactIds = findContacts(context, Arrays.asList(new String[] { senderAddress }));

    // Get the ideal size for this icon.
    final Resources res = context.getResources();
    final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);

    if (contactIds != null) {
        for (final long id : contactIds) {
            final Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
            final Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
            final Cursor cursor = context.getContentResolver().query(photoUri, new String[] { Photo.PHOTO },
                    null, null, null);

            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        final byte[] data = cursor.getBlob(0);
                        if (data != null) {
                            icon = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
                            if (icon != null && icon.getHeight() < idealIconHeight) {
                                // We should scale this image to fit the intended size
                                icon = Bitmap.createScaledBitmap(icon, idealIconWidth, idealIconHeight, true);
                            }
                            if (icon != null) {
                                break;
                            }
                        }
                    }
                } finally {
                    cursor.close();
                }
            }
        }
    }

    if (icon == null) {
        // Make a colorful tile!
        final ImageCanvas.Dimensions dimensions = new ImageCanvas.Dimensions(idealIconWidth, idealIconHeight,
                ImageCanvas.Dimensions.SCALE_ONE);

        icon = new LetterTileProvider(context).getLetterTile(dimensions, displayName, senderAddress);
    }

    if (icon == null) {
        // Icon should be the default mail icon.
        icon = getDefaultNotificationIcon(context, folder, false /* single new message */);
    }
    return icon;
}

From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java

private void onTooltipIconClicked() {
    // Don't show the popup if there's already one showing (or one has been dismissed
    // recently). This prevents a tap on the (?) from hiding and then immediately re-showing
    // the popup.
    if (mStoreLocallyTooltipPopup != null)
        return;/* w  ww .ja  v  a 2  s. co  m*/

    mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext());
    TextView text = new TextView(mDialog.getContext());
    text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip);
    // Width is the dialog's width less the margins and padding around the checkbox and
    // icon.
    text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mStoreLocallyCheckbox)
            - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon)
            - MarginLayoutParamsCompat
                    .getMarginStart((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLayoutParams())
            - MarginLayoutParamsCompat
                    .getMarginEnd((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.getLayoutParams()));
    text.setTextColor(Color.WHITE);
    Resources resources = mDialog.getContext().getResources();
    int hPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_horizontal_padding);
    int vPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_vertical_padding);
    text.setPadding(hPadding, vPadding, hPadding, vPadding);

    mStoreLocallyTooltipPopup.setContentView(text);
    mStoreLocallyTooltipPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setOutsideTouchable(true);
    mStoreLocallyTooltipPopup.setBackgroundDrawable(
            ApiCompatibilityUtils.getDrawable(resources, R.drawable.store_locally_tooltip_background));
    mStoreLocallyTooltipPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Handler h = new Handler();
            h.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mStoreLocallyTooltipPopup = null;
                }
            }, 200);
        }
    });
    mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox,
            ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0);
    text.announceForAccessibility(text.getText());
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private void init(Context context, AttributeSet attrs) {
    Resources resources = getResources();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
    int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding,
            defaultPadding);/*from w  w  w . ja  v  a 2  s. c  om*/
    setClickable(true);

    backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector,
            R.drawable.selector);
    setBackgroundResource(backgroundSelector);
    textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
    setTextColor(textColor);

    listView = new ListView(context);
    // Set the spinner's id into the listview to make it pretend to be the right parent in
    // onItemClick
    listView.setId(getId());
    listView.setDivider(new ColorDrawable(Color.GRAY));
    listView.setDividerHeight(1);
    listView.setItemsCanFocus(true);
    //hide vertical and horizontal scrollbars
    listView.setVerticalScrollBarEnabled(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setOverScrollMode(OVER_SCROLL_NEVER);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectedIndex = position;

            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(parent, view, position, id);
            }

            if (onItemSelectedListener != null) {
                onItemSelectedListener.onItemSelected(parent, view, position, id);
            }

            adapter.setSelectedIndex(position);
            setTextInternal(adapter.getItemInDataset(position).toString());
            dismissDropDown();
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(DEFAULT_ELEVATION);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow));
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (!isArrowHidden) {
                animateArrow(false);
            }
        }
    });

    isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
    arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE);
    arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
    dropDownListPaddingBottom = typedArray
            .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
    typedArray.recycle();

    measureDisplayHeight();
}