本文整理汇总了Java中android.content.res.AssetManager类的典型用法代码示例。如果您正苦于以下问题:Java AssetManager类的具体用法?Java AssetManager怎么用?Java AssetManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssetManager类属于android.content.res包,在下文中一共展示了AssetManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAssetsFileToStream
import android.content.res.AssetManager; //导入依赖的package包/类
public static InputStream readAssetsFileToStream(String fileName, Context context) {
AssetManager assManager = context.getAssets();
InputStream is = null;
try {
is = assManager.open(fileName);
} catch (Exception e) {
e.getMessage();
} finally {
try {
if (is != null)
is.close();
} catch (Exception e2) {
e2.getMessage();
}
}
InputStream isOutput = new BufferedInputStream(is);
return isOutput;
}
示例2: readAssetsFile
import android.content.res.AssetManager; //导入依赖的package包/类
/**
* 读取Assets下的文本文件
*
* @param context 上下文
* @param fileName 文件名
* @return 读取到的字符串
*/
public static String readAssetsFile(Context context, String fileName) {
StringBuilder stringBuffer = new StringBuilder();
AssetManager assetManager = context.getAssets();
try {
InputStream is = assetManager.open(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String str = null;
while ((str = br.readLine()) != null) {
stringBuffer.append(str);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuffer.toString();
}
示例3: getRoundIcon
import android.content.res.AssetManager; //导入依赖的package包/类
private Drawable getRoundIcon(Context context,String packageName, int iconDpi) {
mPackageManager = context.getPackageManager();
try {
Resources resourcesForApplication = mPackageManager.getResourcesForApplication(packageName);
AssetManager assets = resourcesForApplication.getAssets();
XmlResourceParser parseXml = assets.openXmlResourceParser("AndroidManifest.xml");
int eventType;
while ((eventType = parseXml.nextToken()) != XmlPullParser.END_DOCUMENT)
if (eventType == XmlPullParser.START_TAG && parseXml.getName().equals("application"))
for (int i = 0; i < parseXml.getAttributeCount(); i++)
if (parseXml.getAttributeName(i).equals("roundIcon"))
return resourcesForApplication.getDrawableForDensity(Integer.parseInt(parseXml.getAttributeValue(i).substring(1)), iconDpi, context.getTheme());
parseXml.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
示例4: getResources
import android.content.res.AssetManager; //导入依赖的package包/类
@Override
public Resources getResources(Context context, ApplicationInfo appInfo) throws Exception {
InstalledAppInfo appSetting = VAppManagerService.get().getInstalledAppInfo(appInfo.packageName, 0);
if (appSetting != null) {
AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance();
mirror.android.content.res.AssetManager.addAssetPath.call(assets, appSetting.apkPath);
Resources hostRes = context.getResources();
return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration());
}
return null;
}
示例5: setTypeface
import android.content.res.AssetManager; //导入依赖的package包/类
@Override
public void setTypeface(Typeface tf, int style) {
//super.setTypeface(tf, style);
if (!isInEditMode()) {
String customTypefacePath = REGULAR_FONT_PATH;
if (style == Typeface.BOLD) {
customTypefacePath = BOLD_FONT_PATH;
}
// load custom font if available on app bundle.
if (assetExists(getContext(), customTypefacePath)) {
AssetManager assets = getContext().getAssets();
tf = Typeface.createFromAsset(assets, customTypefacePath);
}
super.setTypeface(tf, style);
}
}
示例6: copyAssetDirToFiles
import android.content.res.AssetManager; //导入依赖的package包/类
public boolean copyAssetDirToFiles(Context context, String dirname) {
try {
AssetManager assetManager = context.getAssets();
String[] children = assetManager.list(dirname);
for (String child : children) {
child = dirname + '/' + child;
String[] grandChildren = assetManager.list(child);
if (0 == grandChildren.length)
copyAssetFileToFiles(context, child);
else
copyAssetDirToFiles(context, child);
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
示例7: createSample
import android.content.res.AssetManager; //导入依赖的package包/类
/**
* sample.oudをdataフォルダにコピーする
*/
private void createSample() {
File file = new File(getExternalFilesDir(null), "sample.oud");
if(file.exists()){
//return;
}
try {
AssetManager assetManager = getAssets();
;
InputStream is = assetManager.open("sample.oud");
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
os.write(data);
is.close();
os.close();
} catch (IOException e) {
Log.w("ExternalStorage", "Error writing " + file, e);
}
}
示例8: copyAssetFolder
import android.content.res.AssetManager; //导入依赖的package包/类
public static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
try {
String[] files = assetManager.list(fromAssetPath);
new File(toPath).mkdirs();
boolean res = true;
for (String file : files) {
if (file.contains(".")) {
res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
} else {
res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
}
}
return res;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例9: loadResources
import android.content.res.AssetManager; //导入依赖的package包/类
protected void loadResources() {
try {
AssetManager assetManager = AssetManager.class.newInstance();
Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
addAssetPath.invoke(assetManager, dexpath);
mAssetManager = assetManager;
} catch (Exception e) {
e.printStackTrace();
}
Resources superRes = super.getResources();
superRes.getDisplayMetrics();
superRes.getConfiguration();
mResources = new Resources(mAssetManager, superRes.getDisplayMetrics(),superRes.getConfiguration());
mTheme = mResources.newTheme();
mTheme.setTo(super.getTheme());
}
示例10: loadModel
import android.content.res.AssetManager; //导入依赖的package包/类
public void loadModel(String path) throws IOException {
mInputStream = mContext.getAssets().open(path + "/W", AssetManager.ACCESS_BUFFER);
ByteBuffer bb = readInput(mInputStream);
FloatBuffer.wrap(W).put(bb.asFloatBuffer());
// padding for GPU BLAS when necessary.
int W_height_input = in_channels * ksize * ksize;
if (padded_Y_blas == W_height_input) {
// If the input width already satisfies the requirement, just copy to the Allocation.
W_alloc.copyFrom(W);
} else {
// If not, a temp allocation needs to be created.
Allocation input = Allocation.createTyped(mRS,
Type.createXY(mRS, Element.F32(mRS), W_height_input, out_channels));
input.copyFrom(W);
W_alloc.copy2DRangeFrom(0, 0, W_height_input, out_channels, input, 0, 0);
}
mInputStream = mContext.getAssets().open(path + "/b", AssetManager.ACCESS_BUFFER);
bb = readInput(mInputStream);
FloatBuffer.wrap(b).put(bb.asFloatBuffer());
b_alloc.copyFrom(b);
mInputStream.close();
Log.v(TAG, "Convolution2D loaded: " + b[0]);
}
示例11: copyAssetFolder
import android.content.res.AssetManager; //导入依赖的package包/类
public static boolean copyAssetFolder(AssetManager assetManager,
String fromAssetPath, String toPath) {
try {
String[] files = assetManager.list(fromAssetPath);
new File(toPath).mkdirs();
boolean res = true;
for (String file : files)
if (file.contains(".")) {
res &= copyAsset(assetManager,
fromAssetPath + "/" + file,
toPath + "/" + file);
} else {
res &= copyAssetFolder(assetManager,
fromAssetPath + "/" + file,
toPath + "/" + file);
}
return res;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例12: getTypeface
import android.content.res.AssetManager; //导入依赖的package包/类
public
@Nullable Typeface getTypeface(
String fontFamilyName,
int style,
AssetManager assetManager) {
FontFamily fontFamily = mFontCache.get(fontFamilyName);
if (fontFamily == null) {
fontFamily = new FontFamily();
mFontCache.put(fontFamilyName, fontFamily);
}
Typeface typeface = fontFamily.getTypeface(style);
if (typeface == null) {
typeface = createTypeface(fontFamilyName, style, assetManager);
if (typeface != null) {
fontFamily.setTypeface(style, typeface);
}
}
return typeface;
}
示例13: getJsonFromAssetsPath
import android.content.res.AssetManager; //导入依赖的package包/类
public static String getJsonFromAssetsPath(AssetManager assetManager, String fileName) {
String json;
try {
InputStream is = assetManager.open(fileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
示例14: readAssetJson
import android.content.res.AssetManager; //导入依赖的package包/类
private String readAssetJson() {
AssetManager assetManager = getActivity().getAssets();
try {
InputStream in = assetManager.open("region.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null){
builder.append(line);
}
return builder.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例15: testFetchAssetResource
import android.content.res.AssetManager; //导入依赖的package包/类
@Test
public void testFetchAssetResource() throws Exception {
PooledByteBuffer pooledByteBuffer = mock(PooledByteBuffer.class);
when(mAssetManager.open(eq(TEST_FILENAME), eq(AssetManager.ACCESS_STREAMING)))
.thenReturn(new ByteArrayInputStream(new byte[TEST_DATA_LENGTH]));
when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(TEST_DATA_LENGTH)))
.thenReturn(pooledByteBuffer);
mLocalAssetFetchProducer.produceResults(mConsumer, mProducerContext);
mExecutor.runUntilIdle();
assertEquals(
2,
mCapturedEncodedImage.getByteBufferRef()
.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
assertSame(pooledByteBuffer, mCapturedEncodedImage.getByteBufferRef().get());
verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, null);
verify(mProducerListener).onUltimateProducerReached(mRequestId, PRODUCER_NAME, true);
}