List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:org.indonesiax.mobile.view.custom.popup.menu.MenuPopupHelper.java
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes) { mContext = context;/* w w w.ja va2 s .c om*/ mInflater = LayoutInflater.from(context); mMenu = menu; mAdapter = new MenuAdapter(); mOverflowOnly = overflowOnly; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; final Resources res = context.getResources(); mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(android.support.v7.appcompat.R.dimen.abc_config_prefDialogWidth)); TypedArray a = context.obtainStyledAttributes(null, R.styleable.PopupMenu, mPopupStyleAttr, mPopupStyleRes); mPopupMinWidth = a.getDimensionPixelSize(R.styleable.PopupMenu_android_minWidth, 0); int popupPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_android_padding, -1); if (popupPadding >= 0) { mPopupPaddingStart = popupPadding; mPopupPaddingEnd = popupPadding; mPopupPaddingTop = popupPadding; mPopupPaddingBottom = popupPadding; } else { mPopupPaddingStart = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingStart, a.getDimensionPixelOffset(R.styleable.PopupMenu_android_paddingLeft, 0)); mPopupPaddingEnd = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingEnd, a.getDimensionPixelOffset(R.styleable.PopupMenu_android_paddingRight, 0)); mPopupPaddingTop = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingTop, 0); mPopupPaddingBottom = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingBottom, 0); } mPopupItemVerticalPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_itemVerticalPadding, 0); mPopupIconPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_iconPadding, 0); mPopupIconDefaultSize = a.getDimensionPixelSize(R.styleable.PopupMenu_iconDefaultSize, 0); mPopupHeaderTextAppearance = a.getResourceId(R.styleable.PopupMenu_headerTextAppearance, -1); mPopupRowTextAppearance = a.getResourceId(R.styleable.PopupMenu_rowTextAppearance, -1); a.recycle(); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
From source file:br.com.mauker.materialseekbar.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin//from www . j a v a2 s. c o m * * @param ctx Context * @param y The y coordinate to raw the pin (i.e. the bar location) * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param minFont the minimum font size for the pin text * @param maxFont the maximum font size for the pin text * @param pinsAreTemporary whether to show the pin initially or just the circle */ public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, float minFont, float maxFont, boolean pinsAreTemporary) { Resources res = ctx.getResources(); mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate); mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mIsTemporary = pinsAreTemporary; mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, res.getDisplayMetrics()); mCircleRadiusPx = circleRadius; mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, res.getDisplayMetrics()); // If one of the attributes are set, but the others aren't, set the // attributes to default if (pinRadiusDP == -1) { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP, res.getDisplayMetrics()); } else { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP, res.getDisplayMetrics()); } //Set text size in px from dp int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 5, res.getDisplayMetrics()); // Creates the paint and sets the Paint values mTextPaint = new Paint(); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); //Color filter for the selection pin mPinFilter = new LightingColorFilter(pinColor, pinColor); // Sets the minimum touchable area, but allows it to expand based on // image size int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx); mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius, res.getDisplayMetrics()); mY = y; }
From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java
public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final Resources res = context.getResources(); mAllowTextWithIcon = res.getBoolean(R.bool.abc_config_allowActionMenuItemTextWithIcon); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMenuItemView, defStyle, 0); mMinWidth = a.getDimensionPixelSize(R.styleable.ActionMenuItemView_android_minWidth, 0); a.recycle();//from w ww. j a v a 2 s . c om final float density = res.getDisplayMetrics().density; mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f); setOnClickListener(this); setOnLongClickListener(this); mSavedPaddingLeft = -1; }
From source file:org.lucasr.dspec.DesignSpec.java
public DesignSpec(Resources resources, View hostView) { mHostView = hostView;//from ww w . ja v a 2 s.c o m mDensity = resources.getDisplayMetrics().density; mKeylines = new ArrayList<Keyline>(); mSpacings = new ArrayList<Spacing>(); mBaselineGridPaint = new Paint(); mBaselineGridPaint.setColor(Color.parseColor(DEFAULT_BASELINE_GRID_COLOR)); mKeylinesPaint = new Paint(); mKeylinesPaint.setStrokeWidth(KEYLINE_STROKE_WIDTH_DIP * mDensity); mKeylinesPaint.setColor(Color.parseColor(DEFAULT_KEYLINE_COLOR)); mSpacingsPaint = new Paint(); mSpacingsPaint.setColor(Color.parseColor(DEFAULT_SPACING_COLOR)); mBaselineGridCellSize = mDensity * DEFAULT_BASELINE_GRID_CELL_SIZE_DIP; }
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 w w .ja va2 s . c o m 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.appsimobile.appsii.module.home.SunriseDrawable.java
void customTheme(int drawableResId, int colorPrimary, int textColor, int tintColor) { Resources res = mContext.getResources(); mSunImage = res.getDrawable(drawableResId); DrawableCompat.setTintColorCompat(mSunImage, tintColor); mArcFillPaint.setColor(colorPrimary); mArcFillPaint.setColor(ColorUtils.setAlphaComponent(colorPrimary, 128)); mLinePaint.setColor(textColor);//from w w w . j ava 2 s . c o m mDotPaint.setColor(tintColor); float density = res.getDisplayMetrics().density; int sunBounds = (int) (density * 16); mSunImage.setBounds(0, 0, sunBounds, sunBounds); Callback callback = getCallback(); if (callback != null) { callback.invalidateDrawable(this); } }
From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes) { mContext = context;//from w w w. java 2s. c o m mInflater = LayoutInflater.from(context); mMenu = menu; mAdapter = new MenuAdapter(); mOverflowOnly = overflowOnly; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; final Resources res = context.getResources(); mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(android.support.v7.appcompat.R.dimen.abc_config_prefDialogWidth)); TypedArray a = context.obtainStyledAttributes(null, R.styleable.PopupMenu, mPopupStyleAttr, mPopupStyleRes); mPopupMinWidth = a.getDimensionPixelSize(R.styleable.PopupMenu_android_minWidth, 0); int popupPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_android_padding, -1); if (popupPadding >= 0) { mPopupPaddingLeft = popupPadding; mPopupPaddingRight = popupPadding; mPopupPaddingStart = popupPadding; mPopupPaddingEnd = popupPadding; mPopupPaddingTop = popupPadding; mPopupPaddingBottom = popupPadding; } else { int paddingStart = Integer.MIN_VALUE; int paddingEnd = Integer.MIN_VALUE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { paddingStart = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingStart, Integer.MIN_VALUE); paddingEnd = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingEnd, Integer.MIN_VALUE); } int paddingLeft = 0; int paddingRight = 0; if (paddingStart == Integer.MIN_VALUE && paddingEnd == Integer.MIN_VALUE) { paddingLeft = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingLeft, 0); paddingRight = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingRight, 0); } else { if (paddingStart == Integer.MIN_VALUE) { paddingStart = 0; } if (paddingEnd == Integer.MIN_VALUE) { paddingEnd = 0; } } mPopupPaddingLeft = paddingLeft; mPopupPaddingRight = paddingRight; mPopupPaddingStart = paddingStart; mPopupPaddingEnd = paddingEnd; mPopupPaddingTop = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingTop, 0); mPopupPaddingBottom = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingBottom, 0); } mPopupItemVerticalPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_itemVerticalPadding, 0); mPopupIconPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_iconPadding, 0); mPopupIconDefaultSize = a.getDimensionPixelSize(R.styleable.PopupMenu_iconDefaultSize, 0); a.recycle(); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java
private int getMaxAvailableHeight(View anchor, int yOffset, boolean ignoreBottomDecorations) { final Rect displayFrame = new Rect(); anchor.getWindowVisibleDisplayFrame(displayFrame); final int[] anchorPos = new int[2]; anchor.getLocationOnScreen(anchorPos); int bottomEdge = displayFrame.bottom; if (ignoreBottomDecorations) { Resources res = anchor.getContext().getResources(); bottomEdge = res.getDisplayMetrics().heightPixels; }/*from w ww . j a v a2s.c o m*/ final int distanceToBottom = bottomEdge - (anchorPos[1] + anchor.getHeight()) - yOffset; final int distanceToTop = anchorPos[1] - displayFrame.top + yOffset; // anchorPos[1] is distance from anchor to top of screen int returnedHeight = Math.max(distanceToBottom, distanceToTop); if (mPopup.getBackground() != null) { mPopup.getBackground().getPadding(mTempRect); returnedHeight -= mTempRect.top + mTempRect.bottom; } return returnedHeight; }
From source file:org.edx.mobile.view.custom.popup.menu.MenuPopupHelper.java
public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly, int popupStyleAttr, int popupStyleRes) { mContext = context;/*from w ww .j a v a2 s . c o m*/ mInflater = LayoutInflater.from(context); mMenu = menu; mAdapter = new MenuAdapter(); mOverflowOnly = overflowOnly; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; final Resources res = context.getResources(); mPopupMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(android.support.v7.appcompat.R.dimen.abc_config_prefDialogWidth)); TypedArray a = context.obtainStyledAttributes(null, R.styleable.PopupMenu, mPopupStyleAttr, mPopupStyleRes); mPopupMinWidth = a.getDimensionPixelSize(R.styleable.PopupMenu_android_minWidth, 0); int popupPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_android_padding, -1); if (popupPadding >= 0) { mPopupPaddingLeft = popupPadding; mPopupPaddingRight = popupPadding; mPopupPaddingStart = popupPadding; mPopupPaddingEnd = popupPadding; mPopupPaddingTop = popupPadding; mPopupPaddingBottom = popupPadding; } else { int paddingStart = Integer.MIN_VALUE; int paddingEnd = Integer.MIN_VALUE; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { paddingStart = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingStart, Integer.MIN_VALUE); paddingEnd = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingEnd, Integer.MIN_VALUE); } int paddingLeft = 0; int paddingRight = 0; if (paddingStart == Integer.MIN_VALUE && paddingEnd == Integer.MIN_VALUE) { paddingLeft = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingLeft, 0); paddingRight = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingRight, 0); } else { if (paddingStart == Integer.MIN_VALUE) { paddingStart = 0; } if (paddingEnd == Integer.MIN_VALUE) { paddingEnd = 0; } } mPopupPaddingLeft = paddingLeft; mPopupPaddingRight = paddingRight; mPopupPaddingStart = paddingStart; mPopupPaddingEnd = paddingEnd; mPopupPaddingTop = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingTop, 0); mPopupPaddingBottom = a.getDimensionPixelSize(R.styleable.PopupMenu_android_paddingBottom, 0); } mPopupItemVerticalPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_itemVerticalPadding, 0); mPopupIconPadding = a.getDimensionPixelSize(R.styleable.PopupMenu_iconPadding, 0); mPopupIconDefaultSize = a.getDimensionPixelSize(R.styleable.PopupMenu_iconDefaultSize, 0); mPopupHeaderTextAppearance = a.getResourceId(R.styleable.PopupMenu_headerTextAppearance, -1); mPopupRowTextAppearance = a.getResourceId(R.styleable.PopupMenu_rowTextAppearance, -1); a.recycle(); mAnchorView = anchorView; // Present the menu using our context, not the menu builder's context. menu.addMenuPresenter(this, context); }
From source file:net.naonedbus.appwidget.HoraireWidgetProvider.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private int getHorairesCount(final Context context, final Bundle bundle) { synchronized (sLock) { if (sHoraireTextWidth == Integer.MIN_VALUE) { final TextView horaireTextView = new TextView(context); horaireTextView.setTextAppearance(horaireTextView.getContext(), android.R.style.TextAppearance_Medium); final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00); final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context); horaireTextView.setText(//from www. j av a 2 s .c o m FormatUtils.formatTimeAmPm(context, timeFormat.format(noon.toDate())) + " \u2022 "); final int specY = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); final int specX = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); horaireTextView.measure(specX, specY); sHoraireTextWidth = horaireTextView.getMeasuredWidth(); } } final Resources r = context.getResources(); final int padding = r.getDimensionPixelSize(R.dimen.padding_small); final int minWidth = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); final int minWidthPixel = Math.round( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, minWidth, r.getDisplayMetrics())) - padding; return (minWidthPixel / sHoraireTextWidth); }