免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1564 | 回复: 0
打印 上一主题 下一主题

自定义ImageButton,实现快进快退功能 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-12 17:35 |只看该作者 |倒序浏览
转:月vs枫  

自定义ImageButton,实现快进快退功能


       具体做法是仿照系统的RockAudioPlayer,我也是通过查看源码,然后把它简化出来,更容易于应用。通过自定义一个RepeatingImageButton,当然这个名字可以自己更改,RepeatingImageButton里的代码可以查看RockAudioPlayer的源码,我这里只给出经过简化过的java代码。
  1. 1 public class MainActivity extends Activity {
  2. 2     /** Called when the activity is first created. edit by etgyd*/
  3. 3     private RepeatingImageButton last;
  4. 4     @Override
  5. 5     public void onCreate(Bundle savedInstanceState) {
  6. 6         super.onCreate(savedInstanceState);
  7. 7         setContentView(R.layout.main);
  8. 8         last = (RepeatingImageButton) findViewById(R.id.last);
  9. 9         last.setRepeatListener(rep, 260);
  10. 10         last.setOnClickListener(new OnClickListener() {
  11. 11
  12. 12             @Override
  13. 13             public void onClick(View v) {
  14. 14                 // TODO Auto-generated method stub
  15. 15                  System.out.println("last");
  16. 16             }
  17. 17         });
  18. 18     }
  19. 19
  20. 20     private RepeatingImageButton.RepeatListener rep = new RepeatingImageButton.RepeatListener() {
  21. 21
  22. 22         @Override
  23. 23         public void onRepeat(View v, long duration, int repeatcount) {
  24. 24             // TODO Auto-generated method stub
  25. 25             scanBackward(repeatcount, duration);
  26. 26         }
  27. 27     };
  28. 28
  29. 29     private void scanBackward(int repcnt, long delta) {
  30. 30         try {
  31. 31             if (delta < 5000) {
  32. 32                 // seek at 10x speed for the first 5 seconds
  33. 33                 delta = delta * 10;
  34. 34                 System.out.println("long pause" + delta);
  35. 35             } else {
  36. 36                 // seek at 40x after that
  37. 37                 delta = 50000 + (delta - 5000) * 40;
  38. 38                 System.out.println("long pause fast");
  39. 39             }
  40. 40         } catch (Exception ex) {
  41. 41         }
  42. 42     }
  43. 43 }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP