1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-29 02:40:05 +00:00

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

This commit is contained in:
ed 2017-06-20 16:40:03 +01:00
parent b77a0786fb
commit 201a85acd7
3 changed files with 22 additions and 1 deletions

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());

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.

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*)