|
@@ -4,6 +4,7 @@ package app.brest.testmin3d;
|
|
|
import android.annotation.TargetApi;
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.media.Ringtone;
|
|
@@ -18,15 +19,22 @@ import android.support.v7.app.ActionBar;
|
|
|
import android.preference.PreferenceFragment;
|
|
|
import android.preference.PreferenceManager;
|
|
|
import android.preference.RingtonePreference;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
import android.widget.ToggleButton;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
+import app.brest.app.brest.ui.CustomToggleButton;
|
|
|
+import app.brest.app.brest.ui.OnToggleListener;
|
|
|
+import app.brest.app.brest.ui.RotateButton;
|
|
|
+import app.brest.app.brest.ui.SelectButton;
|
|
|
import app.brest.utils.Settings;
|
|
|
import app.brest.utils.app.brest.game.Game;
|
|
|
|
|
@@ -41,75 +49,219 @@ import app.brest.utils.app.brest.game.Game;
|
|
|
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
|
|
|
* API Guide</a> for more information on developing a Settings UI.
|
|
|
*/
|
|
|
-public class SettingsActivity extends Activity {
|
|
|
+public class SettingsActivity extends Activity implements app.brest.app.brest.ui.OnToggleListener, View.OnClickListener {
|
|
|
|
|
|
protected Game mGame;
|
|
|
protected LinearLayout mRoot;
|
|
|
- protected ToggleButton mAccelerometer;
|
|
|
- protected ToggleButton mGPS;
|
|
|
- protected ToggleButton mPlaces;
|
|
|
- protected ToggleButton mAreas;
|
|
|
+ protected LinearLayout mRootDev;
|
|
|
+ protected CustomToggleButton mAccelerometer;
|
|
|
+ protected CustomToggleButton mGPS;
|
|
|
+ protected CustomToggleButton mPlaces;
|
|
|
+ protected CustomToggleButton mAreas;
|
|
|
+ protected CustomToggleButton mDev;
|
|
|
+ protected CustomToggleButton mRA;
|
|
|
+ protected SelectButton mSensorLatency;
|
|
|
+ protected Button mReset;
|
|
|
+ protected Button mCheat;
|
|
|
+ protected Button mOk;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_settings);
|
|
|
|
|
|
- mGame = (Game) getIntent().getSerializableExtra("game");
|
|
|
-
|
|
|
- mAccelerometer = new ToggleButton(this);
|
|
|
- mGPS = new ToggleButton(this);
|
|
|
- mPlaces=new ToggleButton(this);
|
|
|
- mAreas=new ToggleButton(this);
|
|
|
+ mGame = Game.game();
|
|
|
+ mRootDev=new LinearLayout(this);
|
|
|
+ mRootDev.setOrientation(LinearLayout.VERTICAL);
|
|
|
+ mAccelerometer = new CustomToggleButton(this);
|
|
|
+ mGPS = new CustomToggleButton(this);
|
|
|
+ mDev = new CustomToggleButton(this);
|
|
|
+ mDev.setOnClickListener((app.brest.app.brest.ui.OnToggleListener)this);
|
|
|
+ mPlaces=new CustomToggleButton(this);
|
|
|
+ mRA=new CustomToggleButton(this);
|
|
|
+ mAreas=new CustomToggleButton(this);
|
|
|
+ mSensorLatency = new SelectButton(this, Settings.SENSORS_LATENCIES);
|
|
|
+ mCheat = newButton("Avoir toutes les ressources");
|
|
|
+ mReset = newButton("Supprimer la sauvegarde");
|
|
|
mRoot = (LinearLayout)findViewById(R.id.root_layout);
|
|
|
- addOptionBool("Données acceleromètre", mAccelerometer);
|
|
|
- addOptionBool("Données GPS", mGPS);
|
|
|
- addOptionBool("Distance Resources", mAreas);
|
|
|
- addOptionBool("Resources affichés", mPlaces);
|
|
|
+ mOk = (Button)findViewById(R.id.sbutok);
|
|
|
+ addSelection("Latence des capteurs:", mSensorLatency, mRoot);
|
|
|
+ addAction("", mReset, mRoot);
|
|
|
+ addOptionBool("Mode Réalitée augmentée", mRA, mRoot);
|
|
|
+ addOptionBool("Mode développeur:", mDev, mRoot);
|
|
|
+ mRoot.addView(mRootDev);
|
|
|
+ addOptionBool("GPS préprogrammé:", mGPS, mRootDev);
|
|
|
+ addOptionBool("Afficher les zones:", mAreas, mRootDev);
|
|
|
+ addOptionBool("Afficher les ressources:", mPlaces, mRootDev);
|
|
|
+ addAction("", mCheat, mRootDev);
|
|
|
preset();
|
|
|
}
|
|
|
|
|
|
+ protected Button newButton(String text)
|
|
|
+ {
|
|
|
+ Button b = new Button(this);
|
|
|
+ b.setText(text);
|
|
|
+ b.setBackgroundResource(R.drawable.uibutton);
|
|
|
+ b.setTextColor(getResources().getColor(R.color.dull_4));
|
|
|
+ b.setOnClickListener(this);
|
|
|
+ return b;
|
|
|
+ }
|
|
|
|
|
|
+ private void reset()
|
|
|
+ {
|
|
|
+ final Activity context = this;
|
|
|
+ AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
|
|
|
+ builder1.setMessage("Cette action va supprimer toute la sauvegarde. La progression dans le jeu reviendra donc a 0. Êtes-vous sûr de vouloir continuer ?");
|
|
|
+ builder1.setCancelable(true);
|
|
|
+
|
|
|
+ builder1.setPositiveButton(
|
|
|
+ "Supprimer",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ Game.setGame(new Game("game_medium", context));
|
|
|
+ Toast.makeText(context, "Suppression effectuée", Toast.LENGTH_SHORT);
|
|
|
+ dialog.cancel();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ builder1.setNegativeButton(
|
|
|
+ "Ne pas supprimer",
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ dialog.cancel();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ AlertDialog alert11 = builder1.create();
|
|
|
+ alert11.show();
|
|
|
+ }
|
|
|
|
|
|
public void onClick(View v)
|
|
|
{
|
|
|
- setResults();
|
|
|
- finish();
|
|
|
+ if(v==mOk)
|
|
|
+ {
|
|
|
+ setResults();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ else if(v==mReset)
|
|
|
+ {
|
|
|
+ reset();
|
|
|
+ setResults();
|
|
|
+ }else if(v==mCheat)
|
|
|
+ {
|
|
|
+ mGame.pickAllResoucres();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void addOptionBool(String name, ToggleButton v)
|
|
|
+ public void addOptionBool(String name, CustomToggleButton v, LinearLayout root)
|
|
|
{
|
|
|
LinearLayout ll = new LinearLayout(this);
|
|
|
TextView tv = new TextView(this);
|
|
|
tv.setText(name);
|
|
|
- //tv.setBackgroundColor(0);
|
|
|
- //tv.setTextSize(20);
|
|
|
- //tv.setTextColor(0x33b5e5);
|
|
|
+ tv.setTextColor(getResources().getColor(R.color.dull_4));
|
|
|
|
|
|
ll.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
- //v.setBackgroundColor(0);
|
|
|
ll.addView(tv);
|
|
|
ll.addView(v);
|
|
|
- mRoot.addView(ll);
|
|
|
+ root.addView(ll);
|
|
|
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ lp.setMargins(30, 30, 25, 5);
|
|
|
+ ll.setLayoutParams(lp);
|
|
|
+ lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ lp.setMargins(0, 0, 40 , 40);
|
|
|
+ tv.setLayoutParams(lp);
|
|
|
+ v.setLayoutParams(new LinearLayout.LayoutParams(150, 60));
|
|
|
+ newSeparator(root);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addAction(String name, Button v, LinearLayout root)
|
|
|
+ {
|
|
|
+ LinearLayout ll = new LinearLayout(this);
|
|
|
+ ll.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
+ ll.addView(v);
|
|
|
+ root.addView(ll);
|
|
|
|
|
|
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ lp.setMargins(30, 30, 25, 5);
|
|
|
+ ll.setLayoutParams(lp);
|
|
|
+ v.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 60));
|
|
|
+ newSeparator(root);
|
|
|
}
|
|
|
|
|
|
+ public void addSelection(String name, SelectButton v, LinearLayout root)
|
|
|
+ {
|
|
|
+ LinearLayout ll = new LinearLayout(this);
|
|
|
+ TextView tv = new TextView(this);
|
|
|
+ tv.setText(name);
|
|
|
+ tv.setTextColor(getResources().getColor(R.color.dull_4));
|
|
|
+
|
|
|
+ ll.setOrientation(LinearLayout.VERTICAL);
|
|
|
+ ll.addView(tv);
|
|
|
+ ll.addView(v);
|
|
|
+ root.addView(ll);
|
|
|
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ lp.setMargins(30, 30, 25, 5);
|
|
|
+ ll.setLayoutParams(lp);
|
|
|
+ lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
|
|
+ lp.setMargins(90, 0, 0 , 0);
|
|
|
+ v.setLayoutParams(lp);
|
|
|
+ //v.setLayoutParams(new LinearLayout.LayoutParams(150, 60));
|
|
|
+ newSeparator(root);
|
|
|
+ }
|
|
|
|
|
|
+ public View newSeparator(LinearLayout root)
|
|
|
+ {
|
|
|
+ View v = new View(this);
|
|
|
+ v.setBackgroundColor(getResources().getColor(R.color.dull_3));
|
|
|
+ root.addView(v);
|
|
|
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 2);
|
|
|
+ lp.setMargins(30, 30, 0,0);
|
|
|
+ v.setLayoutParams(lp);
|
|
|
+ return v;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
private void setResults()
|
|
|
{
|
|
|
- mGame.getmSettings().setAccelerometerDebug(mAccelerometer.isChecked());
|
|
|
- mGame.getmSettings().setAreaDebug(mAreas.isChecked());
|
|
|
- mGame.getmSettings().setGPSDebug(mGPS.isChecked());
|
|
|
- mGame.getmSettings().setResourceDebug(mPlaces.isChecked());
|
|
|
+ mGame.getmSettings().setDevelopperMode(mDev.getState());
|
|
|
+ mGame.getmSettings().setGPSDebug(mGPS.getState());
|
|
|
+ mGame.getmSettings().setAreaDebug(mAreas.getState());
|
|
|
+ mGame.getmSettings().setARMode(mRA.getState());
|
|
|
+ mGame.getmSettings().setResourceDebug(mPlaces.getState());
|
|
|
+ mGame.getmSettings().setSensorLatency(mSensorLatency.getState());
|
|
|
+ Settings.setSettings(mGame.getmSettings());
|
|
|
+ mGame.save(this);
|
|
|
+ mGame.getPlayer().newSensorManager(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateVisibility()
|
|
|
+ {
|
|
|
+ int x = mDev.getState()?View.VISIBLE:View.GONE;
|
|
|
+ mRootDev.setVisibility(x);
|
|
|
}
|
|
|
|
|
|
private void preset()
|
|
|
{
|
|
|
- mAccelerometer.setChecked(mGame.getmSettings().isAccelerometerDebug());
|
|
|
- mAreas.setChecked(mGame.getmSettings().isAreaDebug());
|
|
|
- mGPS.setChecked(mGame.getmSettings().isGPSDebug());
|
|
|
- mPlaces.setChecked(mGame.getmSettings().isResourceDebug());
|
|
|
+ mDev.setState(mGame.getmSettings().isDevelopperMode());
|
|
|
+ mGPS.setState(mGame.getmSettings().isGPSDebug());
|
|
|
+ mAreas.setState(mGame.getmSettings().isAreaDebug());
|
|
|
+ mPlaces.setState(mGame.getmSettings().isResourceDebug());
|
|
|
+ mRA.setState(mGame.getmSettings().isARMode());
|
|
|
+ mSensorLatency.setState(mGame.getmSettings().getSensorLatency());
|
|
|
+ updateVisibility();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onToggle(View v) {
|
|
|
+ if(v==mDev) updateVisibility();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onOn(View v) {}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onOff(View v) {}
|
|
|
+
|
|
|
+
|
|
|
}
|