本文整理匯總了Java中android.content.Context.getResources方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getResources方法的具體用法?Java Context.getResources怎麽用?Java Context.getResources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.getResources方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkDeviceHasNavigationBar
import android.content.Context; //導入方法依賴的package包/類
public static boolean checkDeviceHasNavigationBar(Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
示例2: getNavigationBarHeight
import android.content.Context; //導入方法依賴的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;
}
示例3: populate
import android.content.Context; //導入方法依賴的package包/類
public static void populate(Context context, View view, Display display) {
View da = view.findViewById(R.id.display_attributes);
Resources res = context.getResources();
if (da != null) {
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
((TextView) da.findViewById(R.id.density))
.setText(String.format("%s (%f)",
res.getString(R.string.density), metrics.density));
((TextView) da.findViewById(R.id.size)).setText(res
.getString(R.string.size));
((TextView) da.findViewById(R.id.dimensions))
.setText(String
.format("%dx%d (%dx%d)",
metrics.widthPixels,
metrics.heightPixels,
(int) ((float) metrics.widthPixels / metrics.density),
(int) ((float) metrics.heightPixels / metrics.density)));
}
}
示例4: setMinTextSize
import android.content.Context; //導入方法依賴的package包/類
/**
* Set the minimum text size to a given unit and value. See TypedValue for the possible
* dimension units.
*
* @param unit The desired dimension unit.
* @param size The desired size in the given units.
* @attr ref me.grantland.R.styleable#AutofitTextView_minTextSize
*/
public AutofitHelper setMinTextSize(int unit, float size) {
Context context = mTextView.getContext();
Resources r = Resources.getSystem();
if (context != null) {
r = context.getResources();
}
setRawMinTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
return this;
}
示例5: getNavigationBarWidth
import android.content.Context; //導入方法依賴的package包/類
private int getNavigationBarWidth(Context context) {
Resources res = context.getResources();
int result = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (hasNavBar(context)) {
return ResourcesUtils.getDimensionSize(res, NAV_BAR_WIDTH_RES_NAME, "android");
}
}
return result;
}
示例6: getResources
import android.content.Context; //導入方法依賴的package包/類
/**
* getResources
*
* @param apkPath apkPath
* @return resources
*/
public static Resources getResources(Context context, String apkPath) {
if (apkPath == null || "".equals(apkPath)) {
return context.getResources();
}
String key = apkPath;
if (RESOURCES.containsKey(key)) {
return RESOURCES.get(key);
}
AssetManager assetManager = getAssets(context, apkPath);
ApkResources apkResources = new ApkResources(assetManager, context.getResources().getDisplayMetrics(), context.getResources().getConfiguration(), apkPath, context.getResources());
RESOURCES.put(key, apkResources);
return apkResources;
}
示例7: convertDpToPixel
import android.content.Context; //導入方法依賴的package包/類
/**
* This method 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
* @return A float value to represent px equivalent to dp depending on device density
*/
public static int convertDpToPixel(Context context, float dp) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
int px = (int) dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
return px;
}
示例8: MenuBuilder
import android.content.Context; //導入方法依賴的package包/類
public MenuBuilder(Context context) {
mContext = context;
mResources = context.getResources();
mItems = new ArrayList<MenuItemImpl>();
mVisibleItems = new ArrayList<MenuItemImpl>();
mIsVisibleItemsStale = true;
mActionItems = new ArrayList<MenuItemImpl>();
mNonActionItems = new ArrayList<MenuItemImpl>();
mIsActionItemsStale = true;
setShortcutsVisibleInner(true);
}
示例9: getContainerPadding
import android.content.Context; //導入方法依賴的package包/類
/**
* @return the left/right paddings for all containers.
*/
public final int[] getContainerPadding(Context context) {
Resources res = context.getResources();
// No paddings for portrait phone
if (isPhone && !isVerticalBarLayout()) {
return new int[] {0, 0};
}
// In landscape, we match the width of the workspace
int padding = (pageIndicatorLandGutterRightNavBarPx +
hotseatBarHeightPx + hotseatLandGutterPx + mInsets.left) / 2;
return new int[]{ padding, padding };
}
示例10: getNavBarHeight
import android.content.Context; //導入方法依賴的package包/類
public static int getNavBarHeight(Context context) {
Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
示例11: GDriveUploader
import android.content.Context; //導入方法依賴的package包/類
public GDriveUploader(Context ctx, GoogleApiClient googleApiClient, String driveFolderID, String file,
AndiCarAsyncTaskListener taskListener) throws Exception {
try {
// if (FileUtils.isFileSystemAccessGranted(ctx)) {
FileUtils.createFolderIfNotExists(ctx, ConstantValues.LOG_FOLDER);
File debugLogFile = new File(ConstantValues.LOG_FOLDER + "GDriveUploader.log");
debugLogFileWriter = new LogFileWriter(debugLogFile, false);
debugLogFileWriter.appendnl("GDriveUploader started for file: ").append(file);
debugLogFileWriter.flush();
// }
mGoogleApiClient = googleApiClient;
mCtx = ctx;
mDriveFolderID = driveFolderID;
mFile = file;
mMimeType = "application/octet-stream";
mTaskListener = taskListener;
mResource = ctx.getResources();
}
catch (Exception e) {
if (mTaskListener != null) {
mTaskListener.onAndiCarTaskCancelled(null, e);
}
if (debugLogFileWriter != null) {
try {
debugLogFileWriter.appendnl("An error occurred: ").append(e.getMessage()).append(Utils.getStackTrace(e));
debugLogFileWriter.flush();
}
catch (IOException ignored) {
}
}
throw e;
}
}
示例12: updateClientsWithMetadataUri
import android.content.Context; //導入方法依賴的package包/類
/**
* Download latest metadata from the server through DownloadManager for all relevant clients
*
* @param context The context for retrieving resources
* @param metadataUri The client to update
*/
private static void updateClientsWithMetadataUri(
final Context context, final String metadataUri) {
Log.i(TAG, "updateClientsWithMetadataUri() : MetadataUri = " + metadataUri);
// Adding a disambiguator to circumvent a bug in older versions of DownloadManager.
// DownloadManager also stupidly cuts the extension to replace with its own that it
// gets from the content-type. We need to circumvent this.
final String disambiguator = "#" + System.currentTimeMillis()
+ ApplicationUtils.getVersionName(context) + ".json";
final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator));
DebugLogUtils.l("Request =", metadataRequest);
final Resources res = context.getResources();
metadataRequest.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
metadataRequest.setTitle(res.getString(R.string.download_description));
// Do not show the notification when downloading the metadata.
metadataRequest.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
metadataRequest.setVisibleInDownloadsUi(
res.getBoolean(R.bool.metadata_downloads_visible_in_download_UI));
final DownloadManagerWrapper manager = new DownloadManagerWrapper(context);
if (maybeCancelUpdateAndReturnIfStillRunning(context, metadataUri, manager,
DictionaryService.NO_CANCEL_DOWNLOAD_PERIOD_MILLIS)) {
// We already have a recent download in progress. Don't register a new download.
return;
}
final long downloadId;
synchronized (sSharedIdProtector) {
downloadId = manager.enqueue(metadataRequest);
DebugLogUtils.l("Metadata download requested with id", downloadId);
// If there is still a download in progress, it's been there for a while and
// there is probably something wrong with download manager. It's best to just
// overwrite the id and request it again. If the old one happens to finish
// anyway, we don't know about its ID any more, so the downloadFinished
// method will ignore it.
writeMetadataDownloadId(context, metadataUri, downloadId);
}
Log.i(TAG, "updateClientsWithMetadataUri() : DownloadId = " + downloadId);
}
示例13: getResources
import android.content.Context; //導入方法依賴的package包/類
@Override
public Resources getResources(Context context, ApplicationInfo appInfo) throws Exception {
InstalledAppInfo appSetting = VAppManagerService.get().getInstalledAppInfo(appInfo.packageName, 0);
if (appSetting != null) {
AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance();
mirror.android.content.res.AssetManager.addAssetPath.call(assets, appSetting.apkPath);
Resources hostRes = context.getResources();
return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration());
}
return null;
}
示例14: MaterialProgressDrawable
import android.content.Context; //導入方法依賴的package包/類
public MaterialProgressDrawable(Context context, View parent) {
mParent = parent;
mResources = context.getResources();
mRing = new Ring(mCallback);
mRing.setColors(COLORS);
updateSizes(DEFAULT);
setupAnimators();
}
示例15: init
import android.content.Context; //導入方法依賴的package包/類
private void init(Context context,String p,String a,boolean isLeft){
project=new TextView(context);
Resources rs=context.getResources();
project.setTextColor(rs.getColorStateList(R.color.new_text_color_first));
//project.setBackgroundColor(Color.rgb(235, 235, 235));
project.setGravity(Gravity.CENTER_VERTICAL);
project.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
String text=isLeft?p+"<font color=\"#32c0c4\">"+a+"</font>元":p+"<font color=\"#f09c42\">"+a+"</font>元";
project.setText(Html.fromHtml(text));
addView(project);
setPadding(0, dp2px(8), 0, dp2px(10));
/*amount=new TextView(context);
amount.setTextColor(rs.getColorStateList(isLeft?R.color.base_blue:R.color.brown));
amount.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
amount.setText(a);
TextView t3=new TextView(context);
t3.setTextColor(rs.getColorStateList(R.color.new_text_color_first));
t3.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
t3.setText("元");
addView(amount);
addView(t3);*/
project.setGravity(isLeft?Gravity.RIGHT:Gravity.LEFT);
setGravity(isLeft?Gravity.RIGHT:Gravity.LEFT);
setBackgroundResource(R.drawable.press);
setOnLongClickListener(this);
setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(editListener!=null){
editListener.onView(account);
}
}
});
}