コード例 #1
0
ファイル: FTClient.java プロジェクト: K-Lean/AltBridge
  /**
   * Send a query to fusion tables.
   *
   * <p>This component will throw the "Response" event when a response is received. The response is
   * sent in the event.
   *
   * @param query
   */
  public void Query(final String query) {
    final FTClient f = this;
    Runnable run =
        new Runnable() {
          @Override
          public void run() {
            int count = 0;
            while (count < 10) {
              if (authorized) {
                String q = query;
                String result = "";

                // Create the auth header
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("Authorization", "GoogleLogin auth=" + token);

                // Convert to lower for comparison below
                String lower = q.toLowerCase();
                // Encode the query
                q = "sql=" + URLEncoder.encode(q);

                // 		Determine POST or GET based on query
                if (lower.startsWith("select")
                    || lower.startsWith("show")
                    || lower.startsWith("describe")) {

                  result =
                      RequestHandler.sendHttpRequest(REQUEST_URL + "?" + q, "GET", null, headers);

                } else {
                  result = RequestHandler.sendHttpRequest(REQUEST_URL, "POST", q, headers);
                }
                sendResponse(f, result);
                return;
              } else {
                count++;
                try {
                  Thread.sleep(100);
                } catch (InterruptedException e) {
                  Log.e(TAG, "Thread interrupted whlie waiting for authorization.");
                }
              }
            }
            Log.e(TAG, "Client was unable to authorize.");
          }
        };
    ThreadTimer.runOneTimeThread(run);
  }
コード例 #2
0
ファイル: FTClient.java プロジェクト: K-Lean/AltBridge
 public void Login() {
   if (username != null && password != null) {
     final FTClient f = this;
     ThreadTimer.runOneTimeThread(
         new Runnable() {
           @Override
           public void run() {
             token = ClientLogin.authorize(username, password);
             if (token != null || !token.equals("")) {
               authorized = true;
               sendLoginAck(f, true);
             } else {
               sendLoginAck(f, false);
             }
           }
         });
   }
 }