Commit 96742ccf authored by Rominho15's avatar Rominho15
Browse files

Version 9.4.1 : 1er essai de Bluetooth

parent e9e9865e
......@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rleger.cassebrique">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
......@@ -34,7 +36,14 @@
android:name="com.parse.CLIENT_KEY"
android:value="3AZNZ3bMsodgCDq2j7eRGZ4gTblecPsFAAwFrqgC" />
<activity android:name=".Screen.ScoreActivity"></activity>
<activity android:name=".Screen.ScoreActivity" />
<activity android:name=".Screen.OnlineMenuActivity"></activity>
<receiver android:name="com.example.rleger.cassebrique.Online.BluetoothBroadcastReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
</application>
</manifest>
package com.example.rleger.cassebrique.Online;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import java.util.ArrayList;
/**
* Created by Utilisateur on 19/01/2016.
*/
public final class BluetoothBroadcastReceiver extends BroadcastReceiver {
ArrayList<String> arrayConnected = new ArrayList<>();
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = null;
if (action.equals(BluetoothDevice.ACTION_FOUND))
device = (BluetoothDevice)intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
arrayConnected.add(device.getName() + "\n" + device.getAddress());
}
public ArrayList<String> getArrayConnected() {
return arrayConnected;
}
}
package com.example.rleger.cassebrique.Online;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import java.io.IOException;
/**
* Created by Utilisateur on 19/01/2016.
*/
public class ConnectSessionThread extends Thread {
/*private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
public ConnectSessionThread(BluetoothDevice device) {
BluetoothSocket tmp = null;
mmDevice = device;
try {
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) { }
mmSocket = tmp;
}
public void run() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
try {
mmSocket.connect();
} catch (IOException connectException) {
try {
mmSocket.close();
} catch (IOException closeException) { }
return;
}
manageConnectedSocket(mmSocket);
}
public void cancel() {
try {
mmSocket.close();
} catch (IOException e) { }
}
*/
}
package com.example.rleger.cassebrique.Screen;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
......@@ -7,6 +8,7 @@ import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.example.rleger.cassebrique.R;
......@@ -100,4 +102,18 @@ public class MainActivity extends AppCompatActivity {
i.putExtra("difficulty",difficulty);
startActivity(i);
}
public void createOnlineGame(View v) {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(bluetoothAdapter == null) {
Toast.makeText(this, R.string.BluetoothNo,Toast.LENGTH_SHORT).show();
} else {
if (bluetoothAdapter.isEnabled()) {
Toast.makeText(this, R.string.Bluetooth,Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, R.string.BluetoothDis, Toast.LENGTH_SHORT).show();
}
}
}
}
package com.example.rleger.cassebrique.Screen;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.example.rleger.cassebrique.R;
public class OnlineMenuActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_online_menu);
}
public void createSession(View v) {
}
public void joinSession(View v) {
Intent discoveryMode = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
// rend l’appareil visible pendant 60 secondes
discoveryMode.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 60);
startActivity(discoveryMode);
}
}
......@@ -90,4 +90,11 @@
android:text="@string/newGame"
android:id="@+id/newGame"
android:onClick="createGame"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Online"
android:id="@+id/online"
android:onClick="createOnlineGame"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.rleger.cassebrique.Screen.OnlineMenuActivity"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SessionC"
android:onClick="createSession"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SessionJ"
android:onClick="joinSession"/>
</LinearLayout>
......@@ -25,4 +25,10 @@
<string name="Easy">Facile</string>
<string name="Medium">Moyen</string>
<string name="Hard">Difficile</string>
<string name="Online">En ligne</string>
<string name="Bluetooth">Le Bluetooth est activé !</string>
<string name="BluetoothNo">Vous n\'avez pas le Bluetooth sur votre appareil</string>
<string name="BluetoothDis">Le Bluetooth est désactivé</string>
<string name="SessionC">Créer une session</string>
<string name="SessionJ">Rejoindre une session</string>
</resources>
\ No newline at end of file
......@@ -19,9 +19,15 @@
<string name="Tplayers">2 players</string>
<string name="SeeScores">See High-Scores</string>
<string name="Return">Return</string>
<string name="Wait">Please wait ...</string>
<string name="Wait">Please wait </string>
<string name="Level">Level</string>
<string name="Easy">Easy</string>
<string name="Medium">Medium</string>
<string name="Hard">Hard</string>
<string name="Online">Online</string>
<string name="Bluetooth">Bluetooth is activated !</string>
<string name="BluetoothNo">You don\'t have Bluetooth technology</string>
<string name="BluetoothDis">Bluetooth is disable</string>
<string name="SessionC">Create session</string>
<string name="SessionJ">Join session</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment