diff --git a/DroneAppController/app/app.iml b/DroneAppController/app/app.iml
index f704996..2731357 100644
--- a/DroneAppController/app/app.iml
+++ b/DroneAppController/app/app.iml
@@ -84,6 +84,7 @@
+
diff --git a/DroneAppController/app/libs/asmack-2010.05.07.jar b/DroneAppController/app/libs/asmack-2010.05.07.jar
new file mode 100644
index 0000000..69ce0db
Binary files /dev/null and b/DroneAppController/app/libs/asmack-2010.05.07.jar differ
diff --git a/DroneAppController/app/libs/smack.jar b/DroneAppController/app/libs/smack.jar
deleted file mode 100644
index b957edf..0000000
Binary files a/DroneAppController/app/libs/smack.jar and /dev/null differ
diff --git a/DroneAppController/app/src/main/AndroidManifest.xml b/DroneAppController/app/src/main/AndroidManifest.xml
index a3276ba..1c28655 100644
--- a/DroneAppController/app/src/main/AndroidManifest.xml
+++ b/DroneAppController/app/src/main/AndroidManifest.xml
@@ -1,7 +1,7 @@
-
+
@@ -24,13 +24,17 @@
android:label="@string/title_activity_register" >
+
+
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/CalibrationActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/CalibrationActivity.java
index 3691751..117811a 100644
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/CalibrationActivity.java
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/CalibrationActivity.java
@@ -6,6 +6,9 @@ import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
+/**
+ * Created by almeida on 23-12-2014.
+ */
public class CalibrationActivity extends Activity {
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ClientXMPP.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ClientXMPP.java
deleted file mode 100644
index 091bfee..0000000
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ClientXMPP.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package pt.isep.mei.simov.droneappcontroller;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.util.Log;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ListView;
-import org.jivesoftware.smack.PacketListener;
-import org.jivesoftware.smack.XMPPConnection;
-import org.jivesoftware.smack.filter.MessageTypeFilter;
-import org.jivesoftware.smack.filter.PacketFilter;
-import org.jivesoftware.smack.packet.Message;
-import org.jivesoftware.smack.packet.Packet;
-import org.jivesoftware.smack.util.StringUtils;
-
-import java.util.ArrayList;
-/**
- * Created by almeida on 19-12-2014.
- */
-public class ClientXMPP {
-
- public class XMPPClient extends Activity {
-
- private ArrayList messages = new ArrayList();
- private Handler mHandler = new Handler();
- private SettingsDialog mDialog;
- private EditText mRecipient;
- private EditText mSendText;
- private ListView mList;
- private XMPPConnection connection;
-
- /**
- * Called with the activity is first created.
- */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- Log.i("XMPPClient", "onCreate called");
- setContentView(R.layout.main);
-
- mRecipient = (EditText) this.findViewById(R.id.recipient);
- Log.i("XMPPClient", "mRecipient = " + mRecipient);
- mSendText = (EditText) this.findViewById(R.id.sendText);
- Log.i("XMPPClient", "mSendText = " + mSendText);
- mList = (ListView) this.findViewById(R.id.listMessages);
- Log.i("XMPPClient", "mList = " + mList);
- setListAdapter();
-
- // Dialog for getting the xmpp settings
- mDialog = new SettingsDialog(this);
-
- // Set a listener to show the settings dialog
- Button setup = (Button) this.findViewById(R.id.setup);
- setup.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- mHandler.post(new Runnable() {
- public void run() {
- mDialog.show();
- }
- });
- }
- });
-
- // Set a listener to send a chat text message
- Button send = (Button) this.findViewById(R.id.send);
- send.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- String to = mRecipient.getText().toString();
- String text = mSendText.getText().toString();
-
- Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
- Message msg = new Message(to, Message.Type.chat);
- msg.setBody(text);
- connection.sendPacket(msg);
- messages.add(connection.getUser() + ":");
- messages.add(text);
- setListAdapter();
- }
- });
- }
-
- /**
- * Called by Settings dialog when a connection is establised with the XMPP server
- *
- * @param connection
- */
- public void setConnection
- (XMPPConnection
- connection) {
- this.connection = connection;
- if (connection != null) {
- // Add a packet listener to get messages sent to us
- PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
- connection.addPacketListener(new PacketListener() {
- public void processPacket(Packet packet) {
- Message message = (Message) packet;
- if (message.getBody() != null) {
- String fromName = StringUtils.parseBareAddress(message.getFrom());
- Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
- messages.add(fromName + ":");
- messages.add(message.getBody());
- // Add the incoming message to the list view
- mHandler.post(new Runnable() {
- public void run() {
- setListAdapter();
- }
- });
- }
- }
- }, filter);
- }
- }
-
- private void setListAdapter
- () {
- ArrayAdapter adapter = new ArrayAdapter(this,
- R.layout.multi_line_list_item,
- messages);
- mList.setAdapter(adapter);
- }
- }
-
-}
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/Connection.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/Connection.java
new file mode 100644
index 0000000..cdfb6f1
--- /dev/null
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/Connection.java
@@ -0,0 +1,126 @@
+package pt.isep.mei.simov.droneappcontroller;
+
+import android.util.Log;
+import android.widget.Toast;
+
+import org.jivesoftware.smack.AccountManager;
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.Roster;
+import org.jivesoftware.smack.RosterEntry;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.Presence;
+import java.lang.InterruptedException;
+import java.lang.Runnable;
+import java.lang.String;
+import java.lang.System;
+import java.lang.Thread;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * Created by almeida on 23-12-2014.
+ */
+public class Connection {
+ String HOST = "aalmeid.ddns.net";
+ int PORT = 5222;
+ String SERVICE = "xmppserver";
+ String USERNAME = "";
+ String PASSWORD = "";
+
+ static XMPPConnection connection;
+ final ArrayList usersList = new ArrayList<>();
+
+ public Connection(String user, String password) {
+ this.USERNAME = user;
+ this.PASSWORD = password;
+ setConnection();
+ }
+
+ private void setConnection() {
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Create a connection
+ ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT, SERVICE);
+ connection = new XMPPConnection(connConfig);
+ try {
+ connection.connect();
+ Log.i("XMPP", "[SettingsDialog] Connected to " + connection.getHost());
+ } catch (XMPPException ex) {
+ Log.e("XMPP", "[SettingsDialog] Failed to connect to " + connection.getHost());
+ Log.e("XMPP", ex.toString());
+ }
+ try {
+ connection.login(USERNAME, PASSWORD);
+ Log.i("XMPP", "Logged in as " + connection.getUser());
+
+ // Set the status to available
+ Presence presence = new Presence(Presence.Type.available);
+ connection.sendPacket(presence);
+
+ Roster roster = connection.getRoster();
+ Collection entries = roster.getEntries();
+
+ for (final RosterEntry entry : entries) {
+
+ Log.d("XMPP", "--------------------------------------");
+ Log.d("XMPP", "RosterEntry " + entry);
+ Log.d("XMPP", "User: " + entry.getUser());
+
+ Log.d("XMPP", "Name: " + entry.getName());
+ Log.d("XMPP", "Status: " + entry.getStatus());
+ Log.d("XMPP", "Type: " + entry.getType());
+ Presence entryPresence = roster.getPresence(entry.getUser());
+ Log.d("XMPP", "Presence Status: " + entryPresence.getStatus());
+ Log.d("XMPP", "Presence Type: " + entryPresence.getType());
+
+ Presence.Type type = entryPresence.getType();
+ if (type == Presence.Type.available)
+ Log.d("XMPP", "Presence AVIALABLE");
+ Log.d("XMPP", "Presence : " + entryPresence);
+
+ usersList.add(entry.getUser());
+ }
+
+ latch.countDown();
+
+ } catch (XMPPException ex) {
+ Log.e("XMPP", "Failed to log in as " + USERNAME);
+ Log.e("XMPP", ex.toString());
+ }
+ }
+ });
+ t.start();
+
+ try{
+ latch.await();
+ }catch(InterruptedException e){
+ Log.e("Error","got interrupted!",e);
+ }
+ }
+
+ public boolean createAccount (String username, String password){
+ try {
+ AccountManager accountManager = connection.getAccountManager();
+ accountManager.createAccount(username, password);
+ connection.disconnect();
+ return true;
+ }catch (Exception e){
+ Log.e("Error","problem with create account", e);
+ return false;
+ }
+ }
+
+ public ArrayList getUsers(){
+ return usersList;
+ }
+
+ public static XMPPConnection getConnection(){
+ return connection;
+ }
+}
\ No newline at end of file
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ControllerActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ControllerActivity.java
new file mode 100644
index 0000000..402074e
--- /dev/null
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ControllerActivity.java
@@ -0,0 +1,218 @@
+package pt.isep.mei.simov.droneappcontroller;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
+import android.widget.Toast;
+
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.filter.MessageTypeFilter;
+import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.util.StringUtils;
+
+import java.util.ArrayList;
+
+/**
+ * Created by almeida on 18-12-2014.
+ */
+
+public class ControllerActivity extends Activity {
+ private String to;
+ private XMPPConnection connection = Connection.getConnection();
+ private ArrayList messages = new ArrayList();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_controller);
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+
+ Button left = (Button) findViewById(R.id.buttonLeft);
+ Button right = (Button) findViewById(R.id.buttonRight);
+ Button up = (Button) findViewById(R.id.buttonUp);
+ Button down = (Button) findViewById(R.id.buttonDown);
+ Button acelerate = (Button) findViewById(R.id.buttonAcelerate);
+ Button breake = (Button) findViewById(R.id.buttonBreak);
+ Button on_off = (Button) findViewById(R.id.buttonOnOff);
+ Button calibration = (Button) findViewById(R.id.buttonCallibration);
+
+ Bundle b = getIntent().getExtras();
+ to = b.getString("to");
+
+ setConnection(connection);
+
+ left.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "left pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("left");
+ }
+ });
+
+ right.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "right pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("rigth");
+ }
+ });
+
+ up.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "up pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("up");
+ }
+ });
+
+ down.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "down pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("down");
+ }
+ });
+
+ acelerate.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "acelerate pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("acelerate");
+ }
+ });
+
+ breake.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "break pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("break");
+ }
+ });
+
+ on_off.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Toast.makeText(getApplicationContext(), "on_off pressed!",
+ Toast.LENGTH_LONG).show();
+
+ senMessage("On/Off");
+ }
+ });
+
+ calibration.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(v.getContext());
+
+ // set title
+ alertDialogBuilder.setTitle("Expert Mode");
+
+ // set dialog message
+ alertDialogBuilder
+ .setMessage("Atention: Expert Mode")
+ .setCancelable(false)
+ .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,int id) {
+ // if this button is clicked, close
+ // current activity
+ Intent i = new Intent(getApplicationContext(), CalibrationActivity.class);
+ startActivity(i);
+ }
+ })
+ .setNegativeButton("No",new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,int id) {
+ // if this button is clicked, just close
+ // the dialog box and do nothing
+ dialog.cancel();
+ }
+ });
+
+ // create alert dialog
+ AlertDialog alertDialog = alertDialogBuilder.create();
+
+ // show it
+ alertDialog.show();
+
+ }
+ });
+ }
+
+ public void senMessage(String message) {
+ Message msg = new Message(to, Message.Type.chat);
+
+ msg.setBody(message);
+ if (connection != null) {
+ connection.sendPacket(msg);
+ messages.add(connection.getUser() + ":");
+ messages.add(message);
+ }
+ }
+
+ public void setConnection(XMPPConnection connection) {
+ this.connection = connection;
+
+ System.out.println ("connection"+connection);
+ if (connection != null) {
+ // Add a packet listener to get messages sent to us
+ PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
+ connection.addPacketListener(new PacketListener() {
+ @Override
+ public void processPacket(Packet packet) {
+ Message message = (Message) packet;
+ if (message.getBody() != null) {
+ String fromName = StringUtils.parseBareAddress(message.getFrom());
+ Log.i("XMPPChatDemoActivity ", " Text Recieved " + message.getBody() + " from " + fromName);
+ messages.add(fromName + ":");
+ messages.add(message.getBody());
+ }
+ }
+ }, filter);
+ }
+ }
+
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ListOfDrones.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ListOfDrones.java
new file mode 100644
index 0000000..f5ad37c
--- /dev/null
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ListOfDrones.java
@@ -0,0 +1,64 @@
+package pt.isep.mei.simov.droneappcontroller;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import org.jivesoftware.smack.XMPPConnection;
+
+import java.util.ArrayList;
+
+/**
+ * Created by almeida on 18-12-2014.
+ */
+
+
+public class ListOfDrones extends Activity {
+
+ private XMPPConnection connection;
+
+ private ListView listView ;
+ private ArrayAdapter listAdapter ;
+ private ArrayList users;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_list_of_drone);
+
+ Bundle b = getIntent().getExtras();
+ String user = b.getString("id");
+ String passwd = b.getString("passwd");
+
+ Connection c = new Connection(user,passwd);
+ users = c.getUsers();
+ connection = c.getConnection();
+
+
+ listView = (ListView) findViewById( R.id.listOfDrones );
+ listAdapter = new ArrayAdapter(getApplicationContext(), R.layout.simplerow);
+ listView.setAdapter( listAdapter );
+
+ for (int i = 0; i < users.size(); i++){
+ listAdapter.add(users.get(i).toString());
+ }
+
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ Intent i = new Intent(getApplicationContext(), ControllerActivity.class);
+ i.putExtra("to", listAdapter.getItem(position));
+ startActivity(i);
+ }
+ });
+ }
+}
+
+
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java
index 4c1da4f..2da1e78 100644
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java
@@ -1,41 +1,23 @@
package pt.isep.mei.simov.droneappcontroller;
import android.os.Bundle;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
import android.app.Activity;
-import android.app.ProgressDialog;
+
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.os.AsyncTask;
-import android.os.Bundle;
import android.util.Log;
import android.view.View;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
+/**
+ * Created by almeida on 18-12-2014.
+ */
+
public class LoginActivity extends Activity {
- private static final String SERVICE_URL = "link aqui";
String email;
String passwd;
@@ -43,15 +25,6 @@ public class LoginActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
-
- Button register = (Button) findViewById(R.id.btnRegister);
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(getApplicationContext(), RegisterActivity.class);
- startActivity(intent);
- }
- });
}
public void postData(View vw) {
@@ -61,6 +34,8 @@ public class LoginActivity extends Activity {
email = edEmail.getText().toString();
passwd = edPasswd.getText().toString();
+ Log.i("XMPP", "Credencials: " + email + " and " + passwd);
+
if (email.equals("") || passwd.equals("")) {
Toast.makeText(this, "Por favor preencha os campos de autenticação",
Toast.LENGTH_LONG).show();
@@ -70,210 +45,19 @@ public class LoginActivity extends Activity {
if (!(networkInfo != null && networkInfo.isConnected()))
{
- Toast.makeText(getApplicationContext(), "Não existe conexão à internet. Por favor ligue o wireless", Toast.LENGTH_SHORT).show();
+ Toast.makeText(getApplicationContext(), "Não existe conexão à internet. Por favor, ligue o acesso à internet", Toast.LENGTH_SHORT).show();
} else{
- WebServiceTask wst = new WebServiceTask(WebServiceTask.POST_TASK, this, "Validando as credênciais...");
- wst.addNameValuePair("email", email);
- wst.addNameValuePair("passwd", passwd);
-
- // the passed String is the URL we will POST to
- wst.execute(new String[] { SERVICE_URL+"/loginMobile" });
- }
- }
- }
-
-
- public void retrieveSampleData(View vw) {
-
- String sampleURL = SERVICE_URL + "/loginMobile";
-
- WebServiceTask wst = new WebServiceTask(WebServiceTask.GET_TASK, this, "Validando as credênciais");
-
- wst.execute(new String[] { sampleURL });
- }
-
- public void handleResponse(String response) {
- //System.out.println ("resposta login: "+response);
- try {
-
- if (response.toString().compareToIgnoreCase("-1") != 0 ){
- Intent i = new Intent(this, MainActivity.class);
- i.putExtra("events",response);
- i.putExtra("email", email);
+ Intent i=new Intent(this,ListOfDrones.class);
+ i.putExtra("id", email);
i.putExtra("passwd", passwd);
- startActivity(i);
- } else {
- Toast.makeText(this, "Utilizador ou password errados",
- Toast.LENGTH_LONG).show();
+ this.startActivity(i);
}
-
- } catch (Exception e) {
- Log.e("TAG", e.getLocalizedMessage(), e);
}
}
- private void hideKeyboard() {
-
- InputMethodManager inputManager = (InputMethodManager) LoginActivity.this
- .getSystemService(Context.INPUT_METHOD_SERVICE);
-
- inputManager.hideSoftInputFromWindow(
- LoginActivity.this.getCurrentFocus()
- .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
- }
-
- private class WebServiceTask extends AsyncTask {
-
- public static final int POST_TASK = 1;
- public static final int GET_TASK = 2;
-
- private static final String TAG = "WebServiceTask";
-
- // connection timeout, in milliseconds (waiting to connect)
- private static final int CONN_TIMEOUT = 3000;
-
- // socket timeout, in milliseconds (waiting for data)
- private static final int SOCKET_TIMEOUT = 5000;
-
- private int taskType = GET_TASK;
- private Context mContext = null;
- private String processMessage = "Processing...";
-
- private ArrayList params = new ArrayList();
-
- private ProgressDialog pDlg = null;
-
- public WebServiceTask(int taskType, Context mContext, String processMessage) {
-
- this.taskType = taskType;
- this.mContext = mContext;
- this.processMessage = processMessage;
- }
-
- public void addNameValuePair(String name, String value) {
-
- params.add(new BasicNameValuePair(name, value));
- }
-
- @SuppressWarnings("deprecation")
- private void showProgressDialog() {
-
- pDlg = new ProgressDialog(mContext);
- pDlg.setMessage(processMessage);
- pDlg.setProgressDrawable(mContext.getWallpaper());
- pDlg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- pDlg.setCancelable(false);
- pDlg.show();
-
- }
-
- @Override
- protected void onPreExecute() {
-
- hideKeyboard();
- showProgressDialog();
-
- }
-
- protected String doInBackground(String... urls) {
-
- String url = urls[0];
- String result = "";
-
- HttpResponse response = doResponse(url);
-
- if (response == null) {
- return result;
- } else {
-
- try {
-
- result = inputStreamToString(response.getEntity().getContent());
-
- } catch (IllegalStateException e) {
- Log.e(TAG, e.getLocalizedMessage(), e);
-
- } catch (IOException e) {
- Log.e(TAG, e.getLocalizedMessage(), e);
- }
-
- }
-
- return result;
- }
-
- @Override
- protected void onPostExecute(String response) {
-
- handleResponse(response);
- pDlg.dismiss();
-
- }
-
- // Establish connection and socket (data retrieval) timeouts
- private HttpParams getHttpParams() {
-
- HttpParams htpp = new BasicHttpParams();
-
- HttpConnectionParams.setConnectionTimeout(htpp, CONN_TIMEOUT);
- HttpConnectionParams.setSoTimeout(htpp, SOCKET_TIMEOUT);
-
- return htpp;
- }
-
- private HttpResponse doResponse(String url) {
-
- // Use our connection and data timeouts as parameters for our
- // DefaultHttpClient
- HttpClient httpclient = new DefaultHttpClient(getHttpParams());
-
- HttpResponse response = null;
-
- try {
- switch (taskType) {
-
- case POST_TASK:
- HttpPost httppost = new HttpPost(url);
- // Add parameters
- httppost.setEntity(new UrlEncodedFormEntity(params));
-
- response = httpclient.execute(httppost);
- break;
- case GET_TASK:
- HttpGet httpget = new HttpGet(url);
- response = httpclient.execute(httpget);
- break;
- }
- } catch (Exception e) {
-
- Log.e(TAG, e.getLocalizedMessage(), e);
-
- }
-
- return response;
- }
-
- private String inputStreamToString(InputStream is) {
-
- String line = "";
- StringBuilder total = new StringBuilder();
-
- // Wrap a BufferedReader around the InputStream
- BufferedReader rd = new BufferedReader(new InputStreamReader(is));
-
- try {
- // Read response until the end
- while ((line = rd.readLine()) != null) {
- total.append(line);
- }
- } catch (IOException e) {
- Log.e(TAG, e.getLocalizedMessage(), e);
- }
-
- // Return full string
- return total.toString();
- }
-
+ public void registerData (View vw) {
+ Intent i = new Intent(this, RegisterActivity.class);
+ startActivity(i);
}
}
\ No newline at end of file
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/MainActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/MainActivity.java
deleted file mode 100644
index 1701af4..0000000
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/MainActivity.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package pt.isep.mei.simov.droneappcontroller;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.Button;
-import android.widget.Toast;
-
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
-
- Button left = (Button) findViewById(R.id.buttonLeft);
- Button right = (Button) findViewById(R.id.buttonRight);
- Button up = (Button) findViewById(R.id.buttonUp);
- Button down = (Button) findViewById(R.id.buttonDown);
- Button acelerate = (Button) findViewById(R.id.buttonAcelerate);
- Button breake = (Button) findViewById(R.id.buttonBreak);
- Button on_off = (Button) findViewById(R.id.buttonOnOff);
- Button calibration = (Button) findViewById(R.id.buttonCallibration);
-
- left.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "left pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- right.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "right pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- up.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "up pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- down.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "down pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- acelerate.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "acelerate pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- breake.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "break pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- on_off.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "on_off pressed!",
- Toast.LENGTH_LONG).show();
- }
- });
-
- calibration.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(getApplicationContext(), "calibration pressed!",
- Toast.LENGTH_LONG).show();
-
- Intent i = new Intent(getApplicationContext(), CalibrationActivity.class);
- startActivity(i);
- }
- });
-
- }
-
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
-
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
-
- return super.onOptionsItemSelected(item);
- }
-}
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/RegisterActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/RegisterActivity.java
index 645470d..779e4f8 100644
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/RegisterActivity.java
+++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/RegisterActivity.java
@@ -7,7 +7,14 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+import org.jivesoftware.smack.ConnectionConfiguration;
+
+/**
+ * Created by almeida on 18-12-2014.
+ */
public class RegisterActivity extends Activity {
@@ -16,6 +23,24 @@ public class RegisterActivity extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
+ final EditText username = (EditText)findViewById(R.id.editName);
+ final EditText passwd = (EditText)findViewById(R.id.passwd);
+
+ Button buttonReg = (Button) findViewById(R.id.btnReg);
+ buttonReg.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Connection c = new Connection("admin","adminpassword"); //este user não existe, o registo não está a funcionar com esta conta.
+ if (c.createAccount(username.getText().toString(), passwd.getText().toString())){
+ Toast.makeText(getApplicationContext(), "Registration completed!",
+ Toast.LENGTH_LONG).show();
+ finish();
+ }else {
+ Toast.makeText(getApplicationContext(), "Problem with registration!",
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ });
Button cancel = (Button)findViewById(R.id.buttonCancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
@@ -24,27 +49,4 @@ public class RegisterActivity extends Activity {
}
});
}
-
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_register, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
-
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
-
- return super.onOptionsItemSelected(item);
- }
}
diff --git a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/SettingsDialog.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/SettingsDialog.java
deleted file mode 100644
index e8745d5..0000000
--- a/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/SettingsDialog.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package pt.isep.mei.simov.droneappcontroller;
-
-import android.app.Dialog;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-import org.jivesoftware.smack.ConnectionConfiguration;
-import org.jivesoftware.smack.XMPPConnection;
-import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.packet.Presence;
-
-/**
- * Gather the xmpp settings and create an XMPPConnection
- */
-public class SettingsDialog extends Dialog implements View.OnClickListener {
- private XMPPClient xmppClient;
-
- public SettingsDialog(XMPPClient xmppClient) {
- super(xmppClient);
- this.xmppClient = xmppClient;
- }
-
- protected void onStart() {
- super.onStart();
- setContentView(R.layout.settings);
- getWindow().setFlags(4, 4);
- setTitle("XMPP Settings");
- Button ok = (Button) findViewById(R.id.ok);
- ok.setOnClickListener(this);
- }
-
- public void onClick(View v) {
- String host = getText(R.id.host);
- String port = getText(R.id.port);
- String service = getText(R.id.service);
- String username = getText(R.id.userid);
- String password = getText(R.id.password);
-
- // Create a connection
- ConnectionConfiguration connConfig =
- new ConnectionConfiguration(host, Integer.parseInt(port), service);
- XMPPConnection connection = new XMPPConnection(connConfig);
-
- try {
- connection.connect();
- Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
- } catch (XMPPException ex) {
- Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
- Log.e("XMPPClient", ex.toString());
- xmppClient.setConnection(null);
- }
- try {
- connection.login(username, password);
- Log.i("XMPPClient", "Logged in as " + connection.getUser());
-
- // Set the status to available
- Presence presence = new Presence(Presence.Type.available);
- connection.sendPacket(presence);
- xmppClient.setConnection(connection);
- } catch (XMPPException ex) {
- Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
- Log.e("XMPPClient", ex.toString());
- xmppClient.setConnection(null);
- }
- dismiss();
- }
-
- private String getText(int id) {
- EditText widget = (EditText) this.findViewById(id);
- return widget.getText().toString();
- }
-}
diff --git a/DroneAppController/app/src/main/res/layout/activity_main.xml b/DroneAppController/app/src/main/res/layout/activity_controller.xml
similarity index 98%
rename from DroneAppController/app/src/main/res/layout/activity_main.xml
rename to DroneAppController/app/src/main/res/layout/activity_controller.xml
index b836afe..4e8b910 100644
--- a/DroneAppController/app/src/main/res/layout/activity_main.xml
+++ b/DroneAppController/app/src/main/res/layout/activity_controller.xml
@@ -17,7 +17,7 @@
diff --git a/DroneAppController/app/src/main/res/layout/activity_list_of_drone.xml b/DroneAppController/app/src/main/res/layout/activity_list_of_drone.xml
new file mode 100644
index 0000000..c9091ae
--- /dev/null
+++ b/DroneAppController/app/src/main/res/layout/activity_list_of_drone.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DroneAppController/app/src/main/res/layout/activity_login.xml b/DroneAppController/app/src/main/res/layout/activity_login.xml
index 6858ce5..1b1a482 100644
--- a/DroneAppController/app/src/main/res/layout/activity_login.xml
+++ b/DroneAppController/app/src/main/res/layout/activity_login.xml
@@ -4,9 +4,8 @@
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@drawable/back"
- tools:context="simov.dei.isep.pt.droneappcontrol.RegisterActivity">
+ android:paddingBottom="@dimen/activity_vertical_margin">
@@ -41,7 +40,7 @@
diff --git a/DroneAppController/app/src/main/res/layout/activity_register.xml b/DroneAppController/app/src/main/res/layout/activity_register.xml
index a1071f2..a64c203 100644
--- a/DroneAppController/app/src/main/res/layout/activity_register.xml
+++ b/DroneAppController/app/src/main/res/layout/activity_register.xml
@@ -20,7 +20,7 @@
-
-
-
-
+
+
diff --git a/DroneAppController/app/src/main/res/menu/menu_list_of_drones.xml b/DroneAppController/app/src/main/res/menu/menu_list_of_drones.xml
new file mode 100644
index 0000000..83de7d5
--- /dev/null
+++ b/DroneAppController/app/src/main/res/menu/menu_list_of_drones.xml
@@ -0,0 +1,7 @@
+
diff --git a/DroneAppController/app/src/main/res/menu/menu_main.xml b/DroneAppController/app/src/main/res/menu/menu_main.xml
index 9e8b449..39f6b2e 100644
--- a/DroneAppController/app/src/main/res/menu/menu_main.xml
+++ b/DroneAppController/app/src/main/res/menu/menu_main.xml
@@ -1,7 +1,7 @@
diff --git a/DroneAppController/app/src/main/res/values-pt/strings.xml b/DroneAppController/app/src/main/res/values-pt/strings.xml
index 2f2dac7..973f96a 100644
--- a/DroneAppController/app/src/main/res/values-pt/strings.xml
+++ b/DroneAppController/app/src/main/res/values-pt/strings.xml
@@ -1,9 +1,12 @@
- DroneAppControl
+ Drone App Controller
+ Hello world!
Definições
Registo
- Formulário de Registo
+ Controlo
+ Calibração
+ Lista de drones
\ No newline at end of file
diff --git a/DroneAppController/app/src/main/res/values/strings.xml b/DroneAppController/app/src/main/res/values/strings.xml
index 1627d0e..e0a7b25 100644
--- a/DroneAppController/app/src/main/res/values/strings.xml
+++ b/DroneAppController/app/src/main/res/values/strings.xml
@@ -1,11 +1,12 @@
- DroneController
+ Drone App Controller
Hello world!
Settings
Register
- MainActivity
- CalibrationActivity
+ Controlo
+ Calibration Activity
+ List Of Drones