Search in sources :

Example 31 with Theme

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

the class PhoneWindow method initializePanelMenu.

/**
     * Initializes the menu associated with the given panel feature state. You
     * must at the very least set PanelFeatureState.menu to the Menu to be
     * associated with the given panel state. The default implementation creates
     * a new menu for the panel state.
     *
     * @param st The panel whose menu is being initialized.
     * @return Whether the initialization was successful.
     */
protected boolean initializePanelMenu(final PanelFeatureState st) {
    Context context = getContext();
    // If we have an action bar, initialize the menu with the right theme.
    if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR) && mDecorContentParent != null) {
        final TypedValue outValue = new TypedValue();
        final Theme baseTheme = context.getTheme();
        baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
        Theme widgetTheme = null;
        if (outValue.resourceId != 0) {
            widgetTheme = context.getResources().newTheme();
            widgetTheme.setTo(baseTheme);
            widgetTheme.applyStyle(outValue.resourceId, true);
            widgetTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        } else {
            baseTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        }
        if (outValue.resourceId != 0) {
            if (widgetTheme == null) {
                widgetTheme = context.getResources().newTheme();
                widgetTheme.setTo(baseTheme);
            }
            widgetTheme.applyStyle(outValue.resourceId, true);
        }
        if (widgetTheme != null) {
            context = new ContextThemeWrapper(context, 0);
            context.getTheme().setTo(widgetTheme);
        }
    }
    final MenuBuilder menu = new MenuBuilder(context);
    menu.setCallback(this);
    st.setMenu(menu);
    return true;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) Theme(android.content.res.Resources.Theme) ContextMenuBuilder(com.android.internal.view.menu.ContextMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder) TypedValue(android.util.TypedValue)

Example 32 with Theme

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

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)

Example 33 with Theme

use of android.content.res.Resources.Theme in project little-bear-dictionary by daimajia.

the class QueryWordFragment method onCreateOptionsMenu.

@SuppressLint("NewApi")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    mSearchView = new SearchView(mActionBar.getThemedContext());
    mSearchView.setQueryHint(getActivity().getString(R.string.query_hint));
    Theme theme = getActivity().getTheme();
    AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) mSearchView.findViewById(R.id.abs__search_src_text);
    TypedValue typedValue = new TypedValue();
    if (theme.resolveAttribute(R.attr.search_view_text_color, typedValue, true)) {
        autoCompleteTextView.setTextColor(typedValue.data);
    } else {
        autoCompleteTextView.setTextColor(Color.BLACK);
    }
    mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
    layoutParams.setMargins(0, 0, 15, 0);
    mActionBar.setCustomView(mSearchView, layoutParams);
    inflater.inflate(R.menu.search_split_menu, menu);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setId(android.R.id.inputArea);
    mSearchView.setIconifiedByDefault(true);
}
Also used : SearchView(com.actionbarsherlock.widget.SearchView) Theme(android.content.res.Resources.Theme) ActionBar(com.actionbarsherlock.app.ActionBar) AutoCompleteTextView(android.widget.AutoCompleteTextView) TypedValue(android.util.TypedValue) SuppressLint(android.annotation.SuppressLint)

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