下面列出了android.content.res.Resources#getDimensionPixelOffset() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
@NonNull RecyclerView recyclerView, int type, boolean showFavourited) {
mInflater = inflater;
mResources = resources;
mRecyclerView = recyclerView;
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
mPaddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
mShowFavourited = showFavourited;
mRecyclerView.setAdapter(this);
mRecyclerView.setLayoutManager(mLayoutManager);
View calculator = inflater.inflate(R.layout.item_gallery_list_thumb_height, null);
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
mListThumbHeight = calculator.getMeasuredHeight();
mListThumbWidth = mListThumbHeight * 2 / 3;
setType(type);
mDownloadManager = EhApplication.getDownloadManager(inflater.getContext());
}
/**
* @param context The current Android's context.
*/
public void contextChanged(Context context) {
Resources res = context.getResources();
final float pxToDp = 1.0f / res.getDisplayMetrics().density;
mMinScrollMotion = DRAG_MOTION_THRESHOLD_DP;
final float maxOverScrollPx = res.getDimensionPixelOffset(R.dimen.over_scroll);
final float maxUnderScrollPx = Math.round(maxOverScrollPx * MAX_UNDER_SCROLL_SCALE);
mMaxOverScroll = maxOverScrollPx * pxToDp;
mMaxUnderScroll = maxUnderScrollPx * pxToDp;
mMaxOverScrollAngle = res.getInteger(R.integer.over_scroll_angle);
mMaxOverScrollSlide = res.getDimensionPixelOffset(R.dimen.over_scroll_slide) * pxToDp;
mEvenOutRate = 1.0f / (res.getDimension(R.dimen.even_out_scrolling) * pxToDp);
mMinSpacing = res.getDimensionPixelOffset(R.dimen.min_spacing) * pxToDp;
mBorderTransparentTop =
res.getDimension(R.dimen.tabswitcher_border_frame_transparent_top) * pxToDp;
mBorderTransparentSide =
res.getDimension(R.dimen.tabswitcher_border_frame_transparent_side) * pxToDp;
mBorderTopPadding = res.getDimension(R.dimen.tabswitcher_border_frame_padding_top) * pxToDp;
mBorderLeftPadding =
res.getDimension(R.dimen.tabswitcher_border_frame_padding_left) * pxToDp;
// Just in case the density has changed, rebuild the OverScroller.
mScroller = new StackScroller(context);
}
public YearPickerView(Context context, DatePickerController controller) {
super(context);
mController = controller;
mController.registerOnDateChangedListener(this);
ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
setLayoutParams(frame);
Resources res = context.getResources();
mViewSize = mController.getVersion() == DatePickerDialog.Version.VERSION_1
? res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
: res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height_v2);
mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(mChildSize / 3);
init();
setOnItemClickListener(this);
setSelector(new StateListDrawable());
setDividerHeight(0);
onDateChanged();
}
public YearPickerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this._context = context;
final LayoutParams frame = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
setLayoutParams(frame);
final Resources res = context.getResources();
_viewSize = res.getDimensionPixelOffset(R.dimen.datepicker_view_animator_height);
_childSize = res.getDimensionPixelOffset(R.dimen.datepicker_year_label_height);
setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final int year = _adapter.getYearForPosition(position);
_adapter.setSelection(year);
if (_onYearSelectedListener != null) {
_onYearSelectedListener.onYearChanged(YearPickerView.this, year);
}
}
});
_adapter = new YearAdapter(getContext());
setAdapter(_adapter);
}
/**
* @param context
*/
public YearPickerView(Context context, DatePickerController controller) {
super(context);
mController = controller;
mController.registerOnDateChangedListener(this);
ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
setLayoutParams(frame);
Resources res = context.getResources();
mViewSize = res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height);
mChildSize = res.getDimensionPixelOffset(R.dimen.mdtp_year_label_height);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(mChildSize / 3);
init(context);
setOnItemClickListener(this);
setSelector(new StateListDrawable());
setDividerHeight(0);
onDateChanged();
}
/**
* @param context
*/
public YearPickerView(Context context, DatePickerController controller) {
super(context);
mController = controller;
mController.registerOnDateChangedListener(this);
ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
setLayoutParams(frame);
Resources res = context.getResources();
mViewSize = res.getDimensionPixelOffset(R.dimen.range_date_picker_view_animator_height);
mChildSize = res.getDimensionPixelOffset(R.dimen.range_year_label_height);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(mChildSize / 3);
init(context);
setOnItemClickListener(this);
setSelector(new StateListDrawable());
setDividerHeight(0);
onDateChanged();
}
private void initValues(Context context) {
Resources res = context.getResources();
mInterpolator = new AccelerateInterpolator();
mSectionsCount = res.getInteger(R.integer.spb_default_sections_count);
mColors = new int[]{res.getColor(R.color.spb_default_color)};
mSpeed = Float.parseFloat(res.getString(R.string.spb_default_speed));
mReversed = res.getBoolean(R.bool.spb_default_reversed);
mStrokeSeparatorLength = res.getDimensionPixelSize(R.dimen.spb_default_stroke_separator_length);
mStrokeWidth = res.getDimensionPixelOffset(R.dimen.spb_default_stroke_width);
}
public AlbumsAdapter(Fragment fragment) {
this.hostManager = HostManager.getInstance(fragment.getContext());
this.fragment = fragment;
// Get the art dimensions
// Use the same dimensions as in the details fragment, so that it hits Picasso's cache when
// the user transitions to that fragment, avoiding another call and imediatelly showing the image
Resources resources = fragment.getContext().getResources();
artWidth = resources.getDimensionPixelOffset(R.dimen.detail_poster_width_square);
artHeight = resources.getDimensionPixelOffset(R.dimen.detail_poster_height_square);
}
private void initValues(Context context) {
Resources res = context.getResources();
mInterpolator = new AccelerateInterpolator();
mSectionsCount = res.getInteger(R.integer.spb_default_sections_count);
mColors = new int[]{res.getColor(R.color.spb_default_color)};
mSpeed = Float.parseFloat(res.getString(R.string.spb_default_speed));
mProgressiveStartSpeed = mSpeed;
mProgressiveStopSpeed = mSpeed;
mReversed = res.getBoolean(R.bool.spb_default_reversed);
mStrokeSeparatorLength = res.getDimensionPixelSize(R.dimen.spb_default_stroke_separator_length);
mStrokeWidth = res.getDimensionPixelOffset(R.dimen.spb_default_stroke_width);
mProgressiveStartActivated = res.getBoolean(R.bool.spb_default_progressiveStart_activated);
mGradients = false;
}
public static int getStatusHeight(Resources myR)
{
if(StatusHeight!=-1) return StatusHeight;
int height;
int idSbHeight = myR.getIdentifier("status_bar_height", "dimen", "android");
if (idSbHeight > 0) {
height = myR.getDimensionPixelOffset(idSbHeight);
// Toast.makeText(this, "Status Bar Height = "+ height, Toast.LENGTH_SHORT).show();
} else {
height = 0;
// Toast.makeText(this,"Resources NOT found",Toast.LENGTH_LONG).show();
}
StatusHeight =height;
return StatusHeight;
}
@Override
public void initForMenu(@NonNull Context context, @NonNull MenuBuilder menu) {
layoutInflater = LayoutInflater.from(context);
this.menu = menu;
Resources res = context.getResources();
paddingSeparator =
res.getDimensionPixelOffset(R.dimen.design_navigation_separator_vertical_padding);
}
public MusicVideosAdapter(Context context) {
this.context = context;
this.hostManager = HostManager.getInstance(context);
// Get the art dimensions
Resources resources = context.getResources();
artHeight = resources.getDimensionPixelOffset(R.dimen.detail_poster_width_square);
artWidth = resources.getDimensionPixelOffset(R.dimen.detail_poster_height_square);
}
private void init(Context context) {
Resources resources = context.getResources();
mStarDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_x16);
mStarHalfDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_half_x16);
mStarOutlineDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_outline_x16);
mRatingSize = resources.getDimensionPixelOffset(R.dimen.rating_size);
mRatingInterval = resources.getDimensionPixelOffset(R.dimen.rating_interval);
mStarDrawable.setBounds(0, 0, mRatingSize, mRatingSize);
mStarHalfDrawable.setBounds(0, 0, mRatingSize, mRatingSize);
mStarOutlineDrawable.setBounds(0, 0, mRatingSize, mRatingSize);
}
public TextViewWithCircularIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
Resources res = context.getResources();
mCircleColor = res.getColor(R.color.blue);
mRadius = res.getDimensionPixelOffset(R.dimen.month_select_circle_radius);
mItemIsSelectedText = context.getResources().getString(R.string.item_is_selected);
init();
}
ObjectGraphicInMultiMode(
GraphicOverlay overlay,
DetectedObject object,
ObjectConfirmationController confirmationController) {
super(overlay);
this.object = object;
this.confirmationController = confirmationController;
Resources resources = context.getResources();
boxPaint = new Paint();
boxPaint.setStyle(Style.STROKE);
boxPaint.setStrokeWidth(
resources.getDimensionPixelOffset(
confirmationController.isConfirmed()
? R.dimen.bounding_box_confirmed_stroke_width
: R.dimen.bounding_box_stroke_width));
boxPaint.setColor(Color.WHITE);
boxGradientStartColor = ContextCompat.getColor(context, R.color.bounding_box_gradient_start);
boxGradientEndColor = ContextCompat.getColor(context, R.color.bounding_box_gradient_end);
boxCornerRadius = resources.getDimensionPixelOffset(R.dimen.bounding_box_corner_radius);
scrimPaint = new Paint();
scrimPaint.setShader(
new LinearGradient(
0,
0,
overlay.getWidth(),
overlay.getHeight(),
ContextCompat.getColor(context, R.color.object_confirmed_bg_gradient_start),
ContextCompat.getColor(context, R.color.object_confirmed_bg_gradient_end),
TileMode.MIRROR));
eraserPaint = new Paint();
eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
minBoxLen =
resources.getDimensionPixelOffset(R.dimen.object_reticle_outer_ring_stroke_radius) * 2;
}
private static int getPaddedPickerWidth(@NonNull Context context) {
Resources resources = context.getResources();
int padding = resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_content_padding);
int daysInWeek = Month.current().daysInWeek;
int dayWidth = resources.getDimensionPixelSize(R.dimen.mtrl_calendar_day_width);
int horizontalSpace =
resources.getDimensionPixelOffset(R.dimen.mtrl_calendar_month_horizontal_padding);
return 2 * padding + daysInWeek * dayWidth + (daysInWeek - 1) * horizontalSpace;
}
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
super(context, attr);
mController = controller;
Resources res = context.getResources();
mDayLabelCalendar = Calendar.getInstance();
mCalendar = Calendar.getInstance();
mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);
boolean darkTheme = mController != null && mController.isThemeDark();
if(darkTheme) {
mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal_dark_theme);
mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day_dark_theme);
mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme);
mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted_dark_theme);
}
else {
mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal);
mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day);
mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled);
mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted);
}
mSelectedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
mTodayNumberColor = mController.getAccentColor();
mMonthTitleColor = ContextCompat.getColor(context, R.color.mdtp_white);
mStringBuilder = new StringBuilder(50);
mFormatter = new Formatter(mStringBuilder, Locale.getDefault());
MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
DAY_SELECTED_CIRCLE_SIZE = res
.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);
mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
- getMonthHeaderSize()) / 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();
}
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
super(context, attr);
mController = controller;
Resources res = context.getResources();
mDayLabelCalendar = new PersianDate();
mPersianDate = new PersianDate();
mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);
boolean darkTheme = mController != null && mController.isThemeDark();
if (darkTheme) {
mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
} else {
mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
}
mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
mTodayNumberColor = res.getColor(R.color.mdtp_accent_color);
mMonthTitleColor = res.getColor(R.color.mdtp_white);
mStringBuilder = new StringBuilder(50);
MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
DAY_SELECTED_CIRCLE_SIZE = res
.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);
mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
- getMonthHeaderSize()) / 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();
}
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);
Context context = getContext2();
AssertUtils.assertNotNull(context);
Resources resources = context.getResources();
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
tip.setCompoundDrawables(null, drawable, null, null);
mAdapter = new CommentAdapter();
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
RecyclerView.VERTICAL, false));
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
LayoutUtils.dp2pix(context, 1));
decoration.setShowLastDivider(true);
mRecyclerView.addItemDecoration(decoration);
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOnItemClickListener(this);
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
// Cancel change animator
RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
if (itemAnimator instanceof DefaultItemAnimator) {
((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
}
mSendImage.setOnClickListener(this);
mFab.setOnClickListener(this);
addAboveSnackView(mEditPanel);
addAboveSnackView(mFabLayout);
mViewTransition = new ViewTransition(mRecyclerView, tip);
updateView(false);
return view;
}
/**
* check if the TextFieldBox should use a dense spacing,
* then change the layout dimens accordingly
*/
protected void updateDimens(boolean useDenseSpacing) {
final Resources res = getContext().getResources();
/* Floating Label */
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) this.floatingLabel.getLayoutParams();
lp.topMargin = res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.dense_label_idle_margin_top :
R.dimen.label_idle_margin_top
);
this.floatingLabel.setLayoutParams(lp);
/* EditText Layout */
this.inputLayout.setPadding(
0, res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.dense_editTextLayout_padding_top :
R.dimen.editTextLayout_padding_top
),
0, res.getDimensionPixelOffset(R.dimen.editTextLayout_padding_bottom));
/* End Icon */
this.endIconImageButton.setMinimumHeight(
res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.end_icon_min_height :
R.dimen.dense_end_icon_min_height
)
);
this.endIconImageButton.setMinimumWidth(
res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.end_icon_min_width :
R.dimen.dense_end_icon_min_width
)
);
/* Clear Icon */
this.clearButton.setMinimumHeight(
res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.clear_button_min_height :
R.dimen.dense_clear_button_min_height
)
);
this.clearButton.setMinimumWidth(
res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.clear_button_min_width :
R.dimen.dense_clear_button_min_width
)
);
/* Bottom View */
lp = (RelativeLayout.LayoutParams) this.bottomPart.getLayoutParams();
lp.topMargin = res.getDimensionPixelOffset(
useDenseSpacing ?
R.dimen.dense_bottom_marginTop :
R.dimen.bottom_marginTop
);
this.bottomPart.setLayoutParams(lp);
/* EditText */
this.editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, res.getDimension(
useDenseSpacing ?
R.dimen.dense_edittext_text_size :
R.dimen.edittext_text_size
));
this.labelTopMargin = RelativeLayout.LayoutParams.class
.cast(this.floatingLabel.getLayoutParams()).topMargin;
this.requestLayout();
}