I've made a HoldButton for android. It allows you to press and hold the button and then release it, this will trigger 2 listeners, instead of only just one.
It has 2 listeners you can register: OnButtonDownListener and OnButtonUpListener. The OnButtonDownListener will get called when the user presses and holds the HoldButton down, so for example you can start a MediaRecorder. And when the users lets loose of the HoldButton OnButtonUpListener will be called, so the just started MediaRecorder will stop.
Usage example:
Using java Syntax Highlighting
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.holdbutton_example);
- holdbutton = (HoldButton)findViewById(R.id.holdbutton);
- holdbutton.setOnButtonDownListener(new OnButtonDownListener() {
- public void onDown(HoldButton view) {
- // Start recording here
- mediaRecorder.start();
- }
- });
- holdbutton.setOnButtonUpListener(new OnButtonUpListener() {
- public void onUp(HoldButton view) {
- // Stop recording
- mRecorder.stop();
- }
- });
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Using xml Syntax Highlighting
- <com.DeepFrozen.android.view.HoldButton
- android:id="@+id/holdbutton"
- android:text="Holdme down"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
It's released under a BSD style licence, so you can do with it what ever you want as long as you hold to the licence, please read it, it's very short
. Oh and if you want it, would you mind putting my name in the credits please
.

