Skip to content

Commit 98d1649

Browse files
micahscopesrtibbles
authored andcommitted
fix back-button related keyDown handler logic
1 parent 2f11598 commit 98d1649

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,21 @@ public static ViewGroup getLayout() {
273273
@Override
274274
public boolean onKeyDown(int keyCode, KeyEvent event) {
275275
// Check if the key event was the Back button and if there's history
276-
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
277-
mWebView.goBack();
278-
return true;
276+
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
277+
if(mWebView.canGoBack()) {
278+
mWebView.goBack();
279+
return true;
280+
}
281+
if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
282+
lastBackClick = SystemClock.elapsedRealtime();
283+
Toast.makeText(this, "Click again to close the app",
284+
Toast.LENGTH_LONG).show();
285+
return true;
286+
}
279287
}
288+
280289
// If it wasn't the Back key or there's no web page history, bubble up to the default
281290
// system behavior (probably exit the activity)
282-
if (SystemClock.elapsedRealtime() - lastBackClick > 2000){
283-
lastBackClick = SystemClock.elapsedRealtime();
284-
Toast.makeText(this, "Click again to close the app",
285-
Toast.LENGTH_LONG).show();
286-
return true;
287-
}
288-
289-
lastBackClick = SystemClock.elapsedRealtime();
290291
return super.onKeyDown(keyCode, event);
291292
}
292293

0 commit comments

Comments
 (0)