@@ -25,7 +25,7 @@ | |||
</map> | |||
</option> | |||
</component> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK"> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK"> | |||
<output url="file://$PROJECT_DIR$/build/classes" /> | |||
</component> | |||
<component name="ProjectType"> |
@@ -29,7 +29,7 @@ public class MainActivity extends AppCompatActivity { | |||
private ActivityMainBinding binding; | |||
private ExtendedSocket socket; | |||
private DataTransferAsyncTask dataTransferAsyncTask; | |||
Boolean connected = false; | |||
public Boolean connected = false; | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { |
@@ -19,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider; | |||
import com.example.lfrmobileapp.Communication; | |||
import com.example.lfrmobileapp.DataTransferAsyncTask; | |||
import com.example.lfrmobileapp.MainActivity; | |||
import com.example.lfrmobileapp.R; | |||
import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding; | |||
@@ -28,14 +29,21 @@ import java.util.Arrays; | |||
import kotlin.collections.UArraySortingKt; | |||
// Autonomous Mode | |||
public class DashboardFragment extends Fragment { | |||
Communication com = new Communication(); | |||
private FragmentAutomatikBinding binding; | |||
MainActivity mainActivity; | |||
//Keys for Shared Preferences | |||
String listKey = "listkey"; | |||
DataTransferAsyncTask dataTransferAsyncTask; | |||
@Override | |||
public void onAttach(Context context) { | |||
super.onAttach(context); | |||
mainActivity = (MainActivity) context; | |||
} | |||
public View onCreateView(@NonNull LayoutInflater inflater, | |||
ViewGroup container, Bundle savedInstanceState) { | |||
@@ -59,10 +67,12 @@ public class DashboardFragment extends Fragment { | |||
@Override | |||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |||
if(isChecked){ | |||
dataTransferAsyncTask.writeTelegram(com.telegram(true, autoList)); | |||
}else{ | |||
dataTransferAsyncTask.writeTelegram(com.telegram(false, autoList)); | |||
if (mainActivity.connected){ | |||
if(isChecked){ | |||
mainActivity.sendTelegram(com.telegram(true, autoList)); | |||
}else{ | |||
mainActivity.sendTelegram(com.telegram(false, autoList)); | |||
} | |||
} | |||
} | |||
}); | |||
@@ -149,7 +159,6 @@ public class DashboardFragment extends Fragment { | |||
@Override | |||
public void onDestroyView() { | |||
super.onDestroyView(); | |||
dataTransferAsyncTask.cancel(false); | |||
binding = null; | |||
} | |||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint; | |||
import android.content.Context; | |||
import android.content.SharedPreferences; | |||
import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.LayoutInflater; | |||
import android.view.MotionEvent; | |||
import android.view.View; | |||
@@ -74,29 +75,41 @@ public class HomeFragment extends Fragment { | |||
@SuppressLint("ClickableViewAccessibility") | |||
@Override | |||
public boolean onTouch(View v, MotionEvent event) { | |||
if(event.getAction() == MotionEvent.ACTION_UP){ | |||
boolean send = false; | |||
if (System.currentTimeMillis() - lastOnMoveCall > 250){ | |||
send = true; | |||
lastOnMoveCall = System.currentTimeMillis(); | |||
} | |||
if (send && mainActivity.connected) { | |||
if (event.getAction() == MotionEvent.ACTION_UP) { | |||
binding.rotateLeft.performClick(); | |||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0)); | |||
return true; | |||
}else{ | |||
} else { | |||
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100)); | |||
} | |||
return false; | |||
} | |||
}); | |||
return false; | |||
} | |||
}); | |||
binding.rotateRight.setOnTouchListener(new View.OnTouchListener(){ | |||
@SuppressLint("ClickableViewAccessibility") | |||
@Override | |||
public boolean onTouch(View v, MotionEvent event) { | |||
if(event.getAction() == MotionEvent.ACTION_UP){ | |||
binding.rotateRight.performClick(); | |||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0)); | |||
return true; | |||
}else{ | |||
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100)); | |||
boolean send = false; | |||
if (System.currentTimeMillis() - lastOnMoveCall > 250){ | |||
send = true; | |||
lastOnMoveCall = System.currentTimeMillis(); | |||
} | |||
if (send && mainActivity.connected){ | |||
if(event.getAction() == MotionEvent.ACTION_UP){ | |||
binding.rotateRight.performClick(); | |||
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0)); | |||
return true; | |||
}else{ | |||
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100)); | |||
} | |||
} | |||
return false; | |||
} | |||
@@ -145,9 +158,10 @@ public class HomeFragment extends Fragment { | |||
joystick.setBackgroundResource(R.mipmap.blank); | |||
telegram = com.telegram(new int[]{0, 0, 0, 0}, strength); | |||
} | |||
if (send) | |||
if (send && mainActivity.connected) | |||
{ | |||
mainActivity.sendTelegram(telegram); | |||
// Log.v("TAG", telegram + "\n"); | |||
} | |||
} | |||
}); |
@@ -59,8 +59,8 @@ public class NotificationsFragment extends Fragment { | |||
String connectionFailed = "Verbindung fehlgeschlagen."; | |||
String connectionSuccessful = "Verbindung erfolgreich."; | |||
String ipAddress = "192.168.0.1"; | |||
int port = 8000; | |||
String ipAddress = "192.168.4.1"; | |||
int port = 8080; | |||
int duration = Toast.LENGTH_LONG; | |||
DataTransferAsyncTask dataTransferAsyncTask; | |||
@@ -100,8 +100,12 @@ public class NotificationsFragment extends Fragment { | |||
final Button button = binding.connect; | |||
button.setOnClickListener(new View.OnClickListener() { | |||
public void onClick(View v) { | |||
ipAddress = String.valueOf(binding.ipAdress.getText()); | |||
port = Integer.parseInt(String.valueOf(binding.port.getText())); | |||
try { | |||
ipAddress = String.valueOf(binding.ipAdress.getText()); | |||
port = Integer.parseInt(String.valueOf(binding.port.getText())); | |||
} catch (Exception e){ | |||
System.err.println("Parse Exception: " + e.getMessage()); | |||
} | |||
connected = mainActivity.connectToWifi(ipAddress, port); | |||