diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-08-02 03:41:52 +0300 |
---|---|---|
committer | Artur Dryomov <artur.dryomov@gmail.com> | 2013-08-02 03:49:46 +0300 |
commit | 429148c5f10828c50ae41309942f4946b12a7df9 (patch) | |
tree | cb53b53205cda1eb0c6361ab770f83a76df887e0 /android | |
parent | fa484c3b00a70ef00996f9bb694ac88da81cc91b (diff) |
Change computers adding behaviour.
Show a button only when a WiFi tab is selected or there are no Bluetooth
support at all.
Change-Id: I8944f4a4ec0dbcba087744960f467dca87ba7a86
Diffstat (limited to 'android')
-rw-r--r-- | android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java index 8054b893cac0..56b87e7e5777 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java @@ -27,6 +27,14 @@ import org.libreoffice.impressremote.util.Intents; import org.libreoffice.impressremote.R; public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener { + private static final class TabsIndices { + private TabsIndices() { + } + + public static final int BLUETOOTH = 0; + public static final int WIFI = 1; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -47,7 +55,7 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio } private void setUpContent() { - if (BluetoothOperator.isAvailable()) { + if (areMultipleComputersTypesAvailable()) { setUpComputersLists(); } else { @@ -55,6 +63,10 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio } } + private boolean areMultipleComputersTypesAvailable() { + return BluetoothOperator.isAvailable(); + } + private void setUpComputersLists() { setContentView(R.layout.activity_computers); @@ -65,8 +77,8 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio private void setUpTabs() { ActionBar aActionBar = getSupportActionBar(); - aActionBar.addTab(buildActionBarTab(R.string.title_bluetooth)); - aActionBar.addTab(buildActionBarTab(R.string.title_wifi)); + aActionBar.addTab(buildActionBarTab(R.string.title_bluetooth), TabsIndices.BLUETOOTH); + aActionBar.addTab(buildActionBarTab(R.string.title_wifi), TabsIndices.WIFI); } private ActionBar.Tab buildActionBarTab(int aTitleResourceId) { @@ -81,12 +93,18 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio @Override public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aTransaction) { getComputersPager().setCurrentItem(aTab.getPosition()); + + refreshActionBarMenu(); } private ViewPager getComputersPager() { return (ViewPager) findViewById(R.id.pager_computers); } + private void refreshActionBarMenu() { + supportInvalidateOptionsMenu(); + } + @Override public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) { } @@ -133,6 +151,29 @@ public class ComputersActivity extends SherlockFragmentActivity implements Actio } @Override + public boolean onPrepareOptionsMenu(Menu aMenu) { + if (!areMultipleComputersTypesAvailable()) { + return super.onPrepareOptionsMenu(aMenu); + } + + MenuItem aComputerAddingMenuItem = aMenu.findItem(R.id.menu_add_computer); + + switch (getSupportActionBar().getSelectedNavigationIndex()) { + case TabsIndices.BLUETOOTH: + aComputerAddingMenuItem.setVisible(false); + break; + + case TabsIndices.WIFI: + aComputerAddingMenuItem.setVisible(true); + + default: + break; + } + + return super.onPrepareOptionsMenu(aMenu); + } + + @Override public boolean onOptionsItemSelected(MenuItem aMenuItem) { switch (aMenuItem.getItemId()) { case R.id.menu_licenses: |