Skip to content

Repository files navigation

SyncFrameworkAndroid

Implemetation of Android client for Microsoft Sync Framework Toolkit

Using auto content provider:

For setup auto-content-library you need class which describes your database

interfaceDatabase {
@Table(primaryKeys={Status.ID})
interfaceStatus {
@TableNameStringTABLE_NAME = "Status";
@ColumnStringID = "ID";
@Column(type = ColumnType.VARCHAR, extras = Column.COLLATE_NO_CASE)
StringNAME = "Name";
}
}

with such classes we may build ContentHelper

publicfinalstaticStringAUTHORITY = "pl.selvin.android.autocontentprovider.test";
publicfinalstaticContentHelperCONTENT_HELPER = newContentHelper(Database.class, AUTHORITY, newDefaultDatabaseInfoFactory(), "test_db", 2);

this class is used to obtain uris for given table like:

finalUristatusDirUri = CONTENT_HELPER.getDirUri(Database.Status.TABLE_NAME);

should generate Uri like "content://pl.selvin.android.autocontentprovider.test/Status"

which can be easily used with CursorLoaders;

newCursorLoader(getContext(), statusDirUri, newString[] { Status.ID, Status.NAME }, null, null, null);

full setup should looks like this

publicclassTestProviderextendsAutoContentProvider {
publicfinalstaticStringAUTHORITY = "pl.selvin.android.autocontentprovider.test";
publicfinalstaticContentHelperCONTENT_HELPER = newContentHelper(Database.class, AUTHORITY, newDefaultDatabaseInfoFactory(), "test_db", 2);
publicTestProvider() {
super(CONTENT_HELPER, Logger.EmptyLogger.INSTANCE,
newSupportSQLiteOpenHelperFactoryProvider() {
@OverridepublicSupportSQLiteOpenHelper.FactorycreateFactory(Contextcontext) {
returnnewFrameworkSQLiteOpenHelperFactory();
}
});
}
}

But it's only auto content function without synchronization

To add synchronization code you have to add @SyncScope annotation to the table and make use of SyncContentHelper and BaseContentProvider

interfaceDatabase {
@SyncScope("DefaultScope")
@Table(primaryKeys={Status.ID})
interfaceStatus {
@TableNameStringTABLE_NAME = "Status";
@ColumnStringID = "ID";
@Column(type = ColumnType.VARCHAR, extras = Column.COLLATE_NO_CASE)
StringNAME = "Name";
}
}

and then setup out provider with code:

publicclassSyncProviderextendsBaseContentProvider {
publicfinalstaticStringAUTHORITY = "pl.selvin.android.autocontentprovider.test";
publicfinalstaticSyncContentHelperCONTENT_HELPER = SyncContentHelper.getInstance(Database.class, AUTHORITY, "test_db", 2, "http://example.com/service/path");
publicTestProvider() {
super(CONTENT_HELPER, Logger.EmptyLogger.INSTANCE,
newSupportSQLiteOpenHelperFactoryProvider() {
@OverridepublicSupportSQLiteOpenHelper.FactorycreateFactory(Contextcontext) {
returnnewFrameworkSQLiteOpenHelperFactory();
}
}, executor);
}
}

then we can initialize sync with

UrisyncUri = CONTENT_HELPER.getSyncUri("DefaultScopeSyncService", "defaultscope");
Stringparameters = null;
getContentResolver().update(uri, null, parameters, null);

or by using call (on api >= JELLY_BEAN_MR1)

Statsstats = newStats(); BundlesyncParams = newBundle();
syncParams.putParcelable(ListProvider.SYNC_PARAM_IN_SYNC_STATS, stats);
syncParams = getContentResolver().call(uri.toString(), parameters, syncParams);
stats = syncParams.getParcelable(ListProvider.SYNC_PARAM_IN_SYNC_STATS);
License:

Copyright (c) 2014-2017 Selvin 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.

About

Implemetation of Android client for Microsoft Sync Framework Toolkit

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages