|
@@ -11,10 +11,13 @@ import java.io.ObjectOutputStream;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
import java.io.StreamCorruptedException;
|
|
import java.io.StreamCorruptedException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Random;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
import de.tudarmstadt.informatik.hostage.model.Profile;
|
|
@@ -129,14 +132,18 @@ public class ProfileManager {
|
|
}
|
|
}
|
|
|
|
|
|
public void randomizeProtocols(Profile profile){
|
|
public void randomizeProtocols(Profile profile){
|
|
- for(String protocol: MainActivity.getContext().getResources().getStringArray(R.array.protocols)){
|
|
|
|
- double rand = Math.random();
|
|
|
|
|
|
+ LinkedList<String> protocols = new LinkedList<String>(Arrays.asList(MainActivity.getContext().getResources().getStringArray(R.array.protocols)));
|
|
|
|
+ profile.mActiveProtocols.clear();
|
|
|
|
|
|
- if(rand > 0.4){
|
|
|
|
- profile.mActiveProtocols.put(protocol, true);
|
|
|
|
- } else {
|
|
|
|
- profile.mActiveProtocols.put(protocol, false);
|
|
|
|
- }
|
|
|
|
|
|
+ Random rand = new Random();
|
|
|
|
+ int numberOfProtocolsToActivate = rand.nextInt(protocols.size()) + 1;
|
|
|
|
+
|
|
|
|
+ while(numberOfProtocolsToActivate-- > 0){
|
|
|
|
+ int randomIndex = rand.nextInt(protocols.size());
|
|
|
|
+ String protocol = protocols.get(randomIndex);
|
|
|
|
+
|
|
|
|
+ profile.mActiveProtocols.put(protocol, true);
|
|
|
|
+ protocols.remove(protocol);
|
|
}
|
|
}
|
|
|
|
|
|
persistData();
|
|
persistData();
|
|
@@ -194,7 +201,14 @@ public class ProfileManager {
|
|
|
|
|
|
public void deleteProfile(Profile profile){
|
|
public void deleteProfile(Profile profile){
|
|
if(this.holder.mProfiles.containsKey(profile.mId)){
|
|
if(this.holder.mProfiles.containsKey(profile.mId)){
|
|
|
|
+ Profile p = getProfile(profile.mId);
|
|
this.holder.mProfiles.remove(profile.mId);
|
|
this.holder.mProfiles.remove(profile.mId);
|
|
|
|
+
|
|
|
|
+ if(p.mActivated || this.mCurrentActivatedProfile.mId == p.mId){
|
|
|
|
+ mCurrentActivatedProfile = mRandomProfile;
|
|
|
|
+ mRandomProfile.mActivated = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
this.persistData();
|
|
this.persistData();
|
|
//this.dbh.deleteProfile(profile.mId);
|
|
//this.dbh.deleteProfile(profile.mId);
|
|
|
|
|
|
@@ -224,6 +238,14 @@ public class ProfileManager {
|
|
persistData();
|
|
persistData();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public boolean isRandomActive(){
|
|
|
|
+ return this.mCurrentActivatedProfile.equals(this.mRandomProfile);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Profile getRandomProfile(){
|
|
|
|
+ return this.mRandomProfile;
|
|
|
|
+ }
|
|
|
|
+
|
|
public Profile getCurrentActivatedProfile(){
|
|
public Profile getCurrentActivatedProfile(){
|
|
return mCurrentActivatedProfile;
|
|
return mCurrentActivatedProfile;
|
|
}
|
|
}
|