summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2013-12-15 17:19:24 +0100
committerAndrzej Hunt <andrzej.hunt@collabora.com>2014-01-16 15:46:05 +0000
commitf5d14e0234effd16a570ec3f32349f53c1b469f0 (patch)
tree95cee236318887e597ae3254da205898df9f220d /android
parent78b0b970fd72b19c9d49325bec566eb6e92935e5 (diff)
only autostart discovery when there are no known devices
and don't loop autodiscovery, provide a manual trigger button instead. Bluetooth discovery is a hefty process and thus should not be done lightheartedly. Moreover discovery won't even list devices that are already bonded, but not set to visible. As you will be more likely using the remote with the same devices, it makes sense to list the known devices and only do discovery on explicit request/when there are no bonded devices yet. Fix a lifecycle problem (as the service would be quit on screen-rotation as the only bound client is destroyed/restarted - start the service instead to let it keep running, and only stop/release it when finishing) icons from Android's ActionBar Icon Pack, shrinked using optipng Change-Id: Ie8467f942df1aab2d64b337fc7a6f816b9d658a6 Reviewed-on: https://gerrit.libreoffice.org/7091 Reviewed-by: Andrzej Hunt <andrzej.hunt@collabora.com> Tested-by: Andrzej Hunt <andrzej.hunt@collabora.com>
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/res/drawable-hdpi/ic_action_bluetooth_searching.pngbin0 -> 455 bytes
-rw-r--r--android/sdremote/res/drawable-mdpi/ic_action_bluetooth_searching.pngbin0 -> 358 bytes
-rw-r--r--android/sdremote/res/drawable-xhdpi/ic_action_bluetooth_searching.pngbin0 -> 560 bytes
-rw-r--r--android/sdremote/res/drawable-xxhdpi/ic_action_bluetooth_searching.pngbin0 -> 786 bytes
-rw-r--r--android/sdremote/res/layout/progress.xml5
-rw-r--r--android/sdremote/res/menu/menu_action_bar_computers.xml5
-rw-r--r--android/sdremote/res/values/strings.xml1
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java8
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java62
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java17
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/util/Intents.java1
11 files changed, 57 insertions, 42 deletions
diff --git a/android/sdremote/res/drawable-hdpi/ic_action_bluetooth_searching.png b/android/sdremote/res/drawable-hdpi/ic_action_bluetooth_searching.png
new file mode 100644
index 000000000000..0203ea4462c8
--- /dev/null
+++ b/android/sdremote/res/drawable-hdpi/ic_action_bluetooth_searching.png
Binary files differ
diff --git a/android/sdremote/res/drawable-mdpi/ic_action_bluetooth_searching.png b/android/sdremote/res/drawable-mdpi/ic_action_bluetooth_searching.png
new file mode 100644
index 000000000000..22dccb1938b6
--- /dev/null
+++ b/android/sdremote/res/drawable-mdpi/ic_action_bluetooth_searching.png
Binary files differ
diff --git a/android/sdremote/res/drawable-xhdpi/ic_action_bluetooth_searching.png b/android/sdremote/res/drawable-xhdpi/ic_action_bluetooth_searching.png
new file mode 100644
index 000000000000..97252d4e793d
--- /dev/null
+++ b/android/sdremote/res/drawable-xhdpi/ic_action_bluetooth_searching.png
Binary files differ
diff --git a/android/sdremote/res/drawable-xxhdpi/ic_action_bluetooth_searching.png b/android/sdremote/res/drawable-xxhdpi/ic_action_bluetooth_searching.png
new file mode 100644
index 000000000000..8e827e96b715
--- /dev/null
+++ b/android/sdremote/res/drawable-xxhdpi/ic_action_bluetooth_searching.png
Binary files differ
diff --git a/android/sdremote/res/layout/progress.xml b/android/sdremote/res/layout/progress.xml
new file mode 100644
index 000000000000..f768ec4bc623
--- /dev/null
+++ b/android/sdremote/res/layout/progress.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+</ProgressBar>
diff --git a/android/sdremote/res/menu/menu_action_bar_computers.xml b/android/sdremote/res/menu/menu_action_bar_computers.xml
index 7cbffc64fda8..27ddf8ae1a69 100644
--- a/android/sdremote/res/menu/menu_action_bar_computers.xml
+++ b/android/sdremote/res/menu/menu_action_bar_computers.xml
@@ -24,6 +24,11 @@
android:title="@string/menu_add_computer"
android:icon="@drawable/ic_action_add_computer"
compat:showAsAction="always"/>
+ <item
+ android:id="@+id/menu_start_discovery"
+ android:title="@string/menu_start_discovery"
+ android:icon="@drawable/ic_action_bluetooth_searching"
+ compat:showAsAction="always"/>
<item
android:id="@+id/menu_settings"
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 4ec816af049b..deca93b58b10 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -37,6 +37,7 @@
<string name="menu_requirements">Requirements</string>
<string name="menu_reconnect">Reconnect</string>
<string name="menu_add_computer">Add computer</string>
+ <string name="menu_start_discovery">Start Discovery</string>
<string name="menu_remove_computer">Remove</string>
<string name="menu_slides_grid">Slides grid</string>
<string name="menu_slides_pager">Slides pager</string>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 9329cd950110..00d66bed04b5 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -14,6 +14,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
@@ -128,6 +129,13 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
aMenu.findItem(R.id.menu_add_computer)
.setVisible(getSupportActionBar().getSelectedTab().equals(wifiTab));
+ MenuItem btDiscovery = aMenu.findItem(R.id.menu_start_discovery);
+ if( btAdapter != null && btAdapter.isDiscovering()) {
+ btDiscovery.setEnabled(false);
+ MenuItemCompat.setActionView(btDiscovery, R.layout.progress);
+ }
+ btDiscovery.setVisible(getSupportActionBar().getSelectedTab().equals(btTab));
+
return super.onPrepareOptionsMenu(aMenu);
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
index ac6cdc34d1b5..7ae17255c918 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
+import java.util.Set;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
@@ -21,14 +21,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;
-import org.libreoffice.impressremote.util.BluetoothOperator;
import org.libreoffice.impressremote.util.Intents;
-class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder, Runnable {
- private static final int SEARCH_DELAY_IN_SECONDS = 5;
+class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder {
+ private static final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
private final Context mContext;
@@ -42,30 +40,26 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
@Override
public void startSearch() {
- if (!BluetoothOperator.isAvailable()) {
+ if (btAdapter == null) {
return;
}
-
- if (BluetoothOperator.getAdapter().isDiscovering()) {
- return;
- }
-
- setUpBluetoothActionsReceiver();
-
- if (!BluetoothOperator.getAdapter().isEnabled()) {
- return;
- }
-
- BluetoothOperator.getAdapter().startDiscovery();
- }
-
- private void setUpBluetoothActionsReceiver() {
IntentFilter aBluetoothActionsFilter = new IntentFilter();
aBluetoothActionsFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
aBluetoothActionsFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
aBluetoothActionsFilter.addAction(BluetoothDevice.ACTION_FOUND);
mContext.registerReceiver(this, aBluetoothActionsFilter);
+ Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
+ if (pairedDevices.size() > 0) {
+ for (BluetoothDevice device : pairedDevices) {
+ addServer(device);
+ }
+ } else {
+ if (btAdapter.isDiscovering()) {
+ return;
+ }
+ btAdapter.startDiscovery();
+ }
}
@Override
@@ -73,7 +67,7 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(aIntent.getAction())) {
switch (aIntent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) {
case BluetoothAdapter.STATE_ON:
- BluetoothOperator.getAdapter().startDiscovery();
+ startSearch();
return;
default:
@@ -82,7 +76,8 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
}
if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(aIntent.getAction())) {
- startDiscoveryDelayed();
+ LocalBroadcastManager.getInstance(mContext)
+ .sendBroadcast(new Intent(Intents.Actions.BT_DISCOVERY_CHANGED));
return;
}
@@ -93,23 +88,6 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
}
}
- private void startDiscoveryDelayed() {
- // Start discovery again after a small delay.
- // Check whether device is on in case the user manually
- // disabled Bluetooth.
-
- if (!BluetoothOperator.getAdapter().isEnabled()) {
- return;
- }
-
- Handler aDiscoveryHandler = new Handler();
- aDiscoveryHandler.postDelayed(this, TimeUnit.SECONDS.toMillis(SEARCH_DELAY_IN_SECONDS));
- }
-
- @Override
- public void run() {
- BluetoothOperator.getAdapter().startDiscovery();
- }
private void addServer(BluetoothDevice aBluetoothDevice) {
Server.Type aServerType = buildServerType(aBluetoothDevice);
String aServerAddress = aBluetoothDevice.getAddress();
@@ -139,7 +117,7 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
@Override
public void stopSearch() {
- if (!BluetoothOperator.isAvailable()) {
+ if (btAdapter == null) {
return;
}
@@ -150,7 +128,7 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
// Fixed in Honeycomb: Android’s issue #6191.
}
- BluetoothOperator.getAdapter().cancelDiscovery();
+ btAdapter.cancelDiscovery();
}
@Override
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index ff061e655b36..7f35e674d51f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -13,6 +13,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -22,8 +23,10 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ListFragment;
import android.support.v4.content.LocalBroadcastManager;
+import android.support.v4.view.MenuItemCompat;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.ContextMenu;
@@ -141,6 +144,8 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
super.onActivityCreated(aSavedInstanceState);
Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity());
+ // use startService to not kill it on config changes like rotating the screen
+ getActivity().startService(aServiceIntent);
getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
}
@@ -267,6 +272,7 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
mIntentsReceiver = new IntentsReceiver(this);
IntentFilter aIntentFilter = new IntentFilter();
aIntentFilter.addAction(Intents.Actions.SERVERS_LIST_CHANGED);
+ aIntentFilter.addAction(Intents.Actions.BT_DISCOVERY_CHANGED);
getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter);
}
@@ -282,6 +288,8 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onReceive(Context aContext, Intent aIntent) {
if (Intents.Actions.SERVERS_LIST_CHANGED.equals(aIntent.getAction())) {
mComputersFragment.loadComputers();
+ } else if (Intents.Actions.BT_DISCOVERY_CHANGED.equals(aIntent.getAction())) {
+ ActivityCompat.invalidateOptionsMenu(mComputersFragment.getActivity());
}
}
}
@@ -344,6 +352,12 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
callComputerCreationActivity();
return true;
+ case R.id.menu_start_discovery:
+ if (BluetoothAdapter.getDefaultAdapter().startDiscovery()) {
+ MenuItemCompat.setActionView(aMenuItem, R.layout.progress);
+ }
+ return true;
+
default:
return super.onOptionsItemSelected(aMenuItem);
}
@@ -415,6 +429,9 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onDestroy() {
super.onDestroy();
+ if(getActivity().isFinishing()) {
+ getActivity().stopService(Intents.buildCommunicationServiceIntent(getActivity()));
+ }
getActivity().unbindService(this);
}
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index beab7ae03460..25f3c47312d1 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -29,6 +29,7 @@ public final class Intents {
}
public static final String SERVERS_LIST_CHANGED = "SERVERS_LIST_CHANGED";
+ public static final String BT_DISCOVERY_CHANGED = "BT_DISCOVERY_CHANGED";
public static final String PAIRING_SUCCESSFUL = "PAIRING_SUCCESSFUL";
public static final String PAIRING_VALIDATION = "PAIRING_VALIDATION";