当前位置: 首页>>代码示例>>Java>>正文


Java Resources.openRawResource方法代码示例

本文整理汇总了Java中android.content.res.Resources.openRawResource方法的典型用法代码示例。如果您正苦于以下问题:Java Resources.openRawResource方法的具体用法?Java Resources.openRawResource怎么用?Java Resources.openRawResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.res.Resources的用法示例。


在下文中一共展示了Resources.openRawResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStringFromRaw

import android.content.res.Resources; //导入方法依赖的package包/类
private static String getStringFromRaw(Context context, 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;
}
 
开发者ID:SimonCherryGZ,项目名称:face-landmark-android,代码行数:21,代码来源:MyGLUtils.java

示例2: hookDecodeResource

import android.content.res.Resources; //导入方法依赖的package包/类
@DoNotStrip
public static Bitmap hookDecodeResource(
    Resources res,
    int id,
    BitmapFactory.Options opts) {
  Bitmap bm = null;
  TypedValue value = new TypedValue();

  try (InputStream is = res.openRawResource(id, value)) {
    bm = hookDecodeResourceStream(res, value, is, null, opts);
  } catch (Exception e) {
    // Keep resulting bitmap as null
  }

  if (IN_BITMAP_SUPPORTED && bm == null && opts != null && opts.inBitmap != null) {
    throw new IllegalArgumentException("Problem decoding into existing bitmap");
  }

  return bm;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:WebpBitmapFactoryImpl.java

示例3: sampleCompress

import android.content.res.Resources; //导入方法依赖的package包/类
public static Bitmap sampleCompress(int resId, int sampleSize, Tiny.BitmapCompressOptions options) throws Exception {
    InputStream is = null;
    Resources resources = Tiny.getInstance().getApplication().getResources();
    try {
        is = resources.openRawResource(resId, new TypedValue());
        BitmapFactory.Options decodeOptions = CompressKit.getDefaultDecodeOptions();
        decodeOptions.inPreferredConfig = options.config;
        decodeOptions.inSampleSize = sampleSize;
        Bitmap bitmap = BitmapFactory.decodeStream(is, null, decodeOptions);
        bitmap = Degrees.handle(bitmap, resId);
        return bitmap;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                //ignore...
            }
        }
    }
}
 
开发者ID:Sunzxyong,项目名称:Tiny,代码行数:22,代码来源:BitmapCompressor.java

示例4: loadBlockDefinitionsFromResources

import android.content.res.Resources; //导入方法依赖的package包/类
/**
 * Loads list of block definitions from resources or fail with IllegalStateException.
 *
 * @param factory The factory to add block definitions to.
 * @param resIds The resource ids to raw XML files with the block definitions.
 */
private void loadBlockDefinitionsFromResources(BlockFactory factory, List<Integer> resIds) {
    Resources resources = mContext.getResources();
    for (int i = 0; i < resIds.size(); i++) {
        int resourceId = resIds.get(i);
        try {
            InputStream is = resources.openRawResource(resourceId);
            factory.addJsonDefinitions(is);
        } catch (IOException | BlockLoadingException e) {
            factory.clear();  // Clear partially loaded resources.
            // Compile-time bundled assets are assumed to always be valid.
            String resName = resources.getResourceName(resourceId);
            throw new IllegalStateException(
                    "Failed to load block definition from resource id " + resourceId
                    + (resName == null ? "" : " \"" + resName + "\""), e);
        }
    }
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:24,代码来源:BlocklyController.java

示例5: decodeDimensions

import android.content.res.Resources; //导入方法依赖的package包/类
public static Pair<Integer, Integer> decodeDimensions(int resId) throws Exception {
    //for drawable resource,get the original size of resources,without scaling.
    InputStream is = null;
    Resources resources = Tiny.getInstance().getApplication().getResources();
    try {
        is = resources.openRawResource(resId, new TypedValue());
        BitmapFactory.Options options = CompressKit.getDefaultDecodeBoundsOptions();
        BitmapFactory.decodeStream(is, null, options);
        return (options.outWidth == -1 || options.outHeight == -1) ?
                null : Pair.create(options.outWidth, options.outHeight);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                //ignore...
            }
        }
    }
}
 
开发者ID:Sunzxyong,项目名称:Tiny,代码行数:21,代码来源:BitmapKit.java

示例6: getStringFromRaw

import android.content.res.Resources; //导入方法依赖的package包/类
public static String getStringFromRaw(Context context, 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;
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:19,代码来源:GlUtil.java

示例7: testResource

import android.content.res.Resources; //导入方法依赖的package包/类
private void testResource() {
    try {
        int[] resIds = new int[]{R.drawable.test1, R.drawable.test2, R.drawable.test3, R.drawable.test4};
        Resources resources = getApplication().getResources();
        Bitmap[] bitmaps = new Bitmap[4];
        long[] sizes = new long[4];
        for (int index = 0; index < 4; index++) {
            InputStream is = null;
            is = resources.openRawResource(resIds[index], new TypedValue());
            sizes[index] = is.available();
            bitmaps[index] = BitmapFactory.decodeStream(is);
            is.close();
        }
        setupSourceInfo(bitmaps, sizes);

        Flora.with().load(resIds).compress(new Callback<List<String>>() {
            @Override
            public void callback(List<String> strings) {
                setupResultInfo(strings);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:ghnor,项目名称:Flora,代码行数:26,代码来源:BatchActivity.java

示例8: getStreams

import android.content.res.Resources; //导入方法依赖的package包/类
@Override
InputStream[] getStreams(Resources res) {
    if (mRawIds == null || mRawIds.length == 0) return null;
    InputStream[] streams = new InputStream[mRawIds.length];
    for (int i = 0; i < mRawIds.length; ++i) {
        streams[i] = res.openRawResource(mRawIds[i]);
    }
    return streams;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:10,代码来源:PluginManager.java

示例9: getFromResource

import android.content.res.Resources; //导入方法依赖的package包/类
/**
 * Read and parse an SVG from the given resource location.
 *
 * @param resources
 *            the set of Resources in which to locate the file.
 * @param resourceId
 *            the resource identifier of the SVG document.
 * @return an SVG instance on which you can call one of the render methods.
 * @throws SVGParseException
 *             if there is an error parsing the document.
 */
public static SVG getFromResource(Resources resources, int resourceId)
		throws SVGParseException {
	SVGParser parser = new SVGParser();
	InputStream is = resources.openRawResource(resourceId);
	try {
		return parser.parse(is);
	} finally {
		try {
			is.close();
		} catch (IOException e) {
			// Do nothing
		}
	}
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:26,代码来源:SVG.java

示例10: loadBookFromResource

import android.content.res.Resources; //导入方法依赖的package包/类
/**
 * Loads book from resource.
 */
public Book loadBookFromResource(String name, BookName.Format format, Resources resources, int resId) throws IOException {
    InputStream is = resources.openRawResource(resId);
    try {
        return loadBookFromStream(name, format, is);
    } finally {
        is.close();
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:12,代码来源:Shelf.java

示例11: showCode

import android.content.res.Resources; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public void showCode(View view) {
    CodeViewer ui_text = (CodeViewer) view.findViewById(R.id.ui_text);
    try {
        Resources res = getResources();
        InputStream in_s = res.openRawResource(R.raw.button);
        byte[] b = new byte[in_s.available()];
        in_s.read(b);
        ui_text.withoutSymbols(true);
        ui_text.setHighlightedText(new String(b));
    } catch (Exception e) {
        ui_text.setHighlightedText(e.toString());
    }
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:15,代码来源:ButtonFragment.java

示例12: startLoadTask

import android.content.res.Resources; //导入方法依赖的package包/类
protected void startLoadTask(Context context, int id,
                             List<String> wordList)
{
    // Read words from resources
    Resources resources = context.getResources();
    InputStream stream = resources.openRawResource(id);
    InputStreamReader reader = new InputStreamReader(stream);
    BufferedReader buffer = new BufferedReader(reader);

    // Start the task
    LoadTask loadTask = new LoadTask();
    loadTask.wordList = wordList;
    loadTask.execute(buffer);
}
 
开发者ID:billthefarmer,项目名称:crossword,代码行数:15,代码来源:Data.java

示例13: showCode

import android.content.res.Resources; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public void showCode(View view) {
    CodeViewer ui_text = (CodeViewer) view.findViewById(R.id.ui_text);
    try {
        Resources res = getResources();
        InputStream in_s = res.openRawResource(R.raw.menu);
        byte[] b = new byte[in_s.available()];
        in_s.read(b);
        ui_text.withoutSymbols(true);
        ui_text.setHighlightedText(new String(b));
    } catch (Exception e) {
        ui_text.setHighlightedText(e.toString());
    }
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:15,代码来源:MenuFragment.java

示例14: showCode

import android.content.res.Resources; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public void showCode(View view) {
    CodeViewer ui_text = (CodeViewer) view.findViewById(R.id.ui_text);
    try {
        Resources res = getResources();
        InputStream in_s = res.openRawResource(R.raw.button_touchlistener);
        byte[] b = new byte[in_s.available()];
        in_s.read(b);
        ui_text.setHighlightedText(new String(b));
    } catch (Exception e) {
        ui_text.setHighlightedText(e.toString());
    }
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:14,代码来源:ButtonTouchListenerFragment.java

示例15: showCode

import android.content.res.Resources; //导入方法依赖的package包/类
@SuppressWarnings("ResultOfMethodCallIgnored")
public void showCode(View view) {
    CodeViewer ui_text = (CodeViewer) view.findViewById(R.id.ui_text);
    try {
        Resources res = getResources();
        InputStream in_s = res.openRawResource(R.raw.alertdialog);
        byte[] b = new byte[in_s.available()];
        in_s.read(b);
        ui_text.withoutSymbols(true);
        ui_text.setHighlightedText(new String(b));
    } catch (Exception e) {
        ui_text.setHighlightedText(e.toString());
    }
}
 
开发者ID:Light-Team,项目名称:ModPE-IDE-Source,代码行数:15,代码来源:AlertDialogFragment.java


注:本文中的android.content.res.Resources.openRawResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。