Improve the ComputerConnectionFragment.

Show reconnection action bar button only when it is necessary, i. e.
when there is a connection error.

Change-Id: Iecb86f7a1bf0b094f2fffbe12c03bea474774417
This commit is contained in:
Artur Dryomov
2013-07-21 03:59:00 +03:00
committed by Michael Meeks
parent 001552cc8a
commit f01c976a1d

View File

@@ -82,8 +82,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
}
private void bindService() {
Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class);
Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity());
getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
}
@@ -140,18 +139,21 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
String aPin = aIntent.getStringExtra(Intents.Extras.PIN);
mComputerConnectionFragment.setUpPinValidationInstructions(aPin);
mComputerConnectionFragment.refreshActionBarMenu();
return;
}
if (Intents.Actions.PAIRING_SUCCESSFUL.equals(aIntent.getAction())) {
mComputerConnectionFragment.setUpPresentation();
mComputerConnectionFragment.refreshActionBarMenu();
return;
}
if (Intents.Actions.CONNECTION_FAILED.equals(aIntent.getAction())) {
mComputerConnectionFragment.setUpErrorMessage();
mComputerConnectionFragment.refreshActionBarMenu();
}
}
}
@@ -219,17 +221,37 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
}
private void refreshActionBarMenu() {
getSherlockActivity().supportInvalidateOptionsMenu();
}
@Override
public void onCreateOptionsMenu(Menu aMenu, MenuInflater aMenuInflater) {
if (!shouldActionBarMenuBeDisplayed()) {
aMenu.clear();
return;
}
aMenuInflater.inflate(R.menu.menu_action_bar_computer_connection, aMenu);
}
private boolean shouldActionBarMenuBeDisplayed() {
if (getView() == null) {
return false;
}
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator);
return aViewAnimator.getCurrentView().getId() == R.id.layout_error_message;
}
@Override
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
switch (aMenuItem.getItemId()) {
case R.id.menu_reconnect:
showProgressBar();
connectToComputer();
refreshActionBarMenu();
return true;
default: