mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-05 03:50:07 +00:00
Improved Android event callback mechanism.
This commit is contained in:
parent
c70d98dbdd
commit
3f07f45702
3 changed files with 44 additions and 48 deletions
|
|
@ -142,9 +142,9 @@ public final class JuceAppActivity extends Activity
|
|||
//==============================================================================
|
||||
private ViewHolder viewHolder;
|
||||
|
||||
public final ComponentPeerView createNewView (boolean opaque)
|
||||
public final ComponentPeerView createNewView (boolean opaque, long host)
|
||||
{
|
||||
ComponentPeerView v = new ComponentPeerView (this, opaque);
|
||||
ComponentPeerView v = new ComponentPeerView (this, opaque, host);
|
||||
viewHolder.addView (v);
|
||||
return v;
|
||||
}
|
||||
|
|
@ -312,9 +312,10 @@ public final class JuceAppActivity extends Activity
|
|||
public final class ComponentPeerView extends ViewGroup
|
||||
implements View.OnFocusChangeListener
|
||||
{
|
||||
public ComponentPeerView (Context context, boolean opaque_)
|
||||
public ComponentPeerView (Context context, boolean opaque_, long host)
|
||||
{
|
||||
super (context);
|
||||
this.host = host;
|
||||
setWillNotDraw (false);
|
||||
opaque = opaque_;
|
||||
|
||||
|
|
@ -325,13 +326,12 @@ public final class JuceAppActivity extends Activity
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
private native void handlePaint (Canvas canvas);
|
||||
private native void handlePaint (long host, Canvas canvas);
|
||||
|
||||
@Override
|
||||
public void draw (Canvas canvas)
|
||||
public void onDraw (Canvas canvas)
|
||||
{
|
||||
super.draw (canvas);
|
||||
handlePaint (canvas);
|
||||
handlePaint (host, canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -341,11 +341,12 @@ public final class JuceAppActivity extends Activity
|
|||
}
|
||||
|
||||
private boolean opaque;
|
||||
private long host;
|
||||
|
||||
//==============================================================================
|
||||
private native void handleMouseDown (int index, float x, float y, long time);
|
||||
private native void handleMouseDrag (int index, float x, float y, long time);
|
||||
private native void handleMouseUp (int index, float x, float y, long time);
|
||||
private native void handleMouseDown (long host, int index, float x, float y, long time);
|
||||
private native void handleMouseDrag (long host, int index, float x, float y, long time);
|
||||
private native void handleMouseUp (long host, int index, float x, float y, long time);
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent (MotionEvent event)
|
||||
|
|
@ -356,19 +357,19 @@ public final class JuceAppActivity extends Activity
|
|||
switch (action & MotionEvent.ACTION_MASK)
|
||||
{
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
handleMouseDown (event.getPointerId(0), event.getX(), event.getY(), time);
|
||||
handleMouseDown (host, event.getPointerId(0), event.getX(), event.getY(), time);
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
handleMouseUp (event.getPointerId(0), event.getX(), event.getY(), time);
|
||||
handleMouseUp (host, event.getPointerId(0), event.getX(), event.getY(), time);
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
{
|
||||
int n = event.getPointerCount();
|
||||
for (int i = 0; i < n; ++i)
|
||||
handleMouseDrag (event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
handleMouseDrag (host, event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -376,14 +377,14 @@ public final class JuceAppActivity extends Activity
|
|||
case MotionEvent.ACTION_POINTER_UP:
|
||||
{
|
||||
int i = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
||||
handleMouseUp (event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
handleMouseUp (host, event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
return true;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
{
|
||||
int i = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
||||
handleMouseDown (event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
handleMouseDown (host, event.getPointerId(i), event.getX(i), event.getY(i), time);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -395,8 +396,8 @@ public final class JuceAppActivity extends Activity
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
private native void handleKeyDown (int keycode, int textchar);
|
||||
private native void handleKeyUp (int keycode, int textchar);
|
||||
private native void handleKeyDown (long host, int keycode, int textchar);
|
||||
private native void handleKeyUp (long host, int keycode, int textchar);
|
||||
|
||||
public void showKeyboard (boolean shouldShow)
|
||||
{
|
||||
|
|
@ -414,14 +415,23 @@ public final class JuceAppActivity extends Activity
|
|||
@Override
|
||||
public boolean onKeyDown (int keyCode, KeyEvent event)
|
||||
{
|
||||
handleKeyDown (keyCode, event.getUnicodeChar());
|
||||
switch (keyCode)
|
||||
{
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
return super.onKeyDown (keyCode, event);
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
handleKeyDown (host, keyCode, event.getUnicodeChar());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp (int keyCode, KeyEvent event)
|
||||
{
|
||||
handleKeyUp (keyCode, event.getUnicodeChar());
|
||||
handleKeyUp (host, keyCode, event.getUnicodeChar());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -445,7 +455,7 @@ public final class JuceAppActivity extends Activity
|
|||
protected void onSizeChanged (int w, int h, int oldw, int oldh)
|
||||
{
|
||||
super.onSizeChanged (w, h, oldw, oldh);
|
||||
viewSizeChanged();
|
||||
viewSizeChanged (host);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -455,16 +465,16 @@ public final class JuceAppActivity extends Activity
|
|||
requestTransparentRegion (getChildAt (i));
|
||||
}
|
||||
|
||||
private native void viewSizeChanged();
|
||||
private native void viewSizeChanged (long host);
|
||||
|
||||
@Override
|
||||
public void onFocusChange (View v, boolean hasFocus)
|
||||
{
|
||||
if (v == this)
|
||||
focusChanged (hasFocus);
|
||||
focusChanged (host, hasFocus);
|
||||
}
|
||||
|
||||
private native void focusChanged (boolean hasFocus);
|
||||
private native void focusChanged (long host, boolean hasFocus);
|
||||
|
||||
public void setViewName (String newName) {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue