mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-17 16:23:06 +02:00
Fixed comments for 68f1788b686b.
Also fixed: - In ChooseMapActivity and SendFusionTablesActivity, check that the intent inputs are valid. - In ChooseMapAsyncTask, close the GDataParser in the finally block. - In SendFusionTablesAsyncTask, check that a segment has more than 2 points and that the segment stop time is set in prepareTrackSegment.
This commit is contained in:
@@ -98,22 +98,25 @@ public class ChooseMapActivity extends Activity {
|
|||||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
Intent result = new Intent();
|
setResult(
|
||||||
result.putExtra(MAP_ID, arrayAdapter.getItem(position).getMapId());
|
RESULT_OK, new Intent().putExtra(MAP_ID, arrayAdapter.getItem(position).getMapId()));
|
||||||
setResult(RESULT_OK, result);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
list.setAdapter(arrayAdapter);
|
list.setAdapter(arrayAdapter);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
|
||||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
|
||||||
|
|
||||||
Object retained = getLastNonConfigurationInstance();
|
Object retained = getLastNonConfigurationInstance();
|
||||||
if (retained instanceof ChooseMapAsyncTask) {
|
if (retained instanceof ChooseMapAsyncTask) {
|
||||||
asyncTask = (ChooseMapAsyncTask) retained;
|
asyncTask = (ChooseMapAsyncTask) retained;
|
||||||
asyncTask.setActivity(this);
|
asyncTask.setActivity(this);
|
||||||
} else {
|
} else {
|
||||||
|
Intent intent = getIntent();
|
||||||
|
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||||
|
if (account == null) {
|
||||||
|
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
asyncTask = new ChooseMapAsyncTask(this, account);
|
asyncTask = new ChooseMapAsyncTask(this, account);
|
||||||
asyncTask.execute();
|
asyncTask.execute();
|
||||||
}
|
}
|
||||||
@@ -152,18 +155,14 @@ public class ChooseMapActivity extends Activity {
|
|||||||
builder.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
builder.setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int arg1) {
|
public void onClick(DialogInterface dialog, int arg1) {
|
||||||
Intent result = new Intent();
|
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||||
result.putExtra(MAP_ID, (String) null);
|
|
||||||
setResult(RESULT_OK, result);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setOnCancelListener(new OnCancelListener() {
|
builder.setOnCancelListener(new OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
Intent result = new Intent();
|
setResult(RESULT_OK, new Intent().putExtra(MAP_ID, (String) null));
|
||||||
result.putExtra(MAP_ID, (String) null);
|
|
||||||
setResult(RESULT_OK, result);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
// Copyright 2012 Google Inc. All Rights Reserved.
|
/*
|
||||||
|
* Copyright 2012 Google Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
package com.google.android.apps.mytracks.io.maps;
|
package com.google.android.apps.mytracks.io.maps;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
||||||
@@ -129,22 +142,22 @@ public class ChooseMapAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
authToken = AccountManager.get(context).blockingGetAuthToken(
|
authToken = AccountManager.get(context).blockingGetAuthToken(
|
||||||
account, MapsConstants.SERVICE_NAME, false);
|
account, MapsConstants.SERVICE_NAME, false);
|
||||||
} catch (OperationCanceledException e) {
|
} catch (OperationCanceledException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (AuthenticatorException e) {
|
} catch (AuthenticatorException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
GDataParser gDataParser = null;
|
||||||
try {
|
try {
|
||||||
GDataParser gDataParser = mapsClient.getParserForFeed(
|
gDataParser = mapsClient.getParserForFeed(
|
||||||
MapFeatureEntry.class, MapsClient.getMapsFeed(), authToken);
|
MapFeatureEntry.class, MapsClient.getMapsFeed(), authToken);
|
||||||
gDataParser.init();
|
gDataParser.init();
|
||||||
while (gDataParser.hasMoreData()) {
|
while (gDataParser.hasMoreData()) {
|
||||||
@@ -152,16 +165,19 @@ public class ChooseMapAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
mapIds.add(MapsGDataConverter.getMapidForEntry(entry));
|
mapIds.add(MapsGDataConverter.getMapidForEntry(entry));
|
||||||
mapData.add(MapsGDataConverter.getMapMetadataForEntry(entry));
|
mapData.add(MapsGDataConverter.getMapMetadataForEntry(entry));
|
||||||
}
|
}
|
||||||
gDataParser.close();
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get maps", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get maps", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (HttpException e) {
|
} catch (HttpException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get maps", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
|
} finally {
|
||||||
|
if (gDataParser != null) {
|
||||||
|
gDataParser.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+13
-2
@@ -66,7 +66,19 @@ public class SendFusionTablesActivity extends Activity {
|
|||||||
} else {
|
} else {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
Account account = intent.getParcelableExtra(ACCOUNT);
|
Account account = intent.getParcelableExtra(ACCOUNT);
|
||||||
|
if (account == null) {
|
||||||
|
setResult(
|
||||||
|
RESULT_OK, new Intent().putExtra(SUCCESS, false).putExtra(TABLE_ID, (String) null));
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
long trackId = intent.getLongExtra(TRACK_ID, -1L);
|
long trackId = intent.getLongExtra(TRACK_ID, -1L);
|
||||||
|
if (trackId == -1L) {
|
||||||
|
setResult(
|
||||||
|
RESULT_OK, new Intent().putExtra(SUCCESS, false).putExtra(TABLE_ID, (String) null));
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
asyncTask = new SendFusionTablesAsyncTask(this, account, trackId);
|
asyncTask = new SendFusionTablesAsyncTask(this, account, trackId);
|
||||||
asyncTask.execute();
|
asyncTask.execute();
|
||||||
@@ -112,8 +124,7 @@ public class SendFusionTablesActivity extends Activity {
|
|||||||
* @param tableId tableId if available
|
* @param tableId tableId if available
|
||||||
*/
|
*/
|
||||||
public void onAsyncTaskCompleted(boolean success, String tableId) {
|
public void onAsyncTaskCompleted(boolean success, String tableId) {
|
||||||
Intent intent = new Intent().putExtra(SUCCESS, success).putExtra(TABLE_ID, tableId);
|
setResult(RESULT_OK, new Intent().putExtra(SUCCESS, success).putExtra(TABLE_ID, tableId));
|
||||||
setResult(RESULT_OK, intent);
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-24
@@ -178,13 +178,13 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
try {
|
try {
|
||||||
authToken = AccountManager.get(context).blockingGetAuthToken(account, SERVICE_ID, false);
|
authToken = AccountManager.get(context).blockingGetAuthToken(account, SERVICE_ID, false);
|
||||||
} catch (OperationCanceledException e) {
|
} catch (OperationCanceledException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (AuthenticatorException e) {
|
} catch (AuthenticatorException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get auth token", e);
|
||||||
return retryUpload();
|
return retryUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,18 +370,11 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
* @param lastBatch true if it is the last batch of locations
|
* @param lastBatch true if it is the last batch of locations
|
||||||
*/
|
*/
|
||||||
private boolean prepareAndUploadPoints(Track track, List<Location> locations, boolean lastBatch) {
|
private boolean prepareAndUploadPoints(Track track, List<Location> locations, boolean lastBatch) {
|
||||||
int numLocations = locations.size();
|
|
||||||
if (numLocations < 2) {
|
|
||||||
Log.d(TAG, "Not preparing/uploading, too few points");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare locations
|
// Prepare locations
|
||||||
ArrayList<Track> splitTracks = prepareLocations(track, locations);
|
ArrayList<Track> splitTracks = prepareLocations(track, locations);
|
||||||
|
|
||||||
boolean onlyOneSegment = lastBatch && currentSegment == 1 && splitTracks.size() == 1;
|
|
||||||
|
|
||||||
// Upload segments
|
// Upload segments
|
||||||
|
boolean onlyOneSegment = lastBatch && currentSegment == 1 && splitTracks.size() == 1;
|
||||||
for (Track splitTrack : splitTracks) {
|
for (Track splitTrack : splitTracks) {
|
||||||
if (!onlyOneSegment) {
|
if (!onlyOneSegment) {
|
||||||
splitTrack.setName(context.getString(
|
splitTrack.setName(context.getString(
|
||||||
@@ -447,7 +440,6 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
if (segmentStats.getStartTime() < 0) {
|
if (segmentStats.getStartTime() < 0) {
|
||||||
segmentStats.setStartTime(loc.getTime());
|
segmentStats.setStartTime(loc.getTime());
|
||||||
}
|
}
|
||||||
segmentStats.setStopTime(loc.getTime());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,9 +452,9 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
* Prepares a track segment for sending to Google Fusion Tables. The main
|
* Prepares a track segment for sending to Google Fusion Tables. The main
|
||||||
* steps are:
|
* steps are:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>set the stop time</li>
|
* <li>make sure the segment has at least 2 points</li>
|
||||||
|
* <li>set the segment stop time if necessary</li>
|
||||||
* <li>decimate locations precision</li>
|
* <li>decimate locations precision</li>
|
||||||
* <li>make sure the segment has more than 1 point</li>
|
|
||||||
* </ul>
|
* </ul>
|
||||||
* The prepared track will be added to the splitTracks.
|
* The prepared track will be added to the splitTracks.
|
||||||
*
|
*
|
||||||
@@ -470,11 +462,16 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
* @param splitTracks an array of track segments
|
* @param splitTracks an array of track segments
|
||||||
*/
|
*/
|
||||||
private void prepareTrackSegment(Track segment, ArrayList<Track> splitTracks) {
|
private void prepareTrackSegment(Track segment, ArrayList<Track> splitTracks) {
|
||||||
|
// Make sure the segment has at least 2 points
|
||||||
|
if (segment.getLocations().size() < 2) {
|
||||||
|
Log.d(TAG, "segment has less than 2 points");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// For a new segment, sets it stop time
|
// For a new segment, sets it stop time
|
||||||
TripStatistics segmentStats = segment.getStatistics();
|
TripStatistics segmentStats = segment.getStatistics();
|
||||||
ArrayList<Location> locations = segment.getLocations();
|
if (segmentStats.getStopTime() < 0) {
|
||||||
if (segmentStats.getStopTime() < 0 && locations.size() > 0) {
|
Location lastLocation = segment.getLocations().get(segment.getLocations().size() - 1);
|
||||||
Location lastLocation = locations.get(locations.size() - 1);
|
|
||||||
segmentStats.setStopTime(lastLocation.getTime());
|
segmentStats.setStopTime(lastLocation.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,10 +479,7 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
// points.
|
// points.
|
||||||
LocationUtils.decimate(segment, 2.0);
|
LocationUtils.decimate(segment, 2.0);
|
||||||
|
|
||||||
// Only add the segment if it has more than 1 point.
|
splitTracks.add(segment);
|
||||||
if (segment.getLocations().size() > 1) {
|
|
||||||
splitTracks.add(segment);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -572,7 +566,7 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
try {
|
try {
|
||||||
request = httpRequestFactory.buildPostRequest(url, inputStreamContent);
|
request = httpRequestFactory.buildPostRequest(url, inputStreamContent);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to build request", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +581,7 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
try {
|
try {
|
||||||
response = request.execute();
|
response = request.execute();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to execute request", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean isSuccess = response.isSuccessStatusCode();
|
boolean isSuccess = response.isSuccessStatusCode();
|
||||||
@@ -596,7 +590,7 @@ public class SendFusionTablesAsyncTask extends AsyncTask<Void, Integer, Boolean>
|
|||||||
try {
|
try {
|
||||||
content = response.getContent();
|
content = response.getContent();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to get response", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (setTableId) {
|
if (setTableId) {
|
||||||
|
|||||||
+3
-3
@@ -52,7 +52,7 @@ public class SendFusionTablesUtils {
|
|||||||
*/
|
*/
|
||||||
public static String getMapUrl(Track track) {
|
public static String getMapUrl(Track track) {
|
||||||
if (track == null || track.getStatistics() == null || track.getTableId() == null) {
|
if (track == null || track.getStatistics() == null || track.getTableId() == null) {
|
||||||
Log.e(TAG, "Invalid track.");
|
Log.e(TAG, "Invalid track");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ public class SendFusionTablesUtils {
|
|||||||
try {
|
try {
|
||||||
read = inputStream.read(result);
|
read = inputStream.read(result);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to read result", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (read == -1) {
|
if (read == -1) {
|
||||||
@@ -179,7 +179,7 @@ public class SendFusionTablesUtils {
|
|||||||
try {
|
try {
|
||||||
s = new String(result, 0, read, UTF8);
|
s = new String(result, 0, read, UTF8);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
Log.d(TAG, e.getMessage());
|
Log.d(TAG, "Unable to parse result", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user