[Libreoffice-commits] core.git: Branch 'feature/android-remote-ng' - 5 commits - android/sdremote

Artur Dryomov artur.dryomov at gmail.com
Sat Jul 20 18:24:42 PDT 2013


 android/sdremote/res/drawable-hdpi/ic_logo.png                                              |binary
 android/sdremote/res/drawable-mdpi/ic_logo.png                                              |binary
 android/sdremote/res/drawable-xhdpi/ic_logo.png                                             |binary
 android/sdremote/res/layout/activity_computer_creation.xml                                  |   12 
 android/sdremote/res/layout/activity_computers.xml                                          |    6 
 android/sdremote/res/values/dimens.xml                                                      |    1 
 android/sdremote/res/values/strings.xml                                                     |    2 
 android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java   |   12 
 android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java          |   62 +++
 android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java       |   42 ++
 android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java |   26 +
 android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java          |  158 +++++-----
 android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java           |   46 --
 android/sdremote/src/org/libreoffice/impressremote/util/Intents.java                        |    5 
 dev/null                                                                                    |binary
 15 files changed, 233 insertions(+), 139 deletions(-)

New commits:
commit 7f2bc03638f62a1bad4caaad888320c6b05b8eb4
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Jul 21 03:59:00 2013 +0300

    Improve the ComputerConnectionFragment.
    
    Show reconnection action bar button only when it is necessary, i. e.
    when there is a connection error.
    
    Change-Id: Iecb86f7a1bf0b094f2fffbe12c03bea474774417

diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java
index ee9c75b..c70599e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputerConnectionFragment.java
@@ -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:
commit 9cf32ba887192394870ff28dcc3f662d7f1fa6f1
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Jul 21 03:37:09 2013 +0300

    Improve the ComputerCreationActivity.
    
    * Allow using IP address as a name.
    * Provide proper keyboards for typing name and address.
    
    Change-Id: I86ca58282c81eb0705d6bc82b98b2aab94fbf676

diff --git a/android/sdremote/res/layout/activity_computer_creation.xml b/android/sdremote/res/layout/activity_computer_creation.xml
index be1f313..4ef3f86 100644
--- a/android/sdremote/res/layout/activity_computer_creation.xml
+++ b/android/sdremote/res/layout/activity_computer_creation.xml
@@ -8,7 +8,7 @@
     <EditText
         android:id="@+id/edit_ip_address"
         android:singleLine="true"
-        android:inputType="text"
+        android:inputType="phone"
         android:hint="@string/hint_ip_address"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
@@ -16,10 +16,18 @@
     <EditText
         android:id="@+id/edit_name"
         android:singleLine="true"
-        android:inputType="text"
+        android:inputType="text|textCapSentences"
         android:hint="@string/hint_name"
         android:paddingTop="@dimen/padding_vertical_edit"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
 
+    <TextView
+        style="?textAppearanceSmall"
+        android:text="@string/message_name_notice"
+        android:gravity="center_horizontal"
+        android:paddingTop="@dimen/padding_vertical_notice"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"/>
+
 </LinearLayout>
\ No newline at end of file
diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml
index b73555f..d4c2e5b 100644
--- a/android/sdremote/res/values/dimens.xml
+++ b/android/sdremote/res/values/dimens.xml
@@ -15,6 +15,7 @@
     <dimen name="padding_vertical_pin">10dp</dimen>
     <dimen name="padding_vertical_error_message">10dp</dimen>
     <dimen name="padding_vertical_edit">8dp</dimen>
+    <dimen name="padding_vertical_notice">16dp</dimen>
 
     <dimen name="margin_vertical_action_bar_divider">12dp</dimen>
     <dimen name="margin_slide">8dp</dimen>
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 38252bb..072c406 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -27,7 +27,7 @@
     <string name="message_impress_wifi_enabling">You should enable experimental features at “Tools → Options → LibreOffice → Advanced” as well.</string>
     <string name="message_impress_pairing_check">If you have Bluetooth pairing issues check instructions related to your desktop OS.</string>
     <string name="message_ip_address_validation">You should type a valid IP address.</string>
-    <string name="message_name_validation">Name should not be empty.</string>
+    <string name="message_name_notice">Name is optional — IP address would be used instead if you wish.</string>
 
     <string name="hint_ip_address">IP address</string>
     <string name="hint_name">Name</string>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java
index 76f33c6..372e49b 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputerCreationActivity.java
@@ -68,11 +68,9 @@ public class ComputerCreationActivity extends SherlockFragmentActivity implement
     public void onClick(View aView) {
         if (aView.equals(getCancelButton())) {
             cancelCreation();
-
             return;
         }
 
-
         if (aView.equals(getSaveButton())) {
             saveServer();
         }
@@ -88,13 +86,13 @@ public class ComputerCreationActivity extends SherlockFragmentActivity implement
 
         if (!isIpAddressValid(aIpAddress)) {
             getIpAddressEdit().setError(getText(R.string.message_ip_address_validation));
+            return;
         }
 
         if (TextUtils.isEmpty(aName)) {
-            getNameEdit().setError(getText(R.string.message_name_validation));
+            finish(aIpAddress, aIpAddress);
         }
-
-        if (isServerInformationValid(aIpAddress, aName)) {
+        else {
             finish(aIpAddress, aName);
         }
     }
@@ -111,10 +109,6 @@ public class ComputerCreationActivity extends SherlockFragmentActivity implement
         return (EditText) findViewById(R.id.edit_name);
     }
 
-    private boolean isServerInformationValid(String aIpAddress, String aName) {
-        return isIpAddressValid(aIpAddress) && !TextUtils.isEmpty(aName);
-    }
-
     private boolean isIpAddressValid(String aIpAddress) {
         return Patterns.IP_ADDRESS.matcher(aIpAddress).matches();
     }
commit 990c93622c148f0e7c422ddd1a12d770df06044e
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Jul 21 03:01:08 2013 +0300

    Change the logo to a new one.
    
    * The new logo is a flat version of the launcher icon. It follows the
      Google Play store application style.
    * All base densities are available now.
    
    Change-Id: Ieb4cfb7f762421ac1b7a6edeece44788f26dd7d5

diff --git a/android/sdremote/res/drawable-hdpi/ic_logo.png b/android/sdremote/res/drawable-hdpi/ic_logo.png
new file mode 100644
index 0000000..9bef30e
Binary files /dev/null and b/android/sdremote/res/drawable-hdpi/ic_logo.png differ
diff --git a/android/sdremote/res/drawable-mdpi/ic_logo.png b/android/sdremote/res/drawable-mdpi/ic_logo.png
new file mode 100644
index 0000000..abf3401
Binary files /dev/null and b/android/sdremote/res/drawable-mdpi/ic_logo.png differ
diff --git a/android/sdremote/res/drawable-xhdpi/ic_logo.png b/android/sdremote/res/drawable-xhdpi/ic_logo.png
new file mode 100644
index 0000000..cc1f02f
Binary files /dev/null and b/android/sdremote/res/drawable-xhdpi/ic_logo.png differ
diff --git a/android/sdremote/res/drawable/ic_logo.png b/android/sdremote/res/drawable/ic_logo.png
deleted file mode 100644
index ce76471..0000000
Binary files a/android/sdremote/res/drawable/ic_logo.png and /dev/null differ
commit 68e4448495b2344c8b1113d211d58cf9b77ca2ce
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Jul 21 02:11:37 2013 +0300

    Change ComputersActivity to use swipe tabs.
    
    Such method even remembers a current tab on orientation changes.
    
    Change-Id: Iad14af060b41a4b8d225e83af450cdff0a6e78e0

diff --git a/android/sdremote/res/layout/activity_computers.xml b/android/sdremote/res/layout/activity_computers.xml
new file mode 100644
index 0000000..6e5332d
--- /dev/null
+++ b/android/sdremote/res/layout/activity_computers.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v4.view.ViewPager
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/pager_computers"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"/>
\ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 14ace70..3a5bbb6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -10,23 +10,26 @@ package org.libreoffice.impressremote.activity;
 
 import android.content.Intent;
 import android.os.Bundle;
-import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
 
 import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.SherlockFragmentActivity;
 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuItem;
-import org.libreoffice.impressremote.util.ActionBarTabListener;
-import org.libreoffice.impressremote.fragment.ComputersFragment;
+import org.libreoffice.impressremote.adapter.ComputersPagerAdapter;
 import org.libreoffice.impressremote.util.Intents;
 import org.libreoffice.impressremote.R;
 
-public class ComputersActivity extends SherlockFragmentActivity {
+public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_computers);
 
         setUpTabs();
+        setUpComputersPager();
     }
 
     private void setUpTabs() {
@@ -37,26 +40,59 @@ public class ComputersActivity extends SherlockFragmentActivity {
     }
 
     private ActionBar.Tab buildBluetoothServersTab() {
-        ComputersFragment aFragment = ComputersFragment.newInstance(
-            ComputersFragment.Type.BLUETOOTH);
-
-        return buildActionBarTab(aFragment, R.string.title_bluetooth);
+        return buildActionBarTab(R.string.title_bluetooth);
     }
 
-    private ActionBar.Tab buildActionBarTab(Fragment aFragment, int aTitleResourceId) {
+    private ActionBar.Tab buildActionBarTab(int aTitleResourceId) {
         ActionBar.Tab aTab = getSupportActionBar().newTab();
 
-        aTab.setTabListener(new ActionBarTabListener(aFragment));
+        aTab.setTabListener(this);
         aTab.setText(aTitleResourceId);
 
         return aTab;
     }
 
+    @Override
+    public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+        getComputersPager().setCurrentItem(aTab.getPosition());
+    }
+
+    private ViewPager getComputersPager() {
+        return (ViewPager) findViewById(R.id.pager_computers);
+    }
+
+    @Override
+    public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+    }
+
+    @Override
+    public void onTabReselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+    }
+
     private ActionBar.Tab buildWiFiServersTab() {
-        ComputersFragment aFragment = ComputersFragment.newInstance(
-            ComputersFragment.Type.WIFI);
+        return buildActionBarTab(R.string.title_wifi);
+    }
+
+    private void setUpComputersPager() {
+        getComputersPager().setAdapter(buildComputersPagerAdapter());
+        getComputersPager().setOnPageChangeListener(this);
+    }
+
+    private PagerAdapter buildComputersPagerAdapter() {
+        return new ComputersPagerAdapter(getSupportFragmentManager());
+    }
+
+    @Override
+    public void onPageSelected(int aPosition) {
+        getSupportActionBar().setSelectedNavigationItem(aPosition);
+    }
+
+    @Override
+    public void onPageScrolled(int aPosition, float aPositionOffset, int aPositionOffsetPixels) {
+    }
 
-        return buildActionBarTab(aFragment, R.string.title_wifi);
+    @Override
+    public void onPageScrollStateChanged(int aPosition) {
     }
 
     @Override
diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java
new file mode 100644
index 0000000..5a4ddaa
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java
@@ -0,0 +1,42 @@
+package org.libreoffice.impressremote.adapter;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+
+import org.libreoffice.impressremote.fragment.ComputersFragment;
+
+public class ComputersPagerAdapter extends FragmentPagerAdapter {
+    private static final int PAGER_SIZE = 2;
+
+    private static final class PagerPositions {
+        private PagerPositions() {
+        }
+
+        public static final int BLUETOOTH = 0;
+        public static final int WIFI = 1;
+    }
+
+    public ComputersPagerAdapter(FragmentManager aFragmentManager) {
+        super(aFragmentManager);
+    }
+
+    @Override
+    public Fragment getItem(int aPosition) {
+        switch (aPosition) {
+            case PagerPositions.BLUETOOTH:
+                return ComputersFragment.newInstance(ComputersFragment.Type.BLUETOOTH);
+
+            case PagerPositions.WIFI:
+                return ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
+
+            default:
+                return null;
+        }
+    }
+
+    @Override
+    public int getCount() {
+        return PAGER_SIZE;
+    }
+}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index 18491d6..fffd1cf 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -97,10 +97,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
     }
 
     private void loadComputers() {
-        if (!isAdded()) {
-            return;
-        }
-
         if (!isServiceBound()) {
             return;
         }
@@ -196,6 +192,8 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         super.onResume();
 
         registerIntentsReceiver();
+
+        loadComputers();
     }
 
     private void registerIntentsReceiver() {
@@ -277,6 +275,12 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
 
     @Override
     public boolean onContextItemSelected(android.view.MenuItem aMenuItem) {
+        if (!getUserVisibleHint()) {
+            // Wrong context menu could be dispatched.
+            // Android’s issue #20065.
+            return false;
+        }
+
         int aComputerPosition = getListItemPosition(aMenuItem);
         Server aComputer = getComputersAdapter().getItem(aComputerPosition);
 
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java b/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java
deleted file mode 100644
index e21911a..0000000
--- a/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.libreoffice.impressremote.util;
-
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-
-import com.actionbarsherlock.app.ActionBar;
-
-public class ActionBarTabListener implements ActionBar.TabListener {
-    private final Fragment mTabFragment;
-
-    public ActionBarTabListener(Fragment aTabFragment) {
-        mTabFragment = aTabFragment;
-    }
-
-    @Override
-    public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
-        if (mTabFragment.isDetached()) {
-            aFragmentTransaction.attach(mTabFragment);
-        }
-
-        aFragmentTransaction.replace(android.R.id.content, mTabFragment);
-    }
-
-    @Override
-    public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
-        if (mTabFragment.isDetached()) {
-            return;
-        }
-
-        aFragmentTransaction.detach(mTabFragment);
-    }
-
-    @Override
-    public void onTabReselected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
-    }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 899bf0222e526ed61a07f9433f248b050d8cc945
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date:   Sun Jul 21 00:06:49 2013 +0300

    Improve ComputersFragment.
    
    * Load saved computers better.
    * Handle removing and adding computers properly.
    
    Change-Id: I12027ad96f06cfeccbc249f453ccff588ccd79c6

diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index 11d2896..18491d6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -81,8 +81,7 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
     }
 
     private void bindService() {
-        Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class);
-
+        Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity());
         getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
     }
 
@@ -93,6 +92,83 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         mCommunicationService = aServiceBinder.getService();
 
         mCommunicationService.startSearch();
+
+        loadComputers();
+    }
+
+    private void loadComputers() {
+        if (!isAdded()) {
+            return;
+        }
+
+        if (!isServiceBound()) {
+            return;
+        }
+
+        if (getComputers().isEmpty()) {
+            hideComputersList();
+        }
+        else {
+            showComputersList();
+        }
+    }
+
+    private boolean isServiceBound() {
+        return mCommunicationService != null;
+    }
+
+    private void hideComputersList() {
+        setListAdapter(null);
+
+        setListShown(false);
+    }
+
+    private void showComputersList() {
+        if (!isComputersAdapterExist()) {
+            setUpComputersAdapter();
+        }
+
+        getComputersAdapter().clear();
+        getComputersAdapter().add(getComputers());
+
+        setListShown(true);
+    }
+
+    private boolean isComputersAdapterExist() {
+        return getComputersAdapter() != null;
+    }
+
+    private ComputersAdapter getComputersAdapter() {
+        return (ComputersAdapter) getListAdapter();
+    }
+
+    private void setUpComputersAdapter() {
+        setListAdapter(new ComputersAdapter(getActivity()));
+    }
+
+    private List<Server> getComputers() {
+        List<Server> aComputers = new ArrayList<Server>();
+
+        for (Server aServer : mCommunicationService.getServers()) {
+            if (isComputerSupportsRequiredType(aServer)) {
+                aComputers.add(aServer);
+            }
+        }
+
+        return aComputers;
+    }
+
+    private boolean isComputerSupportsRequiredType(Server aServer) {
+        switch (mType) {
+            case WIFI:
+                return aServer.getProtocol() == Server.Protocol.TCP;
+
+            case BLUETOOTH:
+                return aServer.getProtocol() == Server.Protocol.BLUETOOTH;
+
+            default:
+                return false;
+        }
     }
 
     @Override
