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


          具体做法是仿照系统的RockAudioPlayer,我也是通过查看源码,然后把它简化出来,更容易于应用。通过自定义一个RepeatingImageButton,当然这个名字可以自己更改,RepeatingImageButton里的代码可以查看RockAudioPlayer的源码,我这里只给出经过简化过的java代码。

    1 public class MainActivity extends Activity {
    2 /** Called when the activity is first created. edit by etgyd*/
    3 private RepeatingImageButton last;
    4 @Override
    5 public void onCreate(Bundle savedInstanceState) {
    6 super.onCreate(savedInstanceState);
    7 setContentView(R.layout.main);
    8 last = (RepeatingImageButton) findViewById(R.id.last);
    9 last.setRepeatListener(rep, 260);
    10 last.setOnClickListener(new OnClickListener() {
    11
    12 @Override
    13 public void onClick(View v) {
    14 // TODO Auto-generated method stub
    15   System.out.println("last");
    16 }
    17 });
    18 }
    19
    20 private RepeatingImageButton.RepeatListener rep = new RepeatingImageButton.RepeatListener() {
    21
    22 @Override
    23 public void onRepeat(View v, long duration, int repeatcount) {
    24 // TODO Auto-generated method stub
    25 scanBackward(repeatcount, duration);
    26 }
    27 };
    28
    29 private void scanBackward(int repcnt, long delta) {
    30 try {
    31 if (delta < 5000) {
    32 // seek at 10x speed for the first 5 seconds
    33 delta = delta * 10;
    34 System.out.println("long pause" + delta);
    35 } else {
    36 // seek at 40x after that
    37 delta = 50000 + (delta - 5000) * 40;
    38 System.out.println("long pause fast");
    39 }
    40 } catch (Exception ex) {
    41 }
    42 }
    43 }
  • 相关阅读:
    PAT A1147 Heaps (30 分)——完全二叉树,层序遍历,后序遍历
    # 数字签名&数字证书
    # Doing homework again(贪心)
    # Tallest Cows(差分)
    # ACM奇淫技巧
    # 二维前缀和+差分
    # 费解的开关(二进制+递推+思维)
    # log对数Hash映射优化
    # 起床困难综合症(二进制枚举+按位求贡献)
    # 最短Hamilton路径(二进制状态压缩)
  • 原文地址:https://www.cnblogs.com/etgyd/p/2013762.html
Copyright © 2020-2023  润新知