Search in sources :

Example 56 with ContextThemeWrapper

use of android.view.ContextThemeWrapper in project android_frameworks_base by crdroidandroid.

the class WindowDecorActionBar method getThemedContext.

public Context getThemedContext() {
    if (mThemedContext == null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = mContext.getTheme();
        currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;
        if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
            mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
        } else {
            mThemedContext = mContext;
        }
    }
    return mThemedContext;
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 57 with ContextThemeWrapper

use of android.view.ContextThemeWrapper in project little-bear-dictionary by daimajia.

the class ActionBarSherlockCompat method initializePanelMenu.

private boolean initializePanelMenu() {
    //getContext();
    Context context = mActivity;
    // If we have an action bar, initialize the menu with a context themed for it.
    if (wActionBar != null) {
        TypedValue outValue = new TypedValue();
        Resources.Theme currentTheme = context.getTheme();
        currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
        final int targetThemeRes = outValue.resourceId;
        if (targetThemeRes != 0) /*&& context.getThemeResId() != targetThemeRes*/
        {
            context = new ContextThemeWrapper(context, targetThemeRes);
        }
    }
    mMenu = new MenuBuilder(context);
    mMenu.setCallback(this);
    return true;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) Resources(android.content.res.Resources) MenuBuilder(com.actionbarsherlock.internal.view.menu.MenuBuilder) TypedValue(android.util.TypedValue)

Example 58 with ContextThemeWrapper

use of android.view.ContextThemeWrapper in project little-bear-dictionary by daimajia.

the class ActionBarSherlockNative method getThemedContext.

@Override
protected Context getThemedContext() {
    Context context = mActivity;
    TypedValue outValue = new TypedValue();
    mActivity.getTheme().resolveAttribute(android.R.attr.actionBarWidgetTheme, outValue, true);
    if (outValue.resourceId != 0) {
        //We are unable to test if this is the same as our current theme
        //so we just wrap it and hope that if the attribute was specified
        //then the user is intentionally specifying an alternate theme.
        context = new ContextThemeWrapper(context, outValue.resourceId);
    }
    return context;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) TypedValue(android.util.TypedValue)

Example 59 with ContextThemeWrapper

use of android.view.ContextThemeWrapper in project android_frameworks_base by crdroidandroid.

the class DecorView method createStandaloneActionMode.

private ActionMode createStandaloneActionMode(ActionMode.Callback callback) {
    endOnGoingFadeAnimation();
    cleanupPrimaryActionMode();
    // cleanupPrimaryActionMode() invocation above.
    if (mPrimaryActionModeView == null || !mPrimaryActionModeView.isAttachedToWindow()) {
        if (mWindow.isFloating()) {
            // Use the action bar theme.
            final TypedValue outValue = new TypedValue();
            final Resources.Theme baseTheme = mContext.getTheme();
            baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
            final Context actionBarContext;
            if (outValue.resourceId != 0) {
                final Resources.Theme actionBarTheme = mContext.getResources().newTheme();
                actionBarTheme.setTo(baseTheme);
                actionBarTheme.applyStyle(outValue.resourceId, true);
                actionBarContext = new ContextThemeWrapper(mContext, 0);
                actionBarContext.getTheme().setTo(actionBarTheme);
            } else {
                actionBarContext = mContext;
            }
            mPrimaryActionModeView = new ActionBarContextView(actionBarContext);
            mPrimaryActionModePopup = new PopupWindow(actionBarContext, null, R.attr.actionModePopupWindowStyle);
            mPrimaryActionModePopup.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION);
            mPrimaryActionModePopup.setContentView(mPrimaryActionModeView);
            mPrimaryActionModePopup.setWidth(MATCH_PARENT);
            actionBarContext.getTheme().resolveAttribute(R.attr.actionBarSize, outValue, true);
            final int height = TypedValue.complexToDimensionPixelSize(outValue.data, actionBarContext.getResources().getDisplayMetrics());
            mPrimaryActionModeView.setContentHeight(height);
            mPrimaryActionModePopup.setHeight(WRAP_CONTENT);
            mShowPrimaryActionModePopup = new Runnable() {

                public void run() {
                    mPrimaryActionModePopup.showAtLocation(mPrimaryActionModeView.getApplicationWindowToken(), Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
                    endOnGoingFadeAnimation();
                    if (shouldAnimatePrimaryActionModeView()) {
                        mFadeAnim = ObjectAnimator.ofFloat(mPrimaryActionModeView, View.ALPHA, 0f, 1f);
                        mFadeAnim.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationStart(Animator animation) {
                                mPrimaryActionModeView.setVisibility(VISIBLE);
                            }

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                mPrimaryActionModeView.setAlpha(1f);
                                mFadeAnim = null;
                            }
                        });
                        mFadeAnim.start();
                    } else {
                        mPrimaryActionModeView.setAlpha(1f);
                        mPrimaryActionModeView.setVisibility(VISIBLE);
                    }
                }
            };
        } else {
            ViewStub stub = (ViewStub) findViewById(R.id.action_mode_bar_stub);
            if (stub != null) {
                mPrimaryActionModeView = (ActionBarContextView) stub.inflate();
                mPrimaryActionModePopup = null;
            }
        }
    }
    if (mPrimaryActionModeView != null) {
        mPrimaryActionModeView.killMode();
        ActionMode mode = new StandaloneActionMode(mPrimaryActionModeView.getContext(), mPrimaryActionModeView, callback, mPrimaryActionModePopup == null);
        return mode;
    }
    return null;
}
Also used : Context(android.content.Context) PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) ViewStub(android.view.ViewStub) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ContextThemeWrapper(android.view.ContextThemeWrapper) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ActionMode(android.view.ActionMode) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) FloatingActionMode(com.android.internal.view.FloatingActionMode) ActionBarContextView(com.android.internal.widget.ActionBarContextView) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 60 with ContextThemeWrapper

use of android.view.ContextThemeWrapper in project android_frameworks_base by AOSPA.

the class ActivityThread method performConfigurationChanged.

/**
     * Decides whether to update an Activity's configuration and whether to tell the
     * Activity/Component about it.
     * @param cb The component callback to notify of configuration change.
     * @param activityToken The Activity binder token for which this configuration change happened.
     *                      If the change is global, this is null.
     * @param newConfig The new configuration.
     * @param amOverrideConfig The override config that differentiates the Activity's configuration
     *                       from the base global configuration.
     *                       This is supplied by ActivityManager.
     * @param reportToActivity Notify the Activity of the change.
     */
private void performConfigurationChanged(ComponentCallbacks2 cb, IBinder activityToken, Configuration newConfig, Configuration amOverrideConfig, boolean reportToActivity) {
    // Only for Activity objects, check that they actually call up to their
    // superclass implementation.  ComponentCallbacks2 is an interface, so
    // we check the runtime type and act accordingly.
    Activity activity = (cb instanceof Activity) ? (Activity) cb : null;
    if (activity != null) {
        activity.mCalled = false;
    }
    boolean shouldChangeConfig = false;
    if ((activity == null) || (activity.mCurrentConfig == null)) {
        shouldChangeConfig = true;
    } else {
        // If the new config is the same as the config this Activity is already
        // running with and the override config also didn't change, then don't
        // bother calling onConfigurationChanged.
        int diff = activity.mCurrentConfig.diff(newConfig);
        if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken, amOverrideConfig)) {
            // calling onConfigurationChanged as we're going to destroy it.
            if (!mUpdatingSystemConfig || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 || !reportToActivity) {
                shouldChangeConfig = true;
            }
        }
    }
    if (shouldChangeConfig) {
        // Propagate the configuration change to the Activity and ResourcesManager.
        // ContextThemeWrappers may override the configuration for that context.
        // We must check and apply any overrides defined.
        Configuration contextThemeWrapperOverrideConfig = null;
        if (cb instanceof ContextThemeWrapper) {
            final ContextThemeWrapper contextThemeWrapper = (ContextThemeWrapper) cb;
            contextThemeWrapperOverrideConfig = contextThemeWrapper.getOverrideConfiguration();
        }
        // in {@link ComponentCallbacks2#onConfigurationChanged(Configuration)}.
        if (activityToken != null) {
            // Apply the ContextThemeWrapper override if necessary.
            // NOTE: Make sure the configurations are not modified, as they are treated
            // as immutable in many places.
            final Configuration finalOverrideConfig = createNewConfigAndUpdateIfNotNull(amOverrideConfig, contextThemeWrapperOverrideConfig);
            mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig);
        }
        if (reportToActivity) {
            // Apply the ContextThemeWrapper override if necessary.
            // NOTE: Make sure the configurations are not modified, as they are treated
            // as immutable in many places.
            final Configuration configToReport = createNewConfigAndUpdateIfNotNull(newConfig, contextThemeWrapperOverrideConfig);
            cb.onConfigurationChanged(configToReport);
        }
        if (activity != null) {
            if (reportToActivity && !activity.mCalled) {
                throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + " did not call through to super.onConfigurationChanged()");
            }
            activity.mConfigChangeFlags = 0;
            activity.mCurrentConfig = new Configuration(newConfig);
        }
    }
}
Also used : Configuration(android.content.res.Configuration) ContextThemeWrapper(android.view.ContextThemeWrapper) SuperNotCalledException(android.util.SuperNotCalledException)

Aggregations

ContextThemeWrapper (android.view.ContextThemeWrapper)122 Context (android.content.Context)65 TypedValue (android.util.TypedValue)52 Resources (android.content.res.Resources)32 View (android.view.View)22 TextView (android.widget.TextView)17 TypedArray (android.content.res.TypedArray)16 AlertDialog (android.app.AlertDialog)15 DialogInterface (android.content.DialogInterface)13 OnClickListener (android.content.DialogInterface.OnClickListener)11 Drawable (android.graphics.drawable.Drawable)11 LayoutInflater (android.view.LayoutInflater)10 RecyclerView (android.support.v7.widget.RecyclerView)8 ImageView (android.widget.ImageView)8 MenuBuilder (com.actionbarsherlock.internal.view.menu.MenuBuilder)7 Point (android.graphics.Point)6 ViewStub (android.view.ViewStub)6 WindowManagerImpl (android.view.WindowManagerImpl)6 Animator (android.animation.Animator)5 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5