Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Remove the explicit key event listener from InputConfigFrag…
…ment. The AlertDialog class has a key listener built into it.

Also documented the methods/interfaces in MotionAlertDialog.
  • Loading branch information
lioncash committed Aug 26, 2013
1 parent e12c66b commit 670b028
Showing 1 changed file with 19 additions and 15 deletions.
Expand Up @@ -99,9 +99,9 @@ public boolean onPreferenceTreeClick(final PreferenceScreen screen, final Prefer
final MotionAlertDialog dialog = new MotionAlertDialog(m_activity);

// Set the key listener
dialog.setOnKeyEventListener(new MotionAlertDialog.OnKeyEventListener()
dialog.setOnKeyListener(new AlertDialog.OnKeyListener()
{
public boolean onKey(KeyEvent event)
public boolean onKey(DialogInterface dlg, int keyCode, KeyEvent event)
{
Log.d("InputConfigFragment", "Received key event: " + event.getAction());
switch (event.getAction())
Expand Down Expand Up @@ -211,38 +211,42 @@ public void onAttach(Activity activity)
*/
protected static final class MotionAlertDialog extends AlertDialog
{
private OnKeyEventListener keyListener;
private OnMotionEventListener motionListener;

/**
* Constructor
*
* @param ctx context to use this dialog in.
*/
public MotionAlertDialog(Context ctx)
{
super(ctx);
}

public interface OnKeyEventListener
{
boolean onKey(KeyEvent event);
}

/**
* Interface which defines a callback method for general
* motion events. This allows motion event code to be set
* in the event anonymous classes of this dialog are used.
*/
public interface OnMotionEventListener
{
boolean onMotion(MotionEvent event);
}

public void setOnKeyEventListener(OnKeyEventListener listener)
{
this.keyListener = listener;
}

/**
* Sets the motion listener.
*
* @param listener The motion listener to set.
*/
public void setOnMotionEventListener(OnMotionEventListener listener)
{
this.motionListener = listener;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
if (keyListener.onKey(event))
if (this.onKeyDown(event.getKeyCode(), event))
return true;

return super.dispatchKeyEvent(event);
Expand Down

0 comments on commit 670b028

Please sign in to comment.