Search in sources :

Example 21 with Theme

use of android.content.res.Resources.Theme in project NoHttp by yanzhenjie.

the class ResCompat method getColor.

public static int getColor(int colorId, Theme theme) {
    Resources resources = NoHttp.getContext().getResources();
    Class<?> resourcesClass = resources.getClass();
    if (Build.VERSION.SDK_INT >= AndroidVersion.M)
        try {
            Method getColorMethod = resourcesClass.getMethod("getColor", int.class, Theme.class);
            getColorMethod.setAccessible(true);
            return (Integer) getColorMethod.invoke(resources, colorId, theme);
        } catch (Throwable e) {
        }
    else
        try {
            Method getColorMethod = resourcesClass.getMethod("getColor", int.class);
            getColorMethod.setAccessible(true);
            return (Integer) getColorMethod.invoke(resources, colorId);
        } catch (Throwable e) {
        }
    return Color.BLACK;
}
Also used : Theme(android.content.res.Resources.Theme) Resources(android.content.res.Resources) Method(java.lang.reflect.Method)

Example 22 with Theme

use of android.content.res.Resources.Theme in project NoHttp by yanzhenjie.

the class ResCompat method getDrawable.

public static Drawable getDrawable(int drawableId, Theme theme) {
    Resources resources = NoHttp.getContext().getResources();
    Class<?> resourcesClass = resources.getClass();
    if (Build.VERSION.SDK_INT >= AndroidVersion.LOLLIPOP)
        try {
            Method getDrawableMethod = resourcesClass.getMethod("getDrawable", int.class, Theme.class);
            getDrawableMethod.setAccessible(true);
            return (Drawable) getDrawableMethod.invoke(resources, drawableId, theme);
        } catch (Throwable e) {
        }
    else
        try {
            Method getDrawableMethod = resourcesClass.getMethod("getDrawable", int.class);
            getDrawableMethod.setAccessible(true);
            return (Drawable) getDrawableMethod.invoke(resources, drawableId);
        } catch (Throwable e) {
        }
    return null;
}
Also used : Theme(android.content.res.Resources.Theme) Resources(android.content.res.Resources) Method(java.lang.reflect.Method)

Example 23 with Theme

use of android.content.res.Resources.Theme in project SwipeRecyclerView by yanzhenjie.

the class ResCompat method getColor.

public static int getColor(Context context, int colorId, Theme theme) {
    Resources resources = context.getResources();
    Class<?> resourcesClass = resources.getClass();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        try {
            Method getColorMethod = resourcesClass.getMethod("getColor", int.class, Theme.class);
            getColorMethod.setAccessible(true);
            return (Integer) getColorMethod.invoke(resources, colorId, theme);
        } catch (Throwable e) {
        }
    else
        try {
            Method getColorMethod = resourcesClass.getMethod("getColor", int.class);
            getColorMethod.setAccessible(true);
            return (Integer) getColorMethod.invoke(resources, colorId);
        } catch (Throwable e) {
        }
    return Color.BLACK;
}
Also used : Theme(android.content.res.Resources.Theme) Resources(android.content.res.Resources) Method(java.lang.reflect.Method)

Example 24 with Theme

use of android.content.res.Resources.Theme in project android_frameworks_base by DirtyUnicorns.

the class ActivityThread method handleConfigurationChanged.

final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) {
    int configDiff = 0;
    synchronized (mResourcesManager) {
        if (mPendingConfiguration != null) {
            if (!mPendingConfiguration.isOtherSeqNewer(config)) {
                config = mPendingConfiguration;
                mCurDefaultDisplayDpi = config.densityDpi;
                updateDefaultDensity();
            }
            mPendingConfiguration = null;
        }
        if (config == null) {
            return;
        }
        if (DEBUG_CONFIGURATION)
            Slog.v(TAG, "Handle configuration changed: " + config);
        mResourcesManager.applyConfigurationToResourcesLocked(config, compat);
        updateLocaleListFromAppContext(mInitialApplication.getApplicationContext(), mResourcesManager.getConfiguration().getLocales());
        if (mConfiguration == null) {
            mConfiguration = new Configuration();
        }
        if (!mConfiguration.isOtherSeqNewer(config) && compat == null) {
            return;
        }
        configDiff = mConfiguration.updateFrom(config);
        config = applyCompatConfiguration(mCurDefaultDisplayDpi);
        final Theme systemTheme = getSystemContext().getTheme();
        if ((systemTheme.getChangingConfigurations() & configDiff) != 0) {
            systemTheme.rebase();
        }
    }
    ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config);
    freeTextLayoutCachesIfNeeded(configDiff);
    if (callbacks != null) {
        final int N = callbacks.size();
        for (int i = 0; i < N; i++) {
            ComponentCallbacks2 cb = callbacks.get(i);
            if (cb instanceof Activity) {
                // If callback is an Activity - call corresponding method to consider override
                // config and avoid onConfigurationChanged if it hasn't changed.
                Activity a = (Activity) cb;
                performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()), config, REPORT_TO_ACTIVITY);
            } else {
                performConfigurationChanged(cb, null, config, null, REPORT_TO_ACTIVITY);
            }
        }
    }
}
Also used : Configuration(android.content.res.Configuration) Theme(android.content.res.Resources.Theme) ComponentCallbacks2(android.content.ComponentCallbacks2)

Example 25 with Theme

use of android.content.res.Resources.Theme in project android_frameworks_base by AOSPA.

the class AnimatorInflater method loadStateListAnimator.

public static StateListAnimator loadStateListAnimator(Context context, int id) throws NotFoundException {
    final Resources resources = context.getResources();
    final ConfigurationBoundResourceCache<StateListAnimator> cache = resources.getStateListAnimatorCache();
    final Theme theme = context.getTheme();
    StateListAnimator animator = cache.getInstance(id, resources, theme);
    if (animator != null) {
        return animator;
    }
    XmlResourceParser parser = null;
    try {
        parser = resources.getAnimation(id);
        animator = createStateListAnimatorFromXml(context, parser, Xml.asAttributeSet(parser));
        if (animator != null) {
            animator.appendChangingConfigurations(getChangingConfigs(resources, id));
            final ConstantState<StateListAnimator> constantState = animator.createConstantState();
            if (constantState != null) {
                cache.put(id, theme, constantState);
                // return a clone so that the animator in constant state is never used.
                animator = constantState.newInstance(resources, theme);
            }
        }
        return animator;
    } catch (XmlPullParserException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlResourceParser(android.content.res.XmlResourceParser) Theme(android.content.res.Resources.Theme) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Aggregations

Theme (android.content.res.Resources.Theme)33 Resources (android.content.res.Resources)11 Context (android.content.Context)10 Configuration (android.content.res.Configuration)9 TypedValue (android.util.TypedValue)9 Method (java.lang.reflect.Method)7 ComponentCallbacks2 (android.content.ComponentCallbacks2)5 NotFoundException (android.content.res.Resources.NotFoundException)5 XmlResourceParser (android.content.res.XmlResourceParser)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 ContextMenuBuilder (com.android.internal.view.menu.ContextMenuBuilder)5 MenuBuilder (com.android.internal.view.menu.MenuBuilder)5 INotificationManager (android.app.INotificationManager)4 RemoteException (android.os.RemoteException)4 IMountService (android.os.storage.IMountService)4 DisplayMetrics (android.util.DisplayMetrics)4 WindowManager (android.view.WindowManager)4 ILockSettings (com.android.internal.widget.ILockSettings)4 AccessibilityManagerService (com.android.server.accessibility.AccessibilityManagerService)4 AudioService (com.android.server.audio.AudioService)4