What I am trying to do is to handle multitouch buttons. I have 6 buttons and the user may touch from 1 to 6 buttons. The problem is that MotionEvent can handle up to 3 pointers but what I need is up to 6 pointers. Any help please?
This is the code:
public class MultitouchtestActivity extends Activity {
private class TouchListener implements OnTouchListener {
#Override
public boolean onTouch(final View v, final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
switch (v.getId()) {
case R.id.button1:
sqText = "Square 1 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
case R.id.button2:
sq1Text = "Square 2 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
case R.id.button3:
sq2Text = "Square 3 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
case R.id.button4:
sq3Text = "Square 4 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
case R.id.button5:
sq4Text = "Square 5 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
case R.id.button6:
sq5Text = "Square 6 Pressed::Pointer count = "
+ String.valueOf(event.getPointerCount());
break;
}
} else if (event.getAction() == MotionEvent.ACTION_POINTER_1_DOWN) {
switch (v.getId()) {
case R.id.button1:
sqText = "Square 1 Pointer1Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button2:
sq1Text = "Square 2 Pointer1Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button3:
sq2Text = "Square 3 Pointer1Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button4:
sq3Text = "Square 4 Pointer1Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if (event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
switch (v.getId()) {
case R.id.button1:
sqText = "Square 1 Pointer2Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button2:
sq1Text = "Square 2 Pointer2Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button3:
sq2Text = "Square 3 Pointer2Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button4:
sq3Text = "Square 4 Pointer2Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
}
} else if (event.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {
switch (v.getId()) {
case R.id.button1:
sqText = "Square 1 Pointer3Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button2:
sq1Text = "Square 2 Pointer3Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button3:
sq2Text = "Square 3 Pointer3Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
case R.id.button4:
sq3Text = "Square 4 Pointer3Down::Pointer count = "
+ String.valueOf(event.getPointerCount()) + "\n";
break;
}
}
// TODO Auto-generated method stub
return true;
}
}
protected Button sq1;
protected Button sq2;
protected Button sq3;
protected Button sq4;
protected Button sq5;
protected Button sq6;
protected String sqText = new String();
protected String sq1Text = new String();
protected String sq2Text = new String();
protected String sq3Text = new String();
protected String sq4Text = new String();
protected String sq5Text = new String();
private final Handler handler = new Handler();
private final Runnable mUpdateUITimerTask = new Runnable() {
#Override
public void run() {
// do whatever you want to change here, like:
updateTextField();
}
};
/** Called when the activity is first created. */
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setViews();
handler.postDelayed(mUpdateUITimerTask, 5000);
}
private void setViews() {
sq1 = (Button) findViewById(R.id.button1);
sq2 = (Button) findViewById(R.id.button2);
sq3 = (Button) findViewById(R.id.button3);
sq4 = (Button) findViewById(R.id.button4);
sq5 = (Button) findViewById(R.id.button5);
sq6 = (Button) findViewById(R.id.button6);
sq1.setOnTouchListener(new TouchListener());
sq2.setOnTouchListener(new TouchListener());
sq3.setOnTouchListener(new TouchListener());
sq4.setOnTouchListener(new TouchListener());
sq5.setOnTouchListener(new TouchListener());
sq6.setOnTouchListener(new TouchListener());
}
private void updateTextField() {
final TextView view1 = (TextView) findViewById(R.id.logView);
final TextView view2 = (TextView) findViewById(R.id.logView1);
final TextView view3 = (TextView) findViewById(R.id.logView2);
final TextView view4 = (TextView) findViewById(R.id.logView3);
final TextView view5 = (TextView) findViewById(R.id.logView4);
final TextView view6 = (TextView) findViewById(R.id.logView5);
// view1.append(sqText + "\n");
view1.setText(sqText);
view2.setText(sq1Text);
view3.setText(sq2Text);
view4.setText(sq3Text);
view5.setText(sq4Text);
view6.setText(sq5Text);
handler.post(mUpdateUITimerTask);
}
}
The number of pointers that you can detect with android depends on the device. Some older ones can only detect one whereas more modern ones may be able to detect more.
Please make sure that your app also works on devices with less pointers if you want to publish it on the market.
Related
I have a quiz app which has a timer for the whole game-activity where in you should answer as 20 questions and every qustion have 10 sec ..
after the assigned 20 is over, it will take you to the results activity which shows your score. even after calling score activity toast from main activty will show and score activity will open agian and again.
int score = 0;
int unanswer = 0;
int questionasked = 1;
int maxquestion = 20;
TextView first, operator, second, timeview;
Button A, B, C, D;
int ans = 0;
String t;
DecimalFormat df;
CountDownTimer mCountDownTimer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timeview = findViewById(R.id.time);
A = findViewById(R.id.A);
A.setOnClickListener(this);
B = findViewById(R.id.B);
B.setOnClickListener(this);
C = findViewById(R.id.C);
C.setOnClickListener(this);
D = findViewById(R.id.D);
D.setOnClickListener(this);
first = findViewById(R.id.first);
second = findViewById(R.id.second);
operator = findViewById(R.id.operator);
df = new DecimalFormat("###.##");
starTimer();
fillValue();
}
main activity code
private void fillValue() {
if (questionasked > maxquestion)
showscore();
questionasked++;
int a = (int) (Math.random() * 50 + 1);
int b = (int) (Math.random() * 50 + 1);
int op = (int) (Math.random() * 4 + 1);
int buttonoption = (int) (Math.random() * 4 + 1);
char operatorcharter = '+';
switch (op) {
case 1:
ans = a + b;
operatorcharter = '+';
break;
case 2:
ans = a - b;
operatorcharter = '-';
break;
case 3:
ans = a * b;
operatorcharter = 'X';
break;
case 4:
ans = (a) / b;
operatorcharter = '/';
break;
//default:
//Toast.makeText(this,op+"",Toast.LENGTH_SHORT).show();
}
//Toast.makeText(this,a+" "+operatorcharter+" "+b+" "+ans+" "+buttonoption,Toast.LENGTH_LONG).show();
operator.setText(operatorcharter + "");
first.setText(a + "");
second.setText(b + "");
t = df.format(ans);
int temp = 0;
switch (buttonoption) {
case 1:
A.setText(t);
break;
case 2:
B.setText(t);
break;
case 3:
C.setText(t);
break;
case 4:
D.setText(t);
break;
//default:
// Toast.makeText(this,buttonoption+" butt",Toast.LENGTH_SHORT).show();
}
for (int i = 1; i <= 4; i++) {
if (i == buttonoption)
continue;
temp = (int) (Math.random() * ans + 1);
if (temp == ans) ;
temp += 5;
String temp1 = df.format(temp);
if (i == 1)
A.setText(temp1 + "");
else if (i == 2)
B.setText(temp1 + "");
else if (i == 3)
C.setText(temp1 + "");
else if (i == 4)
D.setText(temp1 + "");
}
mCountDownTimer.start();
}
private void showscore() {
Intent i = new Intent(this, final_activity.class);
i.putExtra(Contact.maxquestion, maxquestion);
i.putExtra(Contact.score, score);
i.putExtra(Contact.unanswer, unanswer);
mCountDownTimer.cancel();
Toast.makeText(this, "new activity open", Toast.LENGTH_LONG).show();
startActivity(i);
this.finish();
}
#Override
public void onClick(View v) {
Button b = (Button) v;
String clickbuttonvalue = (String) b.getText();
if (clickbuttonvalue.equals(t))
score++;
//Toast.makeText(this,score+" "+clickbuttonvalue ,Toast.LENGTH_LONG).show();
mCountDownTimer.cancel();
fillValue();
}
public void starTimer() {
mCountDownTimer = new CountDownTimer(10000, 1000) {
public void onTick(long millisUntilFinished) {
timeview.setText("seconds remaining: " + millisUntilFinished / 1000);
Toast.makeText(MainActivity.this, "new" + millisUntilFinished / 1000, Toast.LENGTH_LONG).show();
}
public void onFinish() {
unanswer++;
fillValue();
}
}.start();
}
}
this is my code even after opening new activity and open new activity check method showscore()
plz, help!
You need to override the onDestroy method which will be triggered when the activity is finished(don't forget to add finish() after the startActivty()).
#Override
public void onDestroy() {
super.onDestroy();
mCountDownTimer.cancel();
}
I have a addAllToGroup click function and I use the DialogWithRadioButtonM in many different places, is it possible to place DialogWithRadioButtonM() and redioGroup1() functions in a separate file(class)? Here is my code:
i tried to put it in a class but i get error for onclicklistener in it and also i dont know how to use context in a nonActivity java file. sorry, I am new in android and java thanks for help.
public void addAllToGroup(View view) {
csM = new String[6];
//dialogTitle="Add This to Group";
csM[0] = "Add to Group 1";
csM[1] = "Add to Group 2";
csM[2] = "Add to Group 3";
csM[3] = "Add to Group 4";
csM[4] = "Add to Group 5";
csM[5] = "Remove Grouping";
DialogWithRadioButtonM("Add Selected to Group");
}
public void DialogWithRadioButtonM(String str){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(str);
builder.setSingleChoiceItems(csM, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Log.i("TAG2", "onCreate: "+item);
switch(item)
{
case 0: backFromDialogM=0; break;
case 1: backFromDialogM=1; break;
case 2: backFromDialogM=2; break;
case 3: backFromDialogM=3; break;
case 4: backFromDialogM=4; break;
case 5: backFromDialogM=5; break;
case 6: backFromDialogM=6; break;
case 7: backFromDialogM=7; break;
}
redioGroup1(backFromDialogM);
alertDialogM.dismiss();
}
});
alertDialogM = builder.create();
alertDialogM.show();
}
public void redioGroup1(int group) {
int iCount = myRecycler.getAdapter().getItemCount();
MyDateBase mydbM = new MyDateBase(MainActivity.this);
final SQLiteDatabase databaseM = mydbM.getWritableDatabase();
String strCL = "cl" + "0";
String rawQueryM="";
for (int i = 0; i < iCount; i++) {
if (mAdapter.itemList.get(i).isChecked()) {
mAdapter.itemList.get(i).getuSentId();
rawQueryM ="UPDATE wp_words SET " + strCL + " =" + group + " WHERE wid= " + mAdapter.itemList.get(i).getuSentId();
databaseM.execSQL(rawQueryM);
Log.i("tog", "" + mAdapter.itemList.get(i).getuSentId());
}
}
Log.i("togf", "" + rawQueryM);
}
thanks
Your "DialogWithRadioButtonM" Class depends of the outer class in which it is.
You have to make "DialogWithRadioButtonM" not dependant of other variables/objects outside it, or you cannot move it in a stand alone Class file.
For example: "backFromDialogM" and "alertDialogM" are not declared INSIDE DialogWithRadioButtonM but somewhere else in the same file.
When a Search one value ,get the same value set all show ,,how to do this..
Example.. search value is one,Then click search button showing all values,, one,two,three.
UI Design
cancel = (Button) findViewById(R.id.btncancel);
search = (Button) findViewById(R.id.btnsearch);
textView = (TextView) findViewById(R.id.adapterPhone);
final String[] startplacesearchArrayList = { "one ","two","three" };
final String[] startplacesearchArrayList1 = { "Cat ","Dog","Cow" };
final String[] startplacesearchArrayList2 = { "Carrot ","Pottato","cake" };
final ArrayList<String>f=new ArrayList<String>();
f.addAll( Arrays.asList(startplacesearchArrayList) );
f.addAll( Arrays.asList(startplacesearchArrayList1) );
f.addAll( Arrays.asList(startplacesearchArrayList2) );
final AutoCompleteDogsAdapter endadapter = new AutoCompleteDogsAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, f);
start.setAdapter(endadapter);
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String startval = start.getText().toString();
if (TextUtils.isEmpty(startval)) {
Toasty.warning(getApplicationContext(), "Enter The Places").show();
} else {
if (f.contains(startval)) {
for(int i=0;i<f.size();i++)
Toast.makeText(getApplicationContext(),"values is :- "+f.get(i).toString(),Toast.LENGTH_LONG).show();
} else {
Toasty.warning(getApplicationContext(), "Account not founds").show();
}
}
}
});
You should not relay on ArrayList.contains("") it some time does not return true as it check for exact string match, which might not be the case when use types it manually.
Apply this code,
cancel = (Button) findViewById(R.id.btncancel);
search = (Button) findViewById(R.id.btnsearch);
textView = (TextView) findViewById(R.id.adapterPhone);
final String[] startplacesearchArrayList = { "one ","two","three" };
final String[] startplacesearchArrayList1 = { "Cat ","Dog","Cow" };
final String[] startplacesearchArrayList2 = { "Carrot ","Pottato","cake" };
final ArrayList<String>f=new ArrayList<String>();
f.addAll( Arrays.asList(startplacesearchArrayList) );
f.addAll( Arrays.asList(startplacesearchArrayList1) );
f.addAll( Arrays.asList(startplacesearchArrayList2) );
final AutoCompleteDogsAdapter endadapter = new AutoCompleteDogsAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, f);
start.setAdapter(endadapter);
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String startval = search.getText().toString();
if (TextUtils.isEmpty(startval)) {
Toasty.warning(getApplicationContext(), "Enter The Places").show();
} else {
boolean isExist = false;
for (int i = 0; i < f.size(); i++) {
if (f.get(i).toLowerCase().equals(startval.toLowerCase())) {
isExist = true;
String toastMessage = "";
switch (i) {
case 0:
case 1:
case 2:
toastMessage = getToastMessage(startplacesearchArrayList);
break;
case 3:
case 4:
case 5:
toastMessage = getToastMessage(startplacesearchArrayList1);
break;
case 6:
case 7:
case 8:
toastMessage = getToastMessage(startplacesearchArrayList2);
break;
}
Toast.makeText(getApplicationContext(), "values is :- " + toastMessage, Toast.LENGTH_LONG).show();
break;
}
}
if (isExist)
Toasty.warning(getApplicationContext(), "Account not founds").show();
}
}
});
getToastMessage() goes like this,
private String getToastMessage(String[] arrayList) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < arrayList.length; i++) {
stringBuilder.append(arrayList[i]);
if (i != arrayList.length - 1)
stringBuilder.append(",");
}
return stringBuilder.toString();
}
My code gives the answer for two input i.e 5+10=15 in single editText but for more than two input i.e 5+10*2=20 and also if i click operator second time after some value showing 1+++2. how to display only one time after value and how to calculate full equation of editText
My code is given below
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button reset,root,div,mul,del,four,five,six,seven,eight,nine,one,two,three,minus,plus,zero,deci,eql,percent;
int op1,op2;
String first,second;
String str ="";
Character op ='q';
String displayStr="";
double num,numtemp,temp;
EditText mCalculatorDisplay1;
DecimalFormat df = new DecimalFormat("############");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// mCalculatorBrain = new CalculatorBrain();
mCalculatorDisplay1 = (EditText) findViewById(R.id.edittext1);
one = (Button) findViewById(R.id.one);
two = (Button) findViewById(R.id.two);
three = (Button) findViewById(R.id.three);
four = (Button) findViewById(R.id.four);
five = (Button) findViewById(R.id.five);
six = (Button) findViewById(R.id.six);
seven = (Button) findViewById(R.id.seven);
eight = (Button) findViewById(R.id.eight);
nine = (Button) findViewById(R.id.nine);
zero = (Button) findViewById(R.id.zero);
plus = (Button) findViewById(R.id.plus);
minus = (Button) findViewById(R.id.minus);
mul = (Button) findViewById(R.id.multi);
div = (Button) findViewById(R.id.div);
del = (Button) findViewById(R.id.delete);
eql = (Button) findViewById(R.id.equalTo);
deci = (Button) findViewById(R.id.decimal);
root = (Button) findViewById(R.id.root);
reset = (Button) findViewById(R.id.cancel);
percent = (Button) findViewById(R.id.percent);
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
four.setOnClickListener(this);
five.setOnClickListener(this);
six.setOnClickListener(this);
seven.setOnClickListener(this);
eight.setOnClickListener(this);
nine.setOnClickListener(this);
zero.setOnClickListener(this);
plus.setOnClickListener(this);
minus.setOnClickListener(this);
mul.setOnClickListener(this);
div.setOnClickListener(this);
del.setOnClickListener(this);
eql.setOnClickListener(this);
deci.setOnClickListener(this);
root.setOnClickListener(this);
reset.setOnClickListener(this);
percent.setOnClickListener(this);
// mCalculatorDisplay1.setKeyListener(DigitsKeyListener.getInstance(true, true));
}
private void perform() {
// TODO Auto-generated method stub
str = "";
numtemp = num;
}
private void insert(int j) {
// TODO Auto-generated method stub
str = str + Integer.toString(j);
num = Double.valueOf(str);
displayStr += Integer.toString(j);
mCalculatorDisplay1.setText(displayStr);
}
private void calculate() {
// TODO Auto-generated method stub
first=String.valueOf(numtemp);
second=String.valueOf(num);
if(op == '+'){
num = numtemp+num;
}
else if(op == '-')
num = numtemp-num;
else if(op == '/')
num = numtemp/num;
else if(op == '*')
num = numtemp*num;
else if (op=='%')
num = numtemp*num/100;
else if (op=='√') {
num = Math.sqrt(num);
}
mCalculatorDisplay1.setText(first + op + second + "\n"+ "=" + num );
}
private void insert(String j) {
//Insert the values by clicking button
str = str+String.valueOf(j);
String num = String.valueOf(str);
displayStr += String.valueOf(j);
mCalculatorDisplay1.setText(displayStr);
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.one:
insert(1);
break;
case R.id.two:
insert(2);
break;
case R.id.three:
insert(3);
break;
case R.id.four:
insert(4);
break;
case R.id.five:
insert(5);
break;
case R.id.six:
insert(6);
break;
case R.id.seven:
insert(7);
break;
case R.id.eight:
insert(8);
break;
case R.id.nine:
insert(9);
break;
case R.id.decimal:
insert(".");
break;
case R.id.percent:
perform();
op = '%';
displayStr += "%";
break;
case R.id.zero:
insert(0);
break;
case R.id.plus:
// if (displayStr.contains("+")){
// op = '+';
// displayStr+="";
// perform();
// mCalculatorDisplay1.setText(displayStr);
// }
// else
perform();
op = '+';
displayStr+= "+";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.minus:
perform();
op = '-';
displayStr += "-";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.multi:
perform();
op = '*';
displayStr += "*";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.div:
perform();
op = '/';
displayStr += "/";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.cancel:
str="";
displayStr = "";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.root:
perform();
op = '√';
displayStr += "√";
mCalculatorDisplay1.setText(displayStr);
break;
case R.id.delete:
str="";
displayStr ="";
displayStr=mCalculatorDisplay1.getText().toString();
if (displayStr.length() >1 ) {
displayStr = displayStr.substring(0, displayStr.length() - 1);
mCalculatorDisplay1.setText(displayStr);
}
else if (displayStr.length() <=1 ) {
displayStr ="";
mCalculatorDisplay1.setText( displayStr);
}
// mCalculatorDisplay1.setText(displayStr.substring(0,displayStr.length()-1));
break;
case R.id.equalTo:
calculate();
break;
}
}
}
You should use exp4j. It is a expression evaluator for java.
for your purpose
get string from editText
pass the string to the following segment
Calculable calc = new ExpressionBuilder("5+10*2").build()
double result=calc.calculate();
I made two applications that use the bluetooth in the same way. When I click on the "Connect" button I get the message "complete action using..." with the choice of my two applications. How do I delete it and launch only the activity of the application that I am using?
Thanks.
public class MainActivity extends Activity implements View.OnClickListener{
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
if (Bluetooth.connectedThread != null) {
Bluetooth.connectedThread.write(" ");}//Stop streaming
super.onBackPressed();
}
//toggle Button
static boolean Lock;//whether lock the x-axis to 0-5
static boolean AutoScrollX;//auto scroll to the last x value
static boolean Stream;//Start or stop streaming
boolean dark = true;
//Button init
Button bXminus;
Button bXplus;
Button bYminus;
Button bYplus;
ToggleButton tbScroll;
ToggleButton tbStream;
RadioButton ch1,ch2,ch3,ch4;
//GraphView init
static LinearLayout GraphView, GraphView1;
//graph value
private static double graph2LastXValue = 0;
private static int Xview=10;
Button bConnect, bDisconnect;
Button cambia;
Button bBackground;
int switches = 0;
int range = 1;
int counter = 0;
byte prova = (byte) 187; //188 e 168
Handler mHandler = new Handler(){
#Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch(msg.what){
case Bluetooth.SUCCESS_CONNECT:
Bluetooth.connectedThread = new Bluetooth.ConnectedThread((BluetoothSocket)msg.obj);
Toast.makeText(getApplicationContext(), "Connected!", 0).show();
String s = "successfully connected";
Bluetooth.connectedThread.start();
Bluetooth.connectedThread.write(new byte[]{(byte) prova});
break;
case Bluetooth.MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
int valore_a_16 = ((readBuf[1] & 0xFF) << 8) | (readBuf[0] & 0xFF);
int valore_a_16_2 = ((readBuf[3] & 0xFF) << 8) | (readBuf[2] & 0xFF);
int valore_a_16_3 = ((readBuf[5] & 0xFF) << 8) | (readBuf[4] & 0xFF);
int valore_a_16_4 = ((readBuf[7] & 0xFF) << 8) | (readBuf[6] & 0xFF);
String strIncom = new String(readBuf); // create string from bytes array
String str = String.valueOf(valore_a_16);
String str2 = String.valueOf(valore_a_16_2);
String str3 = String.valueOf(valore_a_16_3);
String str4 = String.valueOf(valore_a_16_4);
Log.d("SHORT", str);
Log.d("strIncom", strIncom);
Log.d("SHORT CH 2", str2);
Log.d("SHORT CH 3", str3);
Log.d("SHORT CH 4", str4);
char c = strIncom.charAt(0);
long foo = Integer.parseInt(str);
long foo2 = Integer.parseInt(str2);
long foo3 = Integer.parseInt(str3);
long foo4 = Integer.parseInt(str4);
//String provola = Integer.toString(foo);
//Log.d("AAAAAAAAAAAAAA", provola);
// int decVal = (int) c;
long risultato = (long) (foo * 5000000)/(65535*150);
long risultato2 = (long) (foo2 * 5000000)/(65535*150);
long risultato3 = (long) (foo3 * 5000000)/(65535*150);
long risultato4 = (long) (foo4 * 5000000)/(65535*150);
String prova = Float.toString(risultato);
String prova2 = Float.toString(risultato2);
String prova3 = Float.toString(risultato3);
String prova4 = Float.toString(risultato4);
Log.d("prova", prova);
// Log.d("testing2", String.valueOf(decVal));
break;
}
}
public boolean isFloatNumber(String num){
//Log.d("checkfloatNum", num);
try{
Double.parseDouble(num);
} catch(NumberFormatException nfe) {
return false;
}
return true;
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);//Hide title
this.getWindow().setFlags(WindowManager.LayoutParams.
FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//Hide Status bar
setContentView(R.layout.activity_main);
//set background color
LinearLayout background = (LinearLayout)findViewById(R.id.bg);
background.setBackgroundColor(Color.BLACK);
init();
ButtonInit();
}
void init(){
Bluetooth.gethandler(mHandler);
}
void ButtonInit(){
bConnect = (Button)findViewById(R.id.bConnect);
bConnect.setOnClickListener(this);
bDisconnect = (Button)findViewById(R.id.bDisconnect);
bDisconnect.setOnClickListener(this);
//X-axis control button
bXminus = (Button)findViewById(R.id.bXminus);
bXminus.setOnClickListener(this);
bXplus = (Button)findViewById(R.id.bXplus);
bXplus.setOnClickListener(this);
bYminus = (Button)findViewById(R.id.bYminus);
bYminus.setOnClickListener(this);
bYplus = (Button)findViewById(R.id.bYplus);
bYplus.setOnClickListener(this);
//
tbScroll = (ToggleButton)findViewById(R.id.tbScroll);
tbScroll.setOnClickListener(this);
tbStream = (ToggleButton)findViewById(R.id.tbStream);
tbStream.setOnClickListener(this);
tbStream.setEnabled(false);
bBackground = (Button)findViewById(R.id.button1);
bBackground.setOnClickListener(this);
//init toggleButton
ch1 = (RadioButton)findViewById(R.id.radioButton1);
ch1.setOnClickListener(this);
ch1.setChecked(true);
ch2 = (RadioButton)findViewById(R.id.radioButton2);
ch2.setOnClickListener(this);
ch3 = (RadioButton)findViewById(R.id.radioButton3);
ch3.setOnClickListener(this);
ch4 = (RadioButton)findViewById(R.id.radioButton4);
ch4.setOnClickListener(this);
Lock=false;
AutoScrollX=true;
Stream=true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bConnect:
startActivity(new Intent("android.intent.action.BT1"));
break;
case R.id.bDisconnect:
Intent myIntent = new Intent(MainActivity.this, RacerGameActivity.class);
MainActivity.this.startActivity(myIntent);
break;
case R.id.bXminus:
if (Xview>1) Xview=Xview/10;
break;
case R.id.bXplus:
if (Xview<100) Xview=Xview*10;
break;
case R.id.bYminus:
if (range==1)
{
range=0;
}
else if (range==0)
{
range=0;
}
else if(range==2)
{
range=1;
}
else if(range==3)
{
range=2;
}
else if(range==4)
{
range=3;
}
break;
case R.id.bYplus:
if (range==1)
{
range=2;
}
else if (range==0)
{
range=1;
}
else if(range==2)
{
range=3;
}
else if(range==3)
{
range=4;
}
else if(range==4)
{
range=4;
}
break;
case R.id.tbScroll:
if (tbScroll.isChecked()){
AutoScrollX = true;
}else{
AutoScrollX = false;
}
break;
case R.id.radioButton1:
ch1.setChecked(true);
ch2.setChecked(false);
ch3.setChecked(false);
ch4.setChecked(false);
switches=0;
break;
case R.id.radioButton2:
ch1.setChecked(false);
ch2.setChecked(true);
ch3.setChecked(false);
ch4.setChecked(false);
switches=1;
break;
case R.id.radioButton3:
ch1.setChecked(false);
ch2.setChecked(false);
ch3.setChecked(true);
ch4.setChecked(false);
switches=2;
break;
case R.id.radioButton4:
ch1.setChecked(false);
ch2.setChecked(false);
ch3.setChecked(false);
ch4.setChecked(true);
switches=3;
break;
/* case R.id.tbStream:
if (tbStream.isChecked()){
if (Bluetooth.connectedThread != null)
Bluetooth.connectedThread.write("E");
}else{
if (Bluetooth.connectedThread != null)
Bluetooth.connectedThread.write("Q");
}
break;
// case R.id.button1:
// GraphView.setBackgroundColor(Color.WHITE);
// break;
case R.id.button1:
switches=1;
break;*/
}
}
}