Commit 353f099a authored by Aous Karoui's avatar Aous Karoui
Browse files

Merge branch 'dev' into 'master'

searchBox Adam

See merge request !2
parents 23cf99cf 68f05487
......@@ -192,7 +192,7 @@ public class Ode implements EntryPoint {
* || ||
* |+-------------------------------------------+|
* |+-- statusPanel ----------------------------+|
* || ||
* || f ||
* |+-------------------------------------------+|
* +---------------------------------------------+
*/
......
......@@ -15,16 +15,18 @@ import com.google.appinventor.client.explorer.commands.ChainableCommand;
import com.google.appinventor.client.explorer.project.Project;
import com.google.appinventor.client.tracking.Tracking;
import com.google.appinventor.client.widgets.boxes.Box;
import com.google.appinventor.shared.rpc.project.ProjectRootNode;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.geolocation.client.Geolocation;
import com.google.gwt.geolocation.client.Position;
import com.google.gwt.geolocation.client.PositionError;
import com.google.gwt.http.client.*;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.maps.client.LoadApi;
import com.google.gwt.maps.client.MapOptions;
import com.google.gwt.maps.client.MapTypeId;
......@@ -43,11 +45,7 @@ import com.google.gwt.maps.client.events.dragstart.DragStartMapHandler;
import com.google.gwt.maps.client.events.place.PlaceChangeMapEvent;
import com.google.gwt.maps.client.events.place.PlaceChangeMapHandler;
import com.google.gwt.maps.client.overlays.*;
import com.google.gwt.maps.client.placeslib.Autocomplete;
import com.google.gwt.maps.client.placeslib.AutocompleteOptions;
import com.google.gwt.maps.client.placeslib.AutocompleteType;
import com.google.gwt.maps.client.placeslib.PlaceGeometry;
import com.google.gwt.maps.client.placeslib.PlaceResult;
import com.google.gwt.maps.client.placeslib.*;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.*;
......@@ -58,6 +56,8 @@ import java.util.List;
import static com.google.appinventor.client.Ode.*;
import static com.google.gwt.user.client.Window.alert;
public class MapBox extends Box {
protected static final Images images = Ode.getImageBundle();
private static final MapBox INSTANCE = new MapBox();
......@@ -91,11 +91,11 @@ public class MapBox extends Box {
*/
private MapBox() {
super(MESSAGES.map(),
544, // height
true, // minimizable
false, // removable
false, // start minimized
550);// width
544, // height
true, // minimizable
false, // removable
false, // start minimized
550);// width
zoom = 4;
geolocated = false;
......@@ -119,46 +119,46 @@ public class MapBox extends Box {
}
public void initializeMap(){
geolocation.getCurrentPosition(new Callback<Position, PositionError>() {
@Override
public void onFailure(PositionError error) { // always called
geolocation.getCurrentPosition(new Callback<Position, PositionError>() {
@Override
public void onFailure(PositionError error) { // always called
// alert("Time-out geolocation callback"); // ... Time-out
userPosition= LatLng.newInstance(46.649436, 2.633423);
drawEmptyMap();
if (mapWidget!=null){
setContent(mapWidget);
scheduleMapResize();
}
}
@Override
public void onSuccess(Position result) {
geolocated=true;
Position.Coordinates coords = result.getCoordinates();
double lat = coords.getLatitude();
double lng = coords.getLongitude();
userPosition = LatLng.newInstance(lat, lng);
zoom=14;
drawEmptyMap();// sans lequel y a pas interaction
if (mapWidget!=null){
setContent(mapWidget);
scheduleMapResize();
}
}
});
userPosition= LatLng.newInstance(48.858370, 2.294481);
drawEmptyMap();
if (mapWidget!=null){
setContent(mapWidget);
scheduleMapResize();
}
}
@Override
public void onSuccess(Position result) {
geolocated=true;
Position.Coordinates coords = result.getCoordinates();
double lat = coords.getLatitude();
double lng = coords.getLongitude();
userPosition = LatLng.newInstance(lat, lng);
zoom=2;
drawEmptyMap();// sans lequel y a pas interaction
if (mapWidget!=null){
setContent(mapWidget);
scheduleMapResize();
}
}
});
}
public void showMap(){
initializeMap();
Timer timerThistimer = new Timer() {
@Override
public void run() {
if (mapWidget!=null){
loadMarkers(markers);
setContent(mapWidget);
scheduleMapResize();
}
initializeMap();
Timer timerThistimer = new Timer() {
@Override
public void run() {
if (mapWidget!=null){
loadMarkers(markers);
setContent(mapWidget);
scheduleMapResize();
}
};
}
};
timerThistimer.schedule(5000);
// Il vaut mieux donner autant de temps nécessaire pour pouvoir charger tous les screens
// afin que la boucle du loadMarker() fonctionne bien
......@@ -173,8 +173,8 @@ public class MapBox extends Box {
public void draw() {
this.clear();
// placeSearchTextField = new TextBox();
// placeSearchTextField.setWidth("350px");
placeSearchTextField = new TextBox();
placeSearchTextField.setWidth("350px");
drawMap();
drawControls();
drawAutoComplete();
......@@ -208,41 +208,71 @@ public class MapBox extends Box {
private void drawControls() {
DesignToolbar.DesignProject currentProject = ode.getDesignToolbar().getCurrentProject();
plusWidget = new FlowPanel();
DesignToolbar.DesignProject currentProject = ode.getDesignToolbar().getCurrentProject();
placeSearchTextField = new TextBox();
placeSearchTextField.addKeyPressHandler( new KeyPressHandler() {
@Override
public void onKeyPress( final KeyPressEvent event ) {
if ( event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER ){
Requete();
}
}
} );
final Button validationTexte = new Button("Valider", new ClickHandler() {
public void onClick(ClickEvent event) {
Requete();
// alert(placeSearchTextField.getValue());
}
});
plusWidget = new FlowPanel();
HTML newActivity = new HTML("Nouvelle</br>&nbsp;Activité");
// newActivity.setStyleName("ode-BlinkingText");
plusWidget.add(newActivity);
plusWidget.add(plus);
plusWidget.add(newActivity);
plusWidget.add(plus);
if (currentProject.screens.size()<2)
if (currentProject.screens.size()<2)
makePlusWidgetBlink();
// TODO I'm not able to get the stylesheet to work, but this works below
DOM.setStyleAttribute(plusWidget.getElement(), "background", "white");
DOM.setStyleAttribute(plusWidget.getElement(), "padding", "5px");
DOM.setStyleAttribute(plusWidget.getElement(), "margin", "3px");
if (ode.getCurrentMode()==STANDARD)
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #5DBB46");
else if (ode.getCurrentMode()==INTERMEDIATE)
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #22A0DA");
else
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #F06626");
// mapWidget.setControls(ControlPosition.RIGHT_TOP, placeSearchTextField );
Timer t = new Timer() {
@Override
public void run() {
mapWidget.setControls(ControlPosition.RIGHT_TOP, plusWidget);
mapWidget.setControls(ControlPosition.TOP_CENTER, reload);
// mapWidget.setControls(ControlPosition.LEFT_TOP, placeSearchTextField );
}
};
t.schedule(2000);
// TODO I'm not able to get the stylesheet to work, but this works below
DOM.setStyleAttribute(plusWidget.getElement(), "background", "white");
DOM.setStyleAttribute(plusWidget.getElement(), "padding", "5px");
DOM.setStyleAttribute(plusWidget.getElement(), "margin", "3px");
if (ode.getCurrentMode()==STANDARD)
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #5DBB46");
else if (ode.getCurrentMode()==INTERMEDIATE)
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #22A0DA");
else
DOM.setStyleAttribute(plusWidget.getElement(), "border", "3px solid #F06626");
// mapWidget.setControls(ControlPosition.RIGHT_TOP, placeSearchTextField );
Timer t = new Timer() {
@Override
public void run() {
mapWidget.setControls(ControlPosition.RIGHT_TOP, plusWidget);
mapWidget.setControls(ControlPosition.TOP_CENTER, reload);
mapWidget.setControls(ControlPosition.LEFT_BOTTOM, placeSearchTextField );
mapWidget.setControls(ControlPosition.BOTTOM_LEFT, validationTexte );
}
};
t.schedule(2000);
// Il vaut mieux retarder l'affichage du plusBouton pour pallier
// au problème du chargement double du POI si on appuie très vite sur le plusBouton
/* Timer u = new Timer() {
@Override
public void run() {
alert(placeSearchTextField.getValue());
}
};
u.schedule(20000);*/
}
......@@ -340,47 +370,47 @@ public class MapBox extends Box {
private void loadMarkers(List<Marker> markers){
DesignToolbar.DesignProject currentProject = ode.getDesignToolbar().getCurrentProject();
if (currentProject != null){
if (currentProject != null){
// AOUS Inutile d'exécuter tout le reste si on est pas sur le DESIGNER (cas page début)
// Autant qu'il y a d'activités autant qu'il y aura de temps de chargement
// donc vaut mieux encore retarder quand screens.size>4 pour garantir l'affichage des POI
for (final DesignToolbar.Screen screen : currentProject.screens.values()) {
if (screen.formEditor instanceof YaFormEditor) {
final YaFormEditor thisFormEditor= (YaFormEditor)screen.formEditor;
final YaBlocksEditor thisBlocksEditor= (YaBlocksEditor)screen.blocksEditor;
if (thisFormEditor.isLoadComplete()) {
String longitude = thisFormEditor.getForm().getPropertyValue("APoiLong");
String latitude = thisFormEditor.getForm().getPropertyValue("APoiLat");
if (longitude.equals("Undefined")) {
if (screen.screenName!="Screen1")
drawMarkerWithBounceAnimation(screen.screenName, userPosition, thisFormEditor.getProjectId());
else { // On est dans Screen1
// désactiver boutons de navigation latéraux car on est dans Screen1
thisFormEditor.getForm().getNextMockFormButton().setEnabled(false);
if (!thisFormEditor.getComponentNames().contains("StartButton")) {
// Ici nous rechargeons les blocs avec la chaine XML du Screen1 m.à.j avec tellNextActivity
thisBlocksEditor.reloadBlocks(JemBlocksMethods.tellNextActivity("Screen1", JemBlocksStrings.SCREEN1));
new JemComponents().addWelcomeComponents(thisFormEditor);
}
else
new JemComponents(); // if JemComponent already exist, we instantiate the class to enable interactions (next, previous buttons, etc.)
}
}
else {
if (screen.screenName!="Screen1") {
LatLng markerPosition = LatLng.newInstance(Double.parseDouble(latitude),Double.parseDouble(longitude));
drawMarkerWithBounceAnimation(screen.screenName, markerPosition, thisFormEditor.getProjectId());
mapWidget.panTo(userPosition);
}
}
// Autant qu'il y a d'activités autant qu'il y aura de temps de chargement
// donc vaut mieux encore retarder quand screens.size>4 pour garantir l'affichage des POI
for (final DesignToolbar.Screen screen : currentProject.screens.values()) {
if (screen.formEditor instanceof YaFormEditor) {
final YaFormEditor thisFormEditor= (YaFormEditor)screen.formEditor;
final YaBlocksEditor thisBlocksEditor= (YaBlocksEditor)screen.blocksEditor;
if (thisFormEditor.isLoadComplete()) {
String longitude = thisFormEditor.getForm().getPropertyValue("APoiLong");
String latitude = thisFormEditor.getForm().getPropertyValue("APoiLat");
if (longitude.equals("Undefined")) {
if (screen.screenName!="Screen1")
drawMarkerWithBounceAnimation(screen.screenName, userPosition, thisFormEditor.getProjectId());
else { // On est dans Screen1
// désactiver boutons de navigation latéraux car on est dans Screen1
thisFormEditor.getForm().getNextMockFormButton().setEnabled(false);
if (!thisFormEditor.getComponentNames().contains("StartButton")) {
// Ici nous rechargeons les blocs avec la chaine XML du Screen1 m.à.j avec tellNextActivity
thisBlocksEditor.reloadBlocks(JemBlocksMethods.tellNextActivity("Screen1", JemBlocksStrings.SCREEN1));
new JemComponents().addWelcomeComponents(thisFormEditor);
}
else
new JemComponents(); // if JemComponent already exist, we instantiate the class to enable interactions (next, previous buttons, etc.)
}
}
else {
if (screen.screenName!="Screen1") {
LatLng markerPosition = LatLng.newInstance(Double.parseDouble(latitude),Double.parseDouble(longitude));
drawMarkerWithBounceAnimation(screen.screenName, markerPosition, thisFormEditor.getProjectId());
mapWidget.panTo(userPosition);
}
else alert("Problème de chargement. Veuillez rafraichir la page. Si le problème persiste, vérifiez la connexion.");
}
}
else alert("Problème de chargement. Veuillez rafraichir la page. Si le problème persiste, vérifiez la connexion.");
}
}
}
// Le zoom arrive une fois tous les marqueurs chargés
mapWidget.setZoom(16);
mapWidget.setZoom(16);
}
private void scheduleMapResize(){
......@@ -457,7 +487,7 @@ public class MapBox extends Box {
LatLng center = geomtry.getLocation();
mapWidget.panTo(center);
mapWidget.setZoom(8);
mapWidget.setZoom(8);
GWT.log("place changed center=" + center);
}
......@@ -488,4 +518,49 @@ public class MapBox extends Box {
public FlowPanel getPlusWidget(){
return plusWidget;
}
}
\ No newline at end of file
// Adam begin
public void Requete(){
String url ="https://maps.googleapis.com/maps/api/geocode/json?address=" + placeSearchTextField.getValue() +",+CA&key=AIzaSyDqzYsKgkd2BkmxtPezUIzAGlk_SwVTi9Q";
url= url.trim().replaceAll("( )+", "+");
url= url.trim().replaceAll("é", "e");
url= url.trim().replaceAll("è", "e");
url= url.trim().replaceAll("ê", "e");
url= url.trim().replaceAll("ë", "e");
url= url.trim().replaceAll("â", "a");
url= url.trim().replaceAll("à", "a");
url= url.trim().replaceAll("ï", "i");
url= url.trim().replaceAll("î", "i");
url= url.trim().replaceAll("ô", "o");
url= url.trim().replaceAll("ç", "c");
url= url.trim().replaceAll("û", "u");
url= url.trim().replaceAll("ù", "u");
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
Request response = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
if (exception instanceof RequestTimeoutException) {
alert("timeout");
} else {
// handle other request errors
}
}
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode()==200) {
JSONValue jsonValue = JSONParser.parseStrict(response.getText());
JSONObject customerObject = jsonValue.isObject();
double latitude = Double.parseDouble(customerObject.get("results").isArray().get(0).isObject().get("geometry").isObject().get("location").isObject().get("lat").isNumber().toString());
double longitude = Double.parseDouble(customerObject.get("results").isArray().get(0).isObject().get("geometry").isObject().get("location").isObject().get("lng").isNumber().toString());
userPosition = LatLng.newInstance(latitude, longitude);
mapWidget.panTo(userPosition);
}
else {alert("Requete invalide");}
}
});
} catch (RequestException e) {
alert(e.getMessage());
}
}
// Adam end
}
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