Skip to content

Commit 51b5c5f

Browse files
committed
Refactor and add songs android app
1 parent e59d270 commit 51b5c5f

File tree

69 files changed

+1463
-156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1463
-156
lines changed
0 Bytes
Binary file not shown.
130 KB
Binary file not shown.

Cart/ControlApp/.idea/codeStyles/Project.xml

Lines changed: 0 additions & 29 deletions
This file was deleted.

Cart/ControlApp/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cart/ControlApp/.idea/gradle.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cart/ControlApp/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cart/ControlApp/app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ android {
2020

2121
dependencies {
2222
implementation fileTree(dir: 'libs', include: ['*.jar'])
23-
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
24-
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
23+
implementation 'com.android.support:appcompat-v7:28.0.0'
24+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
2525
testImplementation 'junit:junit:4.12'
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28-
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
28+
implementation 'com.android.support:recyclerview-v7:28.0.0'
29+
implementation 'io.github.controlwear:virtualjoystick:1.10.1'
2930
}

Cart/ControlApp/app/src/main/java/com/example/iram/controlcart/Activities/ControlActivity.java

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,60 @@
2121
import java.util.Set;
2222
import java.util.UUID;
2323

24+
import io.github.controlwear.virtual.joystick.android.JoystickView;
25+
2426
public class ControlActivity extends AppCompatActivity implements View.OnClickListener {
25-
boolean statusLed=false, statusBuzzer=false;
27+
private boolean statusLed=false, statusBuzzer=false;
2628
public static BluetoothManager bluetoothManager;
27-
ImageView ibUp, ibLeft, ibRight, ibDown, ibBuzzer, ibLeds, ibStop, ibConnect;
29+
private ImageView ibBuzzer, ibLeds, ibConnect;
30+
private JoystickView joystick;
2831

2932

3033
@Override
3134
protected void onCreate(Bundle savedInstanceState) {
3235
super.onCreate(savedInstanceState);
3336
setContentView(R.layout.activity_control);
37+
joystick =findViewById(R.id.joystick);
3438
ibConnect=findViewById(R.id.ibConnect);
3539
ibBuzzer=findViewById(R.id.ibBuzzer);
3640
ibLeds=findViewById(R.id.ibLeds);
37-
ibStop=findViewById(R.id.ibStop);
38-
ibUp=findViewById(R.id.ibUp);
39-
ibDown=findViewById(R.id.ibDown);
40-
ibLeft=findViewById(R.id.ibLeft);
41-
ibRight=findViewById(R.id.ibRight);
4241

4342
bluetoothManager=new BluetoothManager(this);
4443
if (bluetoothManager.getmBluetoothAdapter() == null) {
4544
// Device does not support Bluetooth
4645
Toast.makeText(this, "The devicie doesn't support bluetooth", Toast.LENGTH_SHORT).show();
4746
finish();
4847
}
48+
49+
joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
50+
@Override
51+
public void onMove(int angle, int strength) {
52+
if (bluetoothManager.isDeviceConnected()) {
53+
if (strength > 10) {
54+
if ((angle <= 45 && angle >= 0) || (angle >= 315 && angle < 360))
55+
//right
56+
bluetoothManager.sendMessage("b");
57+
else if ((angle <= 135 && angle >= 90) || (angle > 45 && angle <= 89))
58+
//up
59+
bluetoothManager.sendMessage("a");
60+
else if ((angle <= 225 && angle >= 180) || (angle > 135 && angle <= 179))
61+
//left
62+
bluetoothManager.sendMessage("d");
63+
else if ((angle <= 315 && angle >= 270) || (angle > 225 && angle <= 269))
64+
//down
65+
bluetoothManager.sendMessage("e");
66+
} else {
67+
bluetoothManager.sendMessage("c");
68+
}
69+
}else{
70+
Toast.makeText(getApplicationContext(), "First connect the bluetooth", Toast.LENGTH_SHORT).show();
71+
}
72+
73+
}
74+
});
4975
ibConnect.setOnClickListener(this);
5076
ibBuzzer.setOnClickListener(this);
5177
ibLeds.setOnClickListener(this);
52-
ibStop.setOnClickListener(this);
53-
ibUp.setOnClickListener(this);
54-
ibLeft.setOnClickListener(this);
55-
ibRight.setOnClickListener(this);
56-
ibDown.setOnClickListener(this);
5778
}
5879

5980
@Override
@@ -65,19 +86,25 @@ protected void onResume() {
6586
@Override
6687
public void onClick(View view) {
6788
if(view.getId()==R.id.ibConnect){
68-
if (!bluetoothManager.DEVICE_ADDRESS.equals("") && bluetoothManager.DEVICE_ADDRESS!=null) {
69-
if(bluetoothManager.isDeviceConnected()){
70-
if(bluetoothManager.connectDisconnect()){
71-
ibConnect.setImageResource(R.drawable.connect);
72-
ibConnect.setBackgroundResource(R.color.colorAccent);
73-
Toast.makeText(getApplicationContext(), "Disconnected", Toast.LENGTH_SHORT).show();
74-
}else Toast.makeText(getApplicationContext(), "The device could not disconnect", Toast.LENGTH_SHORT).show();
89+
if (bluetoothManager.DEVICE_ADDRESS!=null) {
90+
if(!bluetoothManager.DEVICE_ADDRESS.equals("")){
91+
if(bluetoothManager.isDeviceConnected()){
92+
if(bluetoothManager.connectDisconnect()){
93+
ibConnect.setImageResource(R.drawable.connect);
94+
ibConnect.setBackgroundResource(R.color.colorAccent);
95+
Toast.makeText(getApplicationContext(), "Disconnected", Toast.LENGTH_SHORT).show();
96+
}else Toast.makeText(getApplicationContext(), "The device could not disconnect", Toast.LENGTH_SHORT).show();
97+
}else{
98+
if(bluetoothManager.connectDisconnect()){
99+
ibConnect.setImageResource(R.drawable.disconnect);
100+
ibConnect.setBackgroundColor(Color.RED);
101+
Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_SHORT).show();
102+
}else Toast.makeText(getApplicationContext(), "The device could not connect", Toast.LENGTH_SHORT).show();
103+
}
75104
}else{
76-
if(bluetoothManager.connectDisconnect()){
77-
ibConnect.setImageResource(R.drawable.disconnect);
78-
ibConnect.setBackgroundColor(Color.RED);
79-
Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_SHORT).show();
80-
}else Toast.makeText(getApplicationContext(), "The device could not connect", Toast.LENGTH_SHORT).show();
105+
Toast.makeText(getApplicationContext(), "Select a device", Toast.LENGTH_SHORT).show();
106+
Intent intent = new Intent(this, PairedDevices.class);
107+
startActivity(intent);
81108
}
82109
} else {
83110
Toast.makeText(getApplicationContext(), "Select a device", Toast.LENGTH_SHORT).show();
@@ -87,21 +114,6 @@ public void onClick(View view) {
87114
}
88115
if (bluetoothManager.isDeviceConnected()) {
89116
switch (view.getId()) {
90-
case R.id.ibUp:
91-
bluetoothManager.sendMessage("a");
92-
break;
93-
case R.id.ibRight:
94-
bluetoothManager.sendMessage("b");
95-
break;
96-
case R.id.ibStop:
97-
bluetoothManager.sendMessage("c");
98-
break;
99-
case R.id.ibLeft:
100-
bluetoothManager.sendMessage("d");
101-
break;
102-
case R.id.ibDown:
103-
bluetoothManager.sendMessage("e");
104-
break;
105117
case R.id.ibBuzzer:
106118
if (statusBuzzer) {
107119
bluetoothManager.sendMessage("z");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="#2C63DD"/>
4+
<corners android:radius="12dp"/>
5+
</shape>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<solid android:color="#8DDDF1"/>
4+
<corners android:radius="12dp"/>
5+
</shape>

0 commit comments

Comments
 (0)