| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.widget; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.util.AttributeSet; |
| 21 |
import android.view.KeyEvent; |
| 22 |
import android.view.MotionEvent; |
| 23 |
import android.view.View; |
| 24 |
import android.view.View.OnLongClickListener; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
@Deprecated |
| 39 |
public class ZoomButton extends ImageButton implements OnLongClickListener { |
| 40 |
|
| 41 |
private final Runnable mRunnable = new Runnable() { |
| 42 |
public void run() { |
| 43 |
if (hasOnClickListeners() && mIsInLongpress && isEnabled()) { |
| 44 |
callOnClick(); |
| 45 |
postDelayed(this, mZoomSpeed); |
| 46 |
} |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
private long mZoomSpeed = 1000; |
| 51 |
private boolean mIsInLongpress; |
| 52 |
|
| 53 |
public ZoomButton(Context context) { |
| 54 |
this(context, null); |
| 55 |
} |
| 56 |
|
| 57 |
public ZoomButton(Context context, AttributeSet attrs) { |
| 58 |
this(context, attrs, 0); |
| 59 |
} |
| 60 |
|
| 61 |
public ZoomButton(Context context, AttributeSet attrs, int defStyleAttr) { |
| 62 |
this(context, attrs, defStyleAttr, 0); |
| 63 |
} |
| 64 |
|
| 65 |
public ZoomButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 66 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 67 |
setOnLongClickListener(this); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public boolean onTouchEvent(MotionEvent event) { |
| 72 |
if ((event.getAction() == MotionEvent.ACTION_CANCEL) |
| 73 |
|| (event.getAction() == MotionEvent.ACTION_UP)) { |
| 74 |
mIsInLongpress = false; |
| 75 |
} |
| 76 |
return super.onTouchEvent(event); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public void setZoomSpeed(long speed) { |
| 86 |
mZoomSpeed = speed; |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
public boolean onLongClick(View v) { |
| 91 |
mIsInLongpress = true; |
| 92 |
post(mRunnable); |
| 93 |
return true; |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 98 |
mIsInLongpress = false; |
| 99 |
return super.onKeyUp(keyCode, event); |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
public void setEnabled(boolean enabled) { |
| 104 |
if (!enabled) { |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
setPressed(false); |
| 111 |
} |
| 112 |
super.setEnabled(enabled); |
| 113 |
} |
| 114 |
|
| 115 |
@Override |
| 116 |
public boolean dispatchUnhandledMove(View focused, int direction) { |
| 117 |
clearFocus(); |
| 118 |
return super.dispatchUnhandledMove(focused, direction); |
| 119 |
} |
| 120 |
|
| 121 |
@Override |
| 122 |
public CharSequence getAccessibilityClassName() { |
| 123 |
return ZoomButton.class.getName(); |
| 124 |
} |
| 125 |
} |