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.tr4android.support.extension.picker.date.SimpleMonthView.java

/**
 * Sets up the text and style properties for painting.
 *//*from w  ww. j  a v  a  2  s. c om*/
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);

    mDayPaint.setAntiAlias(true);
    mDayPaint.setTextSize(dayTextSize);
    mDayPaint.setTypeface(Typeface.create(dayTypeface, 0));
    mDayPaint.setTextAlign(Align.CENTER);
    mDayPaint.setStyle(Style.FILL);
}

From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    AppCompatActivity activity = mActivityDelegate.getActivity();
    final DrawerLayout drawerLayout = mActivityDelegate.getDrawerLayout();
    activity.getMenuInflater().inflate(R.menu.chatbox_menu, menu);
    MenuItem onlineUsersItem = menu.findItem(R.id.online_users);
    mediaAddItem = menu.findItem(R.id.audio_add);

    /**//  www . ja  v  a  2  s  .co  m
     * Create badge view for online user item
     */
    ImageButton iconView = new ImageButton(activity, null, R.style.Widget_AppCompat_ActionButton);
    iconView.setImageDrawable(onlineUsersItem.getIcon());
    iconView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawerLayout.isDrawerOpen(DRAWER_GRAVITY_ONLINE_USER)) {
                drawerLayout.closeDrawer(DRAWER_GRAVITY_ONLINE_USER);
            } else {
                drawerLayout.openDrawer(DRAWER_GRAVITY_ONLINE_USER);
            }
        }
    });

    // The badge view requires target view (iconView in this case)
    // to have a ViewGroup parent
    LinearLayout container = new LinearLayout(activity);
    container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    container.addView(iconView);

    Resources res = activity.getResources();
    mOnlineUsersBadgeView = new BadgeView(activity, iconView);
    mOnlineUsersBadgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
    mOnlineUsersBadgeView.setTextSize(TypedValue.COMPLEX_UNIT_SP,
            res.getDimension(R.dimen.badge_view_text_size));
    mOnlineUsersBadgeView.setBadgeMargin(res.getDimensionPixelSize(R.dimen.default_margin));
    onlineUsersItem.setActionView(container);
    mOnlineUsersBadgeView
            .setBadgeBackgroundColor(mActivityDelegate.getActivity().getResources().getColor(R.color.accent));

    return true;
}

From source file:com.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);/*from   w  w w . j  av  a2 s  .c o  m*/
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.simplealertdialog.SimpleAlertDialog.java

public void setSingleChoiceItems(final CharSequence[] items, final int checkedItem,
        final AdapterView.OnItemClickListener listener) {
    if (items == null) {
        return;//from w  w  w  .j  a v a  2  s . c  o m
    }
    mAdapter = new ArrayAdapter<CharSequence>(getContext(), android.R.layout.simple_list_item_single_choice,
            items) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            if (view != null) {
                CheckedTextView c = (CheckedTextView) view.findViewById(android.R.id.text1);
                if (mListChoiceIndicatorSingle != 0) {
                    c.setCheckMarkDrawable(mListChoiceIndicatorSingle);
                }
                if (mListItemTextStyle != 0) {
                    c.setTextAppearance(getContext(), mListItemTextStyle);
                }
                setBackground(c, mListSelectorBackground);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                    Resources res = getContext().getResources();
                    c.setPadding(res.getDimensionPixelSize(R.dimen.sad__simple_list_item_padding_left), 0,
                            res.getDimensionPixelSize(R.dimen.sad__simple_list_item_padding_right), 0);
                }
            }
            return view;
        }
    };
    mSingleChoice = true;
    mCheckedItem = checkedItem;
    mListItemListener = listener;
}

From source file:hide.com.android.datetimepicker.date.SimpleMonthView.java

public SimpleMonthView(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);
    mMonthTitleColor = res.getColor(R.color.white);
    mMonthTitleBGColor = res.getColor(R.color.circle_background);

    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;//from   w ww.jav  a 2 s .  co  m

    // Set up accessibility components.
    mNodeProvider = new MonthViewNodeProvider(context, this);
    ViewCompat.setAccessibilityDelegate(this, mNodeProvider.getAccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

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

private static ContactIconInfo getContactIcon(final Context context, final Folder folder,
        final ContactPhotoFetcher photoFetcher) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        throw new IllegalStateException("getContactIcon should not be called on the main thread.");
    }/*  www  .j  a va2s .  c  om*/
    final ContactIconInfo contactIconInfo;
    // 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);
    final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width);
    final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height);

    if (photoFetcher != null) {
        contactIconInfo = photoFetcher.getContactPhoto(context, "", "", idealIconWidth, idealIconHeight,
                idealWearableBgWidth, idealWearableBgHeight);
    } else {
        contactIconInfo = getContactInfo(context, "", idealIconWidth, idealIconHeight, idealWearableBgWidth,
                idealWearableBgHeight);
    }

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

        contactIconInfo.icon = new LetterTileProvider(context).getMultiTile(dimensions);
    }
    contactIconInfo.icon = cropSquareIconToCircle(contactIconInfo.icon);

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

    if (contactIconInfo.wearableBg == null) {
        contactIconInfo.wearableBg = getDefaultWearableBg(context);
    }

    return contactIconInfo;
}

From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    Resources res = getResources();
    mHeight = getMeasuredHeight();/*from  w  ww .  ja  va 2s  . c  om*/
    mWidth = getMeasuredWidth();
    mPaddingBottom = getPaddingBottom();
    mChartPaddingTop = res.getDimensionPixelSize(R.dimen.run_review_section_margin);
    mChartHeight = res.getDimensionPixelSize(R.dimen.run_review_chart_height);

    mLabelPadding = res.getDimensionPixelSize(R.dimen.run_review_overlay_label_padding);
    mIntraLabelPadding = res.getDimensionPixelSize(R.dimen.run_review_overlay_label_intra_padding);
    mNotchHeight = res.getDimensionPixelSize(R.dimen.run_review_overlay_label_notch_height);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.run_review_overlay_label_corner_radius);
    mCropFlagBufferX = mLabelPadding;

    mDotRadius = res.getDimensionPixelSize(R.dimen.run_review_value_label_dot_radius);
    mDotBackgroundRadius = res.getDimensionPixelSize(R.dimen.run_review_value_label_dot_background_radius);

    mChartMarginLeft = res.getDimensionPixelSize(R.dimen.chart_margin_size_left)
            + res.getDimensionPixelSize(R.dimen.stream_presenter_padding_sides);
    mChartMarginRight = res.getDimensionPixelSize(R.dimen.stream_presenter_padding_sides);
}

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

private static ContactIconInfo getContactIcon(final Context context, String accountName,
        final String displayName, final String senderAddress, final Folder folder,
        final ContactPhotoFetcher photoFetcher) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        throw new IllegalStateException("getContactIcon should not be called on the main thread.");
    }// w  w w. j  a v a2  s  .c o  m

    final ContactIconInfo contactIconInfo;
    if (senderAddress == null) {
        contactIconInfo = new ContactIconInfo();
    } else {
        // 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);
        final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width);
        final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height);

        if (photoFetcher != null) {
            contactIconInfo = photoFetcher.getContactPhoto(context, accountName, senderAddress, idealIconWidth,
                    idealIconHeight, idealWearableBgWidth, idealWearableBgHeight);
        } else {
            contactIconInfo = getContactInfo(context, senderAddress, idealIconWidth, idealIconHeight,
                    idealWearableBgWidth, idealWearableBgHeight);
        }

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

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

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

    if (contactIconInfo.wearableBg == null) {
        contactIconInfo.wearableBg = getDefaultWearableBg(context);
    }

    return contactIconInfo;
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void setSelectedColor(ImageView button) {
    Drawable select = getResources().getDrawable(R.drawable.dot_design_select);
    select.setColorFilter(getResources().getColor(R.color.overlay_color), Mode.SRC_IN);

    ImageView selectedIcon = (ImageView) mPalette.findViewById(R.id.selected);
    selectedIcon.setBackground(select);//from   w w w . j ava  2s . co m

    Resources res = getResources();
    int id = button.getId();
    int buttonLeft = button.getLeft();
    int buttonTop = button.getTop();
    int m1 = res.getDimensionPixelSize(R.dimen.margin_l);
    int m2 = res.getDimensionPixelSize(R.dimen.margin_m);
    int colorSize = res.getDimensionPixelSize(R.dimen.hv01);
    if (id == R.id.btn_color_11 || id == R.id.btn_color_12 || id == R.id.btn_color_13
            || id == R.id.btn_color_14) {
        buttonTop = m2;
    } else if (id == R.id.btn_color_21 || id == R.id.btn_color_22 || id == R.id.btn_color_23
            || id == R.id.btn_color_24) {
        buttonTop = m2 + colorSize + m1;
    } else {
        buttonTop = m2 + 2 * colorSize + 2 * m1;
    }

    if (id == R.id.btn_color_11 || id == R.id.btn_color_21 || id == R.id.btn_color_31) {
        buttonLeft = m2;
    } else if (id == R.id.btn_color_12 || id == R.id.btn_color_22 || id == R.id.btn_color_32) {
        buttonLeft = 3 * m2 + colorSize;
    } else if (id == R.id.btn_color_13 || id == R.id.btn_color_23 || id == R.id.btn_color_33) {
        buttonLeft = 5 * m2 + 2 * colorSize;
    } else {
        buttonLeft = 7 * m2 + 3 * colorSize;
    }

    int widthDiff = res.getDimensionPixelSize(R.dimen.select_color_width) - colorSize;
    int heightDiff = res.getDimensionPixelSize(R.dimen.select_color_height) - colorSize;
    int marginLeft = buttonLeft - (widthDiff / 2);
    int marginTop = buttonTop - (heightDiff / 2);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) selectedIcon.getLayoutParams();
    params.setMargins(marginLeft, marginTop, 0, 0);
    selectedIcon.setLayoutParams(params);
    selectedIcon.setVisibility(View.VISIBLE);
}

From source file:com.android.screenspeak.contextmenu.RadialMenuView.java

public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) {
    super(context);

    mRootMenu = menu;//from w ww  . j ava 2s  .c o  m
    mRootMenu.setLayoutListener(new RadialMenu.MenuLayoutListener() {
        @Override
        public void onLayoutChanged() {
            invalidate();
        }
    });

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    mHandler = new LongPressHandler(context);
    mHandler.setListener(new LongPressHandler.LongPressListener() {
        @Override
        public void onLongPress() {
            onItemLongPressed(mFocusedItem);
        }
    });

    final SurfaceHolder holder = getHolder();
    holder.setFormat(PixelFormat.TRANSLUCENT);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            mHolder = holder;
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            mHolder = null;
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
            invalidate();
        }
    });

    final Resources res = context.getResources();
    final ViewConfiguration config = ViewConfiguration.get(context);

    mSingleTapRadiusSq = config.getScaledTouchSlop();

    // Dimensions.
    mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius);
    mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius);
    mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius);
    mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius);
    mSpacing = res.getDimensionPixelOffset(R.dimen.spacing);
    mTextSize = res.getDimensionPixelSize(R.dimen.text_size);
    mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius);
    mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius);

    // Colors.
    mOuterFillColor = res.getColor(R.color.outer_fill);
    mTextFillColor = res.getColor(R.color.text_fill);
    mCornerFillColor = res.getColor(R.color.corner_fill);
    mCornerTextFillColor = res.getColor(R.color.corner_text_fill);
    mDotFillColor = res.getColor(R.color.dot_fill);
    mDotStrokeColor = res.getColor(R.color.dot_stroke);
    mSelectionColor = res.getColor(R.color.selection_fill);
    mSelectionTextFillColor = res.getColor(R.color.selection_text_fill);
    mSelectionShadowColor = res.getColor(R.color.selection_shadow);
    mCenterFillColor = res.getColor(R.color.center_fill);
    mCenterTextFillColor = res.getColor(R.color.center_text_fill);
    mTextShadowColor = res.getColor(R.color.text_shadow);

    // Gradient colors.
    final int gradientInnerColor = res.getColor(R.color.gradient_inner);
    final int gradientOuterColor = res.getColor(R.color.gradient_outer);
    final int[] colors = new int[] { gradientInnerColor, gradientOuterColor };
    mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors);
    mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT);
    mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f);

    final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay);

    // Lighting filters generated from colors.
    mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN);

    mInnerRadiusSq = (mInnerRadius * mInnerRadius);
    mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius);

    mUseNodeProvider = useNodeProvider;

    if (mUseNodeProvider) {
        // Lazily-constructed node provider helper.
        ViewCompat.setAccessibilityDelegate(this, new RadialMenuHelper(this));
    }

    // Corner shapes only need to be invalidated and cached once.
    initializeCachedShapes();
}