コード例 #1
0
ファイル: GoogleUtils.java プロジェクト: rborisov/my_tracker
  /**
   * 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;
  }
コード例 #2
0
ファイル: GoogleUtils.java プロジェクト: rborisov/my_tracker
  /**
   * Delete spreadsheet which name is title.
   *
   * @param title the name of spreadsheet
   * @param activity to get context
   * @param accountName the name of Google account
   * @return true means delete successfully
   */
  public static boolean deleteSpreadsheetByTitle(
      String title, Activity activity, String accountName) {
    try {
      GoogleAccountCredential driveCredential =
          SendToGoogleUtils.getGoogleAccountCredential(
              activity.getApplicationContext(), accountName, SendToGoogleUtils.DRIVE_SCOPE);
      if (driveCredential == null) {
        return false;
      }

      Drive drive = SyncUtils.getDriveService(driveCredential);
      com.google.api.services.drive.Drive.Files.List list =
          drive
              .files()
              .list()
              .setQ(
                  String.format(Locale.US, SendSpreadsheetsAsyncTask.GET_SPREADSHEET_QUERY, title));
      List<File> files = list.execute().getItems();
      for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) {
        File file = (File) iterator.next();
        drive.files().delete(file.getId()).execute();
      }
      return true;
    } catch (Exception e) {
      Log.e(EndToEndTestUtils.LOG_TAG, "Search spreadsheet failed.");
    }
    return false;
  }
コード例 #3
0
ファイル: GoogleUtils.java プロジェクト: rborisov/my_tracker
  /**
   * Removes old tracks created by MyTracks test.
   *
   * @param activity
   * @param accountName
   */
  public static void deleteTestTracksOnGoogleDrive(Activity activity, String accountName) {
    try {
      GoogleAccountCredential driveCredential =
          SendToGoogleUtils.getGoogleAccountCredential(
              activity.getApplicationContext(), accountName, SendToGoogleUtils.DRIVE_SCOPE);
      if (driveCredential == null) {
        return;
      }

      Drive drive = SyncUtils.getDriveService(driveCredential);
      com.google.api.services.drive.Drive.Files.List list =
          drive.files().list().setQ(TEST_TRACKS_QUERY);
      List<File> files = list.execute().getItems();
      for (Iterator<File> iterator = files.iterator(); iterator.hasNext(); ) {
        File file = (File) iterator.next();
        drive.files().delete(file.getId()).execute();
      }
    } catch (Exception e) {
      Log.e(EndToEndTestUtils.LOG_TAG, "Delete test tracks failed.");
    }
  }
コード例 #4
0
ファイル: GoogleUtils.java プロジェクト: rborisov/my_tracker
  /**
   * Searches docs in user's Google Documents.
   *
   * @param title the title of doc
   * @param activity to get context
   * @param accountName the name of Google account
   * @return the file list of the document, null means can not find the spreadsheets
   */
  public static List<File> searchAllSpreadsheetByTitle(
      String title, Activity activity, String accountName) {
    try {
      GoogleAccountCredential driveCredential =
          SendToGoogleUtils.getGoogleAccountCredential(
              activity.getApplicationContext(), accountName, SendToGoogleUtils.DRIVE_SCOPE);
      if (driveCredential == null) {
        return null;
      }

      Drive drive = SyncUtils.getDriveService(driveCredential);
      com.google.api.services.drive.Drive.Files.List list =
          drive
              .files()
              .list()
              .setQ(
                  String.format(Locale.US, SendSpreadsheetsAsyncTask.GET_SPREADSHEET_QUERY, title));
      FileList result = list.execute();
      return result.getItems();
    } catch (Exception e) {
      Log.e(EndToEndTestUtils.LOG_TAG, "Search spreadsheet failed.");
    }
    return null;
  }