mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Fix Android back button behavior
Pressing the back button should call mServoView.goBack if possible.
This commit is contained in:
parent
25ebde78aa
commit
9b4017e1e0
1 changed files with 11 additions and 1 deletions
|
@ -37,7 +37,7 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
EditText mUrlField;
|
EditText mUrlField;
|
||||||
ProgressBar mProgressBar;
|
ProgressBar mProgressBar;
|
||||||
TextView mIdleText;
|
TextView mIdleText;
|
||||||
|
boolean mCanGoBack;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -52,6 +52,7 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
mUrlField = findViewById(R.id.urlfield);
|
mUrlField = findViewById(R.id.urlfield);
|
||||||
mProgressBar = findViewById(R.id.progressbar);
|
mProgressBar = findViewById(R.id.progressbar);
|
||||||
mIdleText = findViewById(R.id.redrawing);
|
mIdleText = findViewById(R.id.redrawing);
|
||||||
|
mCanGoBack = false;
|
||||||
|
|
||||||
mBackButton.setEnabled(false);
|
mBackButton.setEnabled(false);
|
||||||
mFwdButton.setEnabled(false);
|
mFwdButton.setEnabled(false);
|
||||||
|
@ -152,6 +153,7 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
public void onHistoryChanged(boolean canGoBack, boolean canGoForward) {
|
public void onHistoryChanged(boolean canGoBack, boolean canGoForward) {
|
||||||
mBackButton.setEnabled(canGoBack);
|
mBackButton.setEnabled(canGoBack);
|
||||||
mFwdButton.setEnabled(canGoForward);
|
mFwdButton.setEnabled(canGoForward);
|
||||||
|
mCanGoBack = canGoBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRedrawing(boolean redrawing) {
|
public void onRedrawing(boolean redrawing) {
|
||||||
|
@ -173,4 +175,12 @@ public class MainActivity extends Activity implements Servo.Client {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (mCanGoBack) {
|
||||||
|
mServoView.goBack();
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue