1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Android: rework back button handling to catch also programmatic requests.

This commit is contained in:
Lukasz Kozakiewicz 2018-02-05 16:11:17 +01:00
parent 8dd4e55557
commit 72116171cc

View file

@ -238,6 +238,32 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
{
launchApp (getApplicationInfo().publicSourceDir,
getApplicationInfo().dataDir);
}
// Need to override this as the default implementation always finishes the activity.
@Override
public void onBackPressed()
{
ComponentPeerView focusedView = getViewWithFocusOrDefaultView();
if (focusedView == null)
return;
focusedView.backButtonPressed();
}
private ComponentPeerView getViewWithFocusOrDefaultView()
{
for (int i = 0; i < viewHolder.getChildCount(); ++i)
{
if (viewHolder.getChildAt (i).hasFocus())
return (ComponentPeerView) viewHolder.getChildAt (i);
}
if (viewHolder.getChildCount() > 0)
return (ComponentPeerView) viewHolder.getChildAt (0);
return null;
}
//==============================================================================
@ -675,7 +701,7 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
//==============================================================================
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);
private native void handleBackButton (long host);
public void showKeyboard (String type)
{
@ -693,6 +719,14 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
imm.hideSoftInputFromWindow (getWindowToken(), 0);
}
}
}
public void backButtonPressed()
{
if (host == 0)
return;
handleBackButton (host);
}
@Override
@ -705,11 +739,11 @@ public class JuceAppActivity extends $$JuceAppActivityBaseClass$$
{
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
return super.onKeyDown (keyCode, event);
case KeyEvent.KEYCODE_BACK:
{
handleBackButton (host);
return true;
return super.onKeyDown (keyCode, event);
case KeyEvent.KEYCODE_BACK:
{
((Activity) getContext()).onBackPressed();
return true;
}
default: