Search in sources :

Example 96 with ContextThemeWrapper

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

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)

Example 97 with ContextThemeWrapper

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

the class Presentation method createPresentationContext.

private static Context createPresentationContext(Context outerContext, Display display, int theme) {
    if (outerContext == null) {
        throw new IllegalArgumentException("outerContext must not be null");
    }
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }
    Context displayContext = outerContext.createDisplayContext(display);
    if (theme == 0) {
        TypedValue outValue = new TypedValue();
        displayContext.getTheme().resolveAttribute(com.android.internal.R.attr.presentationTheme, outValue, true);
        theme = outValue.resourceId;
    }
    // Derive the display's window manager from the outer window manager.
    // We do this because the outer window manager have some extra information
    // such as the parent window, which is important if the presentation uses
    // an application window type.
    final WindowManagerImpl outerWindowManager = (WindowManagerImpl) outerContext.getSystemService(Context.WINDOW_SERVICE);
    final WindowManagerImpl displayWindowManager = outerWindowManager.createPresentationWindowManager(displayContext);
    return new ContextThemeWrapper(displayContext, theme) {

        @Override
        public Object getSystemService(String name) {
            if (Context.WINDOW_SERVICE.equals(name)) {
                return displayWindowManager;
            }
            return super.getSystemService(name);
        }
    };
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) WindowManagerImpl(android.view.WindowManagerImpl) TypedValue(android.util.TypedValue)

Example 98 with ContextThemeWrapper

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

the class ListMenuPresenter method initForMenu.

@Override
public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) {
    if (mThemeRes != 0) {
        mContext = new ContextThemeWrapper(context, mThemeRes);
        mInflater = LayoutInflater.from(mContext);
    } else if (mContext != null) {
        mContext = context;
        if (mInflater == null) {
            mInflater = LayoutInflater.from(mContext);
        }
    }
    mMenu = menu;
    if (mAdapter != null) {
        mAdapter.notifyDataSetChanged();
    }
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper)

Example 99 with ContextThemeWrapper

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

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 100 with ContextThemeWrapper

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

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)

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