當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。