Commit 9df5a520 authored by Xavier's avatar Xavier

BugFix, disable buttons and list of local sim when it is connected

parent 12b3041d
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:id="@+id/RelativeLayoutLocalSim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey5"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:id="@+id/RelativeLayoutLocalSim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey5"
......@@ -53,7 +53,8 @@
android:layout_below="@+id/linearLayout1"
android:layout_margin="5dp"
android:background="@color/grey3"
android:choiceMode="singleChoice" >
android:choiceMode="singleChoice"
android:clickable="true" >
</ListView>
......
......@@ -34,6 +34,7 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.Switch;
import android.widget.Toast;
......@@ -142,10 +143,12 @@ public final class SimulatorFragment extends Fragment implements LoaderCallbacks
String port = sharedPref.getString(getString(R.string.pref_key_sim_remote_port), Parameters.Simulator.Remote.default_port);
host_view.setText(host);
port_view.setText(port);
RelativeLayout localSimLayout = (RelativeLayout) rootView.findViewById(R.id.RelativeLayoutLocalSim);
button_connect = (Button) rootView.findViewById(R.id.buttonConnect);
simulator.setButtonConnect(button_connect);
simulator.setSwitchSelector(switch_remote);
simulator.setSwitchAndListSelector(switch_remote,localSimLayout);
button_connect.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(simulator.getSimulatorStatus().equals(SimulatorStatus.Connected)){
......
......@@ -15,8 +15,11 @@ import android.content.SharedPreferences;
import android.os.ConditionVariable;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.Toast;
......@@ -26,19 +29,31 @@ import android.widget.Toast;
*
*/
public class Simulator {
private SimulatorStatus simulatorStatus = SimulatorStatus.Disconnected;
private SimulationStatus simulationStatus = SimulationStatus.Pause;
//General
private SharedPreferences sharedPref;
private Context context;
private Activity activity;
//Simulation core
private SimulatorStatus simulatorStatus = SimulatorStatus.Disconnected;
private SimulationStatus simulationStatus = SimulationStatus.Pause;
private SocketsThread thread;
@SuppressWarnings("unused")
private SimulatorThread sthread;
//Results
private ModelSimulation simulation;
//GUI views
private Button buttonConnect;
private Switch switchSelector;
private RelativeLayout localSimLayout;
//Mission
private Mission mission;
private int mission_id=-1;
//Flags
private boolean wasPlaying = false;//Flag to restore playing if fragment has paused-resumed while playing
/**
......@@ -107,9 +122,10 @@ public class Simulator {
* Set local/remote switch View
* @param st
*/
public void setSwitchSelector(Switch st){
public void setSwitchAndListSelector(Switch st, RelativeLayout localSim){
switchSelector=st;
updateSwitchEnabled();
localSimLayout = localSim;
updateSwitchAndListEnabled();
}
/**
......@@ -357,7 +373,7 @@ public class Simulator {
public void setSimulatorStatus(SimulatorStatus new_status) {
simulatorStatus = new_status;
updateConnectButtonText();
updateSwitchEnabled();
updateSwitchAndListEnabled();
setCorrectSimulatorControls();
setProgress(100 * 100);
}
......@@ -388,19 +404,39 @@ public class Simulator {
}
/**
* Enable or disable the simulator mode switch according to its status (Connected/Disconnected)
* Enable or disable the simulator mode switch and controls according to its status (Connected/Disconnected)
*/
private void updateSwitchEnabled(){
if(switchSelector!=null){
private void updateSwitchAndListEnabled(){
activity.runOnUiThread( new Runnable() {
public void run() {
if(simulatorStatus.equals(SimulatorStatus.Connected))
switchSelector.setEnabled(false);
else
switchSelector.setEnabled(true);
if(switchSelector!=null){
if(simulatorStatus.equals(SimulatorStatus.Connected))
switchSelector.setEnabled(false);
else
switchSelector.setEnabled(true);
}
if(localSimLayout!=null){
if(simulatorStatus.equals(SimulatorStatus.Connected)){
enableView(localSimLayout, false);
//localSimLayout.setEnabled(false);
}else{
enableView(localSimLayout, true);
//localSimLayout.setEnabled(true);
}
}
}
});
}
}
private static void enableView(ViewGroup layout, boolean enabled) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup && !(child instanceof ListView) ) {
enableView((ViewGroup) child, enabled);
} else {
child.setEnabled(enabled);
}
}
}
private String message = "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment