use of android.view.ContextThemeWrapper in project FloatingActionButton by Clans.
the class MenusFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
menuRed = (FloatingActionMenu) view.findViewById(R.id.menu_red);
menuYellow = (FloatingActionMenu) view.findViewById(R.id.menu_yellow);
menuGreen = (FloatingActionMenu) view.findViewById(R.id.menu_green);
menuBlue = (FloatingActionMenu) view.findViewById(R.id.menu_blue);
menuDown = (FloatingActionMenu) view.findViewById(R.id.menu_down);
menuLabelsRight = (FloatingActionMenu) view.findViewById(R.id.menu_labels_right);
fab1 = (FloatingActionButton) view.findViewById(R.id.fab1);
fab2 = (FloatingActionButton) view.findViewById(R.id.fab2);
fab3 = (FloatingActionButton) view.findViewById(R.id.fab3);
final FloatingActionButton programFab1 = new FloatingActionButton(getActivity());
programFab1.setButtonSize(FloatingActionButton.SIZE_MINI);
programFab1.setLabelText(getString(R.string.lorem_ipsum));
programFab1.setImageResource(R.drawable.ic_edit);
menuRed.addMenuButton(programFab1);
programFab1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
programFab1.setLabelColors(ContextCompat.getColor(getActivity(), R.color.grey), ContextCompat.getColor(getActivity(), R.color.light_grey), ContextCompat.getColor(getActivity(), R.color.white_transparent));
programFab1.setLabelTextColor(ContextCompat.getColor(getActivity(), R.color.black));
}
});
ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), R.style.MenuButtonsStyle);
FloatingActionButton programFab2 = new FloatingActionButton(context);
programFab2.setLabelText("Programmatically added button");
programFab2.setImageResource(R.drawable.ic_edit);
menuYellow.addMenuButton(programFab2);
fab1.setEnabled(false);
menuRed.setClosedOnTouchOutside(true);
menuBlue.setIconAnimated(false);
menuDown.hideMenuButton(false);
menuRed.hideMenuButton(false);
menuYellow.hideMenuButton(false);
menuGreen.hideMenuButton(false);
menuBlue.hideMenuButton(false);
menuLabelsRight.hideMenuButton(false);
fabEdit = (FloatingActionButton) view.findViewById(R.id.fab_edit);
fabEdit.setShowAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.scale_up));
fabEdit.setHideAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.scale_down));
}
use of android.view.ContextThemeWrapper in project AndroidChromium by JackyAndroid.
the class AppMenuHandler method showAppMenu.
/**
* Show the app menu.
* @param anchorView Anchor view (usually a menu button) to be used for the popup, if
* null is passed then hardware menu button anchor will be used.
* @param startDragging Whether dragging is started. For example, if the app menu is
* showed by tapping on a button, this should be false. If it is
* showed by start dragging down on the menu button, this should
* be true. Note that if anchorView is null, this must
* be false since we no longer support hardware menu button
* dragging.
* @return True, if the menu is shown, false, if menu is not shown, example reasons:
* the menu is not yet available to be shown, or the menu is already showing.
*/
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("ResourceType")
public boolean showAppMenu(View anchorView, boolean startDragging) {
if (!mDelegate.shouldShowAppMenu() || isAppMenuShowing())
return false;
boolean isByPermanentButton = false;
int rotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
if (anchorView == null) {
// This fixes the bug where the bottom of the menu starts at the top of
// the keyboard, instead of overlapping the keyboard as it should.
int displayHeight = mActivity.getResources().getDisplayMetrics().heightPixels;
Rect rect = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
mHardwareButtonMenuAnchor.setY((displayHeight - statusBarHeight));
anchorView = mHardwareButtonMenuAnchor;
isByPermanentButton = true;
}
assert !(isByPermanentButton && startDragging);
if (mMenu == null) {
// Use a PopupMenu to create the Menu object. Note this is not the same as the
// AppMenu (mAppMenu) created below.
PopupMenu tempMenu = new PopupMenu(mActivity, anchorView);
tempMenu.inflate(mMenuResourceId);
mMenu = tempMenu.getMenu();
}
mDelegate.prepareMenu(mMenu);
ContextThemeWrapper wrapper = new ContextThemeWrapper(mActivity, R.style.OverflowMenuTheme);
if (mAppMenu == null) {
TypedArray a = wrapper.obtainStyledAttributes(new int[] { android.R.attr.listPreferredItemHeightSmall, android.R.attr.listDivider });
int itemRowHeight = a.getDimensionPixelSize(0, 0);
Drawable itemDivider = a.getDrawable(1);
int itemDividerHeight = itemDivider != null ? itemDivider.getIntrinsicHeight() : 0;
a.recycle();
mAppMenu = new AppMenu(mMenu, itemRowHeight, itemDividerHeight, this, mActivity.getResources());
mAppMenuDragHelper = new AppMenuDragHelper(mActivity, mAppMenu, itemRowHeight);
}
// Get the height and width of the display.
Rect appRect = new Rect();
mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(appRect);
// Use full size of window for abnormal appRect.
if (appRect.left < 0 && appRect.top < 0) {
appRect.left = 0;
appRect.top = 0;
appRect.right = mActivity.getWindow().getDecorView().getWidth();
appRect.bottom = mActivity.getWindow().getDecorView().getHeight();
}
Point pt = new Point();
mActivity.getWindowManager().getDefaultDisplay().getSize(pt);
mAppMenu.show(wrapper, anchorView, isByPermanentButton, rotation, appRect, pt.y, mDelegate.getFooterResourceId());
mAppMenuDragHelper.onShow(startDragging);
RecordUserAction.record("MobileMenuShow");
return true;
}
use of android.view.ContextThemeWrapper in project ActionBarSherlock by JakeWharton.
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;
}
use of android.view.ContextThemeWrapper in project ActionBarSherlock by JakeWharton.
the class ActionBarImpl method getThemedContext.
public Context getThemedContext() {
if (mThemedContext == null) {
TypedValue outValue = new TypedValue();
Resources.Theme currentTheme = mContext.getTheme();
currentTheme.resolveAttribute(R.attr.actionBarWidgetTheme, outValue, true);
final int targetThemeRes = outValue.resourceId;
if (targetThemeRes != 0) {
//XXX && mContext.getThemeResId() != targetThemeRes) {
mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
} else {
mThemedContext = mContext;
}
}
return mThemedContext;
}
use of android.view.ContextThemeWrapper in project u2020 by JakeWharton.
the class DebugViewContainer method forActivity.
@Override
public ViewGroup forActivity(final Activity activity) {
activity.setContentView(R.layout.debug_activity_frame);
final ViewHolder viewHolder = new ViewHolder();
ButterKnife.bind(viewHolder, activity);
final Context drawerContext = new ContextThemeWrapper(activity, R.style.Theme_U2020_Debug);
final DebugView debugView = new DebugView(drawerContext);
viewHolder.debugDrawer.addView(debugView);
// Set up the contextual actions to watch views coming in and out of the content area.
ContextualDebugActions contextualActions = debugView.getContextualDebugActions();
contextualActions.setActionClickListener(v -> viewHolder.drawerLayout.closeDrawers());
viewHolder.content.setOnHierarchyChangeListener(HierarchyTreeChangeListener.wrap(contextualActions));
viewHolder.drawerLayout.setDrawerShadow(R.drawable.debug_drawer_shadow, GravityCompat.END);
viewHolder.drawerLayout.setDrawerListener(new DebugDrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
debugView.onDrawerOpened();
}
});
// Clean up any old screenshots.
TelescopeLayout.cleanUp(activity);
viewHolder.telescopeLayout.setLens(new BugReportLens(activity, lumberYard));
// If you have not seen the debug drawer before, show it with a message
if (!seenDebugDrawer.get()) {
viewHolder.drawerLayout.postDelayed(() -> {
viewHolder.drawerLayout.openDrawer(GravityCompat.END);
Toast.makeText(drawerContext, R.string.debug_drawer_welcome, Toast.LENGTH_LONG).show();
}, 1000);
seenDebugDrawer.set(true);
}
final CompositeSubscription subscriptions = new CompositeSubscription();
setupMadge(viewHolder, subscriptions);
setupScalpel(viewHolder, subscriptions);
final Application app = activity.getApplication();
app.registerActivityLifecycleCallbacks(new EmptyActivityLifecycleCallbacks() {
@Override
public void onActivityDestroyed(Activity lifecycleActivity) {
if (lifecycleActivity == activity) {
subscriptions.unsubscribe();
app.unregisterActivityLifecycleCallbacks(this);
}
}
});
riseAndShine(activity);
return viewHolder.content;
}
Aggregations