Tuesday, January 20, 2009

Sliding drawer, again

The sliding drawer developped by pskink has gone quite a long way from where it came from, and is now a really nice and, I think, usable widget, much like the google home page one !

This kind of widget is fun to use, and fits really well for mobile applications, where there is an obvious lack of place. And, on google phone, users are used with this widget, as there is one on the home page !

Here are some screen of this widget in action :



Enjoy !
[Edit ] :
Ooooppss...
I forget to add the link to the source :
You can find it here !
[/Edit]

Friday, January 16, 2009

Sliding Drawer

Interested in the Home Page sliding drawer ?

pskink has created a new widget like the google one.
Nice job, and easy to use...

Here it is :

Enjoy !

Wednesday, January 14, 2009

To accelerate or to decelerate ?

As many developers discovering a new development environment, I use and abuse of copy and paste.
Starting a new feature process is : 
  • finding in the documentation, or on the internet a similar feature, or something as close as possible, 
  • try to find the parameter/line / bit of code to change to have something like what I had in mind in the first time,
  • Be happy :)
  • ( if I have some time : fully understanding what I've just written... )

And most of the time, I don't have that much have time !

For my tries with animations, I find a sample that moved a view, copied this sample for making my high score list view slide out and in. And that's all.

Only now, I discover that in the sample animation I copied, there was this parameter :
android:interpolator="@android:anim/accelerate_interpolator"

And only now, I discover my mistake. The accelerator interpolator makes the speed of the moving view increase with the time.
So when my high score listview is sliding out of the screen, it has a slow speed at first, when one can see it in its integrality, and a fast speed at the end of the animation, when only a little part of it is visible.

But on the contrary, when it is sliding in in the screen, it has its greatest speed at the end of the animation, when one can see it in its integrality !
This just makes a awful animation !

Now that I discovered that my animation can decelerate for slides in, it is way better !


Wednesday, January 7, 2009

Chaining two animations, or how to repeat animationset...

Yesterday I tried to chain two animations !

Actually, what I wanted was, on my high-score list view : translate the listview out of the screen, change the listview content ( for a different type of game ), and retranslate the new listview in the screen.
But, reading the Android-dev mailing list, I realized that it could also interest people using an animationSet.
Apparently, a bug prevent them from handling the repeat flag correctly( see here )
(Note that in my case, I couldn't use an animationSet, because I want to have an operation between the two animations ).

So I first use a AnimationListener to detect the end of the first animation, and launch there the second animation, and...
Kaboum... it ... failed !!
I had discovered a second bug related to animation ( or at least an undocumented constraint ) : you can't launch an animation in the OnAnimationEnd method of the AnimationListener.
I guess after the OnAnimationEnd, there is something like a ClearAnimation done on the view, that remove both the old and the new ones !

So the solution here is to post a message to launch the second animation on the next trame.
So here's my solution :

public class ScorePage extends ListActivity
{
class LocalAnimationListener implements AnimationListener
{
public void onAnimationEnd(Animation animation)
{
//LaunchInAnimation( ); // FAIL:the animation is not launched
//runOnUiThread( mLaunchSecondAnimation ); // FAIL : the runnable is launched immediatly, so like previous method !
//Handler curHandler = new Handler(); // OK, BUT :
//curHandler.post( mLaunchSecondAnimation); // create an unnecessary object !
getListView().post(mLaunchSecondAnimation); // OK : GOOD method !
}
public void onAnimationRepeat(Animation animation)
{
}
public void onAnimationStart(Animation animation)
{
}
};
private Runnable mLaunchSecondAnimation = new Runnable()
{
public void run()
{
LaunchInAnimation();
}
};
LocalAnimationListener MyAnimationListener = new LocalAnimationListener();

public void LaunchInAnimation()
{
// Change the listView Content :
mCurrentHiScore -=1;
if ( mCurrentHiScore < 0 )
mCurrentHiScore = 2;
ListAdapter curAdapter = mScore.GetScoreListAdapter(ScorePage.this, R.layout.score_entry, mCurrentHiScore);
if ( curAdapter != null )
setListAdapter( curAdapter );

// Launch the second animation :
Animation SlideAnim;
SlideAnim = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
ListView lv = getListView();
lv.startAnimation(SlideAnim);
}

public void LaunchOutAnimation()
{
Animation SlideAnim;
SlideAnim = AnimationUtils.loadAnimation(this, R.anim.slide_out_left);
SlideAnim.setAnimationListener( MyAnimationListener );
ListView lv = getListView();
lv.startAnimation(SlideAnim);
}
(... )


Now it's just fine !

Sunday, January 4, 2009

A flashy widget: the sliding drawer

I recently found where the code for the sliding drawer was in the Android code.

So what is that sliding drawer ?
It is the panel containing your applications in Android Home page.
You know, the panel that you can drag up or down, and that was the first thing you played with when first testing Android emulator or the G1 !

Here's the code :
Sliding Drawer Code

I would like to have time to experiment with it ( ie copy/paste it, and use it in my own application ), but just reading the code is quite an inspiring experience ! I will try that as soon as possible...

This widget is nice and fun to use, give a good feeling to the user, make your application more profunssional, and is a very efficient way to spare space in the screen !

Just one thing : why on earth is the code hidden in the depth of Android source ?
Why isn't the widget available as a part of the API ?
I just can't understand it !

Android definitively misses some standard fun widgets.
Was it because of a lack of time ?
Will the sliding drawer appear in the next version ?
Will we find who killed the colonel Mustard ?