List of usage examples for android.content.res Resources Resources
@Deprecated
public Resources(AssetManager assets, DisplayMetrics metrics, Configuration config)
From source file:com.mk4droid.IMC_Activities.Fragment_Issue_Details.java
private Resources setResources() { SharedPreferences mshPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); LangSTR = mshPrefs.getString("LanguageAR", Constants_API.DefaultLanguage); UserNameSTR = mshPrefs.getString("UserNameAR", ""); PasswordSTR = mshPrefs.getString("PasswordAR", ""); IssuesNoSTR = mshPrefs.getString("IssuesNoAR", "40"); distanceData = mshPrefs.getInt("distanceData", Constants_API.initRange); AuthFlag = mshPrefs.getBoolean("AuthFlag", false); if (!Service_Data.HasInternet) AuthFlag = false;/*ww w.ja va 2 s . c om*/ UserID_STR = mshPrefs.getString("UserID_STR", ""); Configuration conf = getResources().getConfiguration(); conf.locale = new Locale(LangSTR.substring(0, 2)); //----- Convert Greek -> el --------- metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); return new Resources(getActivity().getAssets(), metrics, conf); }
From source file:com.google.code.twisty.Twisty.java
void startTerp(int resource) { String gameName = builtinGames.get(resource); // go-go-autoboxing if (gameName == null) { Log.i(TAG, "Failed to find built-in game resource" + resource); return;//from ww w . j a v a 2 s .c o m } Log.i(TAG, "Loading game resource: " + gameName); String savedGamesDir = getSavedGamesDir(true); if (savedGamesDir == null) { showDialog(DIALOG_CANT_SAVE); return; } // The absolute disk path to the privately-stored gamefile: File gameFile = new File(savedGamesDir + "/" + gameName); String gamePath = gameFile.getAbsolutePath(); Log.i(TAG, "Looking for gamefile at " + gamePath); if (!gameFile.exists()) { // Do a one-time dump from raw resource to disk. FileOutputStream foutstream; Resources r = new Resources(getAssets(), new DisplayMetrics(), null); InputStream gamestream = r.openRawResource(resource); try { foutstream = new FileOutputStream(gameFile); } catch (IOException e) { Log.i(TAG, "Failed to open outputstream for filename " + gamePath); Log.i(TAG, e.getMessage()); return; } try { Log.i(TAG, "About to spew raw data to disk..."); suckstream(gamestream, foutstream); } catch (IOException e) { Log.i(TAG, "Failed to copy raw game to file." + gamePath); return; } Log.i(TAG, "Completed dump of raw data to disk."); } Log.i(TAG, "Starting gamefile located at " + gamePath); startTerp(gamePath); }
From source file:com.mk4droid.IMC_Activities.Fragment_Map.java
private Resources SetResources() { String LangSTR = mshPrefs.getString("LanguageAR", Constants_API.DefaultLanguage); UserID_STR = mshPrefs.getString("UserID_STR", ""); UserRealName = mshPrefs.getString("UserRealName", ""); MyIssuesSW = mshPrefs.getBoolean("MyIssuesSW", false); Configuration conf = getResources().getConfiguration(); conf.locale = new Locale(LangSTR.substring(0, 2)); //----- Convert Greek -> el --------- metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); getActivity().getResources().updateConfiguration(conf, getActivity().getResources().getDisplayMetrics()); return new Resources(getActivity().getAssets(), metrics, conf); }
From source file:android.content.pm.PackageParser.java
private Package parseBaseApk(File apkFile, AssetManager assets, int flags) throws PackageParserException { final String apkPath = apkFile.getAbsolutePath(); String volumeUuid = null;/*from w ww .j av a2s .c om*/ if (apkPath.startsWith(MNT_EXPAND)) { final int end = apkPath.indexOf('/', MNT_EXPAND.length()); volumeUuid = apkPath.substring(MNT_EXPAND.length(), end); } mParseError = PackageManager.INSTALL_SUCCEEDED; mArchiveSourcePath = apkFile.getAbsolutePath(); if (DEBUG_JAR) Slog.d(TAG, "Scanning base APK: " + apkPath); final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); Resources res = null; XmlResourceParser parser = null; try { res = new Resources(assets, mMetrics, null); assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Build.VERSION.RESOURCES_SDK_INT); parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); final String[] outError = new String[1]; final Package pkg = parseBaseApk(res, parser, flags, outError); if (pkg == null) { throw new PackageParserException(mParseError, apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); } pkg.volumeUuid = volumeUuid; pkg.applicationInfo.volumeUuid = volumeUuid; pkg.baseCodePath = apkPath; pkg.mSignatures = null; return pkg; } catch (PackageParserException e) { throw e; } catch (Exception e) { throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, "Failed to read manifest from " + apkPath, e); } finally { IoUtils.closeQuietly(parser); } }
From source file:android.content.pm.PackageParser.java
private void parseSplitApk(Package pkg, int splitIndex, AssetManager assets, int flags) throws PackageParserException { final String apkPath = pkg.splitCodePaths[splitIndex]; final File apkFile = new File(apkPath); mParseError = PackageManager.INSTALL_SUCCEEDED; mArchiveSourcePath = apkPath;/*from w w w . j a v a 2 s. c om*/ if (DEBUG_JAR) Slog.d(TAG, "Scanning split APK: " + apkPath); final int cookie = loadApkIntoAssetManager(assets, apkPath, flags); Resources res = null; XmlResourceParser parser = null; try { res = new Resources(assets, mMetrics, null); assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Build.VERSION.RESOURCES_SDK_INT); parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); final String[] outError = new String[1]; pkg = parseSplitApk(pkg, res, parser, flags, splitIndex, outError); if (pkg == null) { throw new PackageParserException(mParseError, apkPath + " (at " + parser.getPositionDescription() + "): " + outError[0]); } } catch (PackageParserException e) { throw e; } catch (Exception e) { throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, "Failed to read manifest from " + apkPath, e); } finally { IoUtils.closeQuietly(parser); } }
From source file:android.content.pm.PackageParser.java
/** * Utility method that retrieves lightweight details about a single APK * file, including package name, split name, and install location. * * @param apkFile path to a single APK/*from w w w.j ava 2 s . c o m*/ * @param flags optional parse flags, such as * {@link #PARSE_COLLECT_CERTIFICATES} */ public static ApkLite parseApkLite(File apkFile, int flags) throws PackageParserException { final String apkPath = apkFile.getAbsolutePath(); AssetManager assets = null; XmlResourceParser parser = null; try { assets = new AssetManager(); assets.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Build.VERSION.RESOURCES_SDK_INT); int cookie = assets.addAssetPath(apkPath); if (cookie == 0) { throw new PackageParserException(INSTALL_PARSE_FAILED_NOT_APK, "Failed to parse " + apkPath); } final DisplayMetrics metrics = new DisplayMetrics(); metrics.setToDefaults(); final Resources res = new Resources(assets, metrics, null); parser = assets.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME); final Signature[] signatures; if ((flags & PARSE_COLLECT_CERTIFICATES) != 0) { // TODO: factor signature related items out of Package object final Package tempPkg = new Package(null); collectCertificates(tempPkg, apkFile, 0); signatures = tempPkg.mSignatures; } else { signatures = null; } final AttributeSet attrs = parser; return parseApkLite(apkPath, res, parser, attrs, flags, signatures); } catch (XmlPullParserException | IOException | RuntimeException e) { throw new PackageParserException(INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION, "Failed to parse " + apkPath, e); } finally { IoUtils.closeQuietly(parser); IoUtils.closeQuietly(assets); } }
From source file:com.landenlabs.all_devtool.PackageFragment.java
String getResourceName(PackageInfo packInfo, int resId) throws PackageManager.NameNotFoundException { String resName = ""; if (resId != 0) { AssetManager assetMgr = this.getActivity().createPackageContext(packInfo.packageName, 0).getAssets(); try {/*w w w . ja va2 s . c om*/ Resources res; Configuration config = new Configuration(); DisplayMetrics metrics = Utils.getDisplayMetrics(GlobalInfo.s_globalInfo.mainFragActivity); res = new Resources(assetMgr, metrics, config); resName = res.getResourceName(resId); if (resName.length() > 30) resName = resName.substring(resName.length() - 30); // String resName = res.getText(resId).toString(); } finally { // res.getAssets().close(); // assetMgr.close(); } } return resName; }