本文整理汇总了Java中android.support.annotation.RawRes类的典型用法代码示例。如果您正苦于以下问题:Java RawRes类的具体用法?Java RawRes怎么用?Java RawRes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RawRes类属于android.support.annotation包,在下文中一共展示了RawRes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readRawResource
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* Reads the raw resource as plain text from the given resource ID.
*
* @param context Which context to use for reading
* @param rawResourceId The raw resource identifier
* @return A text representation of the raw resource, never {@code null}
*/
@NonNull
@SuppressWarnings("unused")
public static String readRawResource(@NonNull final Context context, @RawRes final int rawResourceId) {
InputStream inputStream = null;
try {
inputStream = openRawResource(context, rawResourceId);
byte[] b = new byte[inputStream.available()];
// noinspection ResultOfMethodCallIgnored - don't care about number of bytes read
inputStream.read(b);
return new String(b);
} catch (Exception e) {
Log.e(TAG, "readRawResource: FAILED!", e);
return "";
} finally {
close(inputStream);
}
}
示例2: loadShader
import android.support.annotation.RawRes; //导入依赖的package包/类
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();
}
示例3: decodeSampledBitmapFromRes
import android.support.annotation.RawRes; //导入依赖的package包/类
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;
}
示例4: readTextFromRawResource
import android.support.annotation.RawRes; //导入依赖的package包/类
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();
}
示例5: BuiltinOfferSource
import android.support.annotation.RawRes; //导入依赖的package包/类
public BuiltinOfferSource(@NonNull Context context, @RawRes int rawResourceID) throws IOException {
InputStream rawFileInputStream = context.getResources().openRawResource(rawResourceID);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(rawFileInputStream));
//Stupid Android Studio forgetting try with resources is only kitkat+
//noinspection TryFinallyCanBeTryWithResources
try {
StringBuilder fileContent = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
fileContent.append(line);
}
offersJSON = fileContent.toString();
} finally {
//noinspection ThrowFromFinallyBlock
reader.close();
}
} finally {
if (rawFileInputStream != null) {
//noinspection ThrowFromFinallyBlock
rawFileInputStream.close();
}
}
}
示例6: playSound
import android.support.annotation.RawRes; //导入依赖的package包/类
public void playSound(@RawRes final int resId) {
if (this.mSoundSourceMap != null) {
if (this.mSoundSourceMap.containsKey(Integer.valueOf(resId))) {
play(((Integer) this.mSoundSourceMap.get(Integer.valueOf(resId))).intValue());
return;
}
this.mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
if (status == 0) {
MQSoundPoolManager.this.mSoundSourceMap.put(Integer.valueOf(resId),
Integer.valueOf(sampleId));
MQSoundPoolManager.this.play(sampleId);
}
}
});
this.mSoundPool.load(this.mContext.getApplicationContext(), resId, 1);
}
}
示例7: decodeBitmapFromResLruCache
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* 读取图片 优先从缓存中获取图片
*/
static BitmapDrawable decodeBitmapFromResLruCache(Resources resources, @RawRes int resId,
int reqWidth, int reqHeight,
ImageCache cache) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
decodeStream(resources.openRawResource(resId), null, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
BitmapDrawable bitmapFromCache;
String resourceName = resources.getResourceName(resId);
bitmapFromCache = cache.getBitmapFromCache(resourceName);
if (bitmapFromCache == null) {
bitmapFromCache = readBitmapFromRes(resources, resId, cache, options);
cache.addBitmapToCache(resourceName, bitmapFromCache);
}
return bitmapFromCache;
}
示例8: loadResourceFile
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* Load a given (html or css) resource file into a String. The input can contain tokens that will
* be replaced with localised strings.
*
* @param substitutionTable A table of substitions, e.g. %shortMessage% -> "Error loading page..."
* Can be null, in which case no substitutions will be made.
* @return The file content, with all substitutions having being made.
*/
public static String loadResourceFile(@NonNull final Context context,
@NonNull final @RawRes int resourceID,
@Nullable final Map<String, String> substitutionTable) {
try (final BufferedReader fileReader =
new BufferedReader(new InputStreamReader(context.getResources().openRawResource(resourceID), StandardCharsets.UTF_8))) {
final StringBuilder outputBuffer = new StringBuilder();
String line;
while ((line = fileReader.readLine()) != null) {
if (substitutionTable != null) {
for (final Map.Entry<String, String> entry : substitutionTable.entrySet()) {
line = line.replace(entry.getKey(), entry.getValue());
}
}
outputBuffer.append(line);
}
return outputBuffer.toString();
} catch (final IOException e) {
throw new IllegalStateException("Unable to load error page data", e);
}
}
示例9: readTextFromRawResource
import android.support.annotation.RawRes; //导入依赖的package包/类
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();
}
示例10: displayLicensesFragment
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* Builds and displays a licenses fragment for you. Requires "/res/raw/licenses.html" and
* "/res/layout/licenses_fragment.xml" to be present.
*
* @param fm A fragment manager instance used to display this LicensesFragment.
*/
public static void displayLicensesFragment(FragmentManager fm, @RawRes int htmlResToShow, String title) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(FRAGMENT_TAG);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
final DialogFragment newFragment;
if (TextUtils.isEmpty(title)) {
newFragment = LicensesFragment.newInstance(htmlResToShow);
} else {
newFragment = LicensesFragment.newInstance(htmlResToShow, title);
}
newFragment.show(ft, FRAGMENT_TAG);
}
示例11: readText
import android.support.annotation.RawRes; //导入依赖的package包/类
public static String readText(Context context, @RawRes int rawTextFileResId) {
InputStream inputStream = context.getResources().openRawResource(rawTextFileResId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1) {
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
示例12: readTextFileFromRawResource
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* 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();
}
示例13: loadLocalFile
import android.support.annotation.RawRes; //导入依赖的package包/类
private String loadLocalFile(@RawRes int id) {
String data = null;
InputStream is = null;
try {
is = service.getResources().openRawResource(id);
byte[] buffer = new byte[is.available()];
is.read(buffer);
data = new String(buffer);
} catch (IOException e) {
logger.e("loadLocalFile " + id, e);
} finally {
try {
is.close();
} catch (IOException ex) {
logger.e("loadLocalFile close " + id, ex);
}
}
return data;
}
示例14: init
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* Initializes Embedded Social SDK.
* @param application the application instance
* @param configResId resource id of the JSON configuration file for the SDK
* @param appKey application key
*/
public static void init(Application application, @RawRes int configResId, String appKey) {
if (BuildConfig.DEBUG) {
initLogging(application);
}
InputStream is = application.getResources().openRawResource(configResId);
Reader reader = new InputStreamReader(is);
Options options = new Gson().fromJson(reader, Options.class);
if (appKey != null) {
options.setAppKey(appKey);
}
options.verify();
GlobalObjectRegistry.addObject(options);
initGlobalObjects(application, options);
WorkerService.getLauncher(application).launchService(ServiceAction.BACKGROUND_INIT);
// TODO: Added to main activity access token tracking
// https://developers.facebook.com/docs/facebook-login/android/v2.2#access_profile
}
示例15: decodeResourceOrThrow
import android.support.annotation.RawRes; //导入依赖的package包/类
/**
* Decodes image from resource.
* Returns {@link GifDrawable} if the image is an animated GIF.
* Returns {@link BitmapDrawable} if the image is s valid static image {@link BitmapFactory}
* can decode.
*
* @param res The resources object containing the image data
* @param id The resource id of the image data
* @param options optional options if an image will be decoded to a Bitmap
* @return decoded {@link Drawable}
* @throws IOException on error
* @throws NullPointerException if Resources is null
* @throws Resources.NotFoundException if resource under the given id does not exist
*/
@NonNull
public static Drawable decodeResourceOrThrow(final Resources res,
@DrawableRes @RawRes final int id,
@Nullable final BitmapFactory.Options options) throws IOException {
if (res == null) {
throw new NullPointerException("Resources must not be null");
}
final AssetFileDescriptor descriptor = res.openRawResourceFd(id);
try {
return decodeStreamOrThrow(res, descriptor.createInputStream(), null, options);
} finally {
descriptor.close();
}
}