Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LEGER ROMAIN
CasseBrique
Commits
96742ccf
Commit
96742ccf
authored
Jan 19, 2016
by
Rominho15
Browse files
Version 9.4.1 : 1er essai de Bluetooth
parent
e9e9865e
Changes
9
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
96742ccf
...
...
@@ -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>
app/src/main/java/com/example/rleger/cassebrique/Online/BluetoothBroadcastReceiver.java
0 → 100644
View file @
96742ccf
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
;
}
}
app/src/main/java/com/example/rleger/cassebrique/Online/ConnectSessionThread.java
0 → 100644
View file @
96742ccf
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) { }
}
*/
}
app/src/main/java/com/example/rleger/cassebrique/Screen/MainActivity.java
View file @
96742ccf
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
();
}
}
}
}
app/src/main/java/com/example/rleger/cassebrique/Screen/OnlineMenuActivity.java
0 → 100644
View file @
96742ccf
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
);
}
}
app/src/main/res/layout/activity_main.xml
View file @
96742ccf
...
...
@@ -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>
app/src/main/res/layout/activity_online_menu.xml
0 → 100644
View file @
96742ccf
<?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>
app/src/main/res/values-fr/strings.xml
View file @
96742ccf
...
...
@@ -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
app/src/main/res/values/strings.xml
View file @
96742ccf
...
...
@@ -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>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment