Skip to content

Commit

Permalink
Poi (#34)
Browse files Browse the repository at this point in the history
* poi

* auto reuest every 5sec

* unvalid color (API 23)

* unvalid color (API 23)

* close #13 close #15
  • Loading branch information
begarco authored Feb 27, 2017
1 parent 6727e79 commit 1d50fd4
Show file tree
Hide file tree
Showing 15 changed files with 765 additions and 356 deletions.
786 changes: 449 additions & 337 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ovh.exception.watchdogzz.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import ovh.exception.watchdogzz.R;

public class AddPoiFragment extends DialogFragment {

public interface PoiDialogListener {
void onDialogPositiveClick(DialogFragment dialog);
void onDialogNegativeClick(DialogFragment dialog);
}

// Use this instance of the interface to deliver action events
PoiDialogListener mListener;

private EditText mName = null;

@Override
public void onAttach(Context context) {
super.onAttach(context);

Activity activity;

if (context instanceof Activity){
activity = (Activity) context;
// Verify that the host activity implements the callback interface
try {
// Instantiate the NoticeDialogListener so we can send events to the host
mListener = (PoiDialogListener) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement PoiDialogListener");
}
}
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();

// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View rootView = inflater.inflate(R.layout.poi_dialog, null);
mName = (EditText) rootView.findViewById(R.id.username);

builder.setView(rootView)
// Add action buttons
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mListener.onDialogPositiveClick(AddPoiFragment.this);
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mListener.onDialogNegativeClick(AddPoiFragment.this);
}
});
return builder.create();
}

public String getName() {
return mName != null ? mName.getText().toString() : "";
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package ovh.exception.watchdogzz.activities;

import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

Expand All @@ -26,6 +28,7 @@
import ovh.exception.watchdogzz.R;
import ovh.exception.watchdogzz.data.GPSPosition;
import ovh.exception.watchdogzz.data.JUser;
import ovh.exception.watchdogzz.data.PoiManager;
import ovh.exception.watchdogzz.data.User;
import ovh.exception.watchdogzz.data.UserManager;
import ovh.exception.watchdogzz.network.IWSConsumer;
Expand All @@ -35,13 +38,35 @@
import ovh.exception.watchdogzz.view.WDRenderer;
import ovh.exception.watchdogzz.view.WDSurfaceView;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, IWSConsumer {
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, IWSConsumer, AddPoiFragment.PoiDialogListener {

private WDSurfaceView glView;
private UserManager users;
private PoiManager pois;
private PostitionManager postitionManager;
private NetworkManager networkManager;
public boolean isSuccess = false, isFinished = false;
private FloatingActionButton mAddPOI, mValidatePOI;
private GPSPosition mNewPoiPosition;

private final static int INTERVAL = 1000 * 5; // 5 secondes
private Handler mHandler = new Handler();

private Runnable mHandlerTask = new Runnable() {
@Override
public void run() {
new WebServiceTask(MainActivity.this, null, users.getMe()).execute(getString(R.string.server) + "/where");
new WebServiceTask(MainActivity.this, MainActivity.this).execute(getString(R.string.server) + "/where");
mHandler.postDelayed(mHandlerTask, INTERVAL);
}
};

private void startRequestingTask() {
mHandlerTask.run();
}

private void stopRequestingTask() {
mHandler.removeCallbacks(mHandlerTask);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,7 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
glView.setRenderer(renderer); // Use a custom renderer
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

/*
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -63,20 +88,48 @@ public void onClick(View view) {
new WebServiceTask(MainActivity.this, MainActivity.this).execute(getString(R.string.server) + "/where");
}
});
*/
mAddPOI = (FloatingActionButton) findViewById(R.id.add_poi);
mAddPOI.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, R.string.add_poi_help, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
glView.setCibleVisible(true);
mAddPOI.hide();
mValidatePOI.show();
}
});

mValidatePOI = (FloatingActionButton) findViewById(R.id.validate_poi);
mValidatePOI.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AddPoiFragment dialog = new AddPoiFragment();
dialog.show(getFragmentManager(), "PoiDialogFragment");
mNewPoiPosition = new GPSPosition(0f,0f,0.5f);
glView.setCibleVisible(false);
mValidatePOI.hide();
mAddPOI.show();
MainActivity.this.glView.requestRender();
}
});
mValidatePOI.hide();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

this.postitionManager = new PostitionManager(this);
this.networkManager = NetworkManager.getInstance(this.getApplicationContext());
setUsers(new UserManager());
this.pois = new PoiManager();
User futurMe = getIntent().getParcelableExtra("user");
getUsers().addObserver(renderer.getMap());
this.users.setMe(futurMe);

/** TODO supppress stub **/
this.users.addUser(new User("tito", "Bob", "[email protected]", "", "http://www.superaktif.net/wp-content/upLoads/2011/07/Han.Solo_.jpg", false, new GPSPosition(3.111185f, 45.759231f, 0.0f)));
this.users.addUser(new User("tata", "Alice", "[email protected]", "", "http://www.superaktif.net/wp-content/upLoads/2011/07/Han.Solo_.jpg", false, new GPSPosition(3.111185f, 45.759271f, 0.5f)));
this.users.addUser(new User("tata", "Alice", "[email protected]", "", "http://static.anakinworld.com/uploads/entries/original/personnage-leia-organa-solo.jpg", false, new GPSPosition(3.111185f, 45.759271f, 0.5f)));
/******************************************************/

// login sur le serveur
Expand Down Expand Up @@ -165,25 +218,35 @@ public boolean onNavigationItemSelected(MenuItem item) {
masterViewIntent.putExtra("users", users.getUsers());
masterViewIntent.putExtra("user", users.getMe());
startActivity(masterViewIntent);
} else if (id == R.id.poi_list) {
Intent masterViewIntent = new Intent(MainActivity.this, UserListActivity.class);
masterViewIntent.putExtra("pois", pois.getUsers());
startActivity(masterViewIntent);
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

private GPSPosition getGPSPosition(GPSPosition loc) {
return glView.getGPSPosition(loc);
}

@Override
protected void onPause() {
super.onPause();
glView.onPause();
this.postitionManager.stop();
this.stopRequestingTask();
}

@Override
protected void onResume() {
super.onResume();
glView.onResume();
this.postitionManager.start();
this.startRequestingTask();
}

@Override
Expand Down Expand Up @@ -249,4 +312,18 @@ public void consume(JSONObject json) {
} else
Log.w("COUCOU", "JSON is null");
}

@Override
public void onDialogPositiveClick(DialogFragment dialog) {
Snackbar.make(findViewById(R.id.content_main), R.string.poi_added, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
this.pois.createNewPoi(((AddPoiFragment)dialog).getName());
pois.finalizeNewPoi(getGPSPosition(mNewPoiPosition));
}

@Override
public void onDialogNegativeClick(DialogFragment dialog) {
Snackbar.make(findViewById(R.id.content_main), R.string.abandon, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ public class UserListActivity extends AppCompatActivity {
*/
private boolean mTwoPane;
private List<User> mUsers;
private boolean isPois = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_list);

mUsers = getIntent().getParcelableArrayListExtra("users");
mUsers = getIntent().getParcelableArrayListExtra("pois");
if(mUsers==null)
mUsers = getIntent().getParcelableArrayListExtra("users");
else
isPois = true;
if(mUsers==null)
mUsers = new ArrayList<>();

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle(getTitle());
toolbar.setTitle(isPois?getString(R.string.poi_title):getTitle());

// Show the Up button in the action bar.
ActionBar actionBar = getSupportActionBar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public float[] getForMap(float[] origin, float scale) {
return res;
}

public void screenToGps(float[] origin, float scale) {
latitude = (getLatitude() / scale + origin[1]);
longitude = (getLongitude() / scale + origin[0]);
altitude = (getAltitude() / scale + origin[2]);
}

@Override
public String toString() {
return getLatitude() + " " + getLongitude() + " " + getAltitude();
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/ovh/exception/watchdogzz/data/PoiManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ovh.exception.watchdogzz.data;

import android.util.Log;

/**
* Manage points of interest
*/
public class PoiManager extends UserManager {

private boolean isCreatingNewPoi = false;
private User mNewUser = null;

public void createNewPoi(String name) {
mNewUser = new User(name,name,"","","https://i.stack.imgur.com/6cDGi.png",false,null);
this.isCreatingNewPoi = true;
}

public void finalizeNewPoi(GPSPosition position) {
if(this.isCreatingNewPoi) {
this.mNewUser.setPosition(position);
Log.i("POIS", position.toString());
this.addUser(this.mNewUser);
this.isCreatingNewPoi = false;
}
}

}
16 changes: 15 additions & 1 deletion app/src/main/java/ovh/exception/watchdogzz/model/WDMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Class for representing the map of an establishment
*/
public class WDMap extends Observable implements WDDrawable, Observer {
private final float scale = 3169.8f;
private WDObjet map;
private HashMap<String,WDArtefact> markers;
private Context context;
Expand Down Expand Up @@ -48,13 +49,14 @@ public void draw(GL10 gl) {
gl.glRotatef(57.55046185f,0.0f,0.0f,1.0f);
gl.glScalef(0.002f,0.002f,0.002f);
gl.glTranslatef(-1682f,-1016f,0); // position dans le mesh du point d'origine
gl.glColor4f(0,0,0,1.0f);
map.draw(gl);
gl.glPopMatrix();

// dessin des marqueurs
for (WDArtefact x : markers.values()) {
gl.glPushMatrix();
float[] tmp = x.getPosition().getForMap(origin,3169.8f);
float[] tmp = x.getPosition().getForMap(getOrigin(), getScale());
gl.glTranslatef(tmp[0],tmp[1], 0.5f);
Log.d("ME", x.getPosition().toString() + " " + x.getLabel());

Expand Down Expand Up @@ -93,4 +95,16 @@ public void update(Observable observable, Object data) {
this.setChanged();
this.notifyObservers();
}

public float[] getOrigin() {
return origin;
}

public void setOrigin(float[] origin) {
this.origin = origin;
}

public float getScale() {
return scale;
}
}
Loading

0 comments on commit 1d50fd4

Please sign in to comment.