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

Strange behavior on Xperia S #6

Open
adgeg opened this issue Oct 25, 2012 · 8 comments
Open

Strange behavior on Xperia S #6

adgeg opened this issue Oct 25, 2012 · 8 comments

Comments

@adgeg
Copy link

adgeg commented Oct 25, 2012

Hello,

I am using your animation for an application, and it works perfectly.

The only bug I have is on Sony Xperia S (with Android 4.0.4), at the end of the animation.
Indeed, buttons don't stay in the place where they should stay : they are all located in a same vertical line (http://file.rspreprod.fr/Screenshot_XperiaS.png)

Do you have an idea on how to fix it ?

Thanks by advance,

Gabriel

@pariharsunny
Copy link

Hi,

I also experienced the same issue on sony Xperia S (Android 4.0.4).

The menu buttons open nicely but gets pushed towards left the next moment.

Any help would be appreciated.

Thanks,

Sunny

@adgeg
Copy link
Author

adgeg commented Dec 12, 2012

Hi Sunny,

I found a really UGLY way to fix this bug on Xperia. Indeed, I didn't find a generic way to fix this, just a special case for this device... BTW, if you really want a fix, it works.

In SatelliteMenu.java :

Modify addItems :

     public void addItems(List<SatelliteMenuItem> items) {
    // special case for Sony Xperia S (ugly, I'm sorry...)
    if(android.os.Build.MODEL.equals("LT26i")){
        theWorstHandlingOfExceptionOfAllTheTimes(items);
        return;
    }
            ....
      }

And create a new method :

 /* Special handling of a strange bug in displaying of items on Sony Xperia S.
 * Caution child, this is done nearly the worst way it could.
 * Don't try this at home ! 
 */
private void theWorstHandlingOfExceptionOfAllTheTimes(List<SatelliteMenuItem> items) {
    RelativeLayout relativeLayout = new RelativeLayout(getContext());
    // Appreciate the hard coding dimensions
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            satelliteDistance + 100, satelliteDistance + 100);
    layoutParams.gravity = Gravity.BOTTOM;
    relativeLayout.setLayoutParams(layoutParams);

    menuItems.addAll(items);
    this.removeView(imgMain);
    float[] degrees = getDegrees(menuItems.size());
    int index = 0;
    for (SatelliteMenuItem menuItem : menuItems) {
        int finalX = SatelliteAnimationCreator.getTranslateX(degrees[index], satelliteDistance);
        int finalY = SatelliteAnimationCreator.getTranslateY(degrees[index], satelliteDistance);

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

        cloneView.setOnClickListener(internalItemClickListener);
        cloneView.setTag(Integer.valueOf(menuItem.getId()));
        RelativeLayout.LayoutParams layoutParamsClone = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        // And again... 
        int finalYInverse = Math.abs(SatelliteAnimationCreator.getTranslateY(degrees[index],
                satelliteDistance)) - 20;
        int finalXInverse = Math.abs(SatelliteAnimationCreator.getTranslateX(degrees[index],
                satelliteDistance));
        layoutParamsClone.setMargins(finalXInverse, satelliteDistance - finalYInverse, 0, 0);
        cloneView.setLayoutParams(layoutParamsClone);
        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);
        relativeLayout.addView(cloneView);
        viewToItemMap.put(itemView, menuItem);
        viewToItemMap.put(cloneView, menuItem);
        index++;
    }

    this.addView(relativeLayout);
    this.addView(imgMain);
}

Hope it will help you...

Gabriel

@pariharsunny
Copy link

Hi Gabriel,

Could please explain what kind of object is: CustomView in the below line of code:

CustomView itemView = (CustomView) LayoutInflater.from(getContext()).inflate(
R.layout.sat_item_cr, this, false);

As, the android is unable to resolve it.

Thanks,
Sunny

@adgeg
Copy link
Author

adgeg commented Dec 13, 2012

Sorry, I forgot that I use my own view instead of the original ImageView.
Just use the same image view than in addItems method :

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);

Cheers,

Gabriel

@dwally89
Copy link

Hi,

I had a similar bug on an Xperia, running 4.0.4.
Changing from a FrameLayout to a RelativeLayout seemed to fix the problem for me

@anilari89
Copy link

Hi dwally,
I tried changing from FrameLayout to a RelativeLayout,but its not working.
Can you please share your code.

Thanks.

@sorooshstrife
Copy link

Hi
I faced the same problem on Xperia Neo L. This fixed it thank you. Do you know if it's like this only on xperia devices or there are other devices that show similar behavior?
EDIT:
I was wrong. I tested it on Xperia M and it works fine. It was just my own device so I added MT25i to the black list.

@dosoos
Copy link

dosoos commented Oct 22, 2014

my device oppo find5t,china phone

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

6 participants