aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/apps/LocusDataStorageProvider.java
blob: 8da7160d79a65ea11acc0074bd5a68cea3729909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cgeo.geocaching.apps;

import java.util.ArrayList;

import menion.android.locus.addon.publiclib.geoData.PointsData;
import menion.android.locus.addon.publiclib.utils.DataCursor;
import menion.android.locus.addon.publiclib.utils.DataStorage;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Parcel;

public class LocusDataStorageProvider extends ContentProvider {

//	private final static String TAG = "DataStorageProvider";
	
	@Override
	public Cursor query(Uri aUri, String[] aProjection, String aSelection,
			String[] aSelectionArgs, String aSortOrder) {
		
		DataCursor cursor = new DataCursor(new String[] {"data"});
		
		ArrayList<PointsData> data = DataStorage.getData();
		if (data == null || data.size() == 0)
			return cursor;
		
		for (int i = 0; i < data.size(); i++) {
			// get byte array
			Parcel par = Parcel.obtain();
			data.get(i).writeToParcel(par, 0);
			byte[] byteData = par.marshall();
			// add to row
			cursor.addRow(new Object[] {byteData});
		}
		// data filled to cursor, clear reference to prevent some memory issue
		DataStorage.clearData();
		// now finally return filled cursor
		return cursor;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		return null;
	}

	@Override
	public boolean onCreate() {
		return false;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		return 0;
	}
	
}