List of usage examples for android.util TypedValue applyDimension
public static float applyDimension(int unit, float value, DisplayMetrics metrics)
From source file:com.yamin.kk.vlc.Util.java
public static int convertDpToPx(int dp) { return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, VLCApplication.getAppResources().getDisplayMetrics())); }
From source file:com.cube.storm.ui.view.PagerSlidingTabStrip.java
private void addIconTab(final int position, Bitmap bitmap) { ImageView tab = new ImageView(getContext()); tab.setImageBitmap(bitmap);//w w w. j ava 2s. c om tab.setColorFilter(tabIconTint); tab.setScaleType(ScaleType.FIT_CENTER); DisplayMetrics dm = getResources().getDisplayMetrics(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm); tab.setPadding(padding + tabPadding, padding, padding + tabPadding, padding); tab.setFocusable(true); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(android.view.View v) { pager.setCurrentItem(position); } }); tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPParentFragment.java
/** * Private helper method to animate toolbar and related views to a position. * @param toY New Y position.//from w ww .j a va 2s .c o m * @param completionHandlers any handlers to be fired after completion of the animation */ private void animateToolbar(final float toY, final Runnable... completionHandlers) { float layoutTranslationY = mInterceptionLayout.getTranslationY(); if (layoutTranslationY != toY) { // get translation final float translationY = -layoutTranslationY + toY; final View toolbarView = getActivity().findViewById(R.id.toolbar); final SearchBox searchView = ((MainActivity) getActivity()).getSearch(); // Need to offset for the -6dp margin on search bar Resources r = getResources(); float offset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6, r.getDisplayMetrics()); // Start animating all the items mInterceptionLayout.animate().y(toY).setDuration(200); toolbarView.animate().y(toY).setDuration(200); searchView.animate().y(toY - offset).setDuration(200); // Relayout child view at animation completion final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); new Handler().postDelayed(new Runnable() { public void run() { lp.height = (int) (Math.max(0, -translationY) + getScreenHeight()); mInterceptionLayout.requestLayout(); } }, translationY < 0 ? 0 : 200); // Start calling all handlers, giving time for re-layout to occur. new Handler().postDelayed(new Runnable() { public void run() { for (Runnable completionHandler : completionHandlers) { completionHandler.run(); } } }, 250); } }
From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java
/** * DIP?/*from w w w . ja va2 s . co m*/ * * @param dipValue * dip * @return int */ protected int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, mContext.getResources().getDisplayMetrics()); return value; }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
public float getTextSize(int unit, float size) { Context c = getContext();/*from w w w . j a v a 2 s . c o m*/ Resources r; if (c == null) r = Resources.getSystem(); else r = c.getResources(); return TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
private float dp2px(int dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, this.metrics); }
From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java
/** * Specify whether this widget should automatically scale the text to try to perfectly fit * within the layout bounds. If all the configuration params are valid the type of auto-size is * set to {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}. * * @param autoSizeMinTextSize the minimum text size available for auto-size * @param autoSizeMaxTextSize the maximum text size available for auto-size * @param autoSizeStepGranularity the auto-size step granularity. It is used in conjunction with * the minimum and maximum text size in order to build the set of * text sizes the system uses to choose from when auto-sizing * @param unit the desired dimension unit for all sizes above. See {@link TypedValue} for the * possible dimension units/*from w ww . ja va 2 s . c o m*/ * * @throws IllegalArgumentException if any of the configuration params are invalid. * * @attr ref R.styleable#AppCompatTextView_autoSizeTextType * @attr ref R.styleable#AppCompatTextView_autoSizeMinTextSize * @attr ref R.styleable#AppCompatTextView_autoSizeMaxTextSize * @attr ref R.styleable#AppCompatTextView_autoSizeStepGranularity * * @see #setAutoSizeTextTypeWithDefaults(int) * @see #setAutoSizeTextTypeUniformWithPresetSizes(int[], int) * @see #getAutoSizeMinTextSize() * @see #getAutoSizeMaxTextSize() * @see #getAutoSizeStepGranularity() * @see #getAutoSizeTextAvailableSizes() * * @hide */ @RestrictTo(LIBRARY_GROUP) void setAutoSizeTextTypeUniformWithConfiguration(int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit) throws IllegalArgumentException { if (supportsAutoSizeText()) { final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); final float autoSizeMinTextSizeInPx = TypedValue.applyDimension(unit, autoSizeMinTextSize, displayMetrics); final float autoSizeMaxTextSizeInPx = TypedValue.applyDimension(unit, autoSizeMaxTextSize, displayMetrics); final float autoSizeStepGranularityInPx = TypedValue.applyDimension(unit, autoSizeStepGranularity, displayMetrics); validateAndSetAutoSizeTextTypeUniformConfiguration(autoSizeMinTextSizeInPx, autoSizeMaxTextSizeInPx, autoSizeStepGranularityInPx); if (setupAutoSizeText()) { autoSizeText(); } } }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
private float dp2px(float dp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, this.metrics); }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
private float sp2px(float sp) { return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, this.metrics); }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * Converts DIP (or DP) to Pixels/*from w w w. j a va2s . c o m*/ */ public static int convertDpToPixel(Context context, float dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); }