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


Java AssetManager类代码示例

本文整理汇总了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;
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:19,代码来源:FileUtils.java

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

示例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;
    }
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:22,代码来源:IconThemer.java

示例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;
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:12,代码来源:AppAccountParser.java

示例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);
    }
}
 
开发者ID:hh-in-zhuzhou,项目名称:ShangHanLun,代码行数:19,代码来源:UILabel.java

示例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;
    }
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:19,代码来源:FileUtils_zm.java

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

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

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

示例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]);
}
 
开发者ID:googlecodelabs,项目名称:style-transfer,代码行数:27,代码来源:Convolution2D.java

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

示例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;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:22,代码来源:ReactFontManager.java

示例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;
}
 
开发者ID:GabrielSamojlo,项目名称:OffIt,代码行数:22,代码来源:CallUtils.java

示例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;
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:17,代码来源:HomeRegionFragment.java

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


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