List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java
private float spToPixels(int sp) { Resources r = getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics()); }
From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java
private float dpToPixels(float dp) { Resources r = getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:com.money.manager.ex.core.Core.java
private void setAppLocale_Internal(String languageToLoad) { Locale locale;/*from w w w . j a va 2s . c om*/ if (!TextUtils.isEmpty(languageToLoad)) { locale = new Locale(languageToLoad); // locale = Locale.forLanguageTag(languageToLoad); } else { locale = Locale.getDefault(); } // http://developer.android.com/reference/java/util/Locale.html#setDefault%28java.util.Locale%29 // Locale.setDefault(locale); // change locale of the configuration Resources resources = getContext().getResources(); Configuration config = resources.getConfiguration(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { config.locale = locale; } else { config.setLocale(locale); } // set new locale resources.updateConfiguration(config, resources.getDisplayMetrics()); }
From source file:be.virtualsushi.gaz.view.ActivityChooserView.java
/** * Create a new instance.//w w w . j a v a 2s.c om * * @param context * The application environment. * @param attrs * A collection of attributes. * @param defStyle * The default style to apply to this view. */ public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView, defStyle, 0); mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount, ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT); Drawable expandActivityOverflowButtonDrawable = attributesArray .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable); attributesArray.recycle(); LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(R.layout.abc_activity_chooser_view, this, true); mCallbacks = new Callbacks(); mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content); mActivityChooserContent.setBackgroundDrawable(null); findViewById(R.id.default_activity_button).setVisibility(GONE); mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button); mExpandActivityOverflowButton.setOnClickListener(mCallbacks); mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.findViewById(R.id.image); mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable); mAdapter = new ActivityChooserViewAdapter(); mAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { super.onChanged(); updateAppearance(); } }); Resources resources = context.getResources(); mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2, resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth)); }
From source file:android.support.v7.view.menu.CascadingMenuPopup.java
/** * Initializes a new cascading-capable menu popup. * * @param anchor A parent view to get the {@link android.view.View#getWindowToken()} token from. *///from w w w. j ava 2 s. c o m public CascadingMenuPopup(@NonNull Context context, @NonNull View anchor, @AttrRes int popupStyleAttr, @StyleRes int popupStyleRes, boolean overflowOnly) { mContext = context; mAnchorView = anchor; mPopupStyleAttr = popupStyleAttr; mPopupStyleRes = popupStyleRes; mOverflowOnly = overflowOnly; mForceShowIcon = false; mLastPosition = getInitialMenuPosition(); final Resources res = context.getResources(); mMenuMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth)); mSubMenuHoverHandler = new Handler(); }
From source file:com.ericsun.duom.Framework.Activity.BaseActivity.java
@Override public Resources getResources() { Resources res = super.getResources(); Configuration config = new Configuration(); // config.setToDefaults(); config.fontScale = 1.0f;//from ww w . j a va 2 s . co m res.updateConfiguration(config, res.getDisplayMetrics()); return res; }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private void measureThingBodyWidth() { if (isSinglePane || drawerLayout != null && navContainer != null) { return;/* w ww . j ava2 s.c om*/ } Resources r = getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int padding = r.getDimensionPixelSize(R.dimen.element_padding); if (navContainer != null) { int newWidth = hasLeftFragment() ? leftWidth : 0; thingBodyWidth = dm.widthPixels - newWidth - padding * 2; } else { thingBodyWidth = dm.widthPixels / 5 * 2 - padding * 3; } }
From source file:mobile.tiis.appv2.LoginActivity.java
public void setLocale(String lang) { myLocale = new Locale(lang); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale;//w ww .ja v a 2 s . c o m res.updateConfiguration(conf, dm); Intent refresh = new Intent(this, LoginActivity.class); refresh.putExtra(BackboneActivity.LANGUAGELOGIN, languagePosition); startActivity(refresh); }
From source file:com.adityarathi.muo.utils.Common.java
/** * Converts dp unit to equivalent pixels, depending on device density. * * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels * @param context Context to get resources and device specific display metrics * @return A float value to represent px equivalent to dp depending on device density *//*from w w w . jav a 2s. c om*/ public float convertDpToPixels(float dp, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float px = dp * (metrics.densityDpi / 160f); return px; }
From source file:com.adityarathi.muo.utils.Common.java
/** * Converts device specific pixels to density independent pixels. * * @param px A value in px (pixels) unit. Which we need to convert into db * @param context Context to get resources and device specific display metrics * @return A float value to represent dp equivalent to px value *//*from www . j a va 2 s. c om*/ public float convertPixelsToDp(float px, Context context) { Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float dp = px / (metrics.densityDpi / 160f); return dp; }