Annexes
Annexes
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Button bluetooth,quit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bluetooth = findViewById(R.id.bluetooth);
quit = findViewById(R.id.quit);
bluetooth.setOnClickListener(this);
quit.setOnClickListener(this);
@Override
public void onClick(View v) {
if(v == bluetooth){
startActivity(new Intent(this,Bluetooth_info.class));
}
else if(v == quit){
finish();
System.exit(0);
}}
}
package com.example.neilbryanlagrimas.remote_control;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
BluetoothAdapter bluetoothAdapter;
private Set<BluetoothDevice> pairedDevices;
public static String EXTRA_ADDRESS = "device_address";
status = findViewById(R.id.status);
bluelist = findViewById(R.id.bluelist);
onBtn = findViewById(R.id.onBtn);
offBtn = findViewById(R.id.offBtn);
discoverBtn = findViewById(R.id.discover);
pairedBtn = findViewById(R.id.paired);
status.setText("");
if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth is available", Toast.LENGTH_SHORT).show();
}
if (bluetoothAdapter.isEnabled()) {
status.setText("Bluetooth is On");
} else {
status.setText("Bluetooth is Off");
}
onBtn.setOnClickListener(this);
offBtn.setOnClickListener(this);
discoverBtn.setOnClickListener(this);
pairedBtn.setOnClickListener(this);
}
if (pairedDevices.size()>0)
{
for(BluetoothDevice bt : pairedDevices)
{
list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the
address
}
}
else
{
Toast.makeText(getApplicationContext(), "No Paired Bluetooth Devices Found.",
Toast.LENGTH_LONG).show();
}
ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
bluelist.setAdapter(adapter);
bluelist.setOnItemClickListener(myListClickListener); //Method called when the device
from the list is clicked
@Override
public void onClick(View v) {
// On Bluetooth
if (v == onBtn) {
if (!bluetoothAdapter.isEnabled()) {
Toast.makeText(this, "Turning on Bluetooth....",
Toast.LENGTH_SHORT).show();
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
status.setText("Bluetooth is On");
} else {
Toast.makeText(this, "Bluetooth is already on",
Toast.LENGTH_SHORT).show();
}
if (v == offBtn) {
if (bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
status.setText("Bluetooth is Off");
} else {
Toast.makeText(this, "Bluetooth is already off",
Toast.LENGTH_SHORT).show();
}
// Paired Bluetooth
else if (v == pairedBtn) {
pairedDevicesList();
bluelist.setBackgroundColor(Color.parseColor("#4BC2BF"));
// if (bluetoothAdapter.isEnabled()) {
// pairedlist.setText("Paired Devices\n\n");
// Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
// for (BluetoothDevice device : devices) {
// pairedlist.append("\nDevice :" + device.getName() + "," + device.getAddress()
+ "," +device + "\n\n");
// }
// } else {
// pairedlist.setText("Turn on bluetooth to get paired devices");
// }
}
// Discover Bluetooth
else if (v == discoverBtn) {
if (!bluetoothAdapter.isDiscovering()) {
Toast.makeText(this, "Bluetooth discovery....",
Toast.LENGTH_SHORT).show();
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(enableBtIntent, REQUEST_DISCOVER_BT);
}
else{
Toast.makeText(this, "Already Discovered....", Toast.LENGTH_SHORT).show();
}
Ben Ahmed Skander A5
Rapport de stage de perfectionnement ISET Nabeul
}
}
}
activité de controle java :
package com.example.neilbryanlagrimas.remote_control;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.IOException;
import java.util.UUID;
ImageView imageView;
@SuppressLint("ClickableViewAccessibility")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_controller);
up = findViewById(R.id.up);
down = findViewById(R.id.down);
up_left = findViewById(R.id.up_left);
up_right = findViewById(R.id.up_right);
down_left = findViewById(R.id.bot_left);
down_right = findViewById(R.id.bot_right);
brake = findViewById(R.id.brake);
up.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
up();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
down.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
down();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
up_left.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Ben Ahmed Skander A7
Rapport de stage de perfectionnement ISET Nabeul
// PRESSED
up_left();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
up_right.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
up_right();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
down_left.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
down_left();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
down_right.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Ben Ahmed Skander A8
Rapport de stage de perfectionnement ISET Nabeul
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
down_right();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
brake.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// PRESSED
brakes();
return true;
case MotionEvent.ACTION_UP:
// RELEASED
brakes();
return true; // if you want to handle the touch event
}
return false;
}
});
// down.setOnClickListener(this);
//
// up_left.setOnClickListener(this);
// up_right.setOnClickListener(this);
// down_left.setOnClickListener(this);
// down_right.setOnClickListener(this);
//
// brake.setOnClickListener(this);
connection();
}
} catch (IOException e) {
Toast.makeText(this, "Error cant sent data", Toast.LENGTH_SHORT).show();
}
}
}
<Button
android:id="@+id/onBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
android:minWidth="200dp"
android:text="Turn On"
android:textAlignment="center"
android:textColor="@android:color/background_light"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/status" />
<Button
android:id="@+id/offBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
android:backgroundTint="@color/colorPrimary"
android:minWidth="200dp"
android:text="Turn Off"
android:textColor="@android:color/background_light"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/onBtn" />
<Button
android:id="@+id/discover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
android:backgroundTint="@color/colorPrimary"
android:minWidth="200dp"
android:text="Discoverabled"
android:textColor="@android:color/background_light"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/offBtn" />
<Button
android:id="@+id/paired"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:background="@color/colorPrimary"
android:backgroundTint="@color/colorPrimary"
android:minWidth="200dp"
android:text="Get Paired Devices"
android:textColor="@android:color/background_light"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/discover" />
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="T"
android:textAlignment="center"
android:textColor="@android:color/background_light"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Ben Ahmed Skander A13
Rapport de stage de perfectionnement ISET Nabeul
<ListView
android:id="@+id/bluelist"
android:layout_width="368dp"
android:layout_height="265dp"
android:layout_marginBottom="32dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.523"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/paired"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:text="Android Controller"
android:textAlignment="center"
android:textColor="#FF5722"
android:textSize="30sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<Button
android:id="@+id/bluetooth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="32dp"
android:background="@color/colorPrimary"
android:backgroundTint="@color/colorPrimary"
android:maxWidth="500dp"
android:text="BLUETOOTH CONNECTION"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/quit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="32dp"
android:background="#F44336"
android:text="QUIT"
android:textAlignment="center"
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bluetooth" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:text="PLEASE CONNECT"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#FFEB3B"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<ImageView
android:id="@+id/imageView"
android:layout_width="194dp"
android:layout_height="179dp"
android:layout_marginStart="32dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/car" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="@+id/up"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="60dp"
android:background="@drawable/up"
android:minWidth="100dp"
app:layout_constraintEnd_toEndOf="@+id/controller"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="@+id/controller"
app:layout_constraintTop_toBottomOf="@+id/controller" />
<Button
android:id="@+id/down"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/down"
android:minWidth="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/brake"
app:layout_constraintStart_toStartOf="@+id/brake"
app:layout_constraintTop_toBottomOf="@+id/brake"
app:layout_constraintVertical_bias="0.009" />
<Button
android:id="@+id/bot_left"
android:layout_width="65dp"
android:layout_height="62dp"
android:layout_marginBottom="64dp"
android:layout_marginEnd="24dp"
android:background="@drawable/down_left"
android:minWidth="100dp"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/down"
app:layout_constraintEnd_toStartOf="@+id/down" />
<Button
android:id="@+id/up_left"
android:layout_width="62dp"
android:layout_height="65dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="60dp"
android:background="@drawable/up_left"
android:minWidth="100dp"
app:layout_constraintEnd_toStartOf="@+id/up"
app:layout_constraintTop_toTopOf="@+id/up" />
<Button
android:id="@+id/bot_right"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginBottom="60dp"
android:layout_marginStart="24dp"
android:background="@drawable/down_right"
android:minWidth="100dp"
app:layout_constraintBottom_toBottomOf="@+id/down"
app:layout_constraintStart_toEndOf="@+id/down" />
<Button
android:id="@+id/up_right"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginStart="24dp"
android:layout_marginTop="60dp"
android:background="@drawable/up_right"
android:minWidth="100dp"
app:layout_constraintStart_toEndOf="@+id/up"
app:layout_constraintTop_toTopOf="@+id/up" />
<Button
android:id="@+id/brake"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:background="@drawable/brake"
app:layout_constraintEnd_toEndOf="@+id/up"
app:layout_constraintHorizontal_bias="1.0"
Ben Ahmed Skander A18
Rapport de stage de perfectionnement ISET Nabeul
app:layout_constraintStart_toStartOf="@+id/up"
app:layout_constraintTop_toBottomOf="@+id/up" />
<ImageView
android:id="@+id/controller"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/car" />
</android.support.constraint.ConstraintLayout>