use of android.content.res.AssetManager in project baker-android by bakerframework.
the class MagazineThumb method renderCover.
/**
* Sets an image file as the cover of this instance of an issue.
*/
private void renderCover() {
String path;
Bitmap bmp;
Log.d(this.getClass().getName(), "Will render cover for magazine " + this.magazine.getName());
try {
if (this.magazine.isStandalone()) {
boolean fromAssets = !(this.getContext().getResources().getBoolean(R.bool.sa_read_from_custom_directory));
if (fromAssets) {
String books = this.getContext().getString(R.string.sa_books_directory);
path = books.concat(File.separator).concat(this.magazine.getName()).concat(File.separator).concat(this.magazine.getCover());
AssetManager assetManager = this.getContext().getAssets();
bmp = BitmapFactory.decodeStream(assetManager.open(path));
} else {
path = Configuration.getMagazinesDirectory(this.getContext()).concat(File.separator).concat(this.magazine.getName()).concat(File.separator).concat(this.magazine.getCover());
bmp = BitmapFactory.decodeFile(path);
}
} else {
path = Configuration.getCacheDirectory(this.getContext()).concat(File.separator).concat(this.magazine.getName());
bmp = BitmapFactory.decodeFile(path);
}
((ImageView) findViewById(R.id.imgCover)).setImageBitmap(bmp);
} catch (IOException ex) {
Log.e(this.getClass().getName(), "Could not render cover for " + this.magazine.getName(), ex);
}
}
use of android.content.res.AssetManager in project ARChon-Packager by bpear96.
the class activityInstalled method copyAssets.
private void copyAssets() {
//Copy template.zip from app assets to /ChromeAPKS
String AppNameFolder = g.getSelectedAppName();
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", "Failed to get asset file list.", e);
}
assert files != null;
for (String filename : files) {
InputStream in;
OutputStream out;
try {
in = assetManager.open(filename);
out = new FileOutputStream(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + AppNameFolder + "/" + filename);
copyFile(in, out);
in.close();
out.flush();
out.close();
} catch (IOException e) {
Log.e("tag", "Failed to copy asset file: " + filename, e);
}
}
}
use of android.content.res.AssetManager in project android-advancedrecyclerview by h6ah4i.
the class AssetFileLibraryLicenseDataCollector method collect.
public List<LibraryInfo> collect() {
ArrayList<LibraryInfo> list = new ArrayList<>();
AssetManager assets = mContext.getAssets();
try {
String[] dirs = assets.list(mBaseAssetDir);
// sort numerically
final Pattern p = Pattern.compile("^([0-9]+).*$");
Arrays.sort(dirs, new Comparator<String>() {
public int compare(String s1, String s2) {
try {
Matcher m1 = p.matcher(s1);
Matcher m2 = p.matcher(s2);
if (m1.find() && m2.find()) {
int n1 = Integer.parseInt(m1.group(1));
int n2 = Integer.parseInt(m2.group(1));
if (n1 == n2) {
return s1.compareTo(s2);
}
return n1 - n2;
} else {
return s1.compareTo(s2);
}
} catch (RuntimeException e) {
return s1.compareTo(s2);
}
}
});
for (String dirname : dirs) {
LibraryInfo info = loadLicenseInfo(assets, mBaseAssetDir + "/" + dirname);
if (info != null) {
list.add(info);
}
}
} catch (IOException e) {
Log.e(TAG, "collect()", e);
}
return list;
}
use of android.content.res.AssetManager in project facebook-android-sdk by facebook.
the class FacebookActivityTestCase method createTempFileFromAsset.
protected File createTempFileFromAsset(String assetPath) throws IOException {
InputStream inputStream = null;
FileOutputStream outStream = null;
try {
AssetManager assets = getActivity().getResources().getAssets();
inputStream = assets.open(assetPath);
// context being the Activity pointer
File outputDir = getActivity().getCacheDir();
File outputFile = File.createTempFile("prefix", assetPath, outputDir);
outStream = new FileOutputStream(outputFile);
final int bufferSize = 1024 * 2;
byte[] buffer = new byte[bufferSize];
int n = 0;
while ((n = inputStream.read(buffer)) != -1) {
outStream.write(buffer, 0, n);
}
return outputFile;
} finally {
Utility.closeQuietly(outStream);
Utility.closeQuietly(inputStream);
}
}
use of android.content.res.AssetManager in project facebook-android-sdk by facebook.
the class FacebookActivityTestCase method readApplicationIdAndSecret.
protected synchronized void readApplicationIdAndSecret() {
synchronized (FacebookTestCase.class) {
if (applicationId != null && applicationSecret != null && clientToken != null) {
return;
}
AssetManager assets = getInstrumentation().getTargetContext().getResources().getAssets();
InputStream stream = null;
final String errorMessage = "could not read applicationId and applicationSecret from config.json; ensure " + "you have run 'configure_unit_tests.sh'. Error: ";
try {
stream = assets.open("config.json");
String string = Utility.readStreamToString(stream);
JSONTokener tokener = new JSONTokener(string);
Object obj = tokener.nextValue();
if (!(obj instanceof JSONObject)) {
fail(errorMessage + "could not deserialize a JSONObject");
}
JSONObject jsonObject = (JSONObject) obj;
applicationId = jsonObject.optString("applicationId");
applicationSecret = jsonObject.optString("applicationSecret");
clientToken = jsonObject.optString("clientToken");
if (Utility.isNullOrEmpty(applicationId) || Utility.isNullOrEmpty(applicationSecret) || Utility.isNullOrEmpty(clientToken)) {
fail(errorMessage + "config values are missing");
}
} catch (IOException e) {
fail(errorMessage + e.toString());
} catch (JSONException e) {
fail(errorMessage + e.toString());
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
fail(errorMessage + e.toString());
}
}
}
}
}
Aggregations