Browse Source

Android: Added a virtual backButtonPressed() method to JUCEApplicationBase which can be overridden to be informed when the back button is pressed on a device.

tags/2021-05-28
ed 8 years ago
parent
commit
201a85acd7
3 changed files with 22 additions and 1 deletions
  1. +8
    -1
      modules/juce_core/native/java/JuceAppActivity.java
  2. +7
    -0
      modules/juce_events/messages/juce_ApplicationBase.h
  3. +7
    -0
      modules/juce_gui_basics/native/juce_android_Windowing.cpp

+ 8
- 1
modules/juce_core/native/java/JuceAppActivity.java View File

@@ -630,6 +630,7 @@ public class JuceAppActivity extends Activity
//==============================================================================
private native void handleKeyDown (long host, int keycode, int textchar);
private native void handleKeyUp (long host, int keycode, int textchar);
private native void handleBackButton (long host);
public void showKeyboard (String type)
{
@@ -657,8 +658,14 @@ public class JuceAppActivity extends Activity
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
return super.onKeyDown (keyCode, event);
case KeyEvent.KEYCODE_BACK:
{
handleBackButton (host);
return true;
}
default: break;
default:
break;
}
handleKeyDown (host, keyCode, event.getUnicodeChar());


+ 7
- 0
modules/juce_events/messages/juce_ApplicationBase.h View File

@@ -188,6 +188,13 @@ public:
const String& sourceFilename,
int lineNumber) = 0;
//==============================================================================
/** Override this method to be informed when the back button is pressed on a device.
This is currently only implemented on Android devices.
*/
virtual void backButtonPressed() { }
//==============================================================================
/** Signals that the main message loop should stop and the application should terminate.


+ 7
- 0
modules/juce_gui_basics/native/juce_android_Windowing.cpp View File

@@ -437,6 +437,12 @@ public:
{
}
void handleBackButtonCallback()
{
if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
app->backButtonPressed();
}
//==============================================================================
bool isFocused() const override
{
@@ -664,6 +670,7 @@ JUCE_VIEW_CALLBACK (void, viewSizeChanged, (JNIEnv* env, jobject /*view*/, jlon
JUCE_VIEW_CALLBACK (void, focusChanged, (JNIEnv* env, jobject /*view*/, jlong host, jboolean hasFocus), handleFocusChangeCallback (hasFocus))
JUCE_VIEW_CALLBACK (void, handleKeyDown, (JNIEnv* env, jobject /*view*/, jlong host, jint k, jint kc), handleKeyDownCallback ((int) k, (int) kc))
JUCE_VIEW_CALLBACK (void, handleKeyUp, (JNIEnv* env, jobject /*view*/, jlong host, jint k, jint kc), handleKeyUpCallback ((int) k, (int) kc))
JUCE_VIEW_CALLBACK (void, handleBackButton, (JNIEnv* env, jobject /*view*/, jlong host), handleBackButtonCallback())
//==============================================================================
ComponentPeer* Component::createNewPeer (int styleFlags, void*)


Loading…
Cancel
Save