zoukankan      html  css  js  c++  java
  • 自定义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 }
  • 相关阅读:
    ch_5102 Mobile Service
    ch_POJ1201 Intervals
    [CodeVs]谁是赢家
    树上莫队
    [NOI2009]管道区珠
    拉格朗日差值
    Simpson&自适应Simpson
    数论学习笔记
    hibernate FetchType理解
    Hibernate的generator属性之意义
  • 原文地址:https://www.cnblogs.com/etgyd/p/2013762.html
Copyright © 2011-2022 走看看