类android.support.annotation.RawRes源码实例Demo

下面列出了怎么用android.support.annotation.RawRes的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: MusicVisualization   文件: MyGLUtils.java
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;
}
 
源代码2 项目: ImageFrame   文件: BitmapLoadUtils.java
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;
}
 
源代码3 项目: LearnOpenGL   文件: Utils.java
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();
}
 
源代码4 项目: AndroidUtilCode   文件: ResourceUtils.java
/**
 * 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 "";
        }
    }
}
 
源代码5 项目: PLDroidMediaStreaming   文件: GlUtil.java
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();
}
 
源代码6 项目: android-sdk   文件: OptimizelyManager.java
/**
 * 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;
}
 
源代码7 项目: StarWars.Android   文件: RawResourceReader.java
/**
 * 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();
}
 
源代码8 项目: Web3View   文件: JsInjectorClient.java
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);
}
 
源代码9 项目: alpha-wallet-android   文件: JsInjectorClient.java
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);
}
 
源代码10 项目: alpha-wallet-android   文件: HelpActivity.java
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;
}
 
源代码11 项目: alpha-wallet-android   文件: HelpHolder.java
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);
}
 
源代码12 项目: android-PictureInPicture   文件: MovieView.java
/**
 * 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);
    }
}
 
源代码13 项目: ImageFrame   文件: ImageFrameHandler.java
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;
}
 
源代码14 项目: ImageFrame   文件: ImageFrameHandler.java
/**
 * 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);
  }
}
 
源代码15 项目: ImageFrame   文件: ImageFrameHandler.java
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();
}
 
源代码16 项目: ImageFrame   文件: BitmapLoadUtils.java
@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));
}
 
源代码17 项目: PLDroidMediaStreaming   文件: GlUtil.java
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);
}
 
源代码18 项目: LearnOpenGL   文件: ShaderProgram.java
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));
}
 
源代码19 项目: memetastic   文件: ContextUtils.java
/**
 * 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 "";
    }
}
 
源代码20 项目: Nibo   文件: NiboPickerFragment.java
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;
}
 
源代码21 项目: font-compat   文件: FontManagerImplBase.java
@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;
}
 
源代码22 项目: openlauncher   文件: ContextUtils.java
/**
 * 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 "";
    }
}
 
源代码23 项目: Stringlate   文件: ContextUtils.java
/**
 * 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 "";
    }
}
 
源代码24 项目: homage   文件: Homage.java
@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;
    }
}
 
源代码25 项目: AlexaAndroid   文件: DisplayCodeFragment.java
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;
}
 
源代码26 项目: android-sdk   文件: OptimizelyManager.java
/** 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;
}
 
源代码27 项目: android-sdk   文件: OptimizelyManager.java
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));
            }
        }
    };
}
 
源代码28 项目: android-sdk   文件: OptimizelyManager.java
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");
    }
}
 
源代码29 项目: pretixdroid   文件: SettingsFragment.java
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();
}
 
源代码30 项目: pybbsMD   文件: ResUtils.java
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();
}
 
 类方法
 同包方法