Add files via upload
28
AndroidManifest.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="com.example.ex4">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/AppTheme"
|
||||||
|
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||||
|
<activity android:name=".JoystickActivity" />
|
||||||
|
<activity android:name=".MainActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"
|
||||||
|
tools:ignore="ManifestOrder" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
|
</manifest>
|
128
java/com/example/ex4/Joystick.java
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
package com.example.ex4;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
|
import android.view.SurfaceView;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class Joystick extends SurfaceView implements SurfaceHolder.Callback, View.OnTouchListener {
|
||||||
|
|
||||||
|
private float centerX;
|
||||||
|
private float centerY;
|
||||||
|
private float baseRadius;
|
||||||
|
private float hatRadius;
|
||||||
|
private JoystickListener joystickCallback;
|
||||||
|
//CTOR
|
||||||
|
public Joystick(Context context, AttributeSet attrs)
|
||||||
|
{
|
||||||
|
super(context, attrs);
|
||||||
|
getHolder().addCallback(this);
|
||||||
|
setOnTouchListener(this);
|
||||||
|
if (context instanceof JoystickListener)
|
||||||
|
joystickCallback = (JoystickListener) context;
|
||||||
|
}
|
||||||
|
//CTOR
|
||||||
|
public Joystick(Context context, AttributeSet attrs, int defStyleAttr)
|
||||||
|
{
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
getHolder().addCallback(this);
|
||||||
|
setOnTouchListener(this);
|
||||||
|
if (context instanceof JoystickListener)
|
||||||
|
joystickCallback = (JoystickListener) context;
|
||||||
|
}
|
||||||
|
//CTOR
|
||||||
|
public Joystick(Context context)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
getHolder().addCallback(this);
|
||||||
|
setOnTouchListener(this);
|
||||||
|
if (context instanceof JoystickListener)
|
||||||
|
joystickCallback = (JoystickListener) context;
|
||||||
|
}
|
||||||
|
//instantiate dimenstions for drawing the Joystick
|
||||||
|
private void setupDimensions()
|
||||||
|
{
|
||||||
|
centerX = getWidth() / 2;
|
||||||
|
centerY = getHeight() / 2;
|
||||||
|
baseRadius = Math.min(getWidth(), getHeight()) / 3;
|
||||||
|
hatRadius = Math.min(getWidth(), getHeight()) / 5;
|
||||||
|
}
|
||||||
|
//method to be called when Joystick surface is created
|
||||||
|
@Override
|
||||||
|
public void surfaceCreated(SurfaceHolder surfaceHolder)
|
||||||
|
{
|
||||||
|
setupDimensions();
|
||||||
|
drawJoystick(centerX, centerY);
|
||||||
|
}
|
||||||
|
//method to be called when Joystick surface is changed
|
||||||
|
@Override
|
||||||
|
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2)
|
||||||
|
{
|
||||||
|
setupDimensions();
|
||||||
|
drawJoystick(centerX,centerY);
|
||||||
|
}
|
||||||
|
//method to be called when Joystick sutface is destroyed
|
||||||
|
@Override
|
||||||
|
public void surfaceDestroyed(SurfaceHolder surfaceHolder)
|
||||||
|
{
|
||||||
|
UserHandler.getInstance().disconnect();
|
||||||
|
}
|
||||||
|
/*when Joystick is touched, method will be called and will compute values to be sent as
|
||||||
|
* arguments to the JoystickCallBack onJoystickMoved even handler*/
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View view, MotionEvent event)
|
||||||
|
{
|
||||||
|
if (view.equals(this))
|
||||||
|
{
|
||||||
|
if (event.getAction() != MotionEvent.ACTION_UP)
|
||||||
|
{
|
||||||
|
float displacement = (float) Math.sqrt((Math.pow(event.getX() - centerX, 2)) +
|
||||||
|
Math.pow(event.getY() - centerY, 2));
|
||||||
|
if (displacement < baseRadius)
|
||||||
|
{
|
||||||
|
drawJoystick(event.getX(), event.getY());
|
||||||
|
joystickCallback.onJoystickMoved((centerX - event.getX()) / baseRadius,
|
||||||
|
(event.getY() - centerY) / baseRadius, getId());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float ratio = baseRadius / displacement;
|
||||||
|
float constrainedX = centerX + (event.getX() - centerX) * ratio;
|
||||||
|
float constrainedY = centerY + (event.getY() - centerY) * ratio;
|
||||||
|
drawJoystick(constrainedX, constrainedY);
|
||||||
|
joystickCallback.onJoystickMoved((constrainedX - centerX) / baseRadius,
|
||||||
|
(centerY - constrainedY) / baseRadius, getId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
drawJoystick(centerX, centerY);
|
||||||
|
joystickCallback.onJoystickMoved(0, 0, getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//draw the Joystick
|
||||||
|
private void drawJoystick(float x, float y)
|
||||||
|
{
|
||||||
|
if (getHolder().getSurface().isValid())
|
||||||
|
{
|
||||||
|
Canvas drawCanvas = this.getHolder().lockCanvas();
|
||||||
|
Paint colors = new Paint();
|
||||||
|
drawCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
|
||||||
|
colors.setARGB(255, 50, 50, 50);
|
||||||
|
drawCanvas.drawCircle(centerX, centerY, baseRadius, colors);
|
||||||
|
colors.setARGB(255, 0, 0, 255);
|
||||||
|
drawCanvas.drawCircle(x, y, hatRadius, colors);
|
||||||
|
getHolder().unlockCanvasAndPost(drawCanvas);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//inteface defining the onJoystickMoved event handler
|
||||||
|
public interface JoystickListener
|
||||||
|
{
|
||||||
|
void onJoystickMoved(float xPercent, float yPercent, int source);
|
||||||
|
}
|
||||||
|
}
|
21
java/com/example/ex4/JoystickActivity.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.example.ex4;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class JoystickActivity extends AppCompatActivity implements Joystick.JoystickListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_joystick);
|
||||||
|
}
|
||||||
|
//method to handle OnJoystickMoved event
|
||||||
|
public void onJoystickMoved(float xPercent, float yPercent, int source)
|
||||||
|
{
|
||||||
|
UserHandler handler = UserHandler.getInstance();
|
||||||
|
handler.send_message(true, xPercent); //true is aileron
|
||||||
|
handler.send_message(false, yPercent); //false is elevator
|
||||||
|
}
|
||||||
|
}
|
30
java/com/example/ex4/MainActivity.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.example.ex4;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
//assign the onClick as the one to be executed once the connect button is pressed
|
||||||
|
Button connect_button = findViewById(R.id.connect_button);
|
||||||
|
connect_button.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
//onClick method of the connect button
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
EditText[] values = new EditText[]{findViewById(R.id.ip_val),findViewById(R.id.port_val)};
|
||||||
|
UserHandler.getInstance().connect(values[0].getText().toString(),
|
||||||
|
Integer.parseInt(values[1].getText().toString()));
|
||||||
|
startActivity(new Intent(this, JoystickActivity.class));
|
||||||
|
}
|
||||||
|
}
|
109
java/com/example/ex4/UserHandler.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package com.example.ex4;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
public class UserHandler
|
||||||
|
{
|
||||||
|
private String aileron_path;
|
||||||
|
private String elevator_path;
|
||||||
|
private volatile String connection_ip;
|
||||||
|
private volatile int connection_port;
|
||||||
|
private volatile boolean stop;
|
||||||
|
private volatile String message;
|
||||||
|
private Thread message_thread;
|
||||||
|
//static instance to be returned by getInstance()
|
||||||
|
private static UserHandler instance = null;
|
||||||
|
//get instance of the this singleton UserHandler
|
||||||
|
public static UserHandler getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new UserHandler();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
//CTOR
|
||||||
|
private UserHandler()
|
||||||
|
{
|
||||||
|
aileron_path = "/controls/flight/aileron";
|
||||||
|
elevator_path = "/controls/flight/elevator";
|
||||||
|
connection_ip = null;
|
||||||
|
connection_port = 0;
|
||||||
|
stop = false;
|
||||||
|
message = null;
|
||||||
|
message_thread = null;
|
||||||
|
}
|
||||||
|
//connect to FlightGear simulator
|
||||||
|
public void connect(String ip, int port)
|
||||||
|
{
|
||||||
|
connection_ip = ip;
|
||||||
|
connection_port = port;
|
||||||
|
message_thread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Socket sock = null;
|
||||||
|
PrintWriter writer = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sock = new Socket(InetAddress.getByName(connection_ip), connection_port);
|
||||||
|
writer = new PrintWriter(new BufferedWriter((new OutputStreamWriter(sock.getOutputStream()))), true);
|
||||||
|
//wait for message to send...
|
||||||
|
while (!stop)
|
||||||
|
{
|
||||||
|
synchronized (this)
|
||||||
|
{
|
||||||
|
if (message != null) {
|
||||||
|
writer.print(message);
|
||||||
|
message = null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sock.close();
|
||||||
|
sock = null;
|
||||||
|
writer.close();
|
||||||
|
writer = null;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
if (sock != null) { try { sock.close(); } catch (Exception ex) { ex.printStackTrace(); }}
|
||||||
|
if (writer != null) { writer.close(); }
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
message_thread.start();
|
||||||
|
}
|
||||||
|
//disconnect from FlightGear simulator
|
||||||
|
public void disconnect()
|
||||||
|
{
|
||||||
|
stop = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
message_thread.join();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//send message to FlightGear
|
||||||
|
public void send_message(boolean aileron, float val)
|
||||||
|
{
|
||||||
|
String aileron_or_elevator = elevator_path;
|
||||||
|
if (aileron)
|
||||||
|
{
|
||||||
|
aileron_or_elevator = aileron_path;
|
||||||
|
}
|
||||||
|
synchronized (this)
|
||||||
|
{
|
||||||
|
message = "set " + aileron_or_elevator + " " + Float.toString(val) + " \r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
res/drawable-v24/ic_launcher_foreground.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillType="evenOdd"
|
||||||
|
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000">
|
||||||
|
<aapt:attr name="android:fillColor">
|
||||||
|
<gradient
|
||||||
|
android:endX="78.5885"
|
||||||
|
android:endY="90.9159"
|
||||||
|
android:startX="48.7653"
|
||||||
|
android:startY="61.0927"
|
||||||
|
android:type="linear">
|
||||||
|
<item
|
||||||
|
android:color="#44000000"
|
||||||
|
android:offset="0.0" />
|
||||||
|
<item
|
||||||
|
android:color="#00000000"
|
||||||
|
android:offset="1.0" />
|
||||||
|
</gradient>
|
||||||
|
</aapt:attr>
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
</vector>
|
170
res/drawable/ic_launcher_background.xml
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#008577"
|
||||||
|
android:pathData="M0,0h108v108h-108z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M9,0L9,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,0L19,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,0L29,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,0L39,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,0L49,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,0L59,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,0L69,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,0L79,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M89,0L89,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M99,0L99,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,9L108,9"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,19L108,19"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,29L108,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,39L108,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,49L108,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,59L108,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,69L108,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,79L108,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,89L108,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,99L108,99"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,29L89,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,39L89,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,49L89,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,59L89,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,69L89,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,79L89,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,19L29,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,19L39,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,19L49,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,19L59,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,19L69,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,19L79,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
</vector>
|
13
res/layout-land/activity_joystick.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".JoystickActivity">
|
||||||
|
|
||||||
|
<com.example.ex4.Joystick
|
||||||
|
android:id="@+id/joystick"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
103
res/layout-land/activity_main.xml
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/welcome_text_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/welcome_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.489"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ip_str"
|
||||||
|
android:layout_width="38dp"
|
||||||
|
android:layout_height="41dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="52dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/ip_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/ip_val"
|
||||||
|
app:layout_constraintHorizontal_bias="0.754"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/welcome_text_view" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/ip_val"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:layout_marginEnd="200dp"
|
||||||
|
android:layout_marginRight="200dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/ip_val_str"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/welcome_text_view"
|
||||||
|
tools:targetApi="o" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/port_str"
|
||||||
|
android:layout_width="66dp"
|
||||||
|
android:layout_height="37dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="68dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/port_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/port_val"
|
||||||
|
app:layout_constraintHorizontal_bias="0.849"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/ip_str" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/port_val"
|
||||||
|
android:layout_width="213dp"
|
||||||
|
android:layout_height="49dp"
|
||||||
|
android:layout_marginTop="56dp"
|
||||||
|
android:layout_marginEnd="200dp"
|
||||||
|
android:layout_marginRight="200dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/port_val_str"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/ip_val"
|
||||||
|
tools:targetApi="o" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/connect_button"
|
||||||
|
android:layout_width="118dp"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginBottom="4dp"
|
||||||
|
android:text="@string/connect_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.478"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
13
res/layout/activity_joystick.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".JoystickActivity">
|
||||||
|
|
||||||
|
<com.example.ex4.Joystick
|
||||||
|
android:id="@+id/joystick"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
101
res/layout/activity_main.xml
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/welcome_text_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="140dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/welcome_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/ip_str"
|
||||||
|
android:layout_width="38dp"
|
||||||
|
android:layout_height="41dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="52dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/ip_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/ip_val"
|
||||||
|
app:layout_constraintHorizontal_bias="0.386"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/welcome_text_view" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/ip_val"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="52dp"
|
||||||
|
android:layout_marginEnd="40dp"
|
||||||
|
android:layout_marginRight="40dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/ip_val_str"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/welcome_text_view"
|
||||||
|
tools:targetApi="o" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/port_str"
|
||||||
|
android:layout_width="66dp"
|
||||||
|
android:layout_height="37dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginTop="48dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:text="@string/port_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/port_val"
|
||||||
|
app:layout_constraintHorizontal_bias="0.45"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/ip_str" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/port_val"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="39dp"
|
||||||
|
android:layout_marginEnd="40dp"
|
||||||
|
android:layout_marginRight="40dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/port_val_str"
|
||||||
|
android:inputType="textPersonName"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/ip_val"
|
||||||
|
android:importantForAutofill="no" tools:targetApi="o" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/connect_button"
|
||||||
|
android:layout_width="118dp"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_marginBottom="132dp"
|
||||||
|
android:text="@string/connect_str"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.487"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
5
res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
5
res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
BIN
res/mipmap-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
res/mipmap-hdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
res/mipmap-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
res/mipmap-mdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
res/mipmap-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
res/mipmap-xhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
res/mipmap-xxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
res/mipmap-xxxhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
After Width: | Height: | Size: 15 KiB |
6
res/values/colors.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="colorPrimary">#008577</color>
|
||||||
|
<color name="colorPrimaryDark">#00574B</color>
|
||||||
|
<color name="colorAccent">#D81B60</color>
|
||||||
|
</resources>
|
3
res/values/dimens.xml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
</resources>
|
10
res/values/strings.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">Ex4</string>
|
||||||
|
<string name="welcome_str">Welcome To FlightInterp Android</string>
|
||||||
|
<string name="ip_str">IP:</string>
|
||||||
|
<string name="port_str">Port:</string>
|
||||||
|
<string name="ip_val_str">Enter IP here</string>
|
||||||
|
<string name="port_val_str">Enter port here</string>
|
||||||
|
<string name="connect_str">Connect</string>
|
||||||
|
<string name="title_activity_joystick">JoystickActivity</string>
|
||||||
|
</resources>
|
20
res/values/styles.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.NoActionBar">
|
||||||
|
<item name="windowActionBar">false</item>
|
||||||
|
<item name="windowNoTitle">true</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||||
|
|
||||||
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
|
</resources>
|