@@ -110,10 +186,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         getActivity().unbindService(this);
     }
 
-    private boolean isServiceBound() {
-        return mCommunicationService != null;
-    }
-
     @Override
     public void onServiceDisconnected(ComponentName aComponentName) {
         mCommunicationService = null;
@@ -123,8 +195,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
     public void onResume() {
         super.onResume();
 
-        loadComputers();
-
         registerIntentsReceiver();
     }
 
@@ -163,60 +233,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         return LocalBroadcastManager.getInstance(aContext);
     }
 
-    private void loadComputers() {
-        if (!isServiceBound()) {
-            return;
-        }
-
-        if (getComputers().isEmpty()) {
-            return;
-        }
-
-        if (!isComputersAdapterExist()) {
-            setUpComputersAdapter();
-        }
-
-        getComputersAdapter().clear();
-        getComputersAdapter().add(getComputers());
-    }
-
-    private boolean isComputersAdapterExist() {
-        return getComputersAdapter() != null;
-    }
-
-    private ComputersAdapter getComputersAdapter() {
-        return (ComputersAdapter) getListAdapter();
-    }
-
-    private void setUpComputersAdapter() {
-        setListAdapter(new ComputersAdapter(getActivity()));
-    }
-
-    private List<Server> getComputers() {
-        List<Server> aComputers = new ArrayList<Server>();
-
-        for (Server aServer : mCommunicationService.getServers()) {
-            if (isComputerSupportsRequiredType(aServer)) {
-                aComputers.add(aServer);
-            }
-        }
-
-        return aComputers;
-    }
-
-    private boolean isComputerSupportsRequiredType(Server aServer) {
-        switch (mType) {
-            case WIFI:
-                return aServer.getProtocol() == Server.Protocol.TCP;
-
-            case BLUETOOTH:
-                return aServer.getProtocol() == Server.Protocol.BLUETOOTH;
-
-            default:
-                return false;
-        }
-    }
-
     @Override
     public void onPause() {
         super.onPause();
@@ -264,9 +280,14 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         int aComputerPosition = getListItemPosition(aMenuItem);
         Server aComputer = getComputersAdapter().getItem(aComputerPosition);
 
-        removeComputer(aComputer);
+        switch (aMenuItem.getItemId()) {
+            case R.id.menu_remove_computer:
+                removeComputer(aComputer);
+                return true;
 
-        return true;
+            default:
+                return super.onContextItemSelected(aMenuItem);
+        }
     }
 
     private int getListItemPosition(android.view.MenuItem aMenuItem) {
@@ -312,10 +333,11 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
         String aServerAddress = aIntent.getStringExtra(Intents.Extras.SERVER_ADDRESS);
         String aServerName = aIntent.getStringExtra(Intents.Extras.SERVER_NAME);
 
-        addServer(aServerAddress, aServerName);
+        addComputer(aServerAddress, aServerName);
+        loadComputers();
     }
 
-    private void addServer(String aAddress, String aName) {
+    private void addComputer(String aAddress, String aName) {
         mCommunicationService.addServer(aAddress, aName);
 
         Intent aIntent = Intents.buildServersListChangedIntent();
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index 0491345..ad7cfc1 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -15,6 +15,7 @@ import org.libreoffice.impressremote.activity.ComputerConnectionActivity;
 import org.libreoffice.impressremote.activity.ComputerCreationActivity;
 import org.libreoffice.impressremote.activity.LicensesActivity;
 import org.libreoffice.impressremote.activity.SlideShowActivity;
+import org.libreoffice.impressremote.communication.CommunicationService;
 import org.libreoffice.impressremote.communication.Server;
 
 public final class Intents {
@@ -134,6 +135,10 @@ public final class Intents {
     public static Intent buildLicensesIntent(Context aContext) {
         return new Intent(aContext, LicensesActivity.class);
     }
+
+    public static Intent buildCommunicationServiceIntent(Context aContext) {
+        return new Intent(aContext, CommunicationService.class);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list