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:
committed by
Michael Meeks
parent
001552cc8a
commit
f01c976a1d
@@ -82,8 +82,7 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindService() {
|
private void bindService() {
|
||||||
Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class);
|
Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity());
|
||||||
|
|
||||||
getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
|
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);
|
String aPin = aIntent.getStringExtra(Intents.Extras.PIN);
|
||||||
|
|
||||||
mComputerConnectionFragment.setUpPinValidationInstructions(aPin);
|
mComputerConnectionFragment.setUpPinValidationInstructions(aPin);
|
||||||
|
mComputerConnectionFragment.refreshActionBarMenu();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Intents.Actions.PAIRING_SUCCESSFUL.equals(aIntent.getAction())) {
|
if (Intents.Actions.PAIRING_SUCCESSFUL.equals(aIntent.getAction())) {
|
||||||
mComputerConnectionFragment.setUpPresentation();
|
mComputerConnectionFragment.setUpPresentation();
|
||||||
|
mComputerConnectionFragment.refreshActionBarMenu();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Intents.Actions.CONNECTION_FAILED.equals(aIntent.getAction())) {
|
if (Intents.Actions.CONNECTION_FAILED.equals(aIntent.getAction())) {
|
||||||
mComputerConnectionFragment.setUpErrorMessage();
|
mComputerConnectionFragment.setUpErrorMessage();
|
||||||
|
mComputerConnectionFragment.refreshActionBarMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,17 +221,37 @@ public class ComputerConnectionFragment extends SherlockFragment implements Serv
|
|||||||
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
|
aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshActionBarMenu() {
|
||||||
|
getSherlockActivity().supportInvalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu aMenu, MenuInflater aMenuInflater) {
|
public void onCreateOptionsMenu(Menu aMenu, MenuInflater aMenuInflater) {
|
||||||
|
if (!shouldActionBarMenuBeDisplayed()) {
|
||||||
|
aMenu.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
aMenuInflater.inflate(R.menu.menu_action_bar_computer_connection, aMenu);
|
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
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
|
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
|
||||||
switch (aMenuItem.getItemId()) {
|
switch (aMenuItem.getItemId()) {
|
||||||
case R.id.menu_reconnect:
|
case R.id.menu_reconnect:
|
||||||
showProgressBar();
|
showProgressBar();
|
||||||
connectToComputer();
|
connectToComputer();
|
||||||
|
refreshActionBarMenu();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user