Rotating images makes ui slow
        Posted  
        
            by 
                5w4rley
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by 5w4rley
        
        
        
        Published on 2012-03-23T10:26:11Z
        Indexed on 
            2012/03/23
            11:29 UTC
        
        
        Read the original article
        Hit count: 221
        
i'm trying to implement kind of speedometer. i'm getting informations about rounds per minute, boost and load of an engine over bluetooth and i try to display them on the screen witch 3 arrows witch should point in the right direktion. i tried to use a rotate animation evry time i get data(10-100ms) to setup the arrows. but that makes my ui extremly slow. 500ms to react on a buttonclick. Doese someone know how to make it work better?
source code:
public void setTacho()
{
//rotate Tachonadel
Rpmcurrentdegree=Rpmcurrentdegree+Rpmdegree;
Rpmdegree=((rpms-lastrpm)*RPMtoDegree);
RpmAnim=new RotateAnimation((float)Rpmcurrentdegree, (float)Rpmdegree,       ivNadel.getWidth()/2, ivNadel.getHeight()/2);
RpmAnim.setFillEnabled(true);
RpmAnim.setFillAfter(true);
ivNadel.setAnimation(RpmAnim);
RpmAnim.start();
//rotate Boostbalken
currentBoostDegree=currentBoostDegree+BoostDegree;
BoostDegree=(boost-lastBoost)*BOOSTtoDegree;
//rotate Loadbalken
currentLoadDegree=currentLoadDegree+LoadDegree;
LoadDegree=(load-lastLoad)*LOADtoDegree;
BoostAnim=new RotateAnimation((float)-currentBoostDegree, (float)-BoostDegree,     ivBoost.getWidth()/2, ivBoost.getHeight()/2);
BoostAnim.setFillEnabled(true);
BoostAnim.setFillAfter(true);
ivBoost.setAnimation(BoostAnim);
BoostAnim.start();
LoadAnim=new RotateAnimation((float)currentLoadDegree, (float)LoadDegree,     ivLoad.getWidth()/2, ivLoad.getHeight()/2);
LoadAnim.setFillEnabled(true);
LoadAnim.setFillAfter(true);
ivLoad.setAnimation(LoadAnim);
LoadAnim.start();
}
when i try to make the rotation only if the values have changed then it works only while they are changing but if they aren't the arrows jump back to the zero position. isnt setfillafter to tell the image that it should hold the new position?
code:
public void setTacho()
{
//rotate Tachonadel
Rpmcurrentdegree=Rpmcurrentdegree+Rpmdegree;
Rpmdegree=((rpms-lastrpm)*RPMtoDegree);
if(Rpmdegree!=0)
{
RpmAnim=new RotateAnimation((float)Rpmcurrentdegree, (float)Rpmdegree,     ivNadel.getWidth()/2, ivNadel.getHeight()/2);
RpmAnim.setFillEnabled(true);
RpmAnim.setFillAfter(true);
ivNadel.setAnimation(RpmAnim);
RpmAnim.start();
}
//rotate Boostbalken
currentBoostDegree=currentBoostDegree+BoostDegree;
BoostDegree=(boost-lastBoost)*BOOSTtoDegree;
//rotate Loadbalken
currentLoadDegree=currentLoadDegree+LoadDegree;
LoadDegree=(load-lastLoad)*LOADtoDegree;
if(BoostDegree!=0)
{
BoostAnim=new RotateAnimation((float)-currentBoostDegree, (float)-BoostDegree,     ivBoost.getWidth()/2, ivBoost.getHeight()/2);
BoostAnim.setFillEnabled(true);
BoostAnim.setFillAfter(true);
ivBoost.setAnimation(BoostAnim);
BoostAnim.start();
}
if(LoadDegree!=0)
{
LoadAnim=new RotateAnimation((float)currentLoadDegree, (float)LoadDegree,     ivLoad.getWidth()/2, ivLoad.getHeight()/2);
LoadAnim.setFillEnabled(true);
LoadAnim.setFillAfter(true);
ivLoad.setAnimation(LoadAnim);
LoadAnim.start();
}
}
i don't get it =(
thx 4 help
EDIT:
part of the bluetooth Thread that calls the callback
while (run) {
                try {
                    bytes = mmInStream.read(buffer);
                    if (connection.btCallback != null)
                    {
                            connection.btCallback.getData(buffer,bytes);
                    }
                } catch (IOException e) {
                    break;
                }
the callback methode of the bluetooth thread:
public void getData(byte[] bytes, int len)
        {
           setTacho(); 
        }
© Stack Overflow or respective owner