new layout and some changes in advanced mode
2
DroneAppController/.idea/.name
generated
@ -1 +1 @@
|
||||
DroneAppController
|
||||
Drone App Controller
|
||||
6
DroneAppController/.idea/gradle.xml
generated
@ -5,11 +5,11 @@
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.2.1" />
|
||||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.2.1" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="/media/almeida/Windows 7/Users/Almeida/Documents/android/DroneAppController" />
|
||||
<option value="/media/almeida/Windows 7/Users/Almeida/Documents/android/DroneAppController/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
|
||||
31
DroneAppController/.idea/misc.xml
generated
@ -3,8 +3,39 @@
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="ProjectInspectionProfilesVisibleTreeState">
|
||||
<entry key="Project Default">
|
||||
<profile-state>
|
||||
<expanded-state>
|
||||
<State>
|
||||
<id />
|
||||
</State>
|
||||
</expanded-state>
|
||||
<selected-state>
|
||||
<State>
|
||||
<id>Abstraction issues</id>
|
||||
</State>
|
||||
</selected-state>
|
||||
</profile-state>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="ScopeChooserConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
|
||||
3
DroneAppController/.idea/modules.xml
generated
@ -2,8 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/DroneAppController.iml" filepath="$PROJECT_DIR$/DroneAppController.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file:///media/almeida/Windows 7/Users/Almeida/Documents/android/DroneAppController/app/app.iml" filepath="/media/almeida/Windows 7/Users/Almeida/Documents/android/DroneAppController/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/classes/main" />
|
||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$USER_HOME$/Documents/android/DroneAppController" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
@ -84,9 +84,9 @@
|
||||
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="asmack-2010.05.07" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@ -3,9 +3,10 @@ apply plugin: 'com.android.application'
|
||||
android {
|
||||
compileSdkVersion 21
|
||||
buildToolsVersion "21.1.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "pt.isep.mei.simov.droneappcontroller"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 21
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@ -16,11 +17,9 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
productFlavors {
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:21.0.3'
|
||||
}
|
||||
|
||||
@ -25,20 +25,13 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ControllerActivity"
|
||||
android:screenOrientation="landscape"
|
||||
android:label="@string/title_activity_main" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CalibrationActivity"
|
||||
android:label="@string/title_activity_calibration" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ListOfDrones"
|
||||
android:label="@string/title_activity_list_of_drones" >
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ExpertMode"
|
||||
android:label="Expert Mode">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package pt.isep.mei.simov.droneappcontroller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* Created by almeida on 23-12-2014.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -21,6 +21,11 @@ public class Connection {
|
||||
String HOST = "aalmeid.ddns.net";
|
||||
int PORT = 5222;
|
||||
String SERVICE = "xmppserver";
|
||||
|
||||
/*String HOST = "sibacsimovisep2014.noip.me";
|
||||
int PORT = 5222;
|
||||
String SERVICE = "sibacsimovisep2014";*/
|
||||
|
||||
String USERNAME = "";
|
||||
String PASSWORD = "";
|
||||
|
||||
@ -99,6 +104,11 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean closeConnection(){
|
||||
connection.disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean createAccount (String username, String password){
|
||||
try {
|
||||
AccountManager accountManager = connection.getAccountManager();
|
||||
|
||||
@ -2,15 +2,22 @@ package pt.isep.mei.simov.droneappcontroller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
@ -21,31 +28,68 @@ 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 {
|
||||
public class ControllerActivity extends Activity implements SensorEventListener {
|
||||
private SensorManager sensorManager;
|
||||
private String to;
|
||||
private XMPPConnection connection = Connection.getConnection();
|
||||
private ArrayList<String> messages = new ArrayList<String>();
|
||||
private int speed;
|
||||
private TextView tv;
|
||||
private Switch onOff;
|
||||
private Switch expertmode;
|
||||
|
||||
@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);
|
||||
Button desacelarate = (Button) findViewById(R.id.buttonBreak);
|
||||
|
||||
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
|
||||
|
||||
sensorManager.registerListener(this,
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
||||
SensorManager.SENSOR_DELAY_GAME);
|
||||
|
||||
tv = (TextView) findViewById(R.id.tv);
|
||||
|
||||
onOff = (Switch) findViewById(R.id.onOff);
|
||||
|
||||
|
||||
|
||||
onOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
senMessage("v-"+100);
|
||||
senMessage("v-"+30);
|
||||
speed = 30;
|
||||
} else {
|
||||
senMessage("v-" + 0);
|
||||
speed = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expertmode = (Switch) findViewById(R.id.expertmode);
|
||||
|
||||
expertmode.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!onOff.isChecked()) {
|
||||
expertmode.setChecked(false);
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
to = b.getString("to");
|
||||
@ -55,128 +99,136 @@ public class ControllerActivity extends Activity {
|
||||
left.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(getApplicationContext(), "left pressed!",
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
senMessage("left");
|
||||
if(onOff.isChecked()) {
|
||||
senMessage("e");
|
||||
}else{
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
right.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(getApplicationContext(), "right pressed!",
|
||||
Toast.LENGTH_LONG).show();
|
||||
if (onOff.isChecked()) {
|
||||
senMessage("d");
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
senMessage("rigth");
|
||||
/*acelerate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (onOff.isChecked()) {
|
||||
if (speed < 91) {
|
||||
speed = speed + 10;
|
||||
senMessage("v-" + speed);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
acelerate.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (onOff.isChecked()) {
|
||||
if (speed < 100) {
|
||||
speed = speed + 1;
|
||||
senMessage("v-" + speed);
|
||||
tv.setText(speed+"/100");
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/*desacelarate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(onOff.isChecked()) {
|
||||
if(speed > 9) {
|
||||
speed = speed - 10;
|
||||
senMessage("v-" + speed);
|
||||
}
|
||||
}else{
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});*/
|
||||
|
||||
desacelarate.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (onOff.isChecked()) {
|
||||
if (speed > 0) {
|
||||
speed = speed - 1;
|
||||
senMessage("v-" + speed);
|
||||
tv.setText(speed+"/100");
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
up.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Toast.makeText(getApplicationContext(), "up pressed!",
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
senMessage("up");
|
||||
if (onOff.isChecked()) {
|
||||
senMessage("up");
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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(), ExpertMode.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();
|
||||
|
||||
if (onOff.isChecked()) {
|
||||
senMessage("down");
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), R.string.turnOn,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void senMessage(String message) {
|
||||
Message msg = new Message(to, Message.Type.chat);
|
||||
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
|
||||
|
||||
msg.setBody(message);
|
||||
if (connection != null) {
|
||||
connection.sendPacket(msg);
|
||||
messages.add(connection.getUser() + ":");
|
||||
messages.add(message);
|
||||
if (!(networkInfo != null && networkInfo.isConnected())) {
|
||||
Toast.makeText(getApplicationContext(), R.string.droneConnection, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}else{
|
||||
connection.sendPacket(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@ -185,34 +237,41 @@ public class ControllerActivity extends Activity {
|
||||
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;
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
|
||||
|
||||
// assign directions
|
||||
float x=event.values[0];
|
||||
float y=event.values[1];
|
||||
|
||||
if (expertmode.isChecked() && onOff.isChecked()) {
|
||||
if(x > 8){
|
||||
if (speed > 0) {
|
||||
speed = speed - 1;
|
||||
senMessage("v-" + speed);
|
||||
tv.setText(speed + "/100");
|
||||
}
|
||||
} else if(x < 2) {
|
||||
if (speed < 100) {
|
||||
speed = speed + 1;
|
||||
senMessage("v-" + speed);
|
||||
tv.setText(speed+"/100");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,85 +0,0 @@
|
||||
package pt.isep.mei.simov.droneappcontroller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
/**
|
||||
* Created by João on 30-12-2014.
|
||||
*/
|
||||
public class ExpertMode extends Activity implements SensorEventListener {
|
||||
|
||||
|
||||
private SensorManager sensorManager;
|
||||
|
||||
TextView x_tilt;
|
||||
TextView y_tilt;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_expert_mode);
|
||||
|
||||
x_tilt=(TextView)findViewById(R.id.x_tilt);
|
||||
y_tilt=(TextView)findViewById(R.id.y_tilt);
|
||||
|
||||
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
|
||||
|
||||
// add listener. The listener will be HelloAndroid (this) class
|
||||
sensorManager.registerListener(this,
|
||||
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
|
||||
SensorManager.SENSOR_DELAY_GAME);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
|
||||
|
||||
// assign directions
|
||||
float x=event.values[0];
|
||||
float y=event.values[1];
|
||||
|
||||
|
||||
if(x > 1){
|
||||
x_tilt.setText("Trás");
|
||||
} else if(x < -1) {
|
||||
x_tilt.setText("Frente");
|
||||
}
|
||||
|
||||
if(y > 1){
|
||||
y_tilt.setText("Direita");
|
||||
}else if(y < -1){
|
||||
y_tilt.setText("Esquerda");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,17 @@
|
||||
package pt.isep.mei.simov.droneappcontroller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
@ -34,28 +39,43 @@ public class ListOfDrones extends Activity {
|
||||
String user = b.getString("id");
|
||||
String passwd = b.getString("passwd");
|
||||
|
||||
Connection c = new Connection(user,passwd);
|
||||
users = c.getUsers();
|
||||
connection = c.getConnection();
|
||||
try {
|
||||
Connection c = new Connection(user, passwd);
|
||||
users = c.getUsers();
|
||||
connection = c.getConnection();
|
||||
|
||||
|
||||
listView = (ListView) findViewById( R.id.listOfDrones );
|
||||
listAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.simplerow);
|
||||
listView.setAdapter( listAdapter );
|
||||
listView = (ListView) findViewById(R.id.listOfDrones);
|
||||
listAdapter = new ArrayAdapter<String>(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);
|
||||
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) {
|
||||
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
|
||||
|
||||
if (connection != null) {
|
||||
if (!(networkInfo != null && networkInfo.isConnected())) {
|
||||
Toast.makeText(getApplicationContext(), R.string.internetConnection, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}else{
|
||||
Intent i = new Intent(getApplicationContext(), ControllerActivity.class);
|
||||
i.putExtra("to", listAdapter.getItem(position));
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
Log.e("Authentication Problem", "Some problem with your account", e);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ public class LoginActivity extends Activity {
|
||||
Log.i("XMPP", "Credencials: " + email + " and " + passwd);
|
||||
|
||||
if (email.equals("") || passwd.equals("")) {
|
||||
Toast.makeText(this, "Por favor preencha os campos de autenticação",
|
||||
Toast.makeText(this, R.string.autField,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@ -43,10 +43,9 @@ public class LoginActivity extends Activity {
|
||||
|
||||
if (!(networkInfo != null && networkInfo.isConnected()))
|
||||
{
|
||||
Toast.makeText(getApplicationContext(), "Não existe conexão à internet. Por favor, ligue o acesso à internet", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(), R.string.internetConnection, Toast.LENGTH_SHORT).show();
|
||||
} else{
|
||||
|
||||
Intent i=new Intent(this,ListOfDrones.class);
|
||||
Intent i = new Intent(this, ListOfDrones.class);
|
||||
i.putExtra("id", email);
|
||||
i.putExtra("passwd", passwd);
|
||||
this.startActivity(i);
|
||||
@ -54,8 +53,8 @@ public class LoginActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerData (View vw) {
|
||||
/*public void registerData (View vw) {
|
||||
Intent i = new Intent(this, RegisterActivity.class);
|
||||
startActivity(i);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@ -25,7 +25,7 @@ public class RegisterActivity extends Activity {
|
||||
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.
|
||||
Connection c = new Connection("user","passwd");
|
||||
if (c.createAccount(username.getText().toString(), passwd.getText().toString())){
|
||||
Toast.makeText(getApplicationContext(), "Registration completed!",
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 13 KiB |
@ -1,12 +0,0 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
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"
|
||||
tools:context="simov.dei.isep.pt.droneappcontrol.CallibrationActivity">
|
||||
|
||||
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</RelativeLayout>
|
||||
@ -9,23 +9,7 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="On / Off"
|
||||
android:id="@+id/buttonOnOff"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Expert Mode"
|
||||
android:id="@+id/buttonCallibration"
|
||||
android:layout_below="@+id/buttonOnOff"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Left"
|
||||
android:text="<"
|
||||
android:id="@+id/buttonLeft"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
@ -34,7 +18,7 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Acelerate"
|
||||
android:text="∧"
|
||||
android:id="@+id/buttonAcelerate"
|
||||
android:layout_above="@+id/buttonBreak"
|
||||
android:layout_toRightOf="@+id/buttonLeft"
|
||||
@ -43,7 +27,7 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Break"
|
||||
android:text="V"
|
||||
android:id="@+id/buttonBreak"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@+id/buttonLeft"
|
||||
@ -54,7 +38,7 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Right"
|
||||
android:text=">"
|
||||
android:id="@+id/buttonRight"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_toRightOf="@+id/buttonBreak"
|
||||
@ -78,4 +62,34 @@
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="30/100"
|
||||
android:id="@+id/tv"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignLeft="@+id/buttonAcelerate"
|
||||
android:layout_alignStart="@+id/buttonAcelerate"
|
||||
android:layout_alignRight="@+id/buttonAcelerate"
|
||||
android:layout_alignEnd="@+id/buttonAcelerate" />
|
||||
|
||||
<Switch
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/onOff"
|
||||
android:id="@+id/onOff"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<Switch
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/expert"
|
||||
android:id="@+id/expertmode"
|
||||
android:layout_below="@+id/onOff"
|
||||
android:layout_alignRight="@+id/onOff"
|
||||
android:layout_alignEnd="@+id/onOff"
|
||||
android:layout_marginTop="26dp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@+id/x_tilt"
|
||||
android:id="@+id/x_tilt"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@+id/y_tilt"
|
||||
android:id="@+id/y_tilt"
|
||||
android:layout_below="@+id/x_tilt"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
@ -2,6 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:background="@drawable/back"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<ListView android:layout_width="fill_parent"
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="JabberID"
|
||||
android:text="Drone ID"
|
||||
android:textColor="#372c24" />
|
||||
|
||||
<EditText
|
||||
@ -82,7 +82,7 @@
|
||||
android:layout_marginTop="34dp"
|
||||
android:onClick="postData"
|
||||
android:text="Login" />
|
||||
|
||||
<!--
|
||||
<Button
|
||||
android:id="@+id/btnRegister"
|
||||
android:layout_width="fill_parent"
|
||||
@ -92,4 +92,5 @@
|
||||
android:layout_below="@+id/btnLogin"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
-->
|
||||
</RelativeLayout>
|
||||
@ -1,8 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/rowTextView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#336633"
|
||||
android:padding="10dp"
|
||||
android:textSize="20sp" >
|
||||
</TextView>
|
||||
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dip" >
|
||||
<LinearLayout
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginRight="5dip"
|
||||
android:padding="3dip" >
|
||||
<ImageView
|
||||
android:id="@+id/list_image"
|
||||
android:contentDescription="@string/app_name"
|
||||
android:layout_width="60dip"
|
||||
android:layout_height="60dip"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/rowTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="75dip"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingBottom ="10dip"
|
||||
android:textColor="#040404"
|
||||
android:textSize="25dip"
|
||||
android:textStyle="bold"
|
||||
android:typeface="sans" />
|
||||
</RelativeLayout> -->
|
||||
@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="pt.isep.mei.simov.droneappcontroller.CalibrationActivity">
|
||||
tools:context="pt.isep.mei.simov.droneappcontroller.ExpertMode">
|
||||
<item android:id="@+id/action_settings" android:title="@string/action_settings"
|
||||
android:orderInCategory="100" app:showAsAction="never" />
|
||||
</menu>
|
||||
|
||||
@ -8,7 +8,15 @@
|
||||
<string name="title_activity_main">Controlo</string>
|
||||
<string name="title_activity_calibration">Calibração</string>
|
||||
<string name="title_activity_list_of_drones">Lista de drones</string>
|
||||
<string name="x_tilt">X Tilt: </string>
|
||||
<string name="y_tilt">Y Tilt: </string>
|
||||
<string name="expertMode">Atenção: Activar o modo avançado?</string>
|
||||
<string name="expert">Modo avançado</string>
|
||||
<string name="autField">Por favor preencha os campos de autenticação</string>
|
||||
<string name="internetConnection">Não existe conexão à internet. Por favor, ligue o acesso à internet</string>
|
||||
<string name="droneConnection">Não existe conexão ao drone.</string>
|
||||
<string name="autFailed">Início de sessão falhou. Por favor, tente novamente</string>
|
||||
<string name="turnOn">Por favor, ligue o drone</string>
|
||||
<string name="onOff">Ligar/Desligar</string>
|
||||
<string name="yes">Sim</string>
|
||||
<string name="no">Não</string>
|
||||
|
||||
</resources>
|
||||
@ -5,10 +5,17 @@
|
||||
<string name="hello_world">Hello world!</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="title_activity_register">Register</string>
|
||||
<string name="title_activity_main">Controlo</string>
|
||||
<string name="title_activity_calibration">Calibration Activity</string>
|
||||
<string name="title_activity_main">Control</string>
|
||||
<string name="title_activity_list_of_drones">List Of Drones</string>
|
||||
<string name="x_tilt">X Tilt: </string>
|
||||
<string name="y_tilt">Y Tilt: </string>
|
||||
<string name="expertMode">Attention: You wanto to enable the Expert Mode?</string>
|
||||
<string name="expert">Expert Mode</string>
|
||||
<string name="autField">Please, use your login credentials</string>
|
||||
<string name="internetConnection">Network problem. Please, turn on your access to the Internet</string>
|
||||
<string name="droneConnection">Drone connection network problem.</string>
|
||||
<string name="autFailed">Autentication failed. Please, try again</string>
|
||||
<string name="turnOn">Please, turn on the drone!</string>
|
||||
<string name="onOff">On/Off</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
|
||||
</resources>
|
||||
|
||||