commit 2280b6651a81edff5be0caa794591e534f5f28f4 Author: andre-almeid Date: Fri Dec 26 13:54:05 2014 +0000 first commit diff --git a/DroneAppController/.gitignore b/DroneAppController/.gitignore new file mode 100644 index 0000000..afbdab3 --- /dev/null +++ b/DroneAppController/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/DroneAppController/.idea/.name b/DroneAppController/.idea/.name new file mode 100644 index 0000000..f1f4cb3 --- /dev/null +++ b/DroneAppController/.idea/.name @@ -0,0 +1 @@ +Drone App Controller \ No newline at end of file diff --git a/DroneAppController/.idea/compiler.xml b/DroneAppController/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/DroneAppController/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/DroneAppController/.idea/copyright/profiles_settings.xml b/DroneAppController/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/DroneAppController/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/DroneAppController/.idea/dictionaries/almeida.xml b/DroneAppController/.idea/dictionaries/almeida.xml new file mode 100644 index 0000000..4c37846 --- /dev/null +++ b/DroneAppController/.idea/dictionaries/almeida.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/DroneAppController/.idea/encodings.xml b/DroneAppController/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/DroneAppController/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/DroneAppController/.idea/gradle.xml b/DroneAppController/.idea/gradle.xml new file mode 100644 index 0000000..d57b206 --- /dev/null +++ b/DroneAppController/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/DroneAppController/.idea/misc.xml b/DroneAppController/.idea/misc.xml new file mode 100644 index 0000000..34d4245 --- /dev/null +++ b/DroneAppController/.idea/misc.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + Abstraction issues + + + + + + + + + + + + + + + + + + + + + diff --git a/DroneAppController/.idea/modules.xml b/DroneAppController/.idea/modules.xml new file mode 100644 index 0000000..abb38fc --- /dev/null +++ b/DroneAppController/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/DroneAppController/.idea/scopes/scope_settings.xml b/DroneAppController/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/DroneAppController/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/DroneAppController/.idea/vcs.xml b/DroneAppController/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/DroneAppController/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/DroneAppController/app/.gitignore b/DroneAppController/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/DroneAppController/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/DroneAppController/app/app.iml b/DroneAppController/app/app.iml new file mode 100644 index 0000000..f704996 --- /dev/null +++ b/DroneAppController/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DroneAppController/app/build.gradle b/DroneAppController/app/build.gradle new file mode 100644 index 0000000..587bf0b --- /dev/null +++ b/DroneAppController/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.2" + + defaultConfig { + applicationId "pt.isep.mei.simov.droneappcontroller" + minSdkVersion 15 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.android.support:appcompat-v7:21.0.3' +} diff --git a/DroneAppController/app/libs/smack.jar b/DroneAppController/app/libs/smack.jar new file mode 100644 index 0000000..b957edf Binary files /dev/null and b/DroneAppController/app/libs/smack.jar differ diff --git a/DroneAppController/app/proguard-rules.pro b/DroneAppController/app/proguard-rules.pro new file mode 100644 index 0000000..c6a72b0 --- /dev/null +++ b/DroneAppController/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/almeida/android-sdk-linux/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/DroneAppController/app/src/androidTest/java/pt/isep/mei/simov/droneappcontroller/ApplicationTest.java b/DroneAppController/app/src/androidTest/java/pt/isep/mei/simov/droneappcontroller/ApplicationTest.java new file mode 100644 index 0000000..eceecaf --- /dev/null +++ b/DroneAppController/app/src/androidTest/java/pt/isep/mei/simov/droneappcontroller/ApplicationTest.java @@ -0,0 +1,13 @@ +package pt.isep.mei.simov.droneappcontroller; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/DroneAppController/app/src/main/AndroidManifest.xml b/DroneAppController/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a3276ba --- /dev/null +++ b/DroneAppController/app/src/main/AndroidManifest.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000..3691751 --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/CalibrationActivity.java @@ -0,0 +1,40 @@ +package pt.isep.mei.simov.droneappcontroller; + +import android.app.Activity; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + + +public class CalibrationActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_calibration); + } + + + @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_calibration, 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/ClientXMPP.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ClientXMPP.java new file mode 100644 index 0000000..091bfee --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/ClientXMPP.java @@ -0,0 +1,128 @@ +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/LoginActivity.java b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java new file mode 100644 index 0000000..4c1da4f --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/LoginActivity.java @@ -0,0 +1,279 @@ +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; + +public class LoginActivity extends Activity { + private static final String SERVICE_URL = "link aqui"; + String email; + String passwd; + + @Override + 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) { + EditText edEmail = (EditText) findViewById(R.id.email); + EditText edPasswd = (EditText) findViewById(R.id.passwd); + + email = edEmail.getText().toString(); + passwd = edPasswd.getText().toString(); + + if (email.equals("") || passwd.equals("")) { + Toast.makeText(this, "Por favor preencha os campos de autenticação", + Toast.LENGTH_LONG).show(); + } else { + ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); + + if (!(networkInfo != null && networkInfo.isConnected())) + { + Toast.makeText(getApplicationContext(), "Não existe conexão à internet. Por favor ligue o wireless", 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); + i.putExtra("passwd", passwd); + startActivity(i); + } else { + Toast.makeText(this, "Utilizador ou password errados", + Toast.LENGTH_LONG).show(); + } + + } 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(); + } + + } +} \ 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 new file mode 100644 index 0000000..1701af4 --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/MainActivity.java @@ -0,0 +1,122 @@ +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 new file mode 100644 index 0000000..645470d --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/RegisterActivity.java @@ -0,0 +1,50 @@ +package pt.isep.mei.simov.droneappcontroller; + +import android.app.Activity; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; + + +public class RegisterActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_register); + + Button cancel = (Button)findViewById(R.id.buttonCancel); + cancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + } + + + @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 new file mode 100644 index 0000000..e8745d5 --- /dev/null +++ b/DroneAppController/app/src/main/java/pt/isep/mei/simov/droneappcontroller/SettingsDialog.java @@ -0,0 +1,73 @@ +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/drawable-hdpi/ic_launcher.png b/DroneAppController/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/DroneAppController/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/DroneAppController/app/src/main/res/drawable-mdpi/ic_launcher.png b/DroneAppController/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/DroneAppController/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/DroneAppController/app/src/main/res/drawable-xhdpi/ic_launcher.png b/DroneAppController/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/DroneAppController/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/DroneAppController/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/DroneAppController/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/DroneAppController/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/DroneAppController/app/src/main/res/drawable/back.jpg b/DroneAppController/app/src/main/res/drawable/back.jpg new file mode 100644 index 0000000..199d9c1 Binary files /dev/null and b/DroneAppController/app/src/main/res/drawable/back.jpg differ diff --git a/DroneAppController/app/src/main/res/layout/activity_calibration.xml b/DroneAppController/app/src/main/res/layout/activity_calibration.xml new file mode 100644 index 0000000..52b7142 --- /dev/null +++ b/DroneAppController/app/src/main/res/layout/activity_calibration.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/DroneAppController/app/src/main/res/layout/activity_login.xml b/DroneAppController/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..6858ce5 --- /dev/null +++ b/DroneAppController/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +