本文整理汇总了Java中com.couchbase.lite.android.AndroidContext类的典型用法代码示例。如果您正苦于以下问题:Java AndroidContext类的具体用法?Java AndroidContext怎么用?Java AndroidContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AndroidContext类属于com.couchbase.lite.android包,在下文中一共展示了AndroidContext类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDatabase
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
/**
* 初始化数据库manager和数据库实例,保证全局唯
*
* @param context 上下文
* @return mDatabase
*/
private synchronized boolean initDatabase(Context context) {
if (context == null) {
return false;
}
try {
if (mDatabase == null) {
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
mDatabase = manager.getDatabase("guanghetv");
}
} catch (Exception e) {
LogUtils.d(e.getMessage());
mDatabase = null;
}
if (mDatabase != null) {
return true;
} else {
return false;
}
}
示例2: initializeCouchbase
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
private void initializeCouchbase(Context context) {
final Map<String, Object> s = new HashMap<>();
s.put("key1", "value1");
s.put("key2", "value2");
s.put("key3", "value3");
s.put("key4", "value4");
s.put("key5", "value5");
s.put("key6", "value6");
s.put("key7", "value7");
s.put("key8", "value8");
s.put("key9", "value9");
s.put("key10", "value10");
try {
mManager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
mDatabase = mManager.getDatabase("stetho-couchbase-sample");
Document doc = mDatabase.getDocument("id:123456");
doc.putProperties(s);
doc = mDatabase.getDocument("p::abcdefg");
doc.putProperties(s);
doc = mDatabase.getDocument("p::123abc");
doc.putProperties(s);
} catch (Exception ignored) {
}
}
示例3: onCreate
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
docCountLabel = (TextView) findViewById(docCount);
try {
manager = new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
} catch (IOException e) {
e.printStackTrace();
}
DatabaseDownloader databaseDownloader = new DatabaseDownloader(getApplicationContext());
databaseDownloader.execute();
databaseDownloader.setDownloaderListener(new DownloaderListener() {
@Override
public void onCompleted() {
setupQuery();
}
});
}
示例4: CouchbaseLite
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
public CouchbaseLite(Context context){
try {
manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
couchDbAuthor = manager.getDatabase("dbauthor");
couchDbPost = manager.getDatabase("dbpost");
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: getAllDocumentIds
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
List<String> getAllDocumentIds(String databaseId) {
Timber.d("getAllDocumentIds: %s", databaseId);
ManagerOptions managerOptions = new ManagerOptions();
managerOptions.setReadOnly(true);
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.setReadOnly(true);
com.couchbase.lite.Database database = null;
try {
// TODO: Create LiveQuery on this?
// TODO: Open manager/database and cache result - could be expensive operation
Manager manager = new Manager(new AndroidContext(mContext), managerOptions);
database = manager.openDatabase(databaseId, databaseOptions);
List<String> docIds = new ArrayList<>();
QueryEnumerator result = database.createAllDocumentsQuery().run();
while (result.hasNext()) {
QueryRow row = result.next();
docIds.add(row.getDocumentId());
}
return docIds;
} catch (Exception e) {
return Collections.emptyList();
} finally {
if (database != null) {
database.close();
}
}
}
示例6: initWithCredentials
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
private void initWithCredentials(Credentials credentials, Callback callback) {
this.allowedCredentials = credentials;
try {
View.setCompiler(new JavaScriptViewCompiler());
Database.setFilterCompiler(new JavaScriptReplicationFilterCompiler());
AndroidContext context = new AndroidContext(this.context);
manager = new Manager(context, Manager.DEFAULT_OPTIONS);
this.startListener();
String url;
if (credentials != null) {
url = String.format(
"http://%s:%[email protected]:%d/",
credentials.getLogin(),
credentials.getPassword(),
listener.getListenPort()
);
} else {
url = String.format(
"http://localhost:%d/",
listener.getListenPort()
);
}
callback.invoke(url, null);
} catch (final Exception e) {
Log.e(TAG, "Couchbase init failed", e);
callback.invoke(null, e.getMessage());
}
}
示例7: Storage
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
public Storage(Context context) throws IOException, CouchbaseLiteException {
mContext = context;
manager = new Manager(new AndroidContext(mContext), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase(BUCKET_NAME);
startSync();
}
示例8: CouchbaseInstance
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
private CouchbaseInstance(Context context) throws CouchbaseLiteException, IOException {
mContext = context.getApplicationContext();
DatabaseOptions options = new DatabaseOptions();
options.setCreate(true);
options.setStorageType(Manager.FORESTDB_STORAGE);
Manager manager = new Manager(new AndroidContext(mContext), Manager.DEFAULT_OPTIONS);
mDatabase = manager.openDatabase(DB_SOLVES, options);
initApiClient();
}
示例9: DataLoader
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
public DataLoader(Query query) {
super(((AndroidContext) query.getDatabase().getManager().getContext()).getWrappedContext());
this.query = query;
}
示例10: setupCouchbase
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
private void setupCouchbase() throws CouchbaseLiteException, IOException {
Manager manager = new Manager(new AndroidContext(getTargetContext()),
Manager.DEFAULT_OPTIONS);
database = manager.getDatabase(DB_NAME);
}
示例11: startCBLite
import com.couchbase.lite.android.AndroidContext; //导入依赖的package包/类
protected void startCBLite() throws CouchbaseLiteException, IOException {
File serverPathFile = getServerPath();
FileDirUtils.deleteRecursive(serverPathFile);
serverPathFile.mkdir();
manager = new Manager(new AndroidContext(getInstrumentation().getContext()), Manager.DEFAULT_OPTIONS);
}