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 Project: MusicVisualization Author: nekocode File: MyGLUtils.java License: 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 #2
Source Project: ImageFrame Author: Mr-wangyong File: BitmapLoadUtils.java License: 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 #3
Source Project: LearnOpenGL Author: Piasy File: Utils.java License: 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 #4
Source Project: AndroidUtilCode Author: Blankj File: ResourceUtils.java License: 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 #5
Source Project: PLDroidMediaStreaming Author: pili-engineering File: GlUtil.java License: 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 #6
Source Project: android-sdk Author: optimizely File: OptimizelyManager.java License: 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 #7
Source Project: StarWars.Android Author: Yalantis File: RawResourceReader.java License: 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 Project: Web3View Author: trustwallet File: JsInjectorClient.java License: 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 #9
Source Project: alpha-wallet-android Author: AlphaWallet File: JsInjectorClient.java License: 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 Project: alpha-wallet-android Author: AlphaWallet File: HelpActivity.java License: 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 #11
Source Project: alpha-wallet-android Author: AlphaWallet File: HelpHolder.java License: MIT License | 5 votes |
private String getResource(@RawRes int rawRes) { byte[] buffer = new byte[0]; try { InputStream in = getContext().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 Base64.encodeToString(buffer, Base64.DEFAULT); }
Example #12
Source Project: android-PictureInPicture Author: googlearchive File: MovieView.java License: 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 #13
Source Project: ImageFrame Author: Mr-wangyong File: ImageFrameHandler.java License: 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 #14
Source Project: ImageFrame Author: Mr-wangyong File: ImageFrameHandler.java License: 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 #15
Source Project: ImageFrame Author: Mr-wangyong File: ImageFrameHandler.java License: 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 #16
Source Project: ImageFrame Author: Mr-wangyong File: BitmapLoadUtils.java License: 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 #17
Source Project: PLDroidMediaStreaming Author: pili-engineering File: GlUtil.java License: 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 #18
Source Project: LearnOpenGL Author: Piasy File: ShaderProgram.java License: 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 #19
Source Project: memetastic Author: gsantner File: ContextUtils.java License: 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 #20
Source Project: Nibo Author: aliumujib File: NiboPickerFragment.java License: 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 #21
Source Project: font-compat Author: MeetMe File: FontManagerImplBase.java License: 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; }
Example #22
Source Project: openlauncher Author: OpenLauncherTeam File: ContextUtils.java License: 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 #23
Source Project: Stringlate Author: LonamiWebs File: ContextUtils.java License: 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 #24
Source Project: homage Author: oriley-me File: Homage.java License: 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 #25
Source Project: AlexaAndroid Author: willblaschko File: DisplayCodeFragment.java License: 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 #26
Source Project: android-sdk Author: optimizely File: OptimizelyManager.java License: 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 #27
Source Project: android-sdk Author: optimizely File: OptimizelyManager.java License: Apache License 2.0 | 5 votes |
DatafileLoadedListener getDatafileLoadedListener(final Context context, @RawRes final Integer datafileRes) { return new DatafileLoadedListener() { @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) @Override public void onDatafileLoaded(@Nullable String datafile) { if (datafile != null && !datafile.isEmpty()) { injectOptimizely(context, userProfileService, datafile); } else { injectOptimizely(context, userProfileService, safeLoadResource(context, datafileRes)); } } }; }
Example #28
Source Project: android-sdk Author: optimizely File: OptimizelyManager.java License: Apache License 2.0 | 5 votes |
public static String loadRawResource(Context context, @RawRes int rawRes) throws IOException { Resources res = context.getResources(); InputStream in = res.openRawResource(rawRes); byte[] b = new byte[in.available()]; int read = in.read(b); if (read > -1) { return new String(b); } else { throw new IOException("Couldn't parse raw res fixture, no bytes"); } }
Example #29
Source Project: pretixdroid Author: pretix File: SettingsFragment.java License: 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 #30
Source Project: pybbsMD Author: tomoya92 File: ResUtils.java License: 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(); }