call asynctask through mainactivity
This commit is contained in:
parent
ffb38996e8
commit
a8e8ccbbe1
@ -38,7 +38,6 @@ public class HomeFragment extends Fragment {
|
||||
MainActivity mainActivity;
|
||||
|
||||
Communication com = new Communication();
|
||||
DataTransferAsyncTask dataTransferAsyncTask;
|
||||
|
||||
private FragmentManuellBinding binding;
|
||||
|
||||
@ -76,10 +75,10 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
if(event.getAction() == MotionEvent.ACTION_UP){
|
||||
binding.rotateLeft.performClick();
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||
return true;
|
||||
}else{
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -92,10 +91,10 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
if(event.getAction() == MotionEvent.ACTION_UP){
|
||||
binding.rotateRight.performClick();
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
|
||||
return true;
|
||||
}else{
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -110,32 +109,32 @@ public class HomeFragment extends Fragment {
|
||||
//8 segments of the joystick
|
||||
if((angle >= 338 || angle < 22) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.right);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{1, -1, -1, 1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, -1, 1}, strength));
|
||||
}else if((angle >= 22 && angle < 67) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.right_forward);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{1, 0, 0, 1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{1, 0, 0, 1}, strength));
|
||||
}else if((angle >=67 && angle < 112) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.forward);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{1, 1, 1, 1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{1, 1, 1, 1}, strength));
|
||||
}else if((angle >=112 && angle < 157) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.left_forward);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{0, 1, 1, 0}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 1, 1, 0}, strength));
|
||||
}else if((angle >=157 && angle < 202) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.left);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{-1, 1, 1, -1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, 1, -1}, strength));
|
||||
}else if((angle >=202 && angle < 247) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.left_back);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{-1, 0, 0, -1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{-1, 0, 0, -1}, strength));
|
||||
}else if((angle >=247 && angle < 292) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.back);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{-1, -1, -1, -1}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{-1, -1, -1, -1}, strength));
|
||||
}else if((angle >=292 && angle < 337) && strength != 0){
|
||||
joystick.setBackgroundResource(R.mipmap.right_back);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{0, -1, -1, 0}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{0, -1, -1, 0}, strength));
|
||||
}
|
||||
else{
|
||||
joystick.setBackgroundResource(R.mipmap.blank);
|
||||
dataTransferAsyncTask.writeTelegram(com.telegram(new int[]{0, 0, 0, 0}, strength));
|
||||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, strength));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user