[Libreoffice-commits] core.git: 3 commits - android/sdremote
Artur Dryomov
artur.dryomov at gmail.com
Thu Aug 1 17:51:36 PDT 2013
android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java | 47 +++++++-
android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java | 56 +++++++---
android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java | 18 ++-
3 files changed, 101 insertions(+), 20 deletions(-)
New commits:
commit 429148c5f10828c50ae41309942f4946b12a7df9
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date: Fri Aug 2 03:41:52 2013 +0300
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
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 8054b89..56b87e7 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:
commit fa484c3b00a70ef00996f9bb694ac88da81cc91b
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date: Fri Aug 2 03:08:48 2013 +0300
Fix possible pin-related bug.
The latest LO release does not allow entering PIN-codes without leading
zero. This change should solve possible issues from client-side.
Change-Id: Ie2f2db9baa5d677cbbed772497d32668cdd5748f
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
index daaeac7..505cdd6 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
@@ -18,21 +18,6 @@ final class Protocol {
public static final String CHARSET = "UTF-8";
- public static final class Pin {
- private Pin() {
- }
-
- private static final int NUMBERS_COUNT = 4;
-
- public static String generate() {
- Random aRandomGenerator = new Random();
- int aMaximumPin = (int) Math.pow(10, NUMBERS_COUNT) - 1;
- int aPinNumber = aRandomGenerator.nextInt(aMaximumPin);
-
- return String.format("%04d", aPinNumber);
- }
- }
-
public static final class Ports {
private Ports() {
}
@@ -91,6 +76,47 @@ final class Protocol {
return prepareCommand(aCommand);
}
}
+
+ public static final class Pin {
+ private static final int NUMBERS_COUNT = 4;
+
+ private Pin() {
+ }
+
+ public static String generate() {
+ return new Pin().generatePinText();
+ }
+
+ private String generatePinText() {
+ int aPin = preventLeadingZeros(generatePinNumber());
+
+ return String.format(buildPinFormat(), aPin);
+ }
+
+ private int generatePinNumber() {
+ int aMaximumPin = (int) Math.pow(10, NUMBERS_COUNT) - 1;
+
+ return new Random().nextInt(aMaximumPin);
+ }
+
+ private int preventLeadingZeros(int aPin) {
+ // Pin cannot have leading zeros.
+ // LibreOffice Impress doesnât allow to enter leading zeros.
+ // Bug exists at least at LibreOffice 4.1.
+
+ int aMinimumPin = (int) Math.pow(10, NUMBERS_COUNT - 1);
+
+ if (aPin >= aMinimumPin) {
+ return aPin;
+ }
+
+ return aPin + aMinimumPin;
+ }
+
+ private String buildPinFormat() {
+ return String.format("%%0%sd", Integer.toString(NUMBERS_COUNT));
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d3cef7ed759d8e30f795c3346b5d71d428246c00
Author: Artur Dryomov <artur.dryomov at gmail.com>
Date: Fri Aug 2 00:08:08 2013 +0300
Add servers sorting.
Change-Id: Idd3d39fcf91fba6d5f7b0615d241f6ad9f46bd5f
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
index 388f48c..337c05c 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
@@ -9,6 +9,8 @@
package org.libreoffice.impressremote.communication;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
@@ -19,7 +21,7 @@ import android.content.Context;
import org.libreoffice.impressremote.util.Preferences;
-class ServersManager {
+class ServersManager implements Comparator<Server> {
private final Context mContext;
private final ServersFinder mBluetoothServersFinder;
@@ -53,7 +55,11 @@ class ServersManager {
aServers.addAll(mTcpServersFinder.getServers());
aServers.addAll(getManualAddedTcpServers());
- return filterBlacklistedServers(aServers);
+ aServers = filterBlacklistedServers(aServers);
+
+ Collections.sort(aServers, this);
+
+ return aServers;
}
private List<Server> getManualAddedTcpServers() {
@@ -89,6 +95,14 @@ class ServersManager {
return aFilteredServers;
}
+ @Override
+ public int compare(Server aFirstServer, Server aSecondServer) {
+ String aFirstServerName = aFirstServer.getName();
+ String aSecondServerName = aSecondServer.getName();
+
+ return aFirstServerName.compareToIgnoreCase(aSecondServerName);
+ }
+
public void addTcpServer(String aAddress, String aName) {
Preferences.set(mContext, Preferences.Locations.STORED_SERVERS,
aAddress, aName);
More information about the Libreoffice-commits
mailing list