本文整理匯總了Java中android.content.Context.getAssets方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getAssets方法的具體用法?Java Context.getAssets怎麽用?Java Context.getAssets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.getAssets方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTypeface
import android.content.Context; //導入方法依賴的package包/類
public static Typeface getTypeface(Context context, String typefaceAssetPath){
Typeface typeface = null;
if(!typefaceAssetPath.contains("fonts/"))
typefaceAssetPath = String.format("fonts/%s",typefaceAssetPath);
if(mTypefaces==null)
mTypefaces = new HashMap<>();
if (mTypefaces.containsKey(typefaceAssetPath)) {
typeface = mTypefaces.get(typefaceAssetPath);
} else
{
AssetManager assets = context.getAssets();
typeface = Typeface.createFromAsset(assets, typefaceAssetPath);
mTypefaces.put(typefaceAssetPath, typeface);
}
return typeface;
}
示例2: readAssetsFileToStream
import android.content.Context; //導入方法依賴的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;
}
示例3: copyAssetsToSdCard
import android.content.Context; //導入方法依賴的package包/類
private void copyAssetsToSdCard(String fileName, String filesDir) throws Exception
{
Context testContext = getContext().createPackageContext("de.yaacc.tests",
Context.CONTEXT_IGNORE_SECURITY);
AssetManager assets = testContext.getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(filesDir, fileName);
try
{
in = assets.open(fileName);
out = getContext().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e)
{
Log.e("tag", e.getMessage());
}
}
示例4: listAssetFonts
import android.content.Context; //導入方法依賴的package包/類
public static List<Font> listAssetFonts(Context context) {
AssetManager assetManager = context.getAssets();
String[] fontNames;
try {
fontNames = assetManager.list("fonts");
} catch (IOException e) {
Log.e("Error", "Unable to list fonts", e);
return new ArrayList<>();
}
ArrayList<Font> fonts = new ArrayList<>(fontNames.length);
for (int i = 0; i < fontNames.length; i++) {
fonts.add(new Font(fontNames[i]));
}
return fonts;
}
示例5: readAssetFile
import android.content.Context; //導入方法依賴的package包/類
public static String readAssetFile(Context c, String path) {
String out = null;
AssetManager am = c.getAssets();
try {
InputStream in = am.open(path);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int i;
try {
i = in.read();
while (i != -1) {
buf.write(i);
i = in.read();
}
in.close();
} catch (IOException ex) {
}
out = buf.toString();
} catch (IOException e) {
e.printStackTrace();
MLog.e(TAG, e.toString());
}
return out;
}
示例6: getCityJson
import android.content.Context; //導入方法依賴的package包/類
private void getCityJson(Context c){
StringBuilder stringBuilder = new StringBuilder();
try {
AssetManager manager = c.getAssets();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(manager.open("city.json")));
String line = "";
while ((line = bufferedReader.readLine())!=null) {
stringBuilder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
//得到json的字符串
String json = stringBuilder.toString();
Gson gson=new Gson();
address=gson.fromJson(json,Address.class);
}
示例7: readAssetsFile
import android.content.Context; //導入方法依賴的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();
}
示例8: DynamicFeeLoader
import android.content.Context; //導入方法依賴的package包/類
public DynamicFeeLoader(final Context context) {
super(context);
final PackageInfo packageInfo = WalletApplication.packageInfoFromContext(context);
final int versionNameSplit = packageInfo.versionName.indexOf('-');
this.dynamicFeesUrl = HttpUrl.parse(Constants.DYNAMIC_FEES_URL
+ (versionNameSplit >= 0 ? packageInfo.versionName.substring(versionNameSplit) : ""));
this.userAgent = WalletApplication.httpUserAgent(packageInfo.versionName);
this.assets = context.getAssets();
}
示例9: CaptchaRecognition
import android.content.Context; //導入方法依賴的package包/類
public CaptchaRecognition(Context context) {
super(context.getAssets(), MODEL_FILE);
graphOperation("Placeholder");
input = new float[WIDTH * HEIGHT * DEPTH];
output = new int[CHARS];
}
示例10: loadJSONFromAsset
import android.content.Context; //導入方法依賴的package包/類
public static String loadJSONFromAsset(Context context, String jsonFileName)
throws IOException {
AssetManager manager = context.getAssets();
InputStream is = manager.open(jsonFileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
return new String(buffer, "UTF-8");
}
示例11: getJsonAsString
import android.content.Context; //導入方法依賴的package包/類
public static String getJsonAsString(String filename, Context context) throws IOException {
AssetManager manager = context.getAssets();
StringBuilder buf = new StringBuilder();
InputStream json = manager.open(filename);
BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
String str;
while ((str=in.readLine()) != null) {
buf.append(str);
}
in.close();
return buf.toString();
}
示例12: setup
import android.content.Context; //導入方法依賴的package包/類
private void setup(Context context) {
AssetManager assetManager = context.getAssets();
Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/DejaVuSerif.ttf");
try {
typeface = Typeface.create(typeface, getTypeface().getStyle());
} catch (Exception e) {
e.printStackTrace();
}
setTypeface(typeface);
}
示例13: CordovaResourceApi
import android.content.Context; //導入方法依賴的package包/類
public CordovaResourceApi(Context context, PluginManager pluginManager) {
this.contentResolver = context.getContentResolver();
this.assetManager = context.getAssets();
this.pluginManager = pluginManager;
}
示例14: applyFontToTextView
import android.content.Context; //導入方法依賴的package包/類
static boolean applyFontToTextView(final Context context, final TextView textView, final String filePath, boolean deferred) {
if (textView == null || context == null) return false;
final AssetManager assetManager = context.getAssets();
final Typeface typeface = TypefaceUtils.load(assetManager, filePath);
return applyFontToTextView(textView, typeface, deferred);
}
示例15: loadJsonFromAssets
import android.content.Context; //導入方法依賴的package包/類
public static InputStream loadJsonFromAssets(Context context, String file) throws IOException {
AssetManager assetManager = context.getAssets();
return assetManager.open(file);
}