Search in sources :

Example 1 with FloatingActionMenu

use of com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu in project CircularFloatingActionMenu by oguzbilgener.

the class MenuWithFABActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu_with_fab);
    // Set up the white button on the lower right corner
    // more or less with default parameter
    final ImageView fabIconNew = new ImageView(this);
    fabIconNew.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_new_light));
    final FloatingActionButton rightLowerButton = new FloatingActionButton.Builder(this).setContentView(fabIconNew).build();
    SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    ImageView rlIcon4 = new ImageView(this);
    rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_chat_light));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera_light));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video_light));
    rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_place_light));
    // Build the menu with default options: light theme, 90 degrees, 72dp radius.
    // Set 4 default SubActionButtons
    final FloatingActionMenu rightLowerMenu = new FloatingActionMenu.Builder(this).addSubActionView(rLSubBuilder.setContentView(rlIcon1).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon2).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon3).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon4).build()).attachTo(rightLowerButton).build();
    // Listen menu open and close events to animate the button content view
    rightLowerMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {

        @Override
        public void onMenuOpened(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees clockwise
            fabIconNew.setRotation(0);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 45);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }

        @Override
        public void onMenuClosed(FloatingActionMenu menu) {
            // Rotate the icon of rightLowerButton 45 degrees counter-clockwise
            fabIconNew.setRotation(45);
            PropertyValuesHolder pvhR = PropertyValuesHolder.ofFloat(View.ROTATION, 0);
            ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(fabIconNew, pvhR);
            animation.start();
        }
    });
    // Set up the large red button on the center right side
    // With custom button and content sizes and margins
    int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
    int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
    int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
    int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
    int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
    int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
    int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);
    ImageView fabIconStar = new ImageView(this);
    fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_important));
    FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(redActionButtonSize, redActionButtonSize);
    starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMargin, redActionButtonMargin);
    fabIconStar.setLayoutParams(starParams);
    FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
    fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);
    final FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_LEFT_CENTER).setLayoutParams(starParams).build();
    // Set up customized SubActionButtons for the right center menu
    SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
    lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
    FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
    lCSubBuilder.setLayoutParams(blueContentParams);
    // Set custom layout params
    FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
    lCSubBuilder.setLayoutParams(blueParams);
    ImageView lcIcon1 = new ImageView(this);
    ImageView lcIcon2 = new ImageView(this);
    ImageView lcIcon3 = new ImageView(this);
    ImageView lcIcon4 = new ImageView(this);
    ImageView lcIcon5 = new ImageView(this);
    lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera));
    lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_picture));
    lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video));
    lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_location_found));
    lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
    // Build another menu with custom options
    final FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this).addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build()).setRadius(redActionMenuRadius).setStartAngle(70).setEndAngle(-70).attachTo(leftCenterButton).build();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) SubActionButton(com.oguzdev.circularfloatingactionmenu.library.SubActionButton) FloatingActionMenu(com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu) FrameLayout(android.widget.FrameLayout) FloatingActionButton(com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton) PropertyValuesHolder(android.animation.PropertyValuesHolder) ImageView(android.widget.ImageView)

Example 2 with FloatingActionMenu

use of com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu in project CircularFloatingActionMenu by oguzbilgener.

the class MenuInScrollViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu_in_scroll_view);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
    LinearLayout scrollViewBody = (LinearLayout) findViewById(R.id.scrollViewBody);
    menus = new ArrayList<FloatingActionMenu>();
    // add 20 views into body, each with a menu attached
    for (int i = 0; i < 20; i++) {
        LinearLayout item = (LinearLayout) inflater.inflate(R.layout.item_scroll_view, null, false);
        scrollViewBody.addView(item);
        View mainActionView = item.findViewById(R.id.itemActionView);
        SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
        ImageView rlIcon1 = new ImageView(this);
        ImageView rlIcon2 = new ImageView(this);
        ImageView rlIcon3 = new ImageView(this);
        rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_chat_light));
        rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera_light));
        rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video_light));
        FloatingActionMenu itemMenu = new FloatingActionMenu.Builder(this).setStartAngle(-45).setEndAngle(-135).setRadius(getResources().getDimensionPixelSize(R.dimen.radius_small)).addSubActionView(rLSubBuilder.setContentView(rlIcon1).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon2).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon3).build()).setStateChangeListener(this).attachTo(mainActionView).build();
        //
        menus.add(itemMenu);
    }
    // listen scroll events on root ScrollView
    scrollView.getViewTreeObserver().addOnScrollChangedListener(this);
    findViewById(R.id.buttom_bar_edit_text).clearFocus();
    // Attach a menu to the button in the bottom bar, just to prove that it works.
    View bottomActionButton = findViewById(R.id.bottom_bar_action_button);
    SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_place_light));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_picture_light));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera_light));
    bottomMenu = new FloatingActionMenu.Builder(this).addSubActionView(rLSubBuilder.setContentView(rlIcon1).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon2).build()).addSubActionView(rLSubBuilder.setContentView(rlIcon3).build()).setStartAngle(-40).setEndAngle(-90).setRadius(getResources().getDimensionPixelSize(R.dimen.radius_medium)).attachTo(bottomActionButton).build();
    // Listen layout (size) changes on a main layout so that we could reposition the bottom menu
    scrollView.addOnLayoutChangeListener(this);
}
Also used : ScrollView(android.widget.ScrollView) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) SubActionButton(com.oguzdev.circularfloatingactionmenu.library.SubActionButton) ImageView(android.widget.ImageView) ScrollView(android.widget.ScrollView) View(android.view.View) LinearLayout(android.widget.LinearLayout) FloatingActionMenu(com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu)

Example 3 with FloatingActionMenu

use of com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu in project CircularFloatingActionMenu by oguzbilgener.

the class SystemOverlayMenuService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    serviceWillBeDismissed = false;
    // Set up the white button on the lower right corner
    // more or less with default parameter
    ImageView fabIconNew = new ImageView(this);
    fabIconNew.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_new_light));
    WindowManager.LayoutParams params = FloatingActionButton.Builder.getDefaultSystemWindowParams(this);
    rightLowerButton = new FloatingActionButton.Builder(this).setContentView(fabIconNew).setSystemOverlay(true).setLayoutParams(params).build();
    SubActionButton.Builder rLSubBuilder = new SubActionButton.Builder(this);
    ImageView rlIcon1 = new ImageView(this);
    ImageView rlIcon2 = new ImageView(this);
    ImageView rlIcon3 = new ImageView(this);
    ImageView rlIcon4 = new ImageView(this);
    rlIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_chat_light));
    rlIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera_light));
    rlIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video_light));
    rlIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_place_light));
    // Build the menu with default options: light theme, 90 degrees, 72dp radius.
    // Set 4 default SubActionButtons
    SubActionButton rlSub1 = rLSubBuilder.setContentView(rlIcon1).build();
    SubActionButton rlSub2 = rLSubBuilder.setContentView(rlIcon2).build();
    SubActionButton rlSub3 = rLSubBuilder.setContentView(rlIcon3).build();
    SubActionButton rlSub4 = rLSubBuilder.setContentView(rlIcon4).build();
    rightLowerMenu = new FloatingActionMenu.Builder(this, true).addSubActionView(rlSub1, rlSub1.getLayoutParams().width, rlSub1.getLayoutParams().height).addSubActionView(rlSub2, rlSub2.getLayoutParams().width, rlSub2.getLayoutParams().height).addSubActionView(rlSub3, rlSub3.getLayoutParams().width, rlSub3.getLayoutParams().height).addSubActionView(rlSub4, rlSub4.getLayoutParams().width, rlSub4.getLayoutParams().height).setStartAngle(180).setEndAngle(270).attachTo(rightLowerButton).build();
    ////////////////////////////////////////////////////////
    // Set up the large red button on the top center side
    // With custom button and content sizes and margins
    int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
    int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
    int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
    int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
    int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
    int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
    int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);
    ImageView fabIconStar = new ImageView(this);
    fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_important));
    FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
    fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);
    WindowManager.LayoutParams params2 = FloatingActionButton.Builder.getDefaultSystemWindowParams(this);
    params2.width = redActionButtonSize;
    params2.height = redActionButtonSize;
    topCenterButton = new FloatingActionButton.Builder(this).setSystemOverlay(true).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_TOP_CENTER).setLayoutParams(params2).build();
    // Set up customized SubActionButtons for the right center menu
    SubActionButton.Builder tCSubBuilder = new SubActionButton.Builder(this);
    tCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
    SubActionButton.Builder tCRedBuilder = new SubActionButton.Builder(this);
    tCRedBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_red_selector));
    FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
    // Set custom layout params
    FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
    tCSubBuilder.setLayoutParams(blueParams);
    tCRedBuilder.setLayoutParams(blueParams);
    ImageView tcIcon1 = new ImageView(this);
    ImageView tcIcon2 = new ImageView(this);
    ImageView tcIcon3 = new ImageView(this);
    ImageView tcIcon4 = new ImageView(this);
    ImageView tcIcon5 = new ImageView(this);
    ImageView tcIcon6 = new ImageView(this);
    tcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_camera));
    tcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_picture));
    tcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_video));
    tcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_location_found));
    tcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
    tcIcon6.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_cancel));
    SubActionButton tcSub1 = tCSubBuilder.setContentView(tcIcon1, blueContentParams).build();
    SubActionButton tcSub2 = tCSubBuilder.setContentView(tcIcon2, blueContentParams).build();
    SubActionButton tcSub3 = tCSubBuilder.setContentView(tcIcon3, blueContentParams).build();
    SubActionButton tcSub4 = tCSubBuilder.setContentView(tcIcon4, blueContentParams).build();
    SubActionButton tcSub5 = tCSubBuilder.setContentView(tcIcon5, blueContentParams).build();
    SubActionButton tcSub6 = tCRedBuilder.setContentView(tcIcon6, blueContentParams).build();
    // Build another menu with custom options
    topCenterMenu = new FloatingActionMenu.Builder(this, true).addSubActionView(tcSub1, tcSub1.getLayoutParams().width, tcSub1.getLayoutParams().height).addSubActionView(tcSub2, tcSub2.getLayoutParams().width, tcSub2.getLayoutParams().height).addSubActionView(tcSub3, tcSub3.getLayoutParams().width, tcSub3.getLayoutParams().height).addSubActionView(tcSub4, tcSub4.getLayoutParams().width, tcSub4.getLayoutParams().height).addSubActionView(tcSub5, tcSub5.getLayoutParams().width, tcSub5.getLayoutParams().height).addSubActionView(tcSub6, tcSub6.getLayoutParams().width, tcSub6.getLayoutParams().height).setRadius(redActionMenuRadius).setStartAngle(0).setEndAngle(180).attachTo(topCenterButton).build();
    topCenterMenu.setStateChangeListener(new FloatingActionMenu.MenuStateChangeListener() {

        @Override
        public void onMenuOpened(FloatingActionMenu menu) {
        }

        @Override
        public void onMenuClosed(FloatingActionMenu menu) {
            if (serviceWillBeDismissed) {
                SystemOverlayMenuService.this.stopSelf();
                serviceWillBeDismissed = false;
            }
        }
    });
    // make the red button terminate the service
    tcSub6.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // the order is important
            serviceWillBeDismissed = true;
            topCenterMenu.close(true);
        }
    });
}
Also used : SubActionButton(com.oguzdev.circularfloatingactionmenu.library.SubActionButton) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) FloatingActionMenu(com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) FloatingActionButton(com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton) ImageView(android.widget.ImageView)

Aggregations

ImageView (android.widget.ImageView)3 FloatingActionMenu (com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu)3 SubActionButton (com.oguzdev.circularfloatingactionmenu.library.SubActionButton)3 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2 FloatingActionButton (com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton)2 ObjectAnimator (android.animation.ObjectAnimator)1 PropertyValuesHolder (android.animation.PropertyValuesHolder)1 LayoutInflater (android.view.LayoutInflater)1 WindowManager (android.view.WindowManager)1 LinearLayout (android.widget.LinearLayout)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1