Add files via upload

master
Nikita Kogan 5 years ago committed by GitHub
parent 5b70036f18
commit 8acaec031b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,11 +11,14 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning"> tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".JoystickActivity" /> <activity android:name=".JoystickActivity" android:configChanges="orientation|screenSize|keyboardHidden">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.ex4.MainActivity"/>
</activity>
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>

@ -50,8 +50,8 @@ public class Joystick extends SurfaceView implements SurfaceHolder.Callback, Vie
{ {
centerX = getWidth() / 2; centerX = getWidth() / 2;
centerY = getHeight() / 2; centerY = getHeight() / 2;
baseRadius = Math.min(getWidth(), getHeight()) / 3; baseRadius = Math.min(getWidth(), getHeight()) / 4;
hatRadius = Math.min(getWidth(), getHeight()) / 5; hatRadius = Math.min(getWidth(), getHeight()) / 7;
} }
//method to be called when Joystick surface is created //method to be called when Joystick surface is created
@Override @Override
@ -71,7 +71,7 @@ public class Joystick extends SurfaceView implements SurfaceHolder.Callback, Vie
@Override @Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) public void surfaceDestroyed(SurfaceHolder surfaceHolder)
{ {
UserHandler.getInstance().disconnect(); //nothing...
} }
/*when Joystick is touched, method will be called and will compute values to be sent as /*when Joystick is touched, method will be called and will compute values to be sent as
* arguments to the JoystickCallBack onJoystickMoved even handler*/ * arguments to the JoystickCallBack onJoystickMoved even handler*/
@ -112,10 +112,10 @@ public class Joystick extends SurfaceView implements SurfaceHolder.Callback, Vie
{ {
Canvas drawCanvas = this.getHolder().lockCanvas(); Canvas drawCanvas = this.getHolder().lockCanvas();
Paint colors = new Paint(); Paint colors = new Paint();
drawCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); drawCanvas.drawColor(Color.WHITE);
colors.setARGB(255, 50, 50, 50); colors.setARGB(175, 50, 50, 50);
drawCanvas.drawCircle(centerX, centerY, baseRadius, colors); drawCanvas.drawCircle(centerX, centerY, baseRadius, colors);
colors.setARGB(255, 0, 0, 255); colors.setARGB(200, 50, 50, 200);
drawCanvas.drawCircle(x, y, hatRadius, colors); drawCanvas.drawCircle(x, y, hatRadius, colors);
getHolder().unlockCanvasAndPost(drawCanvas); getHolder().unlockCanvasAndPost(drawCanvas);
} }

@ -18,4 +18,10 @@ public class JoystickActivity extends AppCompatActivity implements Joystick.Joys
handler.send_message(true, xPercent); //true is aileron handler.send_message(true, xPercent); //true is aileron
handler.send_message(false, yPercent); //false is elevator handler.send_message(false, yPercent); //false is elevator
} }
@Override
protected void onDestroy()
{
super.onDestroy();
UserHandler.getInstance().disconnect();
}
} }

@ -59,9 +59,7 @@ public class UserHandler
{ {
synchronized (this) synchronized (this)
{ {
if (message != null) { if (message != null) { writer.printf(message); message = null; }
writer.print(message);
message = null; }
} }
} }
sock.close(); sock.close();
@ -101,6 +99,7 @@ public class UserHandler
{ {
aileron_or_elevator = aileron_path; aileron_or_elevator = aileron_path;
} }
if (val < 0.99 && val > -0.99) { val *= -1; }
synchronized (this) synchronized (this)
{ {
message = "set " + aileron_or_elevator + " " + Float.toString(val) + " \r\n"; message = "set " + aileron_or_elevator + " " + Float.toString(val) + " \r\n";

@ -87,17 +87,16 @@
<Button <Button
android:id="@+id/connect_button" android:id="@+id/connect_button"
android:layout_width="118dp" android:layout_width="118dp"
android:layout_height="70dp" android:layout_height="51dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginBottom="4dp"
android:text="@string/connect_str" android:text="@string/connect_str"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.478" app:layout_constraintHorizontal_bias="0.48"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -84,8 +84,8 @@
<Button <Button
android:id="@+id/connect_button" android:id="@+id/connect_button"
android:layout_width="118dp" android:layout_width="114dp"
android:layout_height="70dp" android:layout_height="43dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"

Loading…
Cancel
Save