[Libreoffice-commits] core.git: 2 commits - android/sdremote
Christian Lohmaier
lohmaier+LibreOffice at googlemail.com
Thu Jan 16 07:43:39 PST 2014
android/sdremote/res/values/strings.xml | 1
android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java | 113 +-------
android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java | 15 -
android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java | 41 ---
android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java | 135 ++--------
android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java | 10
android/sdremote/src/org/libreoffice/impressremote/util/Intents.java | 5
7 files changed, 63 insertions(+), 257 deletions(-)
New commits:
commit c0693031a7887a3146a049a5aabe36ed0ee14941
Author: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
Date: Sun Dec 15 16:38:17 2013 +0100
get rid of some useless indirection/wrapper functions
there's no point in adding a layer of indirection if all that the called
function does is running one single command, and is only called in one
place. Getting rid of that indirection makes the code easier to read and
understand.
Change-Id: Ie2f3e03fe2870d1d4a84df738ebb3d0f34a2713c
Reviewed-on: https://gerrit.libreoffice.org/7089
Reviewed-by: Andrzej Hunt <andrzej.hunt at collabora.com>
Tested-by: Andrzej Hunt <andrzej.hunt at collabora.com>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index f75d197..0c7bd68 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -36,10 +36,24 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
super.onCreate(aSavedInstanceState);
saveBluetoothState(aSavedInstanceState);
- enableBluetooth();
+ BluetoothOperator.enable();
+
+ // Looks hacky but it seems to be the best way to set activityâs title
+ // different to applicationâs label. The other way is setting title
+ // to intents filter but it shows wrong label for recent apps screen then.
+
+ ActionBar aActionBar = getSupportActionBar();
+
+ aActionBar.setTitle(R.string.title_computers);
+ aActionBar.setDisplayShowTitleEnabled(true);
- setUpTitle();
- setUpContent();
+ if (BluetoothOperator.isAvailable()) {
+ setUpComputersLists();
+ }
+ else {
+ Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
+ Fragments.Operator.add(this, aComputersFragment);
+ }
}
private void saveBluetoothState(Bundle aSavedInstanceState) {
@@ -63,50 +77,22 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
return aSavedInstanceState.getBoolean(SavedStates.Keys.BLUETOOTH_ENABLED);
}
- private void enableBluetooth() {
- BluetoothOperator.enable();
- }
-
- private void setUpTitle() {
- // Looks hacky but it seems to be the best way to set activityâs title
- // different to applicationâs label. The other way is setting title
- // to intents filter but it shows wrong label for recent apps screen then.
-
- ActionBar aActionBar = getSupportActionBar();
-
- aActionBar.setTitle(R.string.title_computers);
- aActionBar.setDisplayShowTitleEnabled(true);
- }
-
- private void setUpContent() {
- if (areMultipleComputersTypesAvailable()) {
- setUpComputersLists();
- }
- else {
- setUpComputersList();
- }
- }
-
- private boolean areMultipleComputersTypesAvailable() {
- return BluetoothOperator.isAvailable();
- }
-
private void setUpComputersLists() {
setContentView(R.layout.activity_computers);
- setUpTabs();
- setUpComputersPager();
-
- setUpSavedTab();
- }
-
- private void setUpTabs() {
ActionBar aActionBar = getSupportActionBar();
aActionBar.addTab(buildActionBarTab(
R.string.title_bluetooth), ComputersPagerAdapter.PagesIndices.BLUETOOTH);
aActionBar.addTab(buildActionBarTab(
R.string.title_wifi), ComputersPagerAdapter.PagesIndices.WIFI);
+
+ ViewPager aComputersPager = getComputersPager();
+
+ aComputersPager.setAdapter(new ComputersPagerAdapter(getSupportFragmentManager()));
+ aComputersPager.setOnPageChangeListener(this);
+
+ getSupportActionBar().setSelectedNavigationItem(loadTabIndex());
}
private ActionBar.Tab buildActionBarTab(int aTitleResourceId) {
@@ -122,17 +108,13 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
getComputersPager().setCurrentItem(aTab.getPosition());
- refreshActionBarMenu();
+ supportInvalidateOptionsMenu();
}
private ViewPager getComputersPager() {
return (ViewPager) findViewById(R.id.pager_computers);
}
- private void refreshActionBarMenu() {
- supportInvalidateOptionsMenu();
- }
-
@Override
public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
}
@@ -141,17 +123,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
public void onTabReselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
}
- private void setUpComputersPager() {
- ViewPager aComputersPager = getComputersPager();
-
- aComputersPager.setAdapter(buildComputersPagerAdapter());
- aComputersPager.setOnPageChangeListener(this);
- }
-
- private PagerAdapter buildComputersPagerAdapter() {
- return new ComputersPagerAdapter(getSupportFragmentManager());
- }
-
@Override
public void onPageSelected(int aPosition) {
getSupportActionBar().setSelectedNavigationItem(aPosition);
@@ -165,22 +136,12 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
public void onPageScrollStateChanged(int aPosition) {
}
- private void setUpSavedTab() {
- getSupportActionBar().setSelectedNavigationItem(loadTabIndex());
- }
-
private int loadTabIndex() {
Preferences aPreferences = Preferences.getApplicationStatesInstance(this);
return aPreferences.getInt(Preferences.Keys.SELECTED_COMPUTERS_TAB_INDEX);
}
- private void setUpComputersList() {
- Fragment aComputersFragment = ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
-
- Fragments.Operator.add(this, aComputersFragment);
- }
-
@Override
public boolean onCreateOptionsMenu(Menu aMenu) {
getMenuInflater().inflate(R.menu.menu_action_bar_computers, aMenu);
@@ -190,7 +151,7 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
@Override
public boolean onPrepareOptionsMenu(Menu aMenu) {
- if (!areMultipleComputersTypesAvailable()) {
+ if (!BluetoothOperator.isAvailable()) {
return super.onPrepareOptionsMenu(aMenu);
}
@@ -250,10 +211,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
protected void onStop() {
super.onStop();
- saveTabIndex();
- }
-
- private void saveTabIndex() {
Preferences aPreferences = Preferences.getApplicationStatesInstance(this);
int aTabIndex = getSupportActionBar().getSelectedNavigationIndex();
@@ -264,10 +221,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
protected void onSaveInstanceState(Bundle aSavedInstanceState) {
super.onSaveInstanceState(aSavedInstanceState);
- rememberBluetoothState(aSavedInstanceState);
- }
-
- private void rememberBluetoothState(Bundle aSavedInstanceState) {
aSavedInstanceState.putBoolean(SavedStates.Keys.BLUETOOTH_ENABLED, mBluetoothWasEnabled);
}
@@ -275,10 +228,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
protected void onDestroy() {
super.onDestroy();
- restoreBluetoothState();
- }
-
- private void restoreBluetoothState() {
if (!BluetoothOperator.isAvailable()) {
return;
}
@@ -287,10 +236,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
return;
}
- disableBluetooth();
- }
-
- private void disableBluetooth() {
BluetoothOperator.disable();
}
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java
index 762c497..b796429 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/SettingsActivity.java
@@ -19,15 +19,6 @@ public class SettingsActivity extends PreferenceActivity {
protected void onCreate(Bundle aSavedInstanceState) {
super.onCreate(aSavedInstanceState);
- setUpPreferences();
- }
-
- private void setUpPreferences() {
- // This action is deprecated
- // but we still need to target pre-Honeycomb devices.
-
- // TODO: try to use a fragment depending on platform version
-
addPreferencesFromResource(R.xml.preferences);
}
@@ -35,17 +26,13 @@ public class SettingsActivity extends PreferenceActivity {
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
switch (aMenuItem.getItemId()) {
case android.R.id.home:
- navigateUp();
+ finish();
return true;
default:
return super.onOptionsItemSelected(aMenuItem);
}
}
-
- private void navigateUp() {
- finish();
- }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
index 29e9b9c..ac6cdc3 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
@@ -89,8 +89,7 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
if (BluetoothDevice.ACTION_FOUND.equals(aIntent.getAction())) {
BluetoothDevice aBluetoothDevice = aIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- addServer(buildServer(aBluetoothDevice));
- callUpdatingServersList();
+ addServer(aBluetoothDevice);
}
}
@@ -111,17 +110,16 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
public void run() {
BluetoothOperator.getAdapter().startDiscovery();
}
-
- private void addServer(Server aServer) {
- mServers.put(aServer.getAddress(), aServer);
- }
-
- private Server buildServer(BluetoothDevice aBluetoothDevice) {
+ private void addServer(BluetoothDevice aBluetoothDevice) {
Server.Type aServerType = buildServerType(aBluetoothDevice);
String aServerAddress = aBluetoothDevice.getAddress();
String aServerName = aBluetoothDevice.getName();
- return Server.newBluetoothInstance(aServerType, aServerAddress, aServerName);
+ Server aServer = Server.newBluetoothInstance(aServerType, aServerAddress, aServerName);
+ mServers.put(aServer.getAddress(), aServer);
+
+ Intent bIntent = Intents.buildServersListChangedIntent();
+ LocalBroadcastManager.getInstance(mContext).sendBroadcast(bIntent);
}
private Server.Type buildServerType(BluetoothDevice aBluetoothDevice) {
@@ -139,29 +137,20 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
}
}
- private void callUpdatingServersList() {
- Intent aIntent = Intents.buildServersListChangedIntent();
- LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
- }
-
@Override
public void stopSearch() {
if (!BluetoothOperator.isAvailable()) {
return;
}
- tearDownBluetoothActionsReceiver();
-
- BluetoothOperator.getAdapter().cancelDiscovery();
- }
-
- private void tearDownBluetoothActionsReceiver() {
try {
mContext.unregisterReceiver(this);
} catch (IllegalArgumentException e) {
// Receiver not registered.
// Fixed in Honeycomb: Androidâs issue #6191.
}
+
+ BluetoothOperator.getAdapter().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 bd80f6c..ff061e6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -76,10 +76,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onCreate(Bundle aSavedInstanceState) {
super.onCreate(aSavedInstanceState);
- setUpActionBar();
- }
-
- private void setUpActionBar() {
setHasOptionsMenu(true);
}
@@ -92,21 +88,8 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onViewStateRestored(Bundle aSavedInstanceState) {
super.onViewStateRestored(aSavedInstanceState);
- if (!isSavedInstanceValid(aSavedInstanceState)) {
- return;
- }
-
- loadProgressMessage(aSavedInstanceState);
- }
-
- private boolean isSavedInstanceValid(Bundle aSavedInstanceState) {
- return aSavedInstanceState != null;
- }
-
- private void loadProgressMessage(Bundle aSavedInstanceState) {
- boolean aProgressMessageDisplayed = aSavedInstanceState.getBoolean(SavedStates.Keys.PROGRESS_MESSAGE);
-
- if (aProgressMessageDisplayed) {
+ if (aSavedInstanceState != null
+ && aSavedInstanceState.getBoolean(SavedStates.Keys.PROGRESS_MESSAGE)) {
showProgressMessage();
showLearnMoreMessage();
}
@@ -127,7 +110,7 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
}
private void showLearnMoreMessage() {
- TextView learnMoreView = getLearnMoreView();
+ TextView learnMoreView = (TextView) getView().findViewById(R.id.text_learn_more);
Animation aFadeInAnimation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
learnMoreView.setMovementMethod(LinkMovementMethod.getInstance());
@@ -136,10 +119,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
learnMoreView.setVisibility(View.VISIBLE);
}
- private TextView getLearnMoreView() {
- return (TextView) getView().findViewById(R.id.text_learn_more);
- }
-
private String getProgressMessage() {
switch (getType()) {
case WIFI:
@@ -161,10 +140,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onActivityCreated(Bundle aSavedInstanceState) {
super.onActivityCreated(aSavedInstanceState);
- bindService();
- }
-
- private void bindService() {
Intent aServiceIntent = Intents.buildCommunicationServiceIntent(getActivity());
getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
}
@@ -187,15 +162,22 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
return;
}
- if (getComputers().isEmpty()) {
- hideComputersList();
+ List<Server> computerList = getComputers();
+ if (computerList.isEmpty()) {
+ setCurrentView(R.id.layout_progress);
+
setUpProgressMessage();
- tearDownComputersAdapter();
- }
- else {
- setUpComputersAdapter();
- fillComputersAdapter();
- showComputersList();
+
+ setListAdapter(null);
+ } else {
+ if (getComputersAdapter() == null) {
+ setListAdapter(new ComputersAdapter(getActivity()));
+ }
+
+ getComputersAdapter().clear();
+ getComputersAdapter().add(computerList);
+
+ setCurrentView(android.R.id.list);
}
}
@@ -224,10 +206,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
}
}
- private void hideComputersList() {
- setCurrentView(R.id.layout_progress);
- }
-
private void setCurrentView(int aViewId) {
ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator);
View aView = getView().findViewById(aViewId);
@@ -261,35 +239,10 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
return getProgressMessageView().getVisibility() == View.INVISIBLE;
}
- private void tearDownComputersAdapter() {
- setListAdapter(null);
- }
-
- private void setUpComputersAdapter() {
- if (isComputersAdapterExist()) {
- return;
- }
-
- setListAdapter(new ComputersAdapter(getActivity()));
- }
-
- private boolean isComputersAdapterExist() {
- return getComputersAdapter() != null;
- }
-
private ComputersAdapter getComputersAdapter() {
return (ComputersAdapter) getListAdapter();
}
- private void fillComputersAdapter() {
- getComputersAdapter().clear();
- getComputersAdapter().add(getComputers());
- }
-
- private void showComputersList() {
- setCurrentView(android.R.id.list);
- }
-
@Override
public void onServiceDisconnected(ComponentName aComponentName) {
mCommunicationService = null;
@@ -302,7 +255,7 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
registerIntentsReceiver();
setUpContextMenu();
- if (!isServiceBound()) {
+ if (mCommunicationService == null) {
return;
}
@@ -312,7 +265,8 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
private void registerIntentsReceiver() {
mIntentsReceiver = new IntentsReceiver(this);
- IntentFilter aIntentFilter = buildIntentsReceiverFilter();
+ IntentFilter aIntentFilter = new IntentFilter();
+ aIntentFilter.addAction(Intents.Actions.SERVERS_LIST_CHANGED);
getBroadcastManager().registerReceiver(mIntentsReceiver, aIntentFilter);
}
@@ -332,13 +286,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
}
}
- private IntentFilter buildIntentsReceiverFilter() {
- IntentFilter aIntentFilter = new IntentFilter();
- aIntentFilter.addAction(Intents.Actions.SERVERS_LIST_CHANGED);
-
- return aIntentFilter;
- }
-
private LocalBroadcastManager getBroadcastManager() {
Context aContext = getActivity().getApplicationContext();
@@ -390,10 +337,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(aIntent);
}
- private boolean isServiceBound() {
- return mCommunicationService != null;
- }
-
@Override
public boolean onOptionsItemSelected(MenuItem aMenuItem) {
switch (aMenuItem.getItemId()) {
@@ -451,20 +394,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onStop() {
super.onStop();
- stopComputersSearch();
-
- unregisterIntentsReceiver();
- }
-
- private void stopComputersSearch() {
- if (!isServiceBound()) {
- return;
- }
-
- mCommunicationService.stopServersSearch();
- }
-
- private void unregisterIntentsReceiver() {
try {
getBroadcastManager().unregisterReceiver(mIntentsReceiver);
} catch (IllegalArgumentException e) {
@@ -477,10 +406,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onSaveInstanceState(Bundle aOutState) {
super.onSaveInstanceState(aOutState);
- saveProgressMessage(aOutState);
- }
-
- private void saveProgressMessage(Bundle aOutState) {
boolean aProgressMessageDisplayed = !TextUtils.isEmpty(getProgressMessageView().getText().toString());
aOutState.putBoolean(SavedStates.Keys.PROGRESS_MESSAGE, aProgressMessageDisplayed);
@@ -490,10 +415,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
public void onDestroy() {
super.onDestroy();
- unbindService();
- }
-
- private void unbindService() {
getActivity().unbindService(this);
}
}
commit 17e7bc358faab29ddb524d478f6b5ca2fed1a5f8
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date: Thu Jan 16 15:38:38 2014 +0000
Revert "fdo#60486 Fix auto-enabling bluetooth and improve bluetooth handling."
This will be superceded by the following sdremote improvments, which
would otherwise have path conflicts due to this patch.
This reverts commit 3cc31f89787e435c893b38a0adc0a23f566ab60f.
Change-Id: I49f004d068fdf852f5690e365a17168b001b9136
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 7dc068a..4ec816a 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -90,6 +90,5 @@
<string name="requirements_network_connection">The Android device and a computer connected to the same network.</string>
<string name="requirements_network_ports">If you have a firewall make sure ports 1598 and 1599 are opened.</string>
<string name="requirements_bluetooth_connection">A computer with enabled Bluetooth.</string>
- <string name="message_bluetooth_disabled">Please enable bluetooth to connect to a bluetooth enabled computer.</string>
</resources>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index ad7c9db..f75d197 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -31,8 +31,6 @@ import org.libreoffice.impressremote.util.SavedStates;
public class ComputersActivity extends ActionBarActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
private boolean mBluetoothWasEnabled;
- private final static int REQUEST_ENABLE_BT = 1;
-
@Override
protected void onCreate(Bundle aSavedInstanceState) {
super.onCreate(aSavedInstanceState);
@@ -44,16 +42,6 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
setUpContent();
}
- @Override
- protected void onActivityResult(int arg0, int arg1, Intent arg2) {
- super.onActivityResult(arg0, arg1, arg2);
-
- if (arg0 == REQUEST_ENABLE_BT) {
- // Ideally we should do all detection based on listening to the bluetooth state
- // as the user can still enable BT separately (see BluetoothServersFinder.java:onReceive)
- }
- }
-
private void saveBluetoothState(Bundle aSavedInstanceState) {
// In more ideal world this work should be done at the service.
// Unfortunately service cannot save or restore its state.
@@ -76,7 +64,7 @@ public class ComputersActivity extends ActionBarActivity implements ActionBar.Ta
}
private void enableBluetooth() {
- BluetoothOperator.enable(this, REQUEST_ENABLE_BT);
+ BluetoothOperator.enable();
}
private void setUpTitle() {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
index e696a1b..29e9b9c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothServersFinder.java
@@ -72,19 +72,9 @@ class BluetoothServersFinder extends BroadcastReceiver implements ServersFinder,
public void onReceive(Context aContext, Intent aIntent) {
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(aIntent.getAction())) {
switch (aIntent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0)) {
- case BluetoothAdapter.STATE_ON: {
+ case BluetoothAdapter.STATE_ON:
BluetoothOperator.getAdapter().startDiscovery();
- Intent aNewIntent = Intents.buildBluetoothStateChangedIntent();
- LocalBroadcastManager.getInstance(mContext).sendBroadcast(aNewIntent);
return;
- }
-
- case BluetoothAdapter.STATE_OFF: {
- mServers.clear();
- Intent aNewIntent = Intents.buildBluetoothStateChangedIntent();
- LocalBroadcastManager.getInstance(mContext).sendBroadcast(aNewIntent);
- return;
- }
default:
return;
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index 4e013c8..bd80f6c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -13,7 +13,6 @@ 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;
@@ -54,8 +53,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
WIFI, BLUETOOTH
}
- boolean mBluetoothDisabled = false;
-
private CommunicationService mCommunicationService;
private BroadcastReceiver mIntentsReceiver;
@@ -149,10 +146,7 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
return getString(R.string.message_search_wifi);
case BLUETOOTH:
- if (mBluetoothDisabled != true)
- return getString(R.string.message_search_bluetooth);
- else
- return getString(R.string.message_bluetooth_disabled);
+ return getString(R.string.message_search_bluetooth);
default:
return "";
@@ -214,8 +208,6 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
}
}
- mBluetoothDisabled = !BluetoothAdapter.getDefaultAdapter().isEnabled();
-
return aComputers;
}
@@ -257,10 +249,18 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
return;
}
+ if (!isShowingProgressMessageRequired()) {
+ return;
+ }
+
showProgressMessage();
showLearnMoreMessage();
}
+ private boolean isShowingProgressMessageRequired() {
+ return getProgressMessageView().getVisibility() == View.INVISIBLE;
+ }
+
private void tearDownComputersAdapter() {
setListAdapter(null);
}
@@ -328,8 +328,6 @@ 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.BLUETOOTH_STATE_CHANGED.equals(aIntent.getAction())) {
- mComputersFragment.loadComputers();
}
}
}
@@ -337,7 +335,7 @@ public class ComputersFragment extends ListFragment implements ServiceConnection
private IntentFilter buildIntentsReceiverFilter() {
IntentFilter aIntentFilter = new IntentFilter();
aIntentFilter.addAction(Intents.Actions.SERVERS_LIST_CHANGED);
- aIntentFilter.addAction(Intents.Actions.BLUETOOTH_STATE_CHANGED);
+
return aIntentFilter;
}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
index c451518..9522838 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/BluetoothOperator.java
@@ -8,9 +8,7 @@
*/
package org.libreoffice.impressremote.util;
-import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
-import android.content.Intent;
public final class BluetoothOperator {
private BluetoothOperator() {
@@ -28,16 +26,12 @@ public final class BluetoothOperator {
return BluetoothAdapter.getDefaultAdapter();
}
- public static void enable(Activity aActivity, int nRequestCode) {
+ public static void enable() {
if (!isAvailable()) {
return;
}
- if (getAdapter() != null) {
- Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
- aActivity.startActivityForResult(enableBtIntent, nRequestCode);
- }
-
+ getAdapter().enable();
}
public static void disable() {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
index e27f2f1..beab7ae 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Intents.java
@@ -29,7 +29,6 @@ public final class Intents {
}
public static final String SERVERS_LIST_CHANGED = "SERVERS_LIST_CHANGED";
- public static final String BLUETOOTH_STATE_CHANGED = "BLUETOOTH_STATE_CHANGED";
public static final String PAIRING_SUCCESSFUL = "PAIRING_SUCCESSFUL";
public static final String PAIRING_VALIDATION = "PAIRING_VALIDATION";
@@ -75,10 +74,6 @@ public final class Intents {
return new Intent(Actions.SERVERS_LIST_CHANGED);
}
- public static Intent buildBluetoothStateChangedIntent() {
- return new Intent(Actions.BLUETOOTH_STATE_CHANGED);
- }
-
public static Intent buildPairingSuccessfulIntent() {
return new Intent(Actions.PAIRING_SUCCESSFUL);
}
More information about the Libreoffice-commits
mailing list