use of android.view.ContextThemeWrapper in project platform_frameworks_base by android.
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);
}
}
}
use of android.view.ContextThemeWrapper in project platform_frameworks_base by android.
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;
}
use of android.view.ContextThemeWrapper in project platform_frameworks_base by android.
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;
}
use of android.view.ContextThemeWrapper in project ActionBarSherlock by JakeWharton.
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;
}
use of android.view.ContextThemeWrapper in project u2020 by JakeWharton.
the class TelescopeViewContainer method showTelescopeDialog.
public void showTelescopeDialog(final Activity activity) {
LayoutInflater inflater = LayoutInflater.from(activity);
TelescopeLayout content = (TelescopeLayout) inflater.inflate(R.layout.telescope_tutorial_dialog, null);
final AlertDialog dialog = new AlertDialog.Builder(activity).setView(content).setCancelable(false).create();
content.setLens(new Lens() {
@Override
public void onCapture(File file) {
dialog.dismiss();
Context toastContext = new ContextThemeWrapper(activity, android.R.style.Theme_DeviceDefault_Dialog);
LayoutInflater toastInflater = LayoutInflater.from(toastContext);
Toast toast = Toast.makeText(toastContext, "", Toast.LENGTH_SHORT);
View toastView = toastInflater.inflate(R.layout.telescope_tutorial_toast, null);
toast.setView(toastView);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
});
dialog.show();
}
Aggregations