Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nkashima opened this issue Apr 18, 2014 · 0 comments
Open

Comments

@nkashima
Copy link

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant