當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.getResources方法代碼示例

本文整理匯總了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;

}
 
開發者ID:ebridfighter,項目名稱:GongXianSheng,代碼行數:23,代碼來源:AndroidWorkaround.java

示例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;
}
 
開發者ID:chengkun123,項目名稱:ReadMark,代碼行數:18,代碼來源:SystemBarTintManager.java

示例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)));
    }
}
 
開發者ID:StylingAndroid,項目名稱:PresenterLite,代碼行數:21,代碼來源:DisplayInfoHelper.java

示例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;
}
 
開發者ID:HK-SHAO,項目名稱:DarkCalculator,代碼行數:20,代碼來源:AutofitHelper.java

示例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;
}
 
開發者ID:ls1110924,項目名稱:ImmerseMode,代碼行數:11,代碼來源:ActivityConfig.java

示例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;
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:20,代碼來源:ApkResources.java

示例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;
}
 
開發者ID:Codigami,項目名稱:CFAlertDialog,代碼行數:13,代碼來源:DeviceUtil.java

示例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);
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:16,代碼來源:MenuBuilder.java

示例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 };
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:17,代碼來源:DeviceProfile.java

示例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;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:9,代碼來源:ScreenUtil.java

示例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;
        }
    }
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:35,代碼來源:GDriveUploader.java

示例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);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:45,代碼來源:UpdateHandler.java

示例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;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:12,代碼來源:AppAccountParser.java

示例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();
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:11,代碼來源:MaterialProgressDrawable.java

示例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);
			}
		}
	});
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:37,代碼來源:AccountingTextView.java


注:本文中的android.content.Context.getResources方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。