Well, there are several reasons why he used those spells when he was riding on Hagrid's bike..
1. He is being chased by Death Eaters, who want to capture him and take him to his certain death.
2. By this time, Lord Voldemort and the Death Eaters have infiltrated the Ministry of Magic, therefore they could care less that he was using underage magic. And Harry would care less that the Ministry knew, especially since many of the memebers were under the Imperius curse.
3. The trace wasn't able to detect him on the bike, so even if the ministry wasn't infiltrated, they wouldn't have known.
When Harry turns 17, the trace has broken and he is able to use magic outside of Hogwarts. That is why he summons his glasses and changes the color of the poster--because he knows he can do it without any consequences whatsoever and he is excited. In the past summers, he could've used magic but he would've suffered consequences as you may remember in The Order of The Phoenix. At that time, restrictions were a lot heavier.
At that point, most of the Ministry was on Pure-Blood mania and were only concerned with capturing Harry Potter. A simple act of underage magic was meaningless.