List of usage examples for android.content.res Resources openRawResource
@NonNull public InputStream openRawResource(@RawRes int id) throws NotFoundException
From source file:com.zia.freshdocs.widget.CMISAdapter.java
/** * Query the server using the query appropriate for the server version * @param term// w ww.j av a2 s. com */ public void query(final String term) { startProgressDlg(true); _dlThread = new ChildDownloadThread(_resultHandler, new Downloadable() { public Object execute() { Context context = getContext(); Resources res = context.getResources(); InputStream is = res .openRawResource(_cmis.getVersion().contains("0.6") ? R.raw.query_0_6 : R.raw.query_1_0); String xml = null; try { xml = String.format(IOUtils.toString(is), term, term); return _cmis.query(xml); } catch (IOException e) { Log.e(CMISAdapter.class.getSimpleName(), "", e); } return null; } }); _dlThread.start(); }
From source file:de.appplant.cordova.emailcomposer.EmailComposerImpl.java
/** * The URI for a resource./*from w ww . ja va2 s .co m*/ * * @param path * The given relative path. * @param ctx * The application context. * @return * The URI pointing to the given path */ @SuppressWarnings("ResultOfMethodCallIgnored") private Uri getUriForResourcePath(String path, Context ctx) { String resPath = path.replaceFirst("res://", ""); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); String resName = fileName.substring(0, fileName.lastIndexOf('.')); String extension = resPath.substring(resPath.lastIndexOf('.')); File dir = ctx.getExternalCacheDir(); if (dir == null) { Log.e("EmailComposer", "Missing external cache dir"); return Uri.EMPTY; } String storage = dir.toString() + ATTACHMENT_FOLDER; int resId = getResId(resPath, ctx); File file = new File(storage, resName + extension); if (resId == 0) { Log.e("EmailComposer", "File not found: " + resPath); } new File(storage).mkdir(); try { Resources res = ctx.getResources(); FileOutputStream outStream = new FileOutputStream(file); InputStream inputStream = res.openRawResource(resId); copyFile(inputStream, outStream); outStream.flush(); outStream.close(); } catch (Exception e) { e.printStackTrace(); } return Uri.fromFile(file); }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Query the server using the query appropriate for the server version * //from w w w . j av a 2s .co m * @param term */ public void query(final String term) { startProgressDlg(true); mDlThread = new ChildDownloadThread(mResultHandler, new Downloadable() { public Object execute() { Context context = getContext(); Resources res = context.getResources(); InputStream is = res .openRawResource(mCmis.getVersion().contains("0.6") ? R.raw.query_0_6 : R.raw.query_1_0); String xml = null; try { xml = String.format(IOUtils.toString(is), term, term); return mCmis.query(xml); } catch (IOException e) { Log.e(CMISAdapter.class.getSimpleName(), "", e); } return null; } }); mDlThread.start(); }
From source file:com.mcxiaoke.licensedialog.v4.LicensesDialogFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Resources resources = getResources(); if (savedInstanceState != null) { mTitleText = savedInstanceState.getString(STATE_TITLE_TEXT); mLicensesText = savedInstanceState.getString(STATE_LICENSES_TEXT); mCloseButtonText = savedInstanceState.getString(STATE_CLOSE_TEXT); } else {/*from ww w . jav a2s. c om*/ try { final Notices notices; final Bundle arguments = getArguments(); if (arguments != null) { if (arguments.containsKey(ARGUMENT_NOTICES_XML_ID)) { notices = NoticesXmlParser.parse(resources.openRawResource(getNoticesXmlResourceId())); } else if (arguments.containsKey(ARGUMENT_NOTICES)) { notices = arguments.getParcelable(ARGUMENT_NOTICES); } else { throw new IllegalStateException("Missing ARGUMENT_NOTICES_XML_ID / ARGUMENT_NOTICES"); } int titleResId = arguments.getInt(ARGUMENT_TITLE_RES_ID, R.string.notices_title); mTitleText = resources.getString(titleResId); int closeResIdd = arguments.getInt(ARGUMENT_CLOSE_RES_ID, R.string.notices_close); mCloseButtonText = resources.getString(closeResIdd); final boolean showFullLicenseText = arguments.getBoolean(ARGUMENT_SHOW_FULL_LICENSE_TEXT, false); mLicensesText = NoticesHtmlBuilder.create(getActivity()).setNotices(notices) .setShowFullLicenseText(showFullLicenseText).build(); } else { throw new IllegalStateException("Missing arguments"); } } catch (final Exception e) { throw new IllegalStateException(e); } } }
From source file:su.comp.bk.arch.Computer.java
/** * Load data of raw resource./*from ww w. java 2s . c o m*/ * @param resources {@link Resources} reference * @param resourceId raw resource ID * @return read raw resource data * @throws IOException in case of loading error */ private byte[] loadRawResourceData(Resources resources, int resourceId) throws IOException { InputStream resourceDataStream = resources.openRawResource(resourceId); byte[] resourceData = new byte[resourceDataStream.available()]; resourceDataStream.read(resourceData); return resourceData; }
From source file:de.psdev.licensesdialog.LicensesDialogFragment.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Resources resources = getResources(); if (savedInstanceState != null) { mTitleText = savedInstanceState.getString(STATE_TITLE_TEXT); mLicensesText = savedInstanceState.getString(STATE_LICENSES_TEXT); mCloseButtonText = savedInstanceState.getString(STATE_CLOSE_TEXT); } else {/*from www . jav a2 s .co m*/ mTitleText = resources.getString(R.string.notices_title); mCloseButtonText = resources.getString(R.string.notices_close); try { final Notices notices; final Bundle arguments = getArguments(); if (arguments != null) { if (arguments.containsKey(ARGUMENT_NOTICES_XML_ID)) { notices = NoticesXmlParser.parse(resources.openRawResource(getNoticesXmlResourceId())); } else if (arguments.containsKey(ARGUMENT_NOTICES)) { notices = arguments.getParcelable(ARGUMENT_NOTICES); } else { throw new IllegalStateException("Missing ARGUMENT_NOTICES_XML_ID / ARGUMENT_NOTICES"); } if (arguments.getBoolean(ARGUMENT_INCLUDE_OWN_LICENSE, false)) { notices.getNotices().add(LicensesDialog.LICENSES_DIALOG_NOTICE); } final boolean showFullLicenseText = arguments.getBoolean(ARGUMENT_FULL_LICENSE_TEXT, false); mLicensesText = NoticesHtmlBuilder.create(getActivity()).setNotices(notices) .setShowFullLicenseText(showFullLicenseText).build(); } else { throw new IllegalStateException("Missing arguments"); } } catch (final Exception e) { throw new IllegalStateException(e); } } }
From source file:com.google.samples.apps.abelana.AbelanaThings.java
public AbelanaThings(Context ctx, String phint) { final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); final HttpTransport httpTransport = new NetHttpTransport(); Resources r = ctx.getResources(); byte[] android, server; byte[] password = new byte[32]; android = Base64.decode("vW7CmbQWdPjpdfpBU39URsjHQV50KEKoSfafHdQPSh8", Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP); server = Base64.decode(phint, Base64.URL_SAFE); int i = 0;//ww w .jav a 2s.c om for (byte b : android) { password[i] = (byte) (android[i] ^ server[i]); i++; } byte[] pw = Base64.encode(password, Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP); String pass = new String(pw); if (storage == null) { try { KeyStore keystore = KeyStore.getInstance("PKCS12"); keystore.load(r.openRawResource(R.raw.abelananew), pass.toCharArray()); credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory) .setServiceAccountId(r.getString(R.string.service_account)) .setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)) .setServiceAccountPrivateKey((PrivateKey) keystore.getKey("privatekey", pass.toCharArray())) .build(); storage = new Storage.Builder(httpTransport, jsonFactory, credential) .setApplicationName(r.getString(R.string.app_name) + "/1.0").build(); } catch (CertificateException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("loaded"); } }
From source file:org.gaeproxy.GAEProxyService.java
private String loadStringFromRawResource(Resources resources, int resId) { InputStream rawResource = resources.openRawResource(resId); String content = streamToString(rawResource); try {/*from w ww . ja v a 2 s .co m*/ rawResource.close(); } catch (IOException ignored) { } return content; }
From source file:com.larvalabs.svgandroid.SVGParser.java
/** * Parse SVG data from an Android application resource. * @param resources the Android context resources. * @param resId the ID of the raw resource SVG. * @return the parsed SVG.//from ww w .j a v a 2 s . c o m * @throws SVGParseException if there is an error while parsing. */ public static SVG getSVGFromResource(Resources resources, int resId) throws SVGParseException { return SVGParser.parse(resources.openRawResource(resId), 0, 0, false); }
From source file:com.larvalabs.svgandroid.SVGParser.java
/** * Parse SVG data from an Android application resource. * @param resources the Android context// w ww .jav a2 s. c o m * @param resId the ID of the raw resource SVG. * @param searchColor the color in the SVG to replace. * @param replaceColor the color with which to replace the search color. * @return the parsed SVG. * @throws SVGParseException if there is an error while parsing. */ public static SVG getSVGFromResource(Resources resources, int resId, int searchColor, int replaceColor) throws SVGParseException { return SVGParser.parse(resources.openRawResource(resId), searchColor, replaceColor, false); }