Browse Source

call asynctask through mainactivity

master
Tim Zeuner 1 year ago
parent
commit
a8e8ccbbe1

+ 13
- 14
MobileApp/app/src/main/java/com/example/lfrmobileapp/ui/home/HomeFragment.java View File

MainActivity mainActivity; MainActivity mainActivity;


Communication com = new Communication(); Communication com = new Communication();
DataTransferAsyncTask dataTransferAsyncTask;


private FragmentManuellBinding binding; private FragmentManuellBinding binding;




if(event.getAction() == MotionEvent.ACTION_UP){ if(event.getAction() == MotionEvent.ACTION_UP){
binding.rotateLeft.performClick(); 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; return true;
}else{ }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; return false;
} }


if(event.getAction() == MotionEvent.ACTION_UP){ if(event.getAction() == MotionEvent.ACTION_UP){
binding.rotateRight.performClick(); 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; return true;
}else{ }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; return false;
} }
//8 segments of the joystick //8 segments of the joystick
if((angle >= 338 || angle < 22) && strength != 0){ if((angle >= 338 || angle < 22) && strength != 0){
joystick.setBackgroundResource(R.mipmap.right); 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){ }else if((angle >= 22 && angle < 67) && strength != 0){
joystick.setBackgroundResource(R.mipmap.right_forward); 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){ }else if((angle >=67 && angle < 112) && strength != 0){
joystick.setBackgroundResource(R.mipmap.forward); 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){ }else if((angle >=112 && angle < 157) && strength != 0){
joystick.setBackgroundResource(R.mipmap.left_forward); 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){ }else if((angle >=157 && angle < 202) && strength != 0){
joystick.setBackgroundResource(R.mipmap.left); 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){ }else if((angle >=202 && angle < 247) && strength != 0){
joystick.setBackgroundResource(R.mipmap.left_back); 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){ }else if((angle >=247 && angle < 292) && strength != 0){
joystick.setBackgroundResource(R.mipmap.back); 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){ }else if((angle >=292 && angle < 337) && strength != 0){
joystick.setBackgroundResource(R.mipmap.right_back); 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{ else{
joystick.setBackgroundResource(R.mipmap.blank); 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…
Cancel
Save