Search in sources :

Example 76 with AssetManager

use of android.content.res.AssetManager in project VirtualAPK by didi.

the class LoadedPlugin method createAssetManager.

private static AssetManager createAssetManager(Context context, File apk) {
    try {
        AssetManager am = AssetManager.class.newInstance();
        ReflectUtil.invoke(AssetManager.class, am, "addAssetPath", apk.getAbsolutePath());
        return am;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : AssetManager(android.content.res.AssetManager)

Example 77 with AssetManager

use of android.content.res.AssetManager in project VirtualAPK by didi.

the class LoadedPlugin method createResources.

@WorkerThread
private static Resources createResources(Context context, File apk) {
    if (Constants.COMBINE_RESOURCES) {
        Resources resources = ResourcesManager.createResources(context, apk.getAbsolutePath());
        ResourcesManager.hookResources(context, resources);
        return resources;
    } else {
        Resources hostResources = context.getResources();
        AssetManager assetManager = createAssetManager(context, apk);
        return new Resources(assetManager, hostResources.getDisplayMetrics(), hostResources.getConfiguration());
    }
}
Also used : AssetManager(android.content.res.AssetManager) Resources(android.content.res.Resources) WorkerThread(android.support.annotation.WorkerThread)

Example 78 with AssetManager

use of android.content.res.AssetManager in project VirtualAPK by didi.

the class ResourcesManager method createResources.

public static synchronized Resources createResources(Context hostContext, String apk) {
    Resources hostResources = hostContext.getResources();
    Resources newResources = null;
    AssetManager assetManager;
    try {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            assetManager = AssetManager.class.newInstance();
            ReflectUtil.invoke(AssetManager.class, assetManager, "addAssetPath", hostContext.getApplicationInfo().sourceDir);
        } else {
            assetManager = hostResources.getAssets();
        }
        ReflectUtil.invoke(AssetManager.class, assetManager, "addAssetPath", apk);
        List<LoadedPlugin> pluginList = PluginManager.getInstance(hostContext).getAllLoadedPlugins();
        for (LoadedPlugin plugin : pluginList) {
            ReflectUtil.invoke(AssetManager.class, assetManager, "addAssetPath", plugin.getLocation());
        }
        if (isMiUi(hostResources)) {
            newResources = MiUiResourcesCompat.createResources(hostResources, assetManager);
        } else if (isVivo(hostResources)) {
            newResources = VivoResourcesCompat.createResources(hostContext, hostResources, assetManager);
        } else if (isNubia(hostResources)) {
            newResources = NubiaResourcesCompat.createResources(hostResources, assetManager);
        } else if (isNotRawResources(hostResources)) {
            newResources = AdaptationResourcesCompat.createResources(hostResources, assetManager);
        } else {
            // is raw android resources
            newResources = new Resources(assetManager, hostResources.getDisplayMetrics(), hostResources.getConfiguration());
        }
        // lastly, sync all LoadedPlugin to newResources
        for (LoadedPlugin plugin : pluginList) {
            plugin.updateResources(newResources);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return newResources;
}
Also used : AssetManager(android.content.res.AssetManager) Resources(android.content.res.Resources)

Example 79 with AssetManager

use of android.content.res.AssetManager in project platform_packages_apps_Galaxy by Cosmic-OS.

the class IconPackGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // intent with package name is REQUIRED here
    mPackageName = getIntent().getStringExtra("icon_package_name");
    if (mPackageName == null) {
        setResult(RESULT_CANCELED);
        finish();
    }
    try {
        PackageManager pm = getPackageManager();
        String title = pm.getApplicationInfo(mPackageName, 0).loadLabel(pm).toString();
        if (title != null) {
            setTitle(title);
        }
    } catch (Exception e) {
        setTitle(R.string.icon_pack_picker_dialog_title);
    }
    try {
        PackageInfo info = getPackageManager().getPackageInfo(mPackageName, 0);
        String iconApk = info.applicationInfo.publicSourceDir;
        AssetManager assets = new AssetManager();
        assets.addAssetPath(iconApk);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        Configuration config = getResources().getConfiguration();
        mIconRes = new Resources(assets, dm, config);
    } catch (Exception e) {
        setResult(RESULT_CANCELED);
        finish();
    }
    if (getActionBar() != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
    setContentView(R.layout.icon_picker_grid);
    // Get memory class of this device, exceeding this amount will throw an
    // OutOfMemory exception.
    final int memClass = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = 1024 * 1024 * memClass / 8;
    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {

        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in bytes rather than number of items.
            return bitmap.getByteCount();
        }
    };
    mGridView = (GridView) findViewById(R.id.icon_grid);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mGridData = new ArrayList<>();
    mAdapter = new IconGridAdapter(this);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            IconInfo info = (IconInfo) parent.getItemAtPosition(position);
            Intent resultIntent = new Intent();
            resultIntent.putExtra("icon_data_type", "iconpack");
            resultIntent.putExtra("icon_data_package", mPackageName);
            resultIntent.putExtra("icon_data_name", info.name);
            IconPackGridActivity.this.setResult(RESULT_OK, resultIntent);
            IconPackGridActivity.this.finish();
        }
    });
    new AsyncIconLoaderTask().execute(mPackageName);
    mProgressBar.setVisibility(View.VISIBLE);
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) DisplayMetrics(android.util.DisplayMetrics) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources)

Example 80 with AssetManager

use of android.content.res.AssetManager in project remote-desktop-clients by iiordanov.

the class AdvancedSettingsActivity method listFiles.

private List<String> listFiles(String dirFrom) throws IOException {
    Resources res = getResources();
    AssetManager am = res.getAssets();
    String[] fileList = am.list(dirFrom);
    if (fileList != null) {
        for (int i = 0; i < fileList.length; i++) {
            Log.d("", fileList[i]);
        }
    }
    return (List<String>) Arrays.asList(fileList);
}
Also used : AssetManager(android.content.res.AssetManager) List(java.util.List) Resources(android.content.res.Resources)

Aggregations

AssetManager (android.content.res.AssetManager)346 IOException (java.io.IOException)141 InputStream (java.io.InputStream)121 Resources (android.content.res.Resources)75 File (java.io.File)54 FileOutputStream (java.io.FileOutputStream)34 XmlResourceParser (android.content.res.XmlResourceParser)32 DisplayMetrics (android.util.DisplayMetrics)31 Bitmap (android.graphics.Bitmap)23 Configuration (android.content.res.Configuration)21 BufferedReader (java.io.BufferedReader)21 InputStreamReader (java.io.InputStreamReader)20 ArrayList (java.util.ArrayList)20 FileInputStream (java.io.FileInputStream)18 OutputStream (java.io.OutputStream)17 Context (android.content.Context)16 Intent (android.content.Intent)16 JsonParser (com.google.gson.JsonParser)16 ByteArrayInputStream (java.io.ByteArrayInputStream)16 Method (java.lang.reflect.Method)16