本文整理汇总了Java中android.database.CursorJoiner类的典型用法代码示例。如果您正苦于以下问题:Java CursorJoiner类的具体用法?Java CursorJoiner怎么用?Java CursorJoiner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CursorJoiner类属于android.database包,在下文中一共展示了CursorJoiner类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCursors
import android.database.CursorJoiner; //导入依赖的package包/类
/**
* todo:
*
* @param newCursor
* @param oldCursor
* @return
*/
@NonNull
@SuppressWarnings("ConstantConditions")
public Result processCursors(@Nullable Cursor newCursor, @Nullable Cursor oldCursor) {
if (newCursor == null && oldCursor == null) return new Result();
Result result;
if ((result = processCursorsTotalChange(oldCursor, newCursor)) != null) {
return result;
}
final CursorJoiner joiner = new CursorJoiner(
oldCursor, COMPARABLE_COLUMN_NAMES,
newCursor, COMPARABLE_COLUMN_NAMES
);
mInsertHandler.clear();
mRemoveHandler.clear();
result = new Result();
DataSetChange[] dataSetChanges;
for (CursorJoiner.Result joinerResult : joiner) {
switch (joinerResult) {
// Row has been removed.
case LEFT:
this.resolvePendingChange(mInsertHandler, result);
dataSetChanges = mRemoveHandler.handleChange(oldCursor.getPosition());
if (dataSetChanges != null) {
if (dataSetChanges.length == 1) {
result.addDataSetChange(dataSetChanges[0]);
} else {
result.addDataSetChange(dataSetChanges[1]);
}
}
break;
// Row has been inserted.
case RIGHT:
this.resolvePendingChange(mRemoveHandler, result);
dataSetChanges = mInsertHandler.handleChange(newCursor.getPosition());
if (dataSetChanges != null) {
if (dataSetChanges.length == 1) {
result.addDataSetChange(dataSetChanges[0]);
} else {
result.addDataSetChange(dataSetChanges[1]);
}
}
break;
// Row has been possibly changed.
case BOTH:
if (mItemChangeHandler != null && mFirstVisibleItemPosition != NO_POSITION && mLastVisibleItemPosition != NO_POSITION) {
final int cursorPosition = newCursor.getPosition();
if (cursorPosition >= mFirstVisibleItemPosition && cursorPosition <= mLastVisibleItemPosition &&
mItemChangeHandler.hasChanged(newCursor)) {
this.resolvePendingChange(mInsertHandler, result);
this.resolvePendingChange(mRemoveHandler, result);
// Item at the current processing position is visible and its data has
// changed so its UI should be re-bound with the new data.
result.addDataSetChange(new ItemChanged(cursorPosition));
// todo: handle item range changes
}
}
break;
}
}
return result;
}
示例2: onCreateCallback
import android.database.CursorJoiner; //导入依赖的package包/类
@Override
protected void onCreateCallback(Bundle savedInstanceState) {
Cursor medias = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Images.Media._ID);
String[] colunsMedia = new String[]{MediaStore.Images.Media._ID};
int idIdx = medias.getColumnIndex(MediaStore.Images.Media._ID);
int displayIdx = medias.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME);
int pathIdx = medias.getColumnIndex(MediaStore.Images.Media.DATA);
Cursor thumbnail = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Images.Thumbnails.IMAGE_ID);
String[] columnsThumbnail = new String[]{MediaStore.Images.Thumbnails.IMAGE_ID};
int thumbIdx = thumbnail.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
CursorJoiner joiner = new CursorJoiner(medias, colunsMedia, thumbnail, columnsThumbnail);
mList = new ArrayList<ImageEntity>();
mFilters = new ArrayList<ImageFilter>();
for (CursorJoiner.Result joinerResult : joiner) {
ImageEntity entity = new ImageEntity();
switch (joinerResult) {
case LEFT:
entity.id = medias.getInt(idIdx);
entity.displayName = medias.getString(displayIdx);
entity.data = medias.getString(pathIdx);
break;
case RIGHT:
Logs.i(TAG, "RIGHT ............");
continue;
case BOTH:
entity.id = medias.getInt(idIdx);
entity.displayName = medias.getString(displayIdx);
entity.data = medias.getString(pathIdx);
entity.thumb = thumbnail.getString(thumbIdx);
break;
}
setToFilter(entity);
mList.add(entity);
}
mGridView = (GridView) findViewById(R.id.gridview);
mAdapter = new ImageAdapter();
mGridView.setAdapter(mAdapter);
medias.close();
thumbnail.close();
setBaseToolBarTitle("选择图片(" + 0 + "/" + mList.size() + ")");
mFilterName = (TextView) findViewById(R.id.filter_name);
mFilterLayout = findViewById(R.id.filter_layout);
mFilterListView = (ListView) findViewById(R.id.filter_listview);
mFilterAdapter = new FilterAdapter();
mFilterListView.setAdapter(mFilterAdapter);
mFilterListView.setOnItemClickListener(mFilterAdapter);
mFilterName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mFilterLayout.getVisibility() == View.VISIBLE) {
mFilterLayout.setVisibility(View.GONE);
} else {
mFilterLayout.setVisibility(View.VISIBLE);
}
}
});
}
示例3: conditionallyAddFlowEvent
import android.database.CursorJoiner; //导入依赖的package包/类
/**
* Conditionally adds a flow event if no flow event exists in the current upload blob.
*/
private void conditionallyAddFlowEvent()
{
/*
* Creating a flow "event" is required to act as a placeholder so that the uploader will know that an upload needs to
* occur. A flow event should only be created if there isn't already a flow event that hasn't been associated with an
* upload blob.
*/
boolean foundUnassociatedFlowEvent = false;
Cursor eventsCursor = null;
Cursor blob_eventsCursor = null;
try
{
eventsCursor = mProvider.query(EventsDbColumns.TABLE_NAME, PROJECTION_FLOW_EVENTS, SELECTION_FLOW_EVENTS, SELECTION_ARGS_FLOW_EVENTS, EVENTS_SORT_ORDER);
blob_eventsCursor = mProvider.query(UploadBlobEventsDbColumns.TABLE_NAME, PROJECTION_FLOW_BLOBS, null, null, UPLOAD_BLOBS_EVENTS_SORT_ORDER);
final CursorJoiner joiner = new CursorJoiner(eventsCursor, PROJECTION_FLOW_EVENTS, blob_eventsCursor, PROJECTION_FLOW_BLOBS);
for (final CursorJoiner.Result joinerResult : joiner)
{
switch (joinerResult)
{
case LEFT:
{
foundUnassociatedFlowEvent = true;
break;
}
case BOTH:
break;
case RIGHT:
break;
}
}
}
finally
{
if (null != eventsCursor)
{
eventsCursor.close();
eventsCursor = null;
}
if (null != blob_eventsCursor)
{
blob_eventsCursor.close();
blob_eventsCursor = null;
}
}
if (!foundUnassociatedFlowEvent)
{
tagEvent(FLOW_EVENT, null);
}
}
示例4: conditionallyAddFlowEvent
import android.database.CursorJoiner; //导入依赖的package包/类
/**
* Conditionally adds a flow event if no flow event exists in the current upload blob.
*/
private void conditionallyAddFlowEvent()
{
/*
* Creating a flow "event" is required to act as a placeholder so that the uploader will know that an upload needs to
* occur. A flow event should only be created if there isn't already a flow event that hasn't been associated with an
* upload blob.
*/
boolean foundUnassociatedFlowEvent = false;
Cursor eventsCursor = null;
Cursor blob_eventsCursor = null;
try
{
eventsCursor = mProvider.query(EventsDbColumns.TABLE_NAME, new String[]
{ EventsDbColumns._ID }, String.format("%s = ?", EventsDbColumns.EVENT_NAME), new String[] //$NON-NLS-1$
{ FLOW_EVENT }, EVENTS_SORT_ORDER);
blob_eventsCursor = mProvider.query(UploadBlobEventsDbColumns.TABLE_NAME, new String[]
{ UploadBlobEventsDbColumns.EVENTS_KEY_REF }, null, null, UPLOAD_BLOBS_EVENTS_SORT_ORDER);
final CursorJoiner joiner = new CursorJoiner(eventsCursor, new String[]
{ EventsDbColumns._ID }, blob_eventsCursor, new String[]
{ UploadBlobEventsDbColumns.EVENTS_KEY_REF });
for (final CursorJoiner.Result joinerResult : joiner)
{
switch (joinerResult)
{
case LEFT:
{
foundUnassociatedFlowEvent = true;
break;
}
case BOTH:
break;
case RIGHT:
break;
}
}
}
finally
{
if (eventsCursor != null)
{
eventsCursor.close();
eventsCursor = null;
}
if (blob_eventsCursor != null)
{
blob_eventsCursor.close();
blob_eventsCursor = null;
}
}
if (!foundUnassociatedFlowEvent)
{
tagEvent(FLOW_EVENT, null);
}
}