-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetUp.java
152 lines (117 loc) · 4.77 KB
/
SetUp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.gameofrobots.robotcontroller1;
/**
* Created by Thomas on 2017-11-24.
*/
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.ActionBar;
import android.os.Bundle;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import java.io.IOException;
public class SetUp extends AppCompatActivity {
int buff_1;
int buff_2;
int buff_3;
public static String BUFF_1,BUFF_2,BUFF_3 = "Buffs chosen by user";
NumberPicker pickSpeed, pickHealth, pickShield;
Button readyToPair;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_up);
//makes screen landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
//Call Widgets
pickSpeed = (NumberPicker)findViewById(R.id.idPickSpeed);
pickHealth = (NumberPicker)findViewById(R.id.idPickHealth);
pickShield = (NumberPicker)findViewById(R.id.idPickShield);
readyToPair = (Button)findViewById(R.id.idReadyToPair);
//set Min and Max values for Spinners
/*
A user may only choose 6 buffs for now
Eventually a full marketplace will be implemented and allow users
to collect points and continuously purchase buffs
*/
pickSpeed.setMinValue(0);
pickSpeed.setMaxValue(6);
pickHealth.setMinValue(0);
pickHealth.setMaxValue(6);
pickShield.setMinValue(0);
pickShield.setMaxValue(6);
//pickSpeed.setWrapSelectorWheel(false); //This will remove the number wrap (number above number picker)
//By default ready to pair is diabled unless there is 6 or less boosts selected
readyToPair.setEnabled(false);
readyToPair.setClickable(false);
pickSpeed.setOnValueChangedListener(speed_onValueChange);
pickHealth.setOnValueChangedListener(health_onValueChange);
pickShield.setOnValueChangedListener(shield_onValueChange);
readyToPair.setOnClickListener(ready_onClickListener);
}//end on create
NumberPicker.OnValueChangeListener speed_onValueChange = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) {
buff_1 = newVal;
checkBuffs(buff_1,buff_2,buff_3);
}
};
NumberPicker.OnValueChangeListener health_onValueChange = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) {
buff_2 = newVal;
checkBuffs(buff_1,buff_2,buff_3);
}
};
NumberPicker.OnValueChangeListener shield_onValueChange = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) {
buff_3 = newVal;
checkBuffs(buff_1,buff_2,buff_3);
}
};
View.OnClickListener ready_onClickListener;
{
ready_onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
checkBuffs(buff_1,buff_2,buff_3);
Intent i = new Intent(SetUp.this,DeviceList.class);
i.putExtra("BUFF_1", String.valueOf(buff_1));
i.putExtra("BUFF_2", String.valueOf(buff_2));
i.putExtra("BUFF_3", String.valueOf(buff_3));
startActivity(i);
}
};
}
private void checkBuffs(int buff_1, int buff_2, int buff_3){
//make sure next button is disabled
readyToPair.setEnabled(false);
readyToPair.setClickable(false);
int buffsTotal = 0;
buffsTotal += buff_1;
buffsTotal += buff_2;
buffsTotal += buff_3;
if(buffsTotal == 0){
readyToPair.setEnabled(false);
readyToPair.setClickable(false);
}
if(buffsTotal <=6){//Can only proceed to pair if 6 or less boosts are chosen
readyToPair.setEnabled(true);
readyToPair.setClickable(true);
}
}
private void msg(String s)
{
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).show();
}
}//End Main