The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. package com.juce;
  19. import android.content.Context;
  20. import android.view.*;
  21. import android.graphics.*;
  22. //==============================================================================
  23. public class ComponentPeerView extends View
  24. implements View.OnFocusChangeListener
  25. {
  26. public ComponentPeerView (Context context, boolean opaque_)
  27. {
  28. super (context);
  29. opaque = opaque_;
  30. setFocusable (true);
  31. setFocusableInTouchMode (true);
  32. setOnFocusChangeListener (this);
  33. requestFocus();
  34. }
  35. //==============================================================================
  36. private native void handlePaint (Canvas canvas);
  37. @Override
  38. public void draw (Canvas canvas)
  39. {
  40. handlePaint (canvas);
  41. }
  42. @Override
  43. public boolean isOpaque()
  44. {
  45. return opaque;
  46. }
  47. private boolean opaque;
  48. //==============================================================================
  49. private native void handleMouseDown (float x, float y, long time);
  50. private native void handleMouseDrag (float x, float y, long time);
  51. private native void handleMouseUp (float x, float y, long time);
  52. @Override
  53. public boolean onTouchEvent (MotionEvent event)
  54. {
  55. switch (event.getAction())
  56. {
  57. case MotionEvent.ACTION_DOWN: handleMouseDown (event.getX(), event.getY(), event.getEventTime()); return true;
  58. case MotionEvent.ACTION_MOVE: handleMouseDrag (event.getX(), event.getY(), event.getEventTime()); return true;
  59. case MotionEvent.ACTION_CANCEL:
  60. case MotionEvent.ACTION_UP: handleMouseUp (event.getX(), event.getY(), event.getEventTime()); return true;
  61. default: break;
  62. }
  63. return false;
  64. }
  65. //==============================================================================
  66. @Override
  67. protected void onSizeChanged (int w, int h, int oldw, int oldh)
  68. {
  69. viewSizeChanged();
  70. }
  71. @Override
  72. protected void onLayout (boolean changed, int left, int top, int right, int bottom)
  73. {
  74. }
  75. private native void viewSizeChanged();
  76. @Override
  77. public void onFocusChange (View v, boolean hasFocus)
  78. {
  79. if (v == this)
  80. focusChanged (hasFocus);
  81. }
  82. private native void focusChanged (boolean hasFocus);
  83. public void setViewName (String newName)
  84. {
  85. }
  86. public boolean isVisible()
  87. {
  88. return getVisibility() == VISIBLE;
  89. }
  90. public void setVisible (boolean b)
  91. {
  92. setVisibility (b ? VISIBLE : INVISIBLE);
  93. }
  94. public boolean containsPoint (int x, int y)
  95. {
  96. return true; //xxx needs to check overlapping views
  97. }
  98. }