Kaydet (Commit) e29c020e authored tarafından Andrzej J.R. Hunt's avatar Andrzej J.R. Hunt

Manual IP adding implemented.

Change-Id: Ifad2a206e3ddbb46094be6638581358484522695
üst e4b0ce88
......@@ -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" />
......
<?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
<?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
......@@ -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
......@@ -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
......@@ -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 {
......@@ -68,6 +76,73 @@ public class SelectorActivity extends SherlockActivity {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mListener);
}
@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();
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment