siyamed / android-satellite-menu

Android Satellite Menu
1.4k stars 644 forks source link

360度のメニューが表示されるように改良しました #19

Open nkashima opened 10 years ago

nkashima commented 10 years ago

SatelliteMenu.java

public void addItems(List items) {

    menuItems.addAll(items);
    this.removeView(imgMain);
    TextView tmpView = new TextView(getContext());
    tmpView.setLayoutParams(new FrameLayout.LayoutParams(0, 0));

// float[] degrees = getDegrees(menuItems.size()); float[] degrees = getDegrees(menuItems.size()+1); // <----- Bug int index = 0; for (SatelliteMenuItem menuItem : menuItems) { int finalX = SatelliteAnimationCreator.getTranslateX( // degrees[index], satelliteDistance); degrees[index], satelliteDistance/2); // 円形の場合は、アイテムをメニュー幅の半分にする int finalY = SatelliteAnimationCreator.getTranslateY( // degrees[index], satelliteDistance); degrees[index], satelliteDistance/2); // 円形の場合は、アイテムをメニュー幅の半分にする

        ImageView itemView = (ImageView) LayoutInflater.from(getContext())
                .inflate(R.layout.sat_item_cr, this, false);
        ImageView cloneView = (ImageView) LayoutInflater.from(getContext())
                .inflate(R.layout.sat_item_cr, this, false);
        cloneView.setTag(menuItem.getId());
        itemView.setTag(menuItem.getId());
        cloneView.setVisibility(View.GONE);
        itemView.setVisibility(View.GONE);

        cloneView.setOnClickListener(internalItemClickListener);

// cloneView.setTag(Integer.valueOf(menuItem.getId())); FrameLayout.LayoutParams layoutParams = getLayoutParams(cloneView); // layoutParams.bottomMargin = Math.abs(finalY); // 絶対値 // layoutParams.leftMargin = Math.abs(finalX); // 絶対値 layoutParams.bottomMargin = -(finalY); layoutParams.leftMargin = finalX; cloneView.setLayoutParams(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(getContext(), index, expandDuration, finalX, finalY);
        Animation itemIn = SatelliteAnimationCreator.createItemInAnimation(getContext(), index, expandDuration, finalX, finalY);
        Animation itemClick = SatelliteAnimationCreator.createItemClickAnimation(getContext());

        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, viewToItemMap));
        itemOut.setAnimationListener(new SatelliteAnimationListener(itemView, false, viewToItemMap));
        itemClick.setAnimationListener(new SatelliteItemClickAnimationListener(this, menuItem.getId()));

        this.addView(itemView);
        this.addView(cloneView);
        viewToItemMap.put(itemView, menuItem);
        viewToItemMap.put(cloneView, menuItem);
        index++;
    }

    this.addView(imgMain);
}