Пример #1
0
  /**
   * Searches a fusion table in user's Google tables.
   *
   * @param tableName name of fusion table to search
   * @param context android context
   * @param accountName name of account
   * @param isDelete whether delete this track
   * @return true means find and delete fusion table
   */
  public static boolean searchFusionTableByTitle(
      String tableName, Context context, String accountName, boolean isDelete) {
    try {
      GoogleAccountCredential credential =
          SendToGoogleUtils.getGoogleAccountCredential(
              context, accountName, SendToGoogleUtils.FUSION_TABLES_SCOPE);
      if (credential == null) {
        return false;
      }
      Fusiontables fusiontables =
          new Fusiontables.Builder(
                  AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
              .build();
      List<Table> tables = fusiontables.table().list().execute().getItems();
      for (Iterator<Table> iterator = tables.iterator(); iterator.hasNext(); ) {
        Table table = (Table) iterator.next();
        String title = table.getName();
        if (title.equals(tableName)) {
          if (isDelete) {
            fusiontables.table().delete(table.getTableId()).execute();
          }
          return true;
        }
      }

    } catch (Exception e) {
      Log.d(EndToEndTestUtils.LOG_TAG, "Failed when operate fusion table.", e);
    }
    return false;
  }
  /** Create a table for the authenticated user. */
  private static String createTable() throws IOException {
    View.header("Create Sample Table");

    // Create a new table
    Table table = new Table();
    table.setName(UUID.randomUUID().toString());
    table.setIsExportable(false);
    table.setDescription("Sample Table");

    // Set columns for new table
    table.setColumns(
        Arrays.asList(
            new Column().setName("Text").setType("STRING"),
            new Column().setName("Number").setType("NUMBER"),
            new Column().setName("Location").setType("LOCATION"),
            new Column().setName("Date").setType("DATETIME")));

    // Adds a new column to the table.
    Fusiontables.Table.Insert t = fusiontables.table().insert(table);
    Table r = t.execute();

    View.show(r);

    return r.getTableId();
  }
 //	----------------------------------------------------------------------------------------------------------------
 //      Method:     GetTableId
 //      Inputs:	    none
 //     Outputs:	    none
 // Description:     Get Table ID from Table Nam
 //	----------------------------------------------------------------------------------------------------------------
 private static String GetTableId(String tableName) throws IOException {
   String tid = null; // Set default return
   System.out.println("Get Table ID: " + tableName); // Print header
   // Get the table list
   Fusiontables.Table.List listTables = FusionTables.table().list();
   TableList tablelist = listTables.execute(); //
   // If there are no tables, print that info
   if (tablelist.getItems() == null || tablelist.getItems().isEmpty()) { //
     System.out.println("No tables found!"); //
   } //
   else // Else, loop through tables, find match
   { // If it matches then save the table ID
     for (Table table : tablelist.getItems()) //
     { //
       if (table.getName().equals(tableName)) tid = table.getTableId();
     } // Printout the results of that
     System.out.println(tableName + " - tableId: " + tid); //
   } //
   return tid; // Return the table ID
 }