android.support.annotation.RawRes Java Examples
The following examples show how to use
android.support.annotation.RawRes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceUtils.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
/** * Return the content of resource in raw. * * @param resId The resource id. * @param charsetName The name of charset. * @return the content of resource in raw */ public static String readRaw2String(@RawRes final int resId, final String charsetName) { InputStream is = Utils.getApp().getResources().openRawResource(resId); byte[] bytes = UtilsBridge.inputStream2Bytes(is); if (bytes == null) return null; if (UtilsBridge.isSpace(charsetName)) { return new String(bytes); } else { try { return new String(bytes, charsetName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return ""; } } }
Example #2
Source File: OptimizelyManager.java From android-sdk with Apache License 2.0 | 6 votes |
/** * Initialize Optimizely Synchronously by loading the resource, use it to initialize Optimizely, * and downloading the latest datafile from the CDN in the background to cache. * <p> * Instantiates and returns an {@link OptimizelyClient} instance using the datafile cached on disk * if not available then it will expect that raw data file should exist on given id. * and initialize using raw file. Will also cache the instance * for future lookups via getClient. The datafile should be stored in res/raw. * * @param context any {@link Context} instance * @param datafileRes the R id that the data file is located under. * @param downloadToCache to check if datafile should get updated in cache after initialization. * @param updateConfigOnNewDatafile When a new datafile is fetched from the server in the background thread, the SDK will be updated with the new datafile immediately if this value is set to true. When it's set to false (default), the new datafile is cached and will be used when the SDK is started again. * @return an {@link OptimizelyClient} instance */ @NonNull public OptimizelyClient initialize(@NonNull Context context, @RawRes Integer datafileRes, boolean downloadToCache, boolean updateConfigOnNewDatafile) { try { String datafile; Boolean datafileInCache = isDatafileCached(context); datafile = getDatafile(context, datafileRes); optimizelyClient = initialize(context, datafile, downloadToCache, updateConfigOnNewDatafile); if (datafileInCache) { cleanupUserProfileCache(getUserProfileService()); } }catch (NullPointerException e){ logger.error("Unable to find compiled data file in raw resource",e); } // return dummy client if not able to initialize a valid one return optimizelyClient; }
Example #3
Source File: GlUtil.java From PLDroidMediaStreaming with Apache License 2.0 | 6 votes |
public static String readTextFromRawResource(final Context applicationContext, @RawRes final int resourceId) { final InputStream inputStream = applicationContext.getResources().openRawResource(resourceId); final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String nextLine; final StringBuilder body = new StringBuilder(); try { while ((nextLine = bufferedReader.readLine()) != null) { body.append(nextLine); body.append('\n'); } } catch (IOException e) { return null; } return body.toString(); }
Example #4
Source File: BitmapLoadUtils.java From ImageFrame with Apache License 2.0 | 6 votes |
static BitmapDrawable decodeSampledBitmapFromRes(Resources resources, @RawRes int resId, int reqWidth, int reqHeight, ImageCache cache, boolean isOpenLruCache) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; decodeStream(resources.openRawResource(resId), null, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // String resourceName = resources.getResourceName(resId); // if (Utils.hasHoneycomb()) { BitmapDrawable bitmapFromCache; if (isOpenLruCache) { String resourceName = resources.getResourceName(resId); bitmapFromCache = cache.getBitmapFromCache(resourceName); if (bitmapFromCache == null) { // if (Utils.hasHoneycomb()) { bitmapFromCache = readBitmapFromRes(resources, resId, cache, options); cache.addBitmap(resourceName, bitmapFromCache); } } else { bitmapFromCache = readBitmapFromRes(resources, resId, cache, options); } return bitmapFromCache; }
Example #5
Source File: MyGLUtils.java From MusicVisualization with Apache License 2.0 | 6 votes |
private static String getStringFromRaw(Context context, @RawRes int id) { String str; try { Resources r = context.getResources(); InputStream is = r.openRawResource(id); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = is.read(); while (i != -1) { baos.write(i); i = is.read(); } str = baos.toString(); is.close(); } catch (IOException e) { str = ""; } return str; }
Example #6
Source File: Utils.java From LearnOpenGL with MIT License | 6 votes |
public static String loadShader(Context context, @RawRes int resId) { StringBuilder builder = new StringBuilder(); try { InputStream inputStream = context.getResources().openRawResource(resId); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { builder.append(line) .append('\n'); } reader.close(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
Example #7
Source File: RawResourceReader.java From StarWars.Android with MIT License | 6 votes |
/** * Reads a raw resource text file into a String * @param context * @param resId * @return */ @Nullable public static String readTextFileFromRawResource(@NonNull final Context context, @RawRes final int resId) { final BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(context.getResources().openRawResource(resId)) ); String line; final StringBuilder body = new StringBuilder(); try { while ((line = bufferedReader.readLine()) != null) { body.append(line).append('\n'); } } catch (IOException e) { return null; } return body.toString(); }
Example #8
Source File: HelpActivity.java From alpha-wallet-android with MIT License | 5 votes |
private boolean isRawResource(@RawRes int rawRes) { try { InputStream in = getResources().openRawResource(rawRes); if (in.available() > 0) { in.close(); return true; } in.close(); } catch (Exception ex) { Log.d("READ_JS_TAG", "Ex", ex); } return false; }
Example #9
Source File: JsInjectorClient.java From alpha-wallet-android with MIT License | 5 votes |
private static String loadFile(Context context, @RawRes int rawRes) { byte[] buffer = new byte[0]; try { InputStream in = context.getResources().openRawResource(rawRes); buffer = new byte[in.available()]; int len = in.read(buffer); if (len < 1) { throw new IOException("Nothing is read."); } } catch (Exception ex) { Log.d("READ_JS_TAG", "Ex", ex); } return new String(buffer); }
Example #10
Source File: DisplayCodeFragment.java From AlexaAndroid with GNU General Public License v2.0 | 5 votes |
public static DisplayCodeFragment getInstance(String title, @RawRes int rawCode){ Bundle b = new Bundle(); b.putString(ARG_TITLE, title); b.putInt(ARG_RAW_CODE, rawCode); DisplayCodeFragment fragment = new DisplayCodeFragment(); fragment.setArguments(b); return fragment; }
Example #11
Source File: ReaderUtils.java From Rhythm with Apache License 2.0 | 5 votes |
/** * Reads lines from given raw resource. Opens the file, reads the lines with {@link #readLines(InputStream)} and * closes the stream afterwards. * * @param context Context to retrieve the resource * @param rawResId Raw resource ID, which is a name of a file in <code>/res/raw</code> folder without extension * @return List of lines read from the file */ public static List<String> readLines(Context context, @RawRes int rawResId) { final InputStream inputStream = context.getResources().openRawResource(rawResId); try { return readLines(inputStream); } finally { try { inputStream.close(); } catch (IOException e) { // Fail quietly } } }
Example #12
Source File: SettingsFragment.java From pretixdroid with GNU General Public License v3.0 | 5 votes |
private void asset_dialog(@RawRes int htmlRes, @StringRes int title) { final View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_about, null, false); final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(title) .setView(view) .setPositiveButton(R.string.dismiss, null) .create(); TextView textView = (TextView) view.findViewById(R.id.aboutText); String text = ""; StringBuilder builder = new StringBuilder(); InputStream fis; try { fis = getResources().openRawResource(htmlRes); BufferedReader reader = new BufferedReader(new InputStreamReader(fis, "utf-8")); String line; while ((line = reader.readLine()) != null) { builder.append(line); } text = builder.toString(); fis.close(); } catch (IOException e) { Sentry.captureException(e); e.printStackTrace(); } textView.setText(Html.fromHtml(text)); textView.setMovementMethod(LinkMovementMethod.getInstance()); dialog.show(); }
Example #13
Source File: Homage.java From homage with Apache License 2.0 | 5 votes |
@Nullable private static Library[] getLibraryArray(@NonNull Context context, @RawRes int rawResourceId) { try { InputStream stream = context.getResources().openRawResource(rawResourceId); return parseLibraries(stream); } catch (Resources.NotFoundException e) { Log.e(TAG, "NotFoundException reading license file: " + rawResourceId, e); return null; } }
Example #14
Source File: JsInjectorClient.java From Web3View with GNU General Public License v3.0 | 5 votes |
private String loadFile(Context context, @RawRes int rawRes) { byte[] buffer = new byte[0]; try { InputStream in = context.getResources().openRawResource(rawRes); buffer = new byte[in.available()]; int len = in.read(buffer); if (len < 1) { throw new IOException("Nothing is read."); } } catch (Exception ex) { Log.d("READ_JS_TAG", "Ex", ex); } return new String(buffer); }
Example #15
Source File: BaseModule.java From localify with Apache License 2.0 | 5 votes |
@Override public Observable<String> loadRawFile(@RawRes final int fileNameRawId) { return RxUtils.defer(new RxUtils.DefFunc<String>() { @Override public String method() { return BaseModule.this.loadRawFile(fileNameRawId); } }); }
Example #16
Source File: GifDrawable.java From android-gif-drawable-eclipse-sample with MIT License | 5 votes |
/** * An {@link GifDrawable#GifDrawable(Resources, int)} wrapper but returns null * instead of throwing exception if creation fails. * * @param res resources to read from * @param resourceId resource id * @return correct drawable or null if creation failed */ @Nullable public static GifDrawable createFromResource(@NonNull Resources res, @DrawableRes @RawRes int resourceId) { try { return new GifDrawable(res, resourceId); } catch (IOException ignored) { return null; } }
Example #17
Source File: ResUtils.java From pybbsMD with Apache License 2.0 | 5 votes |
public static String getRawString(@NonNull Context context, @RawRes int rawId) throws IOException { InputStream is = context.getResources().openRawResource(rawId); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } sb.deleteCharAt(sb.length() - 1); reader.close(); return sb.toString(); }
Example #18
Source File: MovieView.java From android-PictureInPicture with Apache License 2.0 | 5 votes |
/** * Sets the raw resource ID of video to play. * * @param id The raw resource ID. */ public void setVideoResourceId(@RawRes int id) { if (id == mVideoResourceId) { return; } mVideoResourceId = id; Surface surface = mSurfaceView.getHolder().getSurface(); if (surface != null && surface.isValid()) { closeVideo(); openVideo(surface); } }
Example #19
Source File: OptimizelyManager.java From android-sdk with Apache License 2.0 | 5 votes |
/** This function will first try to get datafile from Cache, if file is not cached yet * than it will read from Raw file * @param context * @param datafileRes * @return datafile */ public String getDatafile(Context context,@RawRes Integer datafileRes){ try { if (isDatafileCached(context)) { String datafile = datafileHandler.loadSavedDatafile(context, datafileConfig); if (datafile != null) { return datafile; } } return safeLoadResource(context, datafileRes); } catch (NullPointerException e){ logger.error("Unable to find compiled data file in raw resource",e); } return null; }
Example #20
Source File: ContextUtils.java From Stringlate with MIT License | 5 votes |
/** * Load a markdown file from a {@link RawRes}, prepend each line with {@code prepend} text * and convert markdown to html using {@link SimpleMarkdownParser} */ public String loadMarkdownForTextViewFromRaw(@RawRes int rawMdFile, String prepend) { try { return new SimpleMarkdownParser() .parse(_context.getResources().openRawResource(rawMdFile), prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW) .replaceColor("#000001", rcolor(getResId(ResType.COLOR, "accent"))) .removeMultiNewlines().replaceBulletCharacter("*").getHtml(); } catch (IOException e) { e.printStackTrace(); return ""; } }
Example #21
Source File: ContextUtils.java From openlauncher with Apache License 2.0 | 5 votes |
/** * Load a markdown file from a {@link RawRes}, prepend each line with {@code prepend} text * and convert markdown to html using {@link SimpleMarkdownParser} */ public String loadMarkdownForTextViewFromRaw(@RawRes int rawMdFile, String prepend) { try { return new SimpleMarkdownParser() .parse(_context.getResources().openRawResource(rawMdFile), prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW) .replaceColor("#000001", rcolor(getResId(ResType.COLOR, "accent"))) .removeMultiNewlines().replaceBulletCharacter("*").getHtml(); } catch (IOException e) { e.printStackTrace(); return ""; } }
Example #22
Source File: ImageFrameHandler.java From ImageFrame with Apache License 2.0 | 5 votes |
private void setImageFrame(Resources resources, @RawRes int[] resArray, int width, int height, int fps, OnImageLoadListener onPlayFinish) { this.width = width; this.height = height; this.resources = resources; if (imageCache == null) { imageCache = new ImageCache(); } this.onImageLoadListener = onPlayFinish; frameTime = 1000f / fps + 0.5f; workHandler.addMessageProxy(this); this.resArray = resArray; }
Example #23
Source File: ImageFrameHandler.java From ImageFrame with Apache License 2.0 | 5 votes |
/** * load frame form file resources Array; * * @param resArray resources Array * @param fps The number of broadcast images per second * @param onPlayFinish finish callback */ @Deprecated public void loadImage(Resources resources, @RawRes int[] resArray, int fps, OnImageLoadListener onPlayFinish) { if (!isRunning) { setImageFrame(resources, resArray, width, height, fps, onPlayFinish); load(resArray); } }
Example #24
Source File: ImageFrameHandler.java From ImageFrame with Apache License 2.0 | 5 votes |
public ResourceHandlerBuilder(@NonNull Resources resources, @NonNull @RawRes int[] resArray) { if (resArray.length == 0) { throw new IllegalArgumentException("resArray is not empty"); } this.resources = resources; this.resArray = resArray; createHandler(); }
Example #25
Source File: BitmapLoadUtils.java From ImageFrame with Apache License 2.0 | 5 votes |
@NonNull private static BitmapDrawable readBitmapFromRes(Resources resources, @RawRes int resId, ImageCache cache, BitmapFactory.Options options) { addInBitmapOptions(options, cache); // } // If we're running on Honeycomb or newer, try to use inBitmap. options.inJustDecodeBounds = false; return new BitmapDrawable(resources, decodeStream(resources.openRawResource(resId), null, options)); }
Example #26
Source File: GlUtil.java From PLDroidMediaStreaming with Apache License 2.0 | 5 votes |
public static int createProgram(Context applicationContext, @RawRes int vertexSourceRawId, @RawRes int fragmentSourceRawId) { String vertexSource = readTextFromRawResource(applicationContext, vertexSourceRawId); String fragmentSource = readTextFromRawResource(applicationContext, fragmentSourceRawId); return createProgram(vertexSource, fragmentSource); }
Example #27
Source File: ShaderProgram.java From LearnOpenGL with MIT License | 5 votes |
protected ShaderProgram(Context context, @RawRes int vertexShaderResourceId, @RawRes int fragmentShaderResourceId) { // Compile the shaders and link the program. mProgram = ShaderHelper.buildProgram( Utils.loadShader(context, vertexShaderResourceId), Utils.loadShader(context, fragmentShaderResourceId)); }
Example #28
Source File: ContextUtils.java From memetastic with GNU General Public License v3.0 | 5 votes |
/** * Load a markdown file from a {@link RawRes}, prepend each line with {@code prepend} text * and convert markdown to html using {@link SimpleMarkdownParser} */ public String loadMarkdownForTextViewFromRaw(@RawRes int rawMdFile, String prepend) { try { return new SimpleMarkdownParser() .parse(_context.getResources().openRawResource(rawMdFile), prepend, SimpleMarkdownParser.FILTER_ANDROID_TEXTVIEW) .replaceColor("#000001", rcolor(getResId(ResType.COLOR, "accent"))) .removeMultiNewlines().replaceBulletCharacter("*").getHtml(); } catch (IOException e) { e.printStackTrace(); return ""; } }
Example #29
Source File: NiboPickerFragment.java From Nibo with MIT License | 5 votes |
public static NiboPickerFragment newInstance(String searchBarTitle, String confirmButtonTitle, NiboStyle styleEnum, @RawRes int styleFileID, @DrawableRes int markerIconRes) { Bundle args = new Bundle(); NiboPickerFragment fragment = new NiboPickerFragment(); args.putString(NiboConstants.SEARCHBAR_TITLE_ARG, searchBarTitle); args.putString(NiboConstants.SELECTION_BUTTON_TITLE, confirmButtonTitle); args.putSerializable(NiboConstants.STYLE_ENUM_ARG, styleEnum); args.putInt(NiboConstants.STYLE_FILE_ID, styleFileID); args.putInt(NiboConstants.MARKER_PIN_ICON_RES, markerIconRes); fragment.setArguments(args); return fragment; }
Example #30
Source File: FontManagerImplBase.java From font-compat with Apache License 2.0 | 5 votes |
@Nullable public final FontListParser.Config readFontConfig(@NonNull Context context, @RawRes int resId) { InputStream stream = context.getResources().openRawResource(resId); try { return FontListParser.parse(stream); } catch (Exception e) { Log.w(TAG, "TODO", e); } return null; }