當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。