本文整理匯總了Java中android.content.res.Resources類的典型用法代碼示例。如果您正苦於以下問題:Java Resources類的具體用法?Java Resources怎麽用?Java Resources使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Resources類屬於android.content.res包,在下文中一共展示了Resources類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDrawable
import android.content.res.Resources; //導入依賴的package包/類
/**
* Get drawable
*
* @param context context
* @param resId drawable id
* @return drawable
*/
static public Drawable getDrawable(@NonNull final Context context, int resId)
{
final Resources resources = context.getResources();
Drawable drawable;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP)
{
final Resources.Theme theme = context.getTheme();
drawable = resources.getDrawable(resId, theme);
}
else
{
drawable = resources.getDrawable(resId);
}
return drawable;
}
示例2: init
import android.content.res.Resources; //導入依賴的package包/類
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
Resources r = context.getResources();
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MDRootLayout, defStyleAttr, 0);
reducePaddingNoTitleNoButtons = a.getBoolean(R.styleable.MDRootLayout_md_reduce_padding_no_title_no_buttons, true);
a.recycle();
noTitlePaddingFull = r.getDimensionPixelSize(R.dimen.md_notitle_vertical_padding);
buttonPaddingFull = r.getDimensionPixelSize(R.dimen.md_button_frame_vertical_padding);
buttonHorizontalEdgeMargin = r.getDimensionPixelSize(R.dimen.md_button_padding_frame_side);
buttonBarHeight = r.getDimensionPixelSize(R.dimen.md_button_height);
dividerPaint = new Paint();
dividerWidth = r.getDimensionPixelSize(R.dimen.md_divider_height);
dividerPaint.setColor(DialogUtils.resolveColor(context, R.attr.md_divider_color));
setWillNotDraw(false);
}
示例3: init
import android.content.res.Resources; //導入依賴的package包/類
private void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int
defStyleRes) {
mAttrsHelper.init(context, attrs, defStyleAttr, defStyleRes);
setText(mAttrsHelper.mText);
TextPaint textPaint = getTextPaint();
textPaint.setColor(mAttrsHelper.mTextColor);
textPaint.setTextSize(mAttrsHelper.mTextSize);
final Resources.Theme theme = context.getTheme();
TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.FastTextView, defStyleAttr,
defStyleRes);
mEnableLayoutCache = a.getBoolean(R.styleable.FastTextView_enableLayoutCache, false);
a.recycle();
}
示例4: from
import android.content.res.Resources; //導入依賴的package包/類
private static Shortcut from(Card.Apps c, String ident){
String[] parts = ident.split("\\|");
Context ctx = c.getWrapper().getContext();
if(parts[0].equals("shortcut4") && parts.length >= 5){
try {
Resources res = ctx.getPackageManager().getResourcesForApplication(parts[1]);
int drawableIdent = res.getIdentifier(parts[4], "drawable", parts[1]);
Drawable icon = res.getDrawable(drawableIdent);
String uri = decodeText(parts[2]);
Intent intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
return new Shortcut(parts[3], icon, parts[1], intent, drawableIdent);
} catch (PackageManager.NameNotFoundException | URISyntaxException |
Resources.NotFoundException ignored) {
}
}
return null;
}
示例5: getNavigationBarHeight
import android.content.res.Resources; //導入依賴的package包/類
@TargetApi(14)
private int getNavigationBarHeight(Context context) {
Resources res = context.getResources();
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (hasNavBar(context)) {
String key;
if (mInPortrait) {
key = NAV_BAR_HEIGHT_RES_NAME;
} else {
key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
}
return getInternalDimensionSize(res, key);
}
}
return result;
}
示例6: init
import android.content.res.Resources; //導入依賴的package包/類
private void init(Context context) {
setOrientation(VERTICAL);
Resources r = context.getResources();
int pxPadding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, r.getDisplayMetrics());
setPadding(pxPadding, pxPadding, pxPadding, pxPadding);
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.menu_dialog, this);
mStreamEditText = (EditText) view.findViewById(R.id.stream_url);
mResolutionGroup = (RadioGroup)view.findViewById(R.id.resolution);
mResolutionGroup.check(R.id.resolution_hight);
mOrientationGroup = (RadioGroup)view.findViewById(R.id.orientation);
mOrientationGroup.check(R.id.orientation_landscape);
}
示例7: getCategoryIcon
import android.content.res.Resources; //導入依賴的package包/類
public Drawable getCategoryIcon(final Category category) {
final Resources resources = context.getResources();
switch (category) {
case ACCOMMODATION:
return resources.getDrawable(R.drawable.ic_hotel_black);
case FOOD:
return resources.getDrawable(R.drawable.ic_food_black);
case TRANSPORT:
return resources.getDrawable(R.drawable.ic_transport_black);
case ENTERTAINMENT:
return
resources.getDrawable(R.drawable.ic_entertainment_black);
case BUSINESS:
return resources.getDrawable(R.drawable.ic_business_black);
case OTHER:
default:
return resources.getDrawable(R.drawable.ic_other_black);
}
}
示例8: decodeSampledBitmapFromResource
import android.content.res.Resources; //導入依賴的package包/類
/**
* 獲取壓縮後的圖片
*
* @param res
* @param resId
* @param reqWidth 所需圖片壓縮尺寸最小寬度
* @param reqHeight 所需圖片壓縮尺寸最小高度
* @return
*/
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
/**
* 1.獲取圖片的像素寬高(不加載圖片至內存中,所以不會占用資源)
* 2.計算需要壓縮的比例
* 3.按將圖片用計算出的比例壓縮,並加載至內存中使用
*/
// 首先不加載圖片,僅獲取圖片尺寸
final BitmapFactory.Options options = new BitmapFactory.Options();
// 當inJustDecodeBounds設為true時,不會加載圖片僅獲取圖片尺寸信息
options.inJustDecodeBounds = true;
// 此時僅會將圖片信息會保存至options對象內,decode方法不會返回bitmap對象
BitmapFactory.decodeResource(res, resId, options);
// 計算壓縮比例,如inSampleSize=4時,圖片會壓縮成原圖的1/4
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// 當inJustDecodeBounds設為false時,BitmapFactory.decode...就會返回圖片對象了
options.inJustDecodeBounds = false;
options.inScaled = false;
// 利用計算的比例值獲取壓縮後的圖片對象
return BitmapFactory.decodeResource(res, resId, options);
}
示例9: getSizeDimension
import android.content.res.Resources; //導入依賴的package包/類
private int getSizeDimension(@Size final int size) {
final Resources res = getResources();
switch (size) {
case SIZE_AUTO:
// If we're set to auto, grab the size from resources and refresh
final int width = res.getConfiguration().screenWidthDp;
final int height = res.getConfiguration().screenHeightDp;
return Math.max(width, height) < AUTO_MINI_LARGEST_SCREEN_WIDTH
? getSizeDimension(SIZE_MINI)
: getSizeDimension(SIZE_NORMAL);
case SIZE_MINI:
return res.getDimensionPixelSize(R.dimen.design_fab_size_mini);
case SIZE_NORMAL:
default:
return res.getDimensionPixelSize(R.dimen.design_fab_size_normal);
}
}
示例10: onBind
import android.content.res.Resources; //導入依賴的package包/類
public void onBind(@NonNull CheckInfo checkInfo, int position) {
if (mCheckInfo != null && mCheckInfo.equals(checkInfo)) {
return;
}
mCheckInfo = checkInfo;
Resources res = itemView.getResources();
String desc = res.getString(ChecksHelper.getCheckStringId(mCheckInfo.getTypeCheck()));
title.setText(desc);
if (mCheckInfo.getState() == null) {
icon.setImageBitmap(getNonCheck(itemView.getContext()));
} else if (mCheckInfo.getState() == Boolean.TRUE) {
icon.setImageBitmap(getFound(itemView.getContext()));
} else {
icon.setImageBitmap(getOk(itemView.getContext()));
}
}
示例11: getNavigationBarHeight
import android.content.res.Resources; //導入依賴的package包/類
private int getNavigationBarHeight(Context context) {
Resources res = context.getResources();
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (hasNavBar(context)) {
String key;
if (mInPortrait) {
key = NAV_BAR_HEIGHT_RES_NAME;
} else {
key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;
}
return ResourcesUtils.getDimensionSize(res, key, "android");
}
}
return result;
}
示例12: setRefreshTime
import android.content.res.Resources; //導入依賴的package包/類
public void setRefreshTime(long lastRefreshTime) {
// 獲取當前時間
Calendar mCalendar = Calendar.getInstance();
long refreshTime = mCalendar.getTimeInMillis();
long howLong = refreshTime - lastRefreshTime;
int minutes = (int) (howLong / 1000 / 60);
String refreshTimeText = null;
Resources resources = getContext().getResources();
if (minutes < 1) {
refreshTimeText = resources
.getString(R.string.xrefreshview_refresh_justnow);
} else if (minutes < 60) {
refreshTimeText = resources
.getString(R.string.xrefreshview_refresh_minutes_ago);
refreshTimeText = Utils.format(refreshTimeText, minutes);
} else if (minutes < 60 * 24) {
refreshTimeText = resources
.getString(R.string.xrefreshview_refresh_hours_ago);
refreshTimeText = Utils.format(refreshTimeText, minutes / 60);
} else {
refreshTimeText = resources
.getString(R.string.xrefreshview_refresh_days_ago);
refreshTimeText = Utils.format(refreshTimeText, minutes / 60 / 24);
}
mHeaderTimeTextView.setText(refreshTimeText);
}
示例13: AutoInstallsLayout
import android.content.res.Resources; //導入依賴的package包/類
AutoInstallsLayout(Context context, AppWidgetHost appWidgetHost,
LayoutParserCallback callback, Resources res,
int layoutId, String rootTag) {
mContext = context;
mAppWidgetHost = appWidgetHost;
mCallback = callback;
mPackageManager = context.getPackageManager();
mValues = new ContentValues();
mRootTag = rootTag;
mSourceRes = res;
mLayoutId = layoutId;
mIdp = LauncherAppState.getIDP(context);
mRowCount = mIdp.numRows;
mColumnCount = mIdp.numColumns;
}
示例14: Workspace
import android.content.res.Resources; //導入依賴的package包/類
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
* @param defStyle Unused.
*/
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = Launcher.getLauncher(context);
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
DeviceProfile grid = mLauncher.getDeviceProfile();
mWorkspaceFadeInAdjacentScreens = grid.shouldFadeAdjacentWorkspaceScreens();
mWallpaperManager = WallpaperManager.getInstance(context);
mWallpaperOffset = new WallpaperOffsetInterpolator(this);
mOverviewModeShrinkFactor =
res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100f;
setOnHierarchyChangeListener(this);
setHapticFeedbackEnabled(false);
initWorkspace();
// Disable multitouch across the workspace/all apps/customize tray
setMotionEventSplittingEnabled(true);
}
示例15: DragLayer
import android.content.res.Resources; //導入依賴的package包/類
/**
* Used to create a new DragLayer from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
*/
public DragLayer(Context context, AttributeSet attrs) {
super(context, attrs);
// Disable multitouch across the workspace/all apps/customize tray
setMotionEventSplittingEnabled(false);
setChildrenDrawingOrderEnabled(true);
final Resources res = getResources();
mLeftHoverDrawable = res.getDrawable(R.drawable.page_hover_left);
mRightHoverDrawable = res.getDrawable(R.drawable.page_hover_right);
mLeftHoverDrawableActive = res.getDrawable(R.drawable.page_hover_left_active);
mRightHoverDrawableActive = res.getDrawable(R.drawable.page_hover_right_active);
mIsRtl = Utilities.isRtl(res);
mFocusIndicatorHelper = new ViewGroupFocusHelper(this);
}