[Libreoffice-commits] .: android/sdremote

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Aug 23 06:07:51 PDT 2012


 android/sdremote/AndroidManifest.xml                                                       |    4 
 android/sdremote/res/layout/dialog_addserver.xml                                           |   46 ++++++
 android/sdremote/res/menu/selector_activity.xml                                            |    6 
 android/sdremote/res/values/strings.xml                                                    |    6 
 android/sdremote/res/values/styles.xml                                                     |    3 
 android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java                   |   75 ++++++++++
 android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java |   52 ++++++
 7 files changed, 191 insertions(+), 1 deletion(-)

New commits:
commit e29c020ee25fb820f4ae49c5f8d1e3df38aa76da
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Thu Aug 23 15:06:22 2012 +0200

    Manual IP adding implemented.
    
    Change-Id: Ifad2a206e3ddbb46094be6638581358484522695

diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml
index b21ce6a..6572366 100644
--- a/android/sdremote/AndroidManifest.xml
+++ b/android/sdremote/AndroidManifest.xml
@@ -15,7 +15,9 @@
     <application
         android:label="@string/app_name"
         android:theme="@style/Theme.ImpressRemote" >
-        <activity android:name=".SelectorActivity" >
+        <activity
+            android:name=".SelectorActivity"
+            android:uiOptions="splitActionBarWhenNarrow" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
diff --git a/android/sdremote/res/layout/dialog_addserver.xml b/android/sdremote/res/layout/dialog_addserver.xml
new file mode 100644
index 0000000..01ddba2
--- /dev/null
+++ b/android/sdremote/res/layout/dialog_addserver.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/addserver_root"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical" >
+
+    <TextView
+        android:id="@+id/addserver_namelabel"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/addserver_entername" />
+
+    <EditText
+        android:id="@+id/addserver_nameentry"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:ems="10"
+        android:inputType="textCapWords" >
+
+        <requestFocus />
+    </EditText>
+
+    <TextView
+        android:id="@+id/addserver_addressabel"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/addserver_enteraddress" />
+
+    <EditText
+        android:id="@+id/addserver_addressentry"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:ems="10"
+        android:inputType="textUri" >
+
+    </EditText>
+
+    <CheckBox
+        android:id="@+id/addserver_remember"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:checked="true"
+        android:text="@string/addserver_remember" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/android/sdremote/res/menu/selector_activity.xml b/android/sdremote/res/menu/selector_activity.xml
new file mode 100644
index 0000000..dab6e20
--- /dev/null
+++ b/android/sdremote/res/menu/selector_activity.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+    <item android:id="@+id/menu_selector_addServer" android:title="@string/addserver" android:showAsAction="always"></item>
+
+
+</menu>
\ No newline at end of file
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 6ede30d..fb1ac80 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -32,5 +32,11 @@
     <string name="about_close">Close</string>
     <string name="about_versionstring">Version: {0} (Build ID: {1})</string>
     <string name="about_copyright">Copyright \u00A9 2012 LibreOffice Contributors and/or their affiliates.</string>
+    <string name="addserver">Add Server</string>
+    <string name="addserver_entername">Server name:</string>
+    <string name="addserver_enteraddress">Server address as IP or hostname:</string>
+    <string name="addserver_remember">Remember this server next time</string>
+    <string name="addserver_add">Add</string>
+    <string name="addserver_cancel">Cancel</string>
 
 </resources>
\ No newline at end of file
diff --git a/android/sdremote/res/values/styles.xml b/android/sdremote/res/values/styles.xml
index de47193..73d2209 100644
--- a/android/sdremote/res/values/styles.xml
+++ b/android/sdremote/res/values/styles.xml
@@ -24,6 +24,8 @@
         <item name="background">@color/orange</item>
         <item name="android:titleTextStyle">@style/Theme.ImpressRemote.ActionBar.Title</item>
         <item name="titleTextStyle">@style/Theme.ImpressRemote.ActionBar.Title</item>
+        <item name="backgroundSplit">@color/text_grey</item>
+    <item name="android:backgroundSplit">@color/text_grey</item>
     </style>
 
     <style name="Theme.ImpressRemote.ActionBarWidget" parent="android:style/Widget.Holo.Light">
@@ -54,6 +56,7 @@
         <item name="android:windowBackground">@color/light_grey</item>
         <item name="android:homeAsUpIndicator">@drawable/up_indicator_white</item>
         <item name="android:textColor">@color/text_grey</item>
+
     </style>
 
 </resources>
\ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
index 5c83e5a..0de5b01 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
@@ -16,21 +16,29 @@ import org.libreoffice.impressremote.communication.CommunicationService;
 import org.libreoffice.impressremote.communication.Server;
 import org.libreoffice.impressremote.communication.Server.Protocol;
 
+import android.app.AlertDialog;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.ServiceConnection;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.support.v4.content.LocalBroadcastManager;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.widget.CheckBox;
+import android.widget.EditText;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.actionbarsherlock.app.SherlockActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
 
 public class SelectorActivity extends SherlockActivity {
 
@@ -69,6 +77,73 @@ public class SelectorActivity extends SherlockActivity {
     }
 
     @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        MenuInflater inflater = getSupportMenuInflater();
+        inflater.inflate(R.menu.selector_activity, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+        case R.id.menu_selector_addServer:
+
+            AlertDialog.Builder builder;
+            AlertDialog alertDialog;
+
+            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
+            final View layout = inflater.inflate(R.layout.dialog_addserver,
+                            null);
+
+            //            TextView text = (TextView) layout.findViewById(R.id.text);
+            //            text.setText("Hello, this is a custom dialog!");
+            //            ImageView image = (ImageView) layout.findViewById(R.id.image);
+            //            image.setImageResource(R.drawable.android);
+
+            builder = new AlertDialog.Builder(this);
+            builder.setView(layout);
+            builder.setTitle(R.string.addserver);
+            builder.setPositiveButton(R.string.addserver_add,
+                            new DialogInterface.OnClickListener() {
+                                @Override
+                                public void onClick(DialogInterface dialog,
+                                                int which) {
+                                    EditText aAddressEntry = (EditText) layout
+                                                    .findViewById(R.id.addserver_addressentry);
+                                    EditText aNameEntry = (EditText) layout
+                                                    .findViewById(R.id.addserver_nameentry);
+                                    CheckBox aRememberServer = (CheckBox) layout
+                                                    .findViewById(R.id.addserver_remember);
+                                    mCommunicationService
+                                                    .addServer(aAddressEntry
+                                                                    .getText()
+                                                                    .toString(),
+                                                                    aNameEntry.getText()
+                                                                                    .toString(),
+                                                                    aRememberServer.isChecked());
+                                    refreshLists();
+                                }
+                            });
+            builder.setNegativeButton(R.string.addserver_cancel, null);
+            alertDialog = builder.create();
+            alertDialog.show();
+
+            //            Context mContext = getApplicationContext();
+            //            Dialog dialog = new Dialog(mContext);
+            //
+            //            dialog.setContentView(R.layout.dialog_addserver);
+            //            dialog.setTitle(R.string.addserver);
+
+            //            TextView text = (TextView) dialog.findViewById(R.id.text);
+            //            text.setText("Hello, this is a custom dialog!");
+            //            ImageView image = (ImageView) dialog.findViewById(R.id.image);
+            //            image.setImageResource(R.drawable.android);
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
     public void onBackPressed() {
         mCommunicationService.stopSearching();
         Intent aIntent = new Intent(this, CommunicationService.class);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 3b6334f..bafef5e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -9,10 +9,17 @@
 package org.libreoffice.impressremote.communication;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.libreoffice.impressremote.communication.Server.Protocol;
 
 import android.app.Service;
 import android.bluetooth.BluetoothAdapter;
 import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
 import android.os.Binder;
 import android.os.IBinder;
 
@@ -173,6 +180,8 @@ public class CommunicationService extends Service implements Runnable {
     @Override
     public void onCreate() {
         // TODO Create a notification (if configured).
+        loadServersFromPreferences();
+
         mThread = new Thread(this);
         mThread.start();
     }
@@ -180,6 +189,8 @@ public class CommunicationService extends Service implements Runnable {
     @Override
     public void onDestroy() {
         // TODO Destroy the notification (as necessary).
+        mManualServers.clear();
+
         mThread.interrupt();
         mThread = null;
     }
@@ -192,6 +203,7 @@ public class CommunicationService extends Service implements Runnable {
         ArrayList<Server> aServers = new ArrayList<Server>();
         aServers.addAll(mNetworkFinder.getServerList());
         aServers.addAll(mBluetoothFinder.getServerList());
+        aServers.addAll(mManualServers.values());
         return aServers.toArray(new Server[aServers.size()]);
     }
 
@@ -203,5 +215,45 @@ public class CommunicationService extends Service implements Runnable {
         return mReceiver.isSlideShowRunning();
     }
 
+    /**
+     * Manually add a new (network) server to the list of servers.
+     * @param aAddress
+     * @param aRemember
+     */
+    public void addServer(String aAddress, String aName, boolean aRemember) {
+        for (String aServer : mManualServers.keySet()) {
+            if (aServer.equals(aAddress))
+                return;
+        }
+        mManualServers.put(aAddress, new Server(Protocol.NETWORK, aAddress,
+                        aName, 0));
+        if (aRemember) {
+            SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
+                            MODE_PRIVATE);
+            Editor aEditor = aPref.edit();
+            aEditor.putString(aAddress, aName);
+            aEditor.apply();
+        }
+    }
+
+    /**
+     * Key to use with getSharedPreferences to obtain a Map of stored servers.
+     * The keys are the ip/hostnames, the values are the friendly names.
+     */
+    private static final String SERVERSTORAGE_KEY = "sdremote_storedServers";
+    private HashMap<String, Server> mManualServers = new HashMap<String, Server>();
+
+    void loadServersFromPreferences() {
+        SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
+                        MODE_PRIVATE);
+
+        Map<String, String> aStoredMap = (Map<String, String>) aPref.getAll();
+
+        for (Entry<String, String> aServerEntry : aStoredMap.entrySet()) {
+            mManualServers.put(aServerEntry.getKey(), new Server(
+                            Protocol.NETWORK, aServerEntry.getKey(),
+                            aServerEntry.getValue(), 0));
+        }
+    }
 }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file


More information about the Libreoffice-commits mailing list