当前位置: 首页>>代码示例>>Java>>正文


Java Context.getAssets方法代码示例

本文整理汇总了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;
}
 
开发者ID:Bruno125,项目名称:Unofficial-Ups,代码行数:17,代码来源:FontHelper.java

示例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;
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:19,代码来源:FileUtils.java

示例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());
    }
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:27,代码来源:ActivityTest.java

示例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;
}
 
开发者ID:bignerdranch,项目名称:Typesetter,代码行数:18,代码来源:Font.java

示例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;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:24,代码来源:FileIO.java

示例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);
}
 
开发者ID:yeshuwei,项目名称:MultipleS,代码行数:18,代码来源:DefaultSelector.java

示例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();
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:24,代码来源:StreamUtils.java

示例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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:DynamicFeeLoader.java

示例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];
}
 
开发者ID:mosmetro-android,项目名称:module-captcha-recognition,代码行数:8,代码来源:CaptchaRecognition.java

示例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");
}
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:14,代码来源:CommonUtils.java

示例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();
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:16,代码来源:AssetsUtils.java

示例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);
}
 
开发者ID:tranleduy2000,项目名称:text_converter,代码行数:11,代码来源:BaseTextView.java

示例13: CordovaResourceApi

import android.content.Context; //导入方法依赖的package包/类
public CordovaResourceApi(Context context, PluginManager pluginManager) {
    this.contentResolver = context.getContentResolver();
    this.assetManager = context.getAssets();
    this.pluginManager = pluginManager;
}
 
开发者ID:jie-meng,项目名称:DinningShare,代码行数:6,代码来源:CordovaResourceApi.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:CalligraphyUtils.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:TestHelper.java


注:本文中的android.content.Context.getAssets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。