本文整理匯總了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;
}
示例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;
}
示例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...
}
}
}
}
示例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);
}
}
}
示例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...
}
}
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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
}
}
}
示例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();
}
}
示例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());
}
}
示例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);
}
示例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());
}
}
示例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());
}
}
示例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());
}
}