2013年11月20日 星期三

Display toast on Lockscreen

How to display a toast on Lockscreen?

Situation:
We want to display a toast on Lockscreen.
However, in order to the priority , we can't display a toast on Lockscreen.
In fact, the toast is showing behind the lockscreen.
How we solve this problem?


Solution:
We need to imitate the toast's behavior.
That is, we create a view and set the animation of fade in and fad out .

Here are the example:
LinearLayout layout = (LinearLayout)this.mLayoutInflater.inflate(layout.xml);

LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

addView(layout, lp);
// fade in animation
Animation anmationFirst = new AlphaAnimation(0.0f, 1.0f);
anmationFirst .setDuration(2500);
layout.setAnimation(anmationFirst);

// fade out animation
final Animation anmationSecond = new AlphaAnimation(1.0f, 0.0f);
anmationSecond.setDuration(2500);
layout.setAnimation(anmationSecond);
anmationFirst.startNow();
anmationFirst.setAnimationListener(new AnimationListener() {

     @Override
     public void onAnimationEnd(Animation arg0) {

         // after the first animation finished,
         // start the second animation
         anmationSecond.startNow();
     }

     @Override
     public void onAnimationRepeat(Animation arg0) {

     }

     @Override
     public void onAnimationStart(Animation arg0) {

     }

});



anmationSecond.setAnimationListener(new AnimationListener() {

      @Override
      public void onAnimationEnd(Animation arg0) {

         layout.setVisibility(View.GONE);
      }

      @Override
      public void onAnimationRepeat(Animation arg0) {

      }

      @Override
      public void onAnimationStart(Animation arg0) {

      }
});

沒有留言:

張貼留言