Java Code Examples for android.content.res.Resources#getAssets()

The following examples show how to use android.content.res.Resources#getAssets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IconThemer.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
 
Example 2
Source File: AssetUtil.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
/** Read a properties file from /assets.  Returns null if it does not exist. */
public static Properties getProperties(String name, Context context) {
    Resources resources = context.getResources();
    AssetManager assetManager = resources.getAssets();

    // Read from the /assets directory
    try {
        InputStream inputStream = assetManager.open(name);
        Properties properties = new Properties();
        properties.load(inputStream);
        return properties;
    } catch (IOException e) {
        Log.i("ChatSecure", "no chatsecure.properties available");
        return null;
    }
}
 
Example 3
Source File: DeleteNonRequiredAppsTask.java    From island with Apache License 2.0 6 votes vote down vote up
private static Resources getManagedProvisioningPackageResources(final Context context) {
    try {
        final Resources self_resources = context.getResources();
        final Context target_context = context.createPackageContext(getManagedProvisioningPackageName(context), 0);
        final Resources target_resources = target_context.getResources();
        return new Resources(target_resources.getAssets(), target_resources.getDisplayMetrics(), target_resources.getConfiguration()) {
            @NonNull @Override public String[] getStringArray(final int id) throws NotFoundException {
                final String entry_name = self_resources.getResourceEntryName(id);
                final int target_res_id = target_resources.getIdentifier(entry_name, "array", target_context.getPackageName());
                if (target_res_id == 0) return new String[0];       // Return empty array instead of throwing NotFoundException.
                return target_resources.getStringArray(target_res_id);
            }
        };
    } catch (final NameNotFoundException e) {
        return context.getResources();          // Fall-back to self, with default resource values.
    }
}
 
Example 4
Source File: AccentResources.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
public AccentResources(Context c, Resources resources, int color) {
	super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
	mContext = c;
	mExplicitColor = color;
	mExplicitColorDark = 0;
       mExplicitColorActionBar = 0;
}
 
Example 5
Source File: StarkContextWrapper.java    From Stark with Apache License 2.0 5 votes vote down vote up
@Override
public AssetManager getAssets() {
    Resources resources = Stark.get().getResources();
    if (resources != null) {
        return resources.getAssets();
    }
    return super.getAssets();
}
 
Example 6
Source File: AccentResources.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
public AccentResources(Context c, Resources resources) {
	super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
	mContext = c;
	mExplicitColor = 0;
	mExplicitColorDark = 0;
       mExplicitColorActionBar = 0;
}
 
Example 7
Source File: SocialAuthAdapter.java    From socialauth-android with MIT License 5 votes vote down vote up
/**
 * Internal method to load config
 * 
 * @param context
 *            The Android Activity context
 * 
 */

private void loadConfig(Context ctx) throws Exception {

	SocialAuthConfig config = new SocialAuthConfig();
	Resources resources = ctx.getResources();
	AssetManager assetManager = resources.getAssets();
	InputStream inputStream = null;
	boolean fileExist = false;
	// Check oauth_consumer.properties file exist
	try {
		inputStream = assetManager.open("oauth_consumer.properties");
		fileExist = true;
	} catch (Exception e) {
		fileExist = false;
		Log.d("SocialAuthAdapter", "oauth_consumer.properties not found");
	}

	if (fileExist) {
		// Add keys from oauth_consumers file. loadConfig() method
		// is removed
		config.load(inputStream);
		socialAuthManager.setSocialAuthConfig(config);
	} else {
		// Add user keys if outh_consumers file not exists
		for (String key : authMap.keySet()) {
			config.addProviderConfig(key, authMap.get(key));
		}
		socialAuthManager.setSocialAuthConfig(config);
	}
}
 
Example 8
Source File: AccentResources.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
public AccentResources(Context c, Resources resources, int color, int colorDark, int colorActionBar) {
	super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
	mContext = c;
	mExplicitColor = color;
	mExplicitColorDark = colorDark;
       mExplicitColorActionBar = colorActionBar;
}
 
Example 9
Source File: DateTimePickerDialog.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Resources getResources() {
    if (mWrappedResources == null) {
        Resources r = super.getResources();
        mWrappedResources = new WrappedResources(
                r.getAssets(), r.getDisplayMetrics(), r.getConfiguration()) {};
    }
    return mWrappedResources;
}
 
Example 10
Source File: EdgeEffectOverride.java    From android-edge-effect-override with Apache License 2.0 5 votes vote down vote up
private EdgeEffectResources(Resources res, int color)
{
	super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration());
	mColorMatrixFilter = new ColorMatrixColorFilter(new ColorMatrix(new float[ ] {
		0, 0, 0, 0, Color.red(color),
		0, 0, 0, 0, Color.green(color),
		0, 0, 0, 0, Color.blue(color),
		0, 0, 0, 1, 0,
	}));
}
 
Example 11
Source File: SaiyResources.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param mContext the application context
 * @param sl       the {@link SupportedLanguage}
 */
public SaiyResources(@NonNull final Context mContext, @NonNull final SupportedLanguage sl) {

    this.mContext = mContext;
    final Resources resources = this.mContext.getResources();
    this.assetManager = resources.getAssets();
    this.metrics = resources.getDisplayMetrics();
    this.configuration = new Configuration(resources.getConfiguration());
    this.targetLocale = sl.getLocale();
}
 
Example 12
Source File: SkinCompatManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
/**
 * 获取皮肤包资源{@link Resources}.
 *
 * @param skinPkgPath sdcard中皮肤包路径.
 * @return
 */
@Nullable
public Resources getSkinResources(String skinPkgPath) {
    try {
        PackageInfo packageInfo = mAppContext.getPackageManager().getPackageArchiveInfo(skinPkgPath, 0);
        packageInfo.applicationInfo.sourceDir = skinPkgPath;
        packageInfo.applicationInfo.publicSourceDir = skinPkgPath;
        Resources res = mAppContext.getPackageManager().getResourcesForApplication(packageInfo.applicationInfo);
        Resources superRes = mAppContext.getResources();
        return new Resources(res.getAssets(), superRes.getDisplayMetrics(), superRes.getConfiguration());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 13
Source File: SkinCompatManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
/**
 * 获取皮肤包资源{@link Resources}.
 *
 * @param skinPkgPath sdcard中皮肤包路径.
 * @return
 */
@Nullable
public Resources getSkinResources(String skinPkgPath) {
    try {
        PackageInfo packageInfo = mAppContext.getPackageManager().getPackageArchiveInfo(skinPkgPath, 0);
        packageInfo.applicationInfo.sourceDir = skinPkgPath;
        packageInfo.applicationInfo.publicSourceDir = skinPkgPath;
        Resources res = mAppContext.getPackageManager().getResourcesForApplication(packageInfo.applicationInfo);
        Resources superRes = mAppContext.getResources();
        return new Resources(res.getAssets(), superRes.getDisplayMetrics(), superRes.getConfiguration());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 14
Source File: LeanplumResources.java    From Leanplum-Android-SDK with Apache License 2.0 4 votes vote down vote up
public LeanplumResources(Resources base) {
  super(base.getAssets(), base.getDisplayMetrics(), base.getConfiguration());
}
 
Example 15
Source File: ResourceUtils.java    From Mover with Apache License 2.0 4 votes vote down vote up
public SupportResources(Resources resources) {
    super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
}
 
Example 16
Source File: ContextWrapperEdgeEffect.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public ContextWrapperEdgeEffect(Context context, int color) {
  super(context);
  mColor = color;
  Resources resources = context.getResources();
  mResourcesEdgeEffect = new ResourcesEdgeEffect(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
}
 
Example 17
Source File: ContextWrapperEdgeEffect.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public ContextWrapperEdgeEffect(Context context, int color) {
  super(context);
  mColor = color;
  Resources resources = context.getResources();
  mResourcesEdgeEffect = new ResourcesEdgeEffect(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
}
 
Example 18
Source File: IconShapeOverride.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecated")
 ResourcesOverride(Resources parent, int overrideId, String overrideValue) {
    super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration());
    mOverrideId = overrideId;
    mOverrideValue = overrideValue;
}
 
Example 19
Source File: PluginInfo.java    From Phantom with Apache License 2.0 4 votes vote down vote up
private AssetManager createAssetManager(Context ctx) throws Throwable {
    PackageManager pm = ctx.getPackageManager();
    Resources res = pm.getResourcesForApplication(packageInfo.applicationInfo);
    AssetManager am = res.getAssets();
    return am;
}
 
Example 20
Source File: PluginLoadedApk.java    From Neptune with Apache License 2.0 4 votes vote down vote up
/**
 * 创建插件的Resource {@link ResourcesProxy},通过此Resource对象
 * 插件可以访问主工程和插件的资源
 */
private void createPluginResource() {

    PluginDebugLog.runtimeLog(TAG, "createPluginResource for " + mPluginPackageName);
    PackageManager pm = mHostContext.getPackageManager();
    AssetManager am = null;
    try {
        Class<?>[] paramTypes = new Class[]{String.class};
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            // Android 5.0以下系统方法创建的AssetManager不支持扩展资源表,始终new出来
            am = AssetManager.class.newInstance();
            ReflectionUtils.on(am).call("addAssetPath", sMethods, paramTypes, mPluginPath);
        } else {
            // Android 5.0以上使用PackageManager的公开方法创建, 避免反射
            Resources resources = pm.getResourcesForApplication(mPluginPackageInfo.getApplicationInfo());
            am = resources.getAssets();
        }
        boolean shouldAddHostRes = !mPluginPackageInfo.isIndividualMode() && mPluginPackageInfo.isResourceNeedMerge();
        if (shouldAddHostRes) {
            // 添加宿主的资源到插件的AssetManager
            ReflectionUtils.on(am).call("addAssetPath", sMethods, paramTypes,
                    mHostContext.getApplicationInfo().sourceDir);
            PluginDebugLog.runtimeLog(TAG, "--- Resource merging into plugin @ " + mPluginPackageInfo.getPackageName());
        }
        // 添加系统Webview资源, Android L+
        if (mPluginPackageInfo.isNeedAddWebviewResource()) {
            addWebviewAssetPath(am);
        }

        mPluginAssetManager = am;
    } catch (Exception e) {
        ErrorUtil.throwErrorIfNeed(e);
        String errMsg = "create plugin resources failed: " + e.getMessage();
        PluginManager.deliver(mHostContext, false, mPluginPackageName, ErrorType.ERROR_PLUGIN_INIT_RESOURCES, errMsg);
    }

    Configuration config = new Configuration();
    config.setTo(mHostResource.getConfiguration());
    if (mPluginPackageInfo.isIndividualMode()) {
        // 独立插件包,不依赖宿主的Resource
        mPluginResource = new Resources(mPluginAssetManager, mHostResource.getDisplayMetrics(),
                config);
    } else {
        mPluginResource = new ResourcesProxy(mPluginAssetManager, mHostResource.getDisplayMetrics(),
                config, mHostResource, mPluginPackageName);
    }
    mPluginTheme = mPluginResource.newTheme();
    mPluginTheme.setTo(mHostContext.getTheme());
    mResourceTool = new ResourcesToolForPlugin(mHostContext);
}