Search in sources :

Example 36 with ContextThemeWrapper

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));
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) FloatingActionButton(com.github.clans.fab.FloatingActionButton) View(android.view.View)

Example 37 with ContextThemeWrapper

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;
}
Also used : Rect(android.graphics.Rect) ContextThemeWrapper(android.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) Point(android.graphics.Point) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) PopupMenu(android.widget.PopupMenu) SuppressLint(android.annotation.SuppressLint)

Example 38 with ContextThemeWrapper

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;
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) TypedValue(android.util.TypedValue)

Example 39 with ContextThemeWrapper

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;
}
Also used : ContextThemeWrapper(android.view.ContextThemeWrapper) Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 40 with ContextThemeWrapper

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;
}
Also used : Context(android.content.Context) EmptyActivityLifecycleCallbacks(com.jakewharton.u2020.util.EmptyActivityLifecycleCallbacks) Activity(android.app.Activity) BindView(butterknife.BindView) View(android.view.View) BugReportLens(com.jakewharton.u2020.ui.bugreport.BugReportLens) ContextThemeWrapper(android.view.ContextThemeWrapper) CompositeSubscription(rx.subscriptions.CompositeSubscription) Application(android.app.Application)

Aggregations

ContextThemeWrapper (android.view.ContextThemeWrapper)121 Context (android.content.Context)64 TypedValue (android.util.TypedValue)52 Resources (android.content.res.Resources)32 View (android.view.View)22 TypedArray (android.content.res.TypedArray)16 TextView (android.widget.TextView)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