示例#1
0
  /**
   * Gets Google maps of a user.
   *
   * @param context used to get maps
   * @param mapsClient the client to access Google Maps
   * @return true means set successfully
   */
  private static ArrayList<MapsMapMetadata> getMaps(Context context, MapsClient mapsClient) {
    String authToken = null;
    ArrayList<String> mapIds = new ArrayList<String>();
    ArrayList<MapsMapMetadata> mapData = new ArrayList<MapsMapMetadata>();

    try {
      authToken =
          AccountManager.get(context)
              .blockingGetAuthToken(getAccount(context), MapsConstants.SERVICE_NAME, false);
    } catch (Exception e) {
      Log.d(EndToEndTestUtils.LOG_TAG, "Unable to get auth token", e);
      return mapData;
    }

    GDataParser gDataParser = null;
    try {
      gDataParser =
          mapsClient.getParserForFeed(MapFeatureEntry.class, MapsClient.getMapsFeed(), authToken);
      gDataParser.init();
      while (gDataParser.hasMoreData()) {
        MapFeatureEntry entry = (MapFeatureEntry) gDataParser.readNextEntry(null);
        mapIds.add(MapsGDataConverter.getMapidForEntry(entry));
        mapData.add(MapsGDataConverter.getMapMetadataForEntry(entry));
      }
    } catch (Exception e) {
      Log.d(EndToEndTestUtils.LOG_TAG, "Unable to get maps", e);
    } finally {
      if (gDataParser != null) {
        gDataParser.close();
      }
    }

    return mapData;
  }
示例#2
0
 /**
  * Searches a map in user's Google Maps.
  *
  * @param title the title of map
  * @param activity activity to get context
  * @param isDelete whether delete the map of this track in the Google Maps
  * @return true means find the map
  */
 private static boolean searchMapByTitle(String title, Activity activity, boolean isDelete) {
   Context context = activity.getApplicationContext();
   MapsClient mapsClient =
       new MapsClient(
           GDataClientFactory.getGDataClient(context),
           new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
   ArrayList<MapsMapMetadata> mapData = getMaps(context, mapsClient);
   for (MapsMapMetadata oneData : mapData) {
     if (oneData.getDescription().indexOf(DOCUMENT_NAME_PREFIX) > -1
         && oneData.getTitle().equals(title)) {
       if (isDelete) {
         try {
           mapsClient.deleteEntry(
               oneData.getGDataEditUri(),
               AccountManager.get(context)
                   .blockingGetAuthToken(getAccount(context), MapsConstants.SERVICE_NAME, false));
           return true;
         } catch (Exception e) {
           Log.d(EndToEndTestUtils.LOG_TAG, "Unable to drop map", e);
           return false;
         }
       }
       return true;
     }
   }
   return false;
 }
示例#3
0
  /**
   * Removes old tracks on Google Maps created by MyTracks test.
   *
   * @param activity
   */
  public static void deleteTracksOnGoogleMaps(Activity activity) {
    Context context = activity.getApplicationContext();
    MapsClient mapsClient =
        new MapsClient(
            GDataClientFactory.getGDataClient(context),
            new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
    ArrayList<MapsMapMetadata> mapData = getMaps(context, mapsClient);
    for (MapsMapMetadata oneData : mapData) {

      try {
        mapsClient.deleteEntry(
            oneData.getGDataEditUri(),
            AccountManager.get(context)
                .blockingGetAuthToken(getAccount(context), MapsConstants.SERVICE_NAME, false));
      } catch (Exception e) {
        Log.d(EndToEndTestUtils.LOG_TAG, "Unable to drop map", e);
      }
    }
  }