List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:edu.mit.ll.dcds.android.AboutActivity.java
private void setLocale() { Locale locale = DataManager.getInstance().getLocale(); Locale.setDefault(locale);//from w w w .ja va 2 s . c o m Configuration config = new Configuration(); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); config.locale = locale; res.updateConfiguration(config, dm); }
From source file:com.google.samples.apps.ledtoggler.UserConsentDialogFragment.java
/** * Converts dp's (device independent pixels) to pixel values at runtime. * @param dp Device independent pixels to convert * @return input value in pixels.// w w w . j a v a2s .c om */ private int dpsToPixels(int dp) { Resources r = getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:edu.rowan.app.carousel.CarouselView.java
public CarouselView(Context context) { super(context); numFeatures = 0;//from ww w . j a va 2s . com featuresLoaded = 0; this.setBackgroundColor(Color.BLACK); Resources r = context.getResources(); int width = r.getDisplayMetrics().widthPixels; float ratio = (float) width / CAROUSEL_WIDTH; int height = 0; height = (int) (ratio * CAROUSEL_HEIGHT + 0.5); this.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, height)); // Log.d("Rowan Prototype", "Height of viewpager is " + height); // System.out.println("Height of ViewPager is " + height); adapter = new CarouselAdapter(); this.setAdapter(adapter); fetcher = new CarouselFetch(this, context); fetcher.execute(); }
From source file:dev.nick.tiles.tile.TileView.java
protected float dpToPx(int dp) { Resources r = getResources(); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:co.edu.uniajc.vtf.content.controller.SettingsController.java
private void setLocal(String pISOLang) { Locale loLocale = new Locale(pISOLang); Resources loResource = ((Fragment) this.coView).getResources(); DisplayMetrics loDm = loResource.getDisplayMetrics(); Configuration loConfig = loResource.getConfiguration(); loConfig.locale = loLocale;//from w w w . ja v a 2 s . co m loResource.updateConfiguration(loConfig, loDm); }
From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPickerDialogDash.java
private static void setColorViewValue(View view, int color) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable != null && currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {/*from w w w . ja va 2s .c o m*/ colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color int darkenedColor = Color.rgb(Color.red(color) * 192 / 256, Color.green(color) * 192 / 256, Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); colorChoiceDrawable.setStroke( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()), darkenedColor); imageView.setImageDrawable(colorChoiceDrawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:org.getlantern.firetweet.view.HomeActionButton.java
public HomeActionButton(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Resources resources = context.getResources(); final float elevation = resources.getDisplayMetrics().density * 4; mHelper = new EffectViewHelper(this, new PressElevationProperty(elevation), 200); if (isInEditMode()) { inflate(context, R.layout.action_item_home_actions, this); } else {//from ww w . j av a 2 s .c om inflate(ThemeUtils.getActionBarContext(context), R.layout.action_item_home_actions, this); } mIconView = (ImageView) findViewById(android.R.id.icon); mProgressBar = (ProgressBar) findViewById(android.R.id.progress); ViewAccessor.setOutlineProvider(this, new HomeActionButtonOutlineProvider()); setClipToOutline(true); setButtonColor(Color.WHITE); }
From source file:Main.java
/** * Set the original text size of the View. * * @see TextView#setTextSize(int, float) */// ww w .ja va 2 s . c o m public void setTextSize(int unit, float size) { if (mIsAutofitting) { // We don't want to update the TextView's actual textSize while we're autofitting // since it'd get set to the autofitTextSize return; } Context context = mTextView.getContext(); Resources r = Resources.getSystem(); if (context != null) { r = context.getResources(); } setRawTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics())); }
From source file:android.content.res.VectorResources.java
public VectorResources(Context context, Resources res) { super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration()); mContext = context;//from www .j a va 2 s . c o m mBase = res; }
From source file:org.mariotaku.twidere.view.HomeActionButton.java
public HomeActionButton(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); final Resources resources = context.getResources(); final float elevation = resources.getDisplayMetrics().density * 4; mHelper = new EffectViewHelper(this, new PressElevationProperty(elevation), 200); if (isInEditMode()) { inflate(context, R.layout.action_item_home_actions, this); } else if (context instanceof IThemedActivity) { int themeResourceId = ((IThemedActivity) context).getCurrentThemeResourceId(); int themeColor = ((IThemedActivity) context).getCurrentThemeColor(); inflate(ThemeUtils.getActionBarThemedContext(context, themeResourceId, themeColor), R.layout.action_item_home_actions, this); } else {/*from w ww .j a va2 s . c o m*/ inflate(ThemeUtils.getActionBarThemedContext(context), R.layout.action_item_home_actions, this); } mIconView = (ImageView) findViewById(android.R.id.icon); ViewSupport.setOutlineProvider(this, new HomeActionButtonOutlineProvider()); setClipToOutline(true); setButtonColor(Color.WHITE); }