Ejemplo n.º 1
0
        private void init(Context context, Android.Util.IAttributeSet attrs, int defStyle)
        {
            LayoutInflater.From(context).Inflate(Resource.Layout.sat_main, this, true);
            imgMain = FindViewById <ImageView>(Resource.Id.sat_main);

            if (attrs != null)
            {
                TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.SatelliteMenu, defStyle, 0);
                satelliteDistance  = typedArray.GetDimensionPixelSize(Resource.Styleable.SatelliteMenu_satelliteDistance, DEFAULT_SATELLITE_DISTANCE);
                totalSpacingDegree = typedArray.GetFloat(Resource.Styleable.SatelliteMenu_totalSpacingDegree, DEFAULT_TOTAL_SPACING_DEGREES);
                closeItemsOnClick  = typedArray.GetBoolean(Resource.Styleable.SatelliteMenu_closeOnClick, DEFAULT_CLOSE_ON_CLICK);
                expandDuration     = typedArray.GetInt(Resource.Styleable.SatelliteMenu_expandDuration, DEFAULT_EXPAND_DURATION);
                //float satelliteDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 170, getResources().getDisplayMetrics());
                typedArray.Recycle();
            }


            mainRotateLeft  = SatelliteAnimationCreator.createMainButtonAnimation(context);
            mainRotateRight = SatelliteAnimationCreator.createMainButtonInverseAnimation(context);

            mainRotateLeft.SetAnimationListener(this);
            mainRotateRight.SetAnimationListener(this);
            imgMain.Click += (s, e) =>
            {
                onClick();
            };
            internalItemClickListener = new InternalSatelliteOnClickListener(this);
        }
Ejemplo n.º 2
0
        public void addItems(List <SatelliteMenuItem> items)
        {
            foreach (var item in items)
            {
                menuItems.Add(item);
            }
            this.RemoveView(imgMain);
            TextView tmpView = new TextView(Context);

            tmpView.LayoutParameters = new FrameLayout.LayoutParams(0, 0);

            float[] degrees = getDegrees(menuItems.Count());
            int     index   = 0;

            foreach (SatelliteMenuItem menuItem in menuItems)
            {
                int finalX = SatelliteAnimationCreator.getTranslateX(
                    degrees[index], satelliteDistance);
                int finalY = SatelliteAnimationCreator.getTranslateY(
                    degrees[index], satelliteDistance);

                ImageView itemView = (ImageView)LayoutInflater.From(Context)
                                     .Inflate(Resource.Layout.sat_item_cr, this, false);
                ImageView cloneView = (ImageView)LayoutInflater.From(Context)
                                      .Inflate(Resource.Layout.sat_item_cr, this, false);
                itemView.Tag         = menuItem.getId();
                cloneView.Visibility = ViewStates.Gone;
                itemView.Visibility  = ViewStates.Gone;

                cloneView.SetOnClickListener(internalItemClickListener);
                cloneView.Tag = Java.Lang.Integer.ValueOf(menuItem.getId());
                FrameLayout.LayoutParams layoutParams = getLayoutParams(cloneView);
                layoutParams.BottomMargin  = Math.Abs(finalY);
                layoutParams.LeftMargin    = Math.Abs(finalX);
                cloneView.LayoutParameters = layoutParams;

                if (menuItem.getImgResourceId() > 0)
                {
                    itemView.SetImageResource(menuItem.getImgResourceId());
                    cloneView.SetImageResource(menuItem.getImgResourceId());
                }
                else if (menuItem.getImgDrawable() != null)
                {
                    itemView.SetImageDrawable(menuItem.getImgDrawable());
                    cloneView.SetImageDrawable(menuItem.getImgDrawable());
                }

                Animation itemOut   = SatelliteAnimationCreator.createItemOutAnimation(Context, index, expandDuration, finalX, finalY);
                Animation itemIn    = SatelliteAnimationCreator.createItemInAnimation(Context, index, expandDuration, finalX, finalY);
                Animation itemClick = SatelliteAnimationCreator.createItemClickAnimation(Context);

                menuItem.setView(itemView);
                menuItem.setCloneView(cloneView);
                menuItem.setInAnimation(itemIn);
                menuItem.setOutAnimation(itemOut);
                menuItem.setClickAnimation(itemClick);
                menuItem.setFinalX(finalX);
                menuItem.setFinalY(finalY);

                itemIn.SetAnimationListener(new SatelliteAnimationListener(itemView, true, viewToItemDic));
                itemOut.SetAnimationListener(new SatelliteAnimationListener(itemView, false, viewToItemDic));
                itemClick.SetAnimationListener(new SatelliteItemClickAnimationListener(this, menuItem.getId()));


                this.AddView(itemView);
                this.AddView(cloneView);
                viewToItemDic.Add(itemView, menuItem);
                viewToItemDic.Add(cloneView, menuItem);
                index++;
            }

            this.AddView(imgMain);
        }