@Override
  public void onSendMessage(final SendMessageEvent event) {
    if (event.resendOnFail()) {
      googleAnalytics.trackEvent("Chat", "Send Message");
    }
    final String message = event.getMessage();
    if (!message.isEmpty()) {
      final JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
      jsonp.requestObject(
          JsessionUrlEncoder.encode(CAConstants.HOST + "/send", "msg", message),
          new SuccessCallback<SendMessageResponse>() {

            @Override
            public void onSuccess(final SendMessageResponse response) {
              if (response.getUser() != null) {
                User.update(getEventBus(), response.getUser());
              }
              if (response.getMessage() != null) {
                final MessageWrapper msg = new MessageWrapper(response.getMessage());
                if (gameStateProvider.getGameState().swapColors()) {
                  msg.swapColor();
                }
                if (event.resendOnFail()) {
                  addToMessagesCheckQueue(msg);
                }
              }
            }
          });
    }
  }
  private void createPostList() {
    view.showProgressIndicator();

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);
    jsonp.requestObject(
        EXPRESS_LANES_URL,
        new AsyncCallback<ExpressLanesFeed>() {

          @Override
          public void onFailure(Throwable caught) {
            view.hideProgressIndicator();
            phoneGap
                .getNotification()
                .alert(
                    "Can't load data. Check your connection.",
                    new AlertCallback() {
                      @Override
                      public void onOkButtonClicked() {
                        // TODO Auto-generated method stub
                      }
                    },
                    "Connection Error");
          }

          @Override
          public void onSuccess(ExpressLanesFeed result) {
            ExpressLaneItem item = null;

            if (result.getExpressLanes() != null) {
              ArrayList<ExpressLaneItem> expressLaneItems = new ArrayList<ExpressLaneItem>();
              HashMap<Integer, String> routeIcon = new HashMap<Integer, String>();
              routeIcon.put(5, AppBundle.INSTANCE.css().i5Icon());
              routeIcon.put(90, AppBundle.INSTANCE.css().i90Icon());

              int numEntries = result.getExpressLanes().getRoutes().length();
              for (int i = 0; i < numEntries; i++) {
                item = new ExpressLaneItem();

                item.setStatus(result.getExpressLanes().getRoutes().get(i).getStatus());
                item.setRoute(result.getExpressLanes().getRoutes().get(i).getRoute());
                item.setTitle(result.getExpressLanes().getRoutes().get(i).getTitle());
                item.setUpdated(result.getExpressLanes().getRoutes().get(i).getUpdated());
                item.setRouteIcon(
                    routeIcon.get(result.getExpressLanes().getRoutes().get(i).getRoute()));

                expressLaneItems.add(item);
              }

              view.hideProgressIndicator();
              view.render(expressLaneItems);
              view.refresh();
              accessibility.postScreenChangeNotification();
            }
          }
        });
  }
 @Override
 public <M extends JModel> JRequest requestObject(JRequestURL url, AsyncCallback<M> callback) {
   if (url == null || callback == null) throw new NullPointerException();
   String urlString = url.setPrefix(jServicePath);
   Log.finest("call " + url.getMethodName() + " by: " + urlString);
   JsonpRequest<JavaScriptObject> req =
       builder.requestObject(url.toString(), new JAsyncCallback<M>(callback));
   return new JRequestCSImpl(req);
 }
Beispiel #4
0
  private void getFriendsFromServer(final AuthManager authManager, String pageToken) {
    String url =
        URL.encode(
            "https://www.googleapis.com/plus/v1/people/me/people/visible?"
                + "pageToken="
                + pageToken
                + "&fields=items(displayName,id,image,name(familyName,givenName)),nextPageToken,totalItems"
                + "&pp=1"
                + "&access_token="
                + authManager.getAccessToken());
    JsonpRequestBuilder builder = new JsonpRequestBuilder();
    builder.requestObject(
        url,
        new AsyncCallback<Response>() {
          public void onFailure(Throwable throwable) {
            Window.alert("Error: " + throwable);
          }

          public void onSuccess(Response feed) {
            // String text = feed.toString();
            // Window.alert(text);
            // String ids = feed.getIds();

            JsArray<Profile> entries = feed.getEntries();

            for (int i = 0; i < entries.length(); i++) {
              Profile entry = entries.get(i);
              UserAccountInfo friend =
                  new UserAccountInfo(entry.getId(), UserAccountInfo.GPLUSUSER);
              String firstName = entry.getFirstName();
              String lastName = entry.getLastName();
              if (firstName == null) {
                String displayName = entry.getDisplayName();
                lastName = displayName.split(" ", 2)[1];
                firstName = displayName.split(" ", 2)[0];
              }
              friend.setFirstName(firstName);
              friend.setLastName(lastName);
              friend.setPhoto(entry.getPhoto());
              friends.add(friend);
            }
            String nextPageToken = feed.getNextPageToken();
            if (nextPageToken == null) {
              authManager.setUserFriends(friends);
            } else {
              getFriendsFromServer(authManager, nextPageToken);
            }
          }
        });
  }
Beispiel #5
0
  public void getProfileFromServer(final AuthManager authManager) {
    String url =
        URL.encode(
            "https://www.googleapis.com/plus/v1/people/me?"
                + "fields=displayName,id,image,name(familyName,givenName)"
                + "&pp=1"
                + "&access_token="
                + authManager.getAccessToken());
    JsonpRequestBuilder builder = new JsonpRequestBuilder();
    builder.requestObject(
        url,
        new AsyncCallback<Profile>() {
          public void onFailure(Throwable throwable) {
            Window.alert("Error: " + throwable);
          }

          public void onSuccess(Profile entry) {
            // String text = feed.toString();
            // Window.alert(text);
            // String ids = feed.getIds();
            // CurrentUser currentUser = authManager.getCurrentUser();
            // JsArray<Profile> entries = feed.getEntries();
            String id = "";
            String firstName = "";
            String lastName = "";
            String photo = "";
            // for (int i = 0; i < entries.length(); i++) {
            // Profile entry = entries.get(i);
            id = entry.getId();
            firstName = entry.getFirstName();
            lastName = entry.getLastName();
            photo = entry.getPhoto();
            // }

            authManager.setCurrentUserId(id);
            authManager.setUserFirstName(firstName);
            authManager.setUserLastName(lastName);
            authManager.setUserPhoto(photo);
          }
        });
  }
  private void checkForUpdate() {
    UrlBuilder urlBuilder;

    try {
      urlBuilder = new UrlBuilder(updateCheckUrl);
    } catch (IllegalArgumentException e) {
      eventBus.fireEventDeferred(new ErrorNotificationEvent(Level.WARNING, e.getMessage()));
      return;
    }

    String data =
        "version=" + version + "&hostSystem=" + hostSystem + "&serverVersion=" + serverVersion;
    data = MimeBase64.encode(data);

    urlBuilder.setParameter("data", URL.encodeQueryString(data));

    JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder();
    try {
      requestBuilder.requestObject(
          urlBuilder.buildString(),
          new AsyncCallback<UpdateServiceResponse>() {

            @Override
            public void onFailure(Throwable caught) {
              errorHandler(caught.getMessage());
            }

            @Override
            public void onSuccess(UpdateServiceResponse response) {
              successHandler(response);
            }
          });

    } catch (Throwable exception) {
      errorHandler(exception.getMessage());
    }
  }