-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* poi * auto reuest every 5sec * unvalid color (API 23) * unvalid color (API 23) * close #13 close #15
- Loading branch information
Showing
15 changed files
with
765 additions
and
356 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
app/src/main/java/ovh/exception/watchdogzz/activities/AddPoiFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() : ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
@@ -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; | ||
|
@@ -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) { | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/ovh/exception/watchdogzz/data/PoiManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.