List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.bq.robotic.robopad_plusplus.fragments.ScheduleRobotMovementsFragment.java
public static int getSmallestScreenWidthDp(Context context) { Resources resources = context.getResources(); try {//from ww w . j av a 2 s . c o m Field field = Configuration.class.getDeclaredField("smallestScreenWidthDp"); return (Integer) field.get(resources.getConfiguration()); } catch (Exception e) { // not perfect because reported screen size might not include status and button bars DisplayMetrics displayMetrics = resources.getDisplayMetrics(); int smallestScreenWidthPixels = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels); return Math.round(smallestScreenWidthPixels / displayMetrics.density); } }
From source file:ly.count.android.api.DeviceInfoTests.java
private Context mockContextForTestingDensity(final int density) { final DisplayMetrics metrics = new DisplayMetrics(); metrics.densityDpi = density;/*from ww w .ja v a2 s . c o m*/ final Resources mockResources = mock(Resources.class); when(mockResources.getDisplayMetrics()).thenReturn(metrics); final Context mockContext = mock(Context.class); when(mockContext.getResources()).thenReturn(mockResources); return mockContext; }
From source file:org.dmfs.android.colorpicker.PalettesPagerAdapter.java
public PalettesPagerAdapter(Resources res, FragmentManager fm, Palette... palettes) { super(fm);// w ww. j a va 2 s. c o m mPalettes = palettes; mResources = res; mDensity = res.getDisplayMetrics().density; }
From source file:ti.org.dmfs.android.colorpicker.PalettesPagerAdapter.java
public PalettesPagerAdapter(Resources res, FragmentManager fm, AbstractPalette... palettes) { super(fm);/*from w w w . j a va 2 s. c o m*/ mPalettes = palettes; mResources = res; mDensity = res.getDisplayMetrics().density; }
From source file:com.willowtreeapps.spurceexampleapp.fragments.ViewFragment.java
@Nullable @Override/*from w w w .jav a 2 s .c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.view_fragment, container, false); parent = (GridLayout) rootView.findViewById(R.id.view_group_to_animate); final int CHILD_VIEW_COUNT = parent.getColumnCount() * parent.getRowCount(); for (int i = 0; i < CHILD_VIEW_COUNT; i++) { View childView = new View(getContext()); childView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.spruceViewColor)); childView.setAlpha(0F); parent.addView(childView); children.add(childView); } parent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Resources res = getResources(); int tileMargins = Math .round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics())); final int childWidth = parent.getWidth() / parent.getColumnCount() - (tileMargins * 2); final int childHeight = parent.getHeight() / parent.getRowCount() - (tileMargins * 2); for (int i = 0; i < parent.getChildCount(); i++) { View childView = parent.getChildAt(i); GridLayout.LayoutParams params = (GridLayout.LayoutParams) childView.getLayoutParams(); params.width = childWidth; params.height = childHeight; params.setMargins(tileMargins, tileMargins, tileMargins, tileMargins); childView.setLayoutParams(params); } parent.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); listener.onParentAndChildrenPrepared(parent, children); return rootView; }
From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingLanguageActivity.java
public void setLocale(String lang) { Resources res = this.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale(lang.toLowerCase()); res.updateConfiguration(conf, dm);/*from w w w . j a v a2s.com*/ Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); /* FLAG_ACTIVITY_CLEAR_TOP If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent. */ startActivity(intent); }
From source file:at.amartinz.hardware.device.Device.java
protected Device(@NonNull Context context) { mContext = context;/* www.jav a 2 s .c om*/ platformVersion = Build.VERSION.RELEASE; platformId = Build.DISPLAY; platformType = Build.VERSION.CODENAME + " " + Build.TYPE; platformTags = Build.TAGS; platformBuildType = HwUtils.getDate(Build.TIME); vmVersion = System.getProperty("java.vm.version", "-"); vmLibrary = getRuntime(); final Resources res = context.getResources(); screenWidth = res.getDisplayMetrics().widthPixels; screenHeight = res.getDisplayMetrics().heightPixels; androidId = getAndroidId(context); manufacturer = Build.MANUFACTURER; model = Build.MODEL; device = Build.DEVICE; product = Build.PRODUCT; board = Build.BOARD; bootloader = Build.BOOTLOADER; radio = Build.getRadioVersion(); // initialize defaults hasBusyBox = false; hasRoot = false; suVersion = "-"; isSELinuxEnforcing = isSELinuxEnforcing(); // ehm, alright, if you say so... }
From source file:fm.krui.kruifm.ScheduleFragment.java
/** * Converts dp values to an appropriate amount of pixels based on screen density of this device. * @param dp value of dp to convert// ww w . jav a 2 s. c om * @return equivalent pixel count */ private int dpToPixels(int dp) { Resources r = getResources(); return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }
From source file:com.ryg.dynamicload.DLProxyFragmentActivity.java
protected void loadResources() { try {//from w w w .j a va 2s .c o m AssetManager assetManager = AssetManager.class.newInstance(); Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class); addAssetPath.invoke(assetManager, mDexPath); mAssetManager = assetManager; } catch (Exception e) { e.printStackTrace(); } Resources superRes = super.getResources(); mResources = new Resources(mAssetManager, superRes.getDisplayMetrics(), superRes.getConfiguration()); }
From source file:org.mariotaku.twidere.view.NameView.java
private float calculateTextSize(final int unit, final float size) { Context c = getContext();//from w ww . j av a2s .co m Resources r; if (c == null) r = Resources.getSystem(); else r = c.getResources(); return TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); }