本文整理了Java中android.content.res.Resources.getSystem
方法的一些代码示例,展示了Resources.getSystem
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.getSystem
方法的具体详情如下:
包路径:android.content.res.Resources
类名称:Resources
方法名:getSystem
暂无
代码示例来源:origin: airbnb/lottie-android
public static float dpScale() {
if (dpScale == -1) {
dpScale = Resources.getSystem().getDisplayMetrics().density;
}
return dpScale;
}
代码示例来源:origin: scwang90/SmartRefreshLayout
/**
* 現在の向きが600dpを超えているかどうか
*
* @return 600dpを超えているかどうか
*/
public static boolean isOver600dp() {
// Resources resources = context.getResources();
DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
return displayMetrics.widthPixels / displayMetrics.density >= 600;
}
/**
代码示例来源:origin: scwang90/SmartRefreshLayout
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
* @param pxValue 像素
* @return 虚拟像素
*/
public static float px2dp(int pxValue) {
return (pxValue / Resources.getSystem().getDisplayMetrics().density);
}
代码示例来源:origin: scwang90/SmartRefreshLayout
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
* @param dpValue 虚拟像素
* @return 像素
*/
public static int dp2px(float dpValue) {
return (int) (0.5f + dpValue * Resources.getSystem().getDisplayMetrics().density);
}
代码示例来源:origin: scwang90/SmartRefreshLayout
public DensityUtil() {
density = Resources.getSystem().getDisplayMetrics().density;
}
代码示例来源:origin: mikepenz/MaterialDrawer
public static int getScreenOrientation() {
return Resources.getSystem().getConfiguration().orientation;
}
}
代码示例来源:origin: Bearded-Hen/Android-Bootstrap
/**
* Converts density-independent pixels to pixels
* @param dip the dips
* @return size in pixels
*/
public static int dpToPixels(float dip) {
return (int) (dip * Resources.getSystem().getDisplayMetrics().density);
}
代码示例来源:origin: Bearded-Hen/Android-Bootstrap
/**
* Converts pixels to density-independent pixels
* @param pixels the pixels
* @return size in dp
*/
public static int pixelsToDp(float pixels) {
return (int) (pixels / Resources.getSystem().getDisplayMetrics().density);
}
代码示例来源:origin: scwang90/SmartRefreshLayout
/** 获取状态栏高度 */
public static int getStatusBarHeight(Context context) {
int result = 24;
int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resId > 0) {
result = context.getResources().getDimensionPixelSize(resId);
} else {
result = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
result, Resources.getSystem().getDisplayMetrics());
}
return result;
}
}
代码示例来源:origin: bumptech/glide
@DrawableRes
private int findResourceIdFromTypeAndNameResourceUri(Context context, Uri source) {
List<String> segments = source.getPathSegments();
String packageName = source.getAuthority();
String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX);
String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX);
int result = context.getResources().getIdentifier(resourceName, typeName, packageName);
if (result == MISSING_RESOURCE_ID) {
result = Resources.getSystem().getIdentifier(resourceName, typeName, ANDROID_PACKAGE_NAME);
}
if (result == MISSING_RESOURCE_ID) {
throw new IllegalArgumentException("Failed to find resource id for: " + source);
}
return result;
}
代码示例来源:origin: JessYanCoding/AndroidAutoSize
public static int getStatusBarHeight() {
int result = 0;
try {
int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = Resources.getSystem().getDimensionPixelSize(resourceId);
}
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
return result;
}
代码示例来源:origin: robolectric/robolectric
/**
* Returns a qualifier string describing the current {@link Configuration} of the system resources.
*
* @return a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
*/
public static String getQualifiers() {
Resources systemResources = Resources.getSystem();
return getQualifiers(systemResources.getConfiguration(), systemResources.getDisplayMetrics());
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected Drawable getDefaultActivityIcon() {
return Resources.getSystem().getDrawable(com.android.internal.R.drawable.sym_def_app_icon);
}
代码示例来源:origin: scwang90/SmartRefreshLayout
private void setSizeParameters(int progressCircleWidth, int progressCircleHeight,
float centerRadius, float strokeWidth, float arrowWidth, float arrowHeight) {
final DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
mRing.setColorIndex(0);
mRing.mPaint.setStrokeWidth(strokeWidth * screenDensity);
mRing.mStrokeWidth = strokeWidth * screenDensity;
mRing.mRingCenterRadius = (centerRadius * screenDensity);
mRing.mArrowWidth = (int) (arrowWidth * screenDensity);
mRing.mArrowHeight = (int) (arrowHeight * screenDensity);
mRing.setInsets((int) mWidth, (int) mHeight);
final Drawable thisDrawable = this;
thisDrawable.invalidateSelf();
}
代码示例来源:origin: scwang90/SmartRefreshLayout
public StoreHouseHeader(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
DensityUtil density = new DensityUtil();
mLineWidth = density.dip2px(1);
mDropHeight = density.dip2px(40);
mHorizontalRandomness = Resources.getSystem().getDisplayMetrics().widthPixels / 2;
mBackgroundColor = 0xff333333;
setTextColor(0xffcccccc);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.StoreHouseHeader);
mLineWidth = ta.getDimensionPixelOffset(R.styleable.StoreHouseHeader_shhLineWidth, mLineWidth);
mDropHeight = ta.getDimensionPixelOffset(R.styleable.StoreHouseHeader_shhDropHeight, mDropHeight);
mEnableFadeAnimation = ta.getBoolean(R.styleable.StoreHouseHeader_shhEnableFadeAnimation, mEnableFadeAnimation);
if (ta.hasValue(R.styleable.StoreHouseHeader_shhText)) {
initWithString(ta.getString(R.styleable.StoreHouseHeader_shhText));
} else {
initWithString("StoreHouse");
}
ta.recycle();
final View thisView = this;
thisView.setMinimumHeight(mDrawZoneHeight + DensityUtil.dp2px(40));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testGetDrawable_red() throws Exception {
assertNotNull(Resources.getSystem().getDrawable(android.R.drawable.ic_menu_help));
}
代码示例来源:origin: robolectric/robolectric
@Test @Config(qualifiers = "land")
public void setQualifiers_updatesSystemAndAppResources() throws Exception {
Resources systemResources = Resources.getSystem();
Resources appResources = getApplicationContext().getResources();
assertThat(systemResources.getConfiguration().orientation).isEqualTo(
Configuration.ORIENTATION_LANDSCAPE);
assertThat(appResources.getConfiguration().orientation).isEqualTo(
Configuration.ORIENTATION_LANDSCAPE);
RuntimeEnvironment.setQualifiers("port");
assertThat(systemResources.getConfiguration().orientation).isEqualTo(
Configuration.ORIENTATION_PORTRAIT);
assertThat(appResources.getConfiguration().orientation).isEqualTo(
Configuration.ORIENTATION_PORTRAIT);
}
代码示例来源:origin: robolectric/robolectric
@Test @Config(qualifiers = "w100dp-h125dp")
public void whenDimensAndSizeSpecified_setQualifiers_should() throws Exception {
bootstrapWrapper.callSetUpApplicationState();
RuntimeEnvironment.setQualifiers("+xlarge");
Configuration configuration = Resources.getSystem().getConfiguration();
assertThat(configuration.screenWidthDp).isEqualTo(ScreenSize.xlarge.width);
assertThat(configuration.screenHeightDp).isEqualTo(ScreenSize.xlarge.height);
assertThat(DeviceConfig.getScreenSize(configuration)).isEqualTo(ScreenSize.xlarge);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSetUpSystemResources() {
Resources systemResources = Resources.getSystem();
Resources appResources = ApplicationProvider.getApplicationContext().getResources();
assertThat(systemResources).named("system resources").isNotNull();
assertThat(systemResources.getString(android.R.string.copy)).named("system resource")
.isEqualTo(appResources.getString(android.R.string.copy));
assertThat(appResources.getString(R.string.howdy)).named("app resource")
.isNotNull();
try {
systemResources.getString(R.string.howdy);
fail("Expected Exception not thrown");
} catch (Resources.NotFoundException e) {
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void forSystemResources_unknownResourceIdsShouldReportPackagesSearched()
throws IOException {
if (!useLegacy()) return;
expectedException.expect(Resources.NotFoundException.class);
expectedException.expectMessage("Resource ID #0xffffffff");
Resources.getSystem().newTheme().applyStyle(-1, false);
assetManager.openNonAsset(0, "res/drawable/does_not_exist.png", 0);
}
内容来源于网络,如有侵权,请联系作者删除!