forked from upstream-mirrors/OpenTracks
Cleanup Database: removed unused data fields.
This commit is contained in:
@@ -27,25 +27,4 @@ Releases since **2.0.5** :
|
|||||||
More information about **Google MyTracks**:
|
More information about **Google MyTracks**:
|
||||||
- [Wikipedia page](https://en.wikipedia.org/wiki/MyTracks)
|
- [Wikipedia page](https://en.wikipedia.org/wiki/MyTracks)
|
||||||
- [Google code archive](https://code.google.com/archive/p/mytracks/)
|
- [Google code archive](https://code.google.com/archive/p/mytracks/)
|
||||||
- [Release history on AppBrain](http://www.appbrain.com/app/my-tracks/com.google.android.maps.mytracks)
|
- [Release history on AppBrain](http://www.appbrain.com/app/my-tracks/com.google.android.maps.mytracks)
|
||||||
|
|
||||||
#How to build
|
|
||||||
Two Google API keys are needed to build this project:
|
|
||||||
- Google Map API key
|
|
||||||
- Google Backup API key
|
|
||||||
|
|
||||||
Those keys can be obtained using the [Google API console](https://console.developers.google.com/apis/).
|
|
||||||
|
|
||||||
As keys are not meant to be shared, they are located in their own value file: `/myTracks/src/main/res/values/apikeys.xml`, which is *git-ignored*. This means you have to **create it in your local project** to be able to build. Here is how it should look:
|
|
||||||
|
|
||||||
```xml
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<string name="backup_api_key">xxxxxx</string>
|
|
||||||
<string name="maps_api_key">yyyyyy</string>
|
|
||||||
</resources>
|
|
||||||
```
|
|
||||||
|
|
||||||
Once you have added this file, the project should be able to find and use your keys.
|
|
||||||
|
|
||||||
Note: you can use any other file if you prefer than `apikeys.xml`, but in that case be careful to not commit it.
|
|
||||||
-137
@@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 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;
|
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.content.TracksColumns;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import androidx.cursoradapter.widget.ResourceCursorAdapter;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A section based resource cursor adapter. Currently only supports one
|
|
||||||
* additional section header, "Shared with me".
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public abstract class SectionResourceCursorAdapter extends ResourceCursorAdapter {
|
|
||||||
|
|
||||||
private enum ItemType {
|
|
||||||
TRACK, HEADER
|
|
||||||
}
|
|
||||||
|
|
||||||
private final LayoutInflater layoutInflater;
|
|
||||||
private int sharedWithMeIndex = -1;
|
|
||||||
|
|
||||||
public SectionResourceCursorAdapter(Context context, int layout, Cursor cursor, int flags) {
|
|
||||||
super(context, layout, cursor, flags);
|
|
||||||
this.layoutInflater = LayoutInflater.from(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
if (getItemViewType(position) == ItemType.TRACK.ordinal()) {
|
|
||||||
return super.getView(getCursorPosition(position), convertView, parent);
|
|
||||||
} else {
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getViewTypeCount() {
|
|
||||||
return ItemType.values().length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
int count = super.getCount();
|
|
||||||
return count != 0 && sharedWithMeIndex != -1 ? count + 1 : count;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int position) {
|
|
||||||
return getItemViewType(position) == ItemType.TRACK.ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getItem(int position) {
|
|
||||||
if (getItemViewType(position) == ItemType.TRACK.ordinal()) {
|
|
||||||
return super.getItem(getCursorPosition(position));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getItemId(int position) {
|
|
||||||
if (getItemViewType(position) == ItemType.TRACK.ordinal()) {
|
|
||||||
return super.getItemId(getCursorPosition(position));
|
|
||||||
}
|
|
||||||
return -1L;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemViewType(int position) {
|
|
||||||
if (sharedWithMeIndex != -1 && sharedWithMeIndex == position) {
|
|
||||||
return ItemType.HEADER.ordinal();
|
|
||||||
}
|
|
||||||
return ItemType.TRACK.ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Cursor swapCursor(Cursor newCursor) {
|
|
||||||
Cursor oldCursor = super.swapCursor(newCursor);
|
|
||||||
sharedWithMeIndex = getSharedWithMeIndex();
|
|
||||||
return oldCursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Shared with me header index.
|
|
||||||
*/
|
|
||||||
private int getSharedWithMeIndex() {
|
|
||||||
int i = 0;
|
|
||||||
Cursor cursor = getCursor();
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
|
||||||
int index = cursor.getColumnIndex(TracksColumns.SHAREDWITHME);
|
|
||||||
do {
|
|
||||||
int sharedWithMe = cursor.getInt(index);
|
|
||||||
if (sharedWithMe == 1) {
|
|
||||||
// Returns the index where sharedWithMe == 1
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
} while (cursor.moveToNext());
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the underlying cursor position.
|
|
||||||
*
|
|
||||||
* @param position the requested position
|
|
||||||
*/
|
|
||||||
private int getCursorPosition(int position) {
|
|
||||||
if (sharedWithMeIndex != -1 && position > sharedWithMeIndex) {
|
|
||||||
return position - 1;
|
|
||||||
}
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,6 @@ import android.database.Cursor;
|
|||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -48,6 +47,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.cursoradapter.widget.ResourceCursorAdapter;
|
||||||
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
||||||
import androidx.loader.content.CursorLoader;
|
import androidx.loader.content.CursorLoader;
|
||||||
import androidx.loader.content.Loader;
|
import androidx.loader.content.Loader;
|
||||||
@@ -85,8 +85,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||||
private static final String[] PROJECTION = new String[] { TracksColumns._ID, TracksColumns.NAME,
|
private static final String[] PROJECTION = new String[] { TracksColumns._ID, TracksColumns.NAME,
|
||||||
TracksColumns.DESCRIPTION, TracksColumns.CATEGORY, TracksColumns.STARTTIME,
|
TracksColumns.DESCRIPTION, TracksColumns.CATEGORY, TracksColumns.STARTTIME,
|
||||||
TracksColumns.TOTALDISTANCE, TracksColumns.TOTALTIME, TracksColumns.ICON,
|
TracksColumns.TOTALDISTANCE, TracksColumns.TOTALTIME, TracksColumns.ICON };
|
||||||
TracksColumns.SHAREDWITHME, TracksColumns.SHAREDOWNER };
|
|
||||||
|
|
||||||
// Callback when the trackRecordingServiceConnection binding changes.
|
// Callback when the trackRecordingServiceConnection binding changes.
|
||||||
private final Runnable bindChangedCallback = new Runnable() {
|
private final Runnable bindChangedCallback = new Runnable() {
|
||||||
@@ -233,12 +232,12 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||||
sectionResourceCursorAdapter.swapCursor(cursor);
|
resourceCursorAdapter.swapCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<Cursor> loader) {
|
public void onLoaderReset(Loader<Cursor> loader) {
|
||||||
sectionResourceCursorAdapter.swapCursor(null);
|
resourceCursorAdapter.swapCursor(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -248,7 +247,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||||
private TrackController trackController;
|
private TrackController trackController;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private SectionResourceCursorAdapter sectionResourceCursorAdapter;
|
private ResourceCursorAdapter resourceCursorAdapter;
|
||||||
|
|
||||||
// Preferences
|
// Preferences
|
||||||
private boolean metricUnits = true;
|
private boolean metricUnits = true;
|
||||||
@@ -310,8 +309,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
startActivity(newIntent);
|
startActivity(newIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sectionResourceCursorAdapter = new SectionResourceCursorAdapter(
|
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
|
||||||
this, R.layout.list_item, null, 0) {
|
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
int idIndex = cursor.getColumnIndex(TracksColumns._ID);
|
int idIndex = cursor.getColumnIndex(TracksColumns._ID);
|
||||||
@@ -341,7 +339,7 @@ public class TrackListActivity extends AbstractTrackActivity implements FileType
|
|||||||
startTime, true, category, description, null);
|
startTime, true, category, description, null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
listView.setAdapter(sectionResourceCursorAdapter);
|
listView.setAdapter(resourceCursorAdapter);
|
||||||
AbstractTrackActivity.configureListViewContextualMenu(this, listView, contextualActionModeCallback);
|
AbstractTrackActivity.configureListViewContextualMenu(this, listView, contextualActionModeCallback);
|
||||||
|
|
||||||
getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
|
getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
|
||||||
|
|||||||
+9
-84
@@ -100,13 +100,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
+ TrackPointsColumns.SENSOR + " BLOB");
|
+ TrackPointsColumns.SENSOR + " BLOB");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add track TABLEID column
|
|
||||||
if (oldVersion <= 18) {
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track tableid column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.TABLEID
|
|
||||||
+ " STRING");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add track ICON column
|
// Add track ICON column
|
||||||
if (oldVersion <= 19) {
|
if (oldVersion <= 19) {
|
||||||
Log.w(TAG, "Upgrade DB: Adding track icon column.");
|
Log.w(TAG, "Upgrade DB: Adding track icon column.");
|
||||||
@@ -114,37 +107,10 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
"ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.ICON + " STRING");
|
"ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.ICON + " STRING");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add track DRIVEID, MODIFIEDTIME, and SHAREDWITHME columns
|
|
||||||
if (oldVersion <= 20) {
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track driveid column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.DRIVEID
|
|
||||||
+ " STRING");
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track modifiedtime column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD "
|
|
||||||
+ TracksColumns.MODIFIEDTIME + " INTEGER");
|
|
||||||
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track sharedwithme column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD "
|
|
||||||
+ TracksColumns.SHAREDWITHME + " INTEGER");
|
|
||||||
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track sharedowner column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.SHAREDOWNER
|
|
||||||
+ " STRING");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add waypoint CALORIE and PHOTOURL columns. Add track CALORIE column.
|
// Add waypoint CALORIE and PHOTOURL columns. Add track CALORIE column.
|
||||||
if (oldVersion <= 21) {
|
if (oldVersion <= 21) {
|
||||||
Log.w(TAG, "Upgrade DB: Adding waypoint calorie column.");
|
|
||||||
db.execSQL("ALTER TABLE " + WaypointsColumns.TABLE_NAME + " ADD "
|
|
||||||
+ WaypointsColumns.CALORIE + " FLOAT");
|
|
||||||
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding waypoint photo url column.");
|
Log.w(TAG, "Upgrade DB: Adding waypoint photo url column.");
|
||||||
db.execSQL("ALTER TABLE " + WaypointsColumns.TABLE_NAME + " ADD "
|
db.execSQL("ALTER TABLE " + WaypointsColumns.TABLE_NAME + " ADD " + WaypointsColumns.PHOTOURL + " STRING");
|
||||||
+ WaypointsColumns.PHOTOURL + " STRING");
|
|
||||||
|
|
||||||
Log.w(TAG, "Upgrade DB: Adding track calorie column.");
|
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.CALORIE
|
|
||||||
+ " FLOAT");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,18 +131,12 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
public MyTracksProvider() {
|
public MyTracksProvider() {
|
||||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME,
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME, UrlType.TRACKPOINTS.ordinal());
|
||||||
UrlType.TRACKPOINTS.ordinal());
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME + "/#", UrlType.TRACKPOINTS_ID.ordinal());
|
||||||
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TrackPointsColumns.TABLE_NAME + "/#",
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
|
||||||
UrlType.TRACKPOINTS_ID.ordinal());
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME + "/#", UrlType.TRACKS_ID.ordinal());
|
||||||
uriMatcher.addURI(
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
|
||||||
MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
|
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME + "/#", UrlType.WAYPOINTS_ID.ordinal());
|
||||||
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, TracksColumns.TABLE_NAME + "/#",
|
|
||||||
UrlType.TRACKS_ID.ordinal());
|
|
||||||
uriMatcher.addURI(
|
|
||||||
MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
|
|
||||||
uriMatcher.addURI(MyTracksProviderUtils.AUTHORITY, WaypointsColumns.TABLE_NAME + "/#",
|
|
||||||
UrlType.WAYPOINTS_ID.ordinal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,9 +152,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean onCreate(Context context) {
|
boolean onCreate(Context context) {
|
||||||
if (!canAccess()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DatabaseHelper databaseHelper = new DatabaseHelper(context);
|
DatabaseHelper databaseHelper = new DatabaseHelper(context);
|
||||||
try {
|
try {
|
||||||
db = databaseHelper.getWritableDatabase();
|
db = databaseHelper.getWritableDatabase();
|
||||||
@@ -206,9 +163,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri url, String where, String[] selectionArgs) {
|
public int delete(Uri url, String where, String[] selectionArgs) {
|
||||||
if (!canAccess()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
String table;
|
String table;
|
||||||
boolean shouldVacuum = false;
|
boolean shouldVacuum = false;
|
||||||
switch (getUrlType(url)) {
|
switch (getUrlType(url)) {
|
||||||
@@ -247,9 +201,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri url) {
|
public String getType(Uri url) {
|
||||||
if (!canAccess()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
switch (getUrlType(url)) {
|
switch (getUrlType(url)) {
|
||||||
case TRACKPOINTS:
|
case TRACKPOINTS:
|
||||||
return TrackPointsColumns.CONTENT_TYPE;
|
return TrackPointsColumns.CONTENT_TYPE;
|
||||||
@@ -270,9 +221,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri url, ContentValues initialValues) {
|
public Uri insert(Uri url, ContentValues initialValues) {
|
||||||
if (!canAccess()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (initialValues == null) {
|
if (initialValues == null) {
|
||||||
initialValues = new ContentValues();
|
initialValues = new ContentValues();
|
||||||
}
|
}
|
||||||
@@ -290,9 +238,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int bulkInsert(Uri url, ContentValues[] valuesBulk) {
|
public int bulkInsert(Uri url, ContentValues[] valuesBulk) {
|
||||||
if (!canAccess()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int numInserted;
|
int numInserted;
|
||||||
try {
|
try {
|
||||||
// Use a transaction in order to make the insertions run as a single batch
|
// Use a transaction in order to make the insertions run as a single batch
|
||||||
@@ -315,11 +260,7 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(
|
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
|
||||||
Uri url, String[] projection, String selection, String[] selectionArgs, String sort) {
|
|
||||||
if (!canAccess()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
|
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
|
||||||
String sortOrder = null;
|
String sortOrder = null;
|
||||||
switch (getUrlType(url)) {
|
switch (getUrlType(url)) {
|
||||||
@@ -350,17 +291,13 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown url " + url);
|
throw new IllegalArgumentException("Unknown url " + url);
|
||||||
}
|
}
|
||||||
Cursor cursor = queryBuilder.query(
|
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
|
||||||
db, projection, selection, selectionArgs, null, null, sortOrder);
|
|
||||||
cursor.setNotificationUri(getContext().getContentResolver(), url);
|
cursor.setNotificationUri(getContext().getContentResolver(), url);
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri url, ContentValues values, String where, String[] selectionArgs) {
|
public int update(Uri url, ContentValues values, String where, String[] selectionArgs) {
|
||||||
if (!canAccess()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
String table;
|
String table;
|
||||||
String whereClause;
|
String whereClause;
|
||||||
switch (getUrlType(url)) {
|
switch (getUrlType(url)) {
|
||||||
@@ -428,18 +365,6 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
getContext().revokeUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
getContext().revokeUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the caller can access the content provider.
|
|
||||||
*/
|
|
||||||
private boolean canAccess() {
|
|
||||||
if (Binder.getCallingPid() == Process.myPid()) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return PreferencesUtils.getBoolean(
|
|
||||||
getContext(), R.string.allow_access_key, PreferencesUtils.ALLOW_ACCESS_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link UrlType} for a url.
|
* Gets the {@link UrlType} for a url.
|
||||||
|
|||||||
+3
-10
@@ -86,8 +86,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
int minGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINGRADE);
|
int minGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MINGRADE);
|
||||||
int maxGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE);
|
int maxGradeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE);
|
||||||
int iconIndex = cursor.getColumnIndexOrThrow(TracksColumns.ICON);
|
int iconIndex = cursor.getColumnIndexOrThrow(TracksColumns.ICON);
|
||||||
int modifiedTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MODIFIEDTIME);
|
|
||||||
|
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
TripStatistics tripStatistics = track.getTripStatistics();
|
TripStatistics tripStatistics = track.getTripStatistics();
|
||||||
if (!cursor.isNull(idIndex)) {
|
if (!cursor.isNull(idIndex)) {
|
||||||
@@ -126,8 +125,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
if (!cursor.isNull(movingTimeIndex)) {
|
if (!cursor.isNull(movingTimeIndex)) {
|
||||||
tripStatistics.setMovingTime(cursor.getLong(movingTimeIndex));
|
tripStatistics.setMovingTime(cursor.getLong(movingTimeIndex));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(minLatIndex) && !cursor.isNull(maxLatIndex) && !cursor.isNull(minLonIndex)
|
if (!cursor.isNull(minLatIndex) && !cursor.isNull(maxLatIndex) && !cursor.isNull(minLonIndex) && !cursor.isNull(maxLonIndex)) {
|
||||||
&& !cursor.isNull(maxLonIndex)) {
|
|
||||||
int bottom = cursor.getInt(minLatIndex);
|
int bottom = cursor.getInt(minLatIndex);
|
||||||
int top = cursor.getInt(maxLatIndex);
|
int top = cursor.getInt(maxLatIndex);
|
||||||
int left = cursor.getInt(minLonIndex);
|
int left = cursor.getInt(minLonIndex);
|
||||||
@@ -155,9 +153,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
if (!cursor.isNull(iconIndex)) {
|
if (!cursor.isNull(iconIndex)) {
|
||||||
track.setIcon(cursor.getString(iconIndex));
|
track.setIcon(cursor.getString(iconIndex));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(modifiedTimeIndex)) {
|
|
||||||
track.setModifiedTime(cursor.getLong(modifiedTimeIndex));
|
|
||||||
}
|
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +229,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Track getLastTrack() {
|
public Track getLastTrack() {
|
||||||
try (Cursor cursor = getTrackCursor(null, null, null,
|
try (Cursor cursor = getTrackCursor(null, null, null,TracksColumns.STARTTIME + " DESC")) {
|
||||||
TracksColumns.SHAREDWITHME + " ASC, " + TracksColumns.STARTTIME + " DESC")) {
|
|
||||||
// Using the same order as shown in the track list
|
// Using the same order as shown in the track list
|
||||||
if (cursor != null && cursor.moveToNext()) {
|
if (cursor != null && cursor.moveToNext()) {
|
||||||
return createTrack(cursor);
|
return createTrack(cursor);
|
||||||
@@ -306,7 +300,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
values.put(TracksColumns.MINGRADE, tripStatistics.getMinGrade());
|
values.put(TracksColumns.MINGRADE, tripStatistics.getMinGrade());
|
||||||
values.put(TracksColumns.MAXGRADE, tripStatistics.getMaxGrade());
|
values.put(TracksColumns.MAXGRADE, tripStatistics.getMaxGrade());
|
||||||
values.put(TracksColumns.ICON, track.getIcon());
|
values.put(TracksColumns.ICON, track.getIcon());
|
||||||
values.put(TracksColumns.MODIFIEDTIME, track.getModifiedTime());
|
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,22 +75,7 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
String ELEVATIONGAIN = "elevationgain"; // elevation gain
|
String ELEVATIONGAIN = "elevationgain"; // elevation gain
|
||||||
String MINGRADE = "mingrade"; // minimum grade
|
String MINGRADE = "mingrade"; // minimum grade
|
||||||
String MAXGRADE = "maxgrade"; // maximum grade
|
String MAXGRADE = "maxgrade"; // maximum grade
|
||||||
String MAPID = "mapid"; // Google Maps id
|
|
||||||
String TABLEID = "tableid"; // Google Fusion Tables id
|
|
||||||
String ICON = "icon"; // track activity type icon
|
String ICON = "icon"; // track activity type icon
|
||||||
String DRIVEID = "driveid"; // Google Drive file id
|
|
||||||
|
|
||||||
// Google drive file modified time
|
|
||||||
String MODIFIEDTIME = "modifiedtime";
|
|
||||||
|
|
||||||
// 1 if the Google Drive file is from the "Shared with me" directory
|
|
||||||
String SHAREDWITHME = "sharedwithme";
|
|
||||||
|
|
||||||
// The owner of the shared with me track
|
|
||||||
String SHAREDOWNER = "sharedOwner";
|
|
||||||
|
|
||||||
// Calorie burned of the track
|
|
||||||
String CALORIE = "calorie";
|
|
||||||
|
|
||||||
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" // table
|
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" // table
|
||||||
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // id
|
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // id
|
||||||
@@ -117,79 +102,5 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
+ ELEVATIONGAIN + " FLOAT, " // elevation gain
|
+ ELEVATIONGAIN + " FLOAT, " // elevation gain
|
||||||
+ MINGRADE + " FLOAT, " // min grade
|
+ MINGRADE + " FLOAT, " // min grade
|
||||||
+ MAXGRADE + " FLOAT, " // max grade
|
+ MAXGRADE + " FLOAT, " // max grade
|
||||||
+ MAPID + " STRING, " // map id
|
+ ICON + " STRING);"; // icon
|
||||||
+ TABLEID + " STRING, " // table id
|
|
||||||
+ ICON + " STRING, " // icon
|
|
||||||
+ DRIVEID + " STRING, " // drive id
|
|
||||||
+ MODIFIEDTIME + " INTEGER, " // modified time
|
|
||||||
+ SHAREDWITHME + " INTEGER, " // shared with me
|
|
||||||
+ SHAREDOWNER + " STRING, " // shared owner
|
|
||||||
+ CALORIE + " FLOAT);"; // calorie
|
|
||||||
|
|
||||||
String[] COLUMNS = { _ID, // id
|
|
||||||
NAME, // name
|
|
||||||
DESCRIPTION, // description
|
|
||||||
CATEGORY, // category
|
|
||||||
STARTID, // start id
|
|
||||||
STOPID, // stop id
|
|
||||||
STARTTIME, // start time
|
|
||||||
STOPTIME, // stop time
|
|
||||||
NUMPOINTS, // num points
|
|
||||||
TOTALDISTANCE, // total distance
|
|
||||||
TOTALTIME, // total time
|
|
||||||
MOVINGTIME, // moving time
|
|
||||||
MINLAT, // min latitude
|
|
||||||
MAXLAT, // max latitude
|
|
||||||
MINLON, // min longitude
|
|
||||||
MAXLON, // max longitude
|
|
||||||
AVGSPEED, // average speed
|
|
||||||
AVGMOVINGSPEED, // average moving speed
|
|
||||||
MAXSPEED, // max speed
|
|
||||||
MINELEVATION, // min elevation
|
|
||||||
MAXELEVATION, // max elevation
|
|
||||||
ELEVATIONGAIN, // elevation gain
|
|
||||||
MINGRADE, // min grade
|
|
||||||
MAXGRADE, // max grade
|
|
||||||
MAPID, // map id
|
|
||||||
TABLEID, // table id
|
|
||||||
ICON, // icon
|
|
||||||
DRIVEID, // drive id
|
|
||||||
MODIFIEDTIME, // modified time
|
|
||||||
SHAREDWITHME, // shared with me
|
|
||||||
SHAREDOWNER,// shared owner
|
|
||||||
CALORIE }; // calorie
|
|
||||||
|
|
||||||
byte[] COLUMN_TYPES = { ContentTypeIds.LONG_TYPE_ID, // id
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // name
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // description
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // category
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // start id
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // stop id
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // start time
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // stop time
|
|
||||||
ContentTypeIds.INT_TYPE_ID, // num points
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // total distance
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // total time
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // moving time
|
|
||||||
ContentTypeIds.INT_TYPE_ID, // min latitude
|
|
||||||
ContentTypeIds.INT_TYPE_ID, // max latitude
|
|
||||||
ContentTypeIds.INT_TYPE_ID, // min longitude
|
|
||||||
ContentTypeIds.INT_TYPE_ID, // max longitude
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // average speed
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // average moving speed
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // max speed
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // min elevation
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // max elevation
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // elevation gain
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // min grade
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID, // max grade
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // map id
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // table id
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // icon
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // drive id
|
|
||||||
ContentTypeIds.LONG_TYPE_ID, // modified time
|
|
||||||
ContentTypeIds.BOOLEAN_TYPE_ID, // shared with me
|
|
||||||
ContentTypeIds.STRING_TYPE_ID, // shared owner
|
|
||||||
ContentTypeIds.FLOAT_TYPE_ID // calorie
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-75
@@ -32,8 +32,7 @@ import android.provider.BaseColumns;
|
|||||||
public interface WaypointsColumns extends BaseColumns {
|
public interface WaypointsColumns extends BaseColumns {
|
||||||
|
|
||||||
String TABLE_NAME = "waypoints";
|
String TABLE_NAME = "waypoints";
|
||||||
Uri CONTENT_URI = Uri.parse(
|
Uri CONTENT_URI = Uri.parse("content://com.google.android.maps.mytracks/waypoints");
|
||||||
"content://com.google.android.maps.mytracks/waypoints");
|
|
||||||
String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.waypoint";
|
String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.waypoint";
|
||||||
String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.google.waypoint";
|
String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.google.waypoint";
|
||||||
String DEFAULT_SORT_ORDER = "_id";
|
String DEFAULT_SORT_ORDER = "_id";
|
||||||
@@ -70,8 +69,7 @@ public interface WaypointsColumns extends BaseColumns {
|
|||||||
String ELEVATIONGAIN = "elevationgain"; // elevation gain
|
String ELEVATIONGAIN = "elevationgain"; // elevation gain
|
||||||
String MINGRADE = "mingrade"; // min grade
|
String MINGRADE = "mingrade"; // min grade
|
||||||
String MAXGRADE = "maxgrade"; // max grade
|
String MAXGRADE = "maxgrade"; // max grade
|
||||||
String CALORIE = "calorie"; // calorie
|
|
||||||
|
|
||||||
String PHOTOURL = "photoUrl"; // url for the photo
|
String PHOTOURL = "photoUrl"; // url for the photo
|
||||||
|
|
||||||
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ("
|
String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ("
|
||||||
@@ -105,77 +103,6 @@ public interface WaypointsColumns extends BaseColumns {
|
|||||||
+ ELEVATIONGAIN + " FLOAT, "
|
+ ELEVATIONGAIN + " FLOAT, "
|
||||||
+ MINGRADE + " FLOAT, "
|
+ MINGRADE + " FLOAT, "
|
||||||
+ MAXGRADE + " FLOAT, "
|
+ MAXGRADE + " FLOAT, "
|
||||||
+ CALORIE + " FLOAT, "
|
|
||||||
+ PHOTOURL + " STRING"
|
+ PHOTOURL + " STRING"
|
||||||
+ ");";
|
+ ");";
|
||||||
|
|
||||||
String[] COLUMNS = {
|
|
||||||
_ID,
|
|
||||||
NAME,
|
|
||||||
DESCRIPTION,
|
|
||||||
CATEGORY,
|
|
||||||
ICON,
|
|
||||||
TRACKID,
|
|
||||||
TYPE,
|
|
||||||
LENGTH,
|
|
||||||
DURATION,
|
|
||||||
STARTTIME,
|
|
||||||
STARTID,
|
|
||||||
STOPID,
|
|
||||||
LONGITUDE,
|
|
||||||
LATITUDE,
|
|
||||||
TIME,
|
|
||||||
ALTITUDE,
|
|
||||||
ACCURACY,
|
|
||||||
SPEED,
|
|
||||||
BEARING,
|
|
||||||
TOTALDISTANCE,
|
|
||||||
TOTALTIME,
|
|
||||||
MOVINGTIME,
|
|
||||||
AVGSPEED,
|
|
||||||
AVGMOVINGSPEED,
|
|
||||||
MAXSPEED,
|
|
||||||
MINELEVATION,
|
|
||||||
MAXELEVATION,
|
|
||||||
ELEVATIONGAIN,
|
|
||||||
MINGRADE,
|
|
||||||
MAXGRADE,
|
|
||||||
CALORIE,
|
|
||||||
PHOTOURL
|
|
||||||
};
|
|
||||||
|
|
||||||
byte[] COLUMN_TYPES = {
|
|
||||||
LONG_TYPE_ID, // id
|
|
||||||
STRING_TYPE_ID, // name
|
|
||||||
STRING_TYPE_ID, // description
|
|
||||||
STRING_TYPE_ID, // category
|
|
||||||
STRING_TYPE_ID, // icon
|
|
||||||
LONG_TYPE_ID, // track id
|
|
||||||
INT_TYPE_ID, // type
|
|
||||||
FLOAT_TYPE_ID, // length
|
|
||||||
LONG_TYPE_ID, // duration
|
|
||||||
LONG_TYPE_ID, // start time
|
|
||||||
LONG_TYPE_ID, // start id
|
|
||||||
LONG_TYPE_ID, // stop id
|
|
||||||
INT_TYPE_ID, // longitude
|
|
||||||
INT_TYPE_ID, // latitude
|
|
||||||
LONG_TYPE_ID, // time
|
|
||||||
FLOAT_TYPE_ID, // altitude
|
|
||||||
FLOAT_TYPE_ID, // accuracy
|
|
||||||
FLOAT_TYPE_ID, // speed
|
|
||||||
FLOAT_TYPE_ID, // bearing
|
|
||||||
FLOAT_TYPE_ID, // total distance
|
|
||||||
LONG_TYPE_ID, // total time
|
|
||||||
LONG_TYPE_ID, // moving time
|
|
||||||
FLOAT_TYPE_ID, // average speed
|
|
||||||
FLOAT_TYPE_ID, // average moving speed
|
|
||||||
FLOAT_TYPE_ID, // max speed
|
|
||||||
FLOAT_TYPE_ID, // min elevation
|
|
||||||
FLOAT_TYPE_ID, // max elevation
|
|
||||||
FLOAT_TYPE_ID, // elevation gain
|
|
||||||
FLOAT_TYPE_ID, // min grade
|
|
||||||
FLOAT_TYPE_ID, // max grade
|
|
||||||
FLOAT_TYPE_ID, // calorie
|
|
||||||
STRING_TYPE_ID // photo url
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,9 @@ public class TrackUtils {
|
|||||||
|
|
||||||
private TrackUtils() {}
|
private TrackUtils() {}
|
||||||
|
|
||||||
public static String TRACK_SORT_ORDER = "IFNULL(" + TracksColumns.SHAREDWITHME + ",0) ASC, "
|
public static String TRACK_SORT_ORDER = TracksColumns.STARTTIME + " DESC";
|
||||||
+ TracksColumns.STARTTIME + " DESC";
|
|
||||||
|
|
||||||
public static void updateTrack(Context context, Track track, String name, String category,
|
public static void updateTrack(Context context, Track track, String name, String category, String description, MyTracksProviderUtils myTracksProviderUtils) {
|
||||||
String description, MyTracksProviderUtils myTracksProviderUtils) {
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
track.setName(name);
|
track.setName(name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user