public class LoadMore extends Component implements Animation {
private long m_prevTime = 0; //Dummy initialized the previous time, more accurate values will be inside the paint methos private long m_animationSteps = 100;//How many steps in this animation private long m_animationStep = 0; //Current step if this animation, FROM 0 TO m_animationSteps private long m_timeStep; //How much time it takes to each step, calculated by the duration
private Dimension m_preSize = new Dimension(100, 40);// loaded should have a fixed size! @Override protected Dimension calcPreferredSize(){ return m_preSize; }
/** * @param duration the duration of the animation */ public LoadMore(long duration) {
m_timeStep = duration / m_animationSteps; } public boolean animate(){ return true; }
public void paint(Graphics g){ long currenttime = System.currentTimeMillis(); long diff = currenttime - m_prevTime; long stepsPassed = diff / m_timeStep; m_animationStep += stepsPassed; if(m_animationStep > m_animationSteps) { m_animationStep = 0; }
/* * DO THE PAINT HERE !!! */ m_prevTime = currenttime; }
}
/*
* DO THE PAINT HERE !!!
*/
int arcSize = (int)m_animationStep;
if(m_animationStep > (m_animationSteps/2)) {
arcSize = (int)(m_animationSteps - m_animationStep);
}
g.setColor(Color.RED);
g.fillArc(50, 50, arcSize, arcSize, 0, 270);
//END THE PAINT HERE
m_prevTime = currenttime;
private Dimension m_preSize = new Dimension(100, 100);// loaded should have a fixed size!
/*
* DO THE PAINT HERE !!!
*/
g.setAntiAliased(true);
int arcSize = (int)m_animationStep;
if(m_animationStep > (m_animationSteps/2)) {
arcSize = (int)(m_animationSteps - m_animationStep);
}
g.setColor(0xD23939);
int location = 60 - (arcSize / 2);
g.fillArc(location, location, arcSize, arcSize, 0, 360);
//END THE PAINT HERE
public class LoadMore extends Component implements Animation {
private long m_prevTime = 0; //Dummy initialized the previous time, more accurate values will be inside the paint methos
private long m_animationSteps = 400;//How many steps in this animation
private long m_animationStep = 0; //Current step if this animation, FROM 0 TO m_animationSteps
private long m_timeStep; //How much time it takes to each step, calculated by the duration
private Dimension m_preSize = new Dimension(130, 30);// loaded should have a fixed size!
@Override
protected Dimension calcPreferredSize(){
return m_preSize;
}
/**
* @param duration the duration of the animation
*/
public LoadMore() {
int duration = 2800;
m_timeStep = duration / m_animationSteps;
}
public boolean animate(){
return true;
}
public void paint(Graphics g){
long currenttime = System.currentTimeMillis();
long diff = currenttime - m_prevTime;
long stepsPassed = diff / m_timeStep;
m_animationStep += stepsPassed;
if(m_animationStep > m_animationSteps) {
m_animationStep = 0;
}
/*
* DO THE PAINT HERE !!!
*/
g.setAntiAliased(true);
g.setColor(0xD23939);
long animationElements = 5;
long animationItemSteps = m_animationSteps / animationElements;
for(int index = 0 ; index < animationElements-1 ; index++) {
int arcSize = 0;
int itemStep = (int)(animationItemSteps * index);
if(m_animationStep > itemStep) {
arcSize = (int)m_animationStep - itemStep;
if(arcSize > animationItemSteps) {
arcSize = (int)animationItemSteps - (arcSize - (int)animationItemSteps);
}
}
int newArcSize = arcSize / 4; //Need to fix the size is calculated by the timeing......
if(newArcSize < 5) {
newArcSize = 5;
}
double locationX = index*28 + 20.0 - (newArcSize / 2.0) ;
double locationY = 50 - (newArcSize / 2);
g.fillArc((int)locationX, (int)locationY, (int)newArcSize, (int)newArcSize, 0, 360);
}
/*
* END THE PAINT HERE
*/
m_prevTime = currenttime;
}
}