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;
}
}
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());
}
}
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;
}
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);
}
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);
}
Aggregations