use of android.content.CursorLoader in project KJFrameForAndroid by kymjs.
the class FileUtils method uri2File.
/**
* 把uri转为File对象
*/
public static File uri2File(Activity aty, Uri uri) {
if (SystemTool.getSDKVersion() < 11) {
// 在API11以下可以使用:managedQuery
String[] proj = { MediaStore.Images.Media.DATA };
@SuppressWarnings("deprecation") Cursor actualimagecursor = aty.managedQuery(uri, proj, null, null, null);
int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
actualimagecursor.moveToFirst();
String img_path = actualimagecursor.getString(actual_image_column_index);
return new File(img_path);
} else {
// 在API11以上:要转为使用CursorLoader,并使用loadInBackground来返回
String[] projection = { MediaStore.Images.Media.DATA };
CursorLoader loader = new CursorLoader(aty, uri, projection, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return new File(cursor.getString(column_index));
}
}
use of android.content.CursorLoader in project glimmr by brk3.
the class LocalPhotosGridFragment method initGridView.
@Override
protected void initGridView() {
mGridView = (GridView) mLayout.findViewById(R.id.gridview);
mGridView.setVisibility(View.VISIBLE);
mGridView.setMultiChoiceModeListener(this);
mShowDetailsOverlay = false;
String[] from = { MediaStore.MediaColumns.TITLE };
int[] to = { android.R.id.text1 };
CursorLoader cursorLoader = new CursorLoader(getActivity(), SOURCE_URI, null, null, null, MediaStore.Audio.Media.TITLE);
Cursor cursor = cursorLoader.loadInBackground();
mAdapter = new MediaStoreImagesAdapter(getActivity(), R.layout.gridview_item, cursor, from, to);
mGridView.setAdapter(mAdapter);
mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
final String usageTip = getString(R.string.upload_photos_tip);
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
UsageTips.getInstance().show(mActivity, usageTip, true);
}
});
}
use of android.content.CursorLoader in project iosched by google.
the class ExploreIOModel method createCursorLoader.
@Override
public Loader<Cursor> createCursorLoader(final ExploreIOQueryEnum query, final Bundle args) {
CursorLoader loader = null;
switch(query) {
case SESSIONS:
// Create and return the Loader.
loader = getCursorLoaderInstance(mContext, mSessionsUri, ExploreIOQueryEnum.SESSIONS.getProjection(), null, null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME);
break;
case TAGS:
LOGI(TAG, "Starting sessions tag query");
loader = TagMetadata.createCursorLoader(mContext);
break;
case CARDS:
String currentTime = TimeUtils.getCurrentTime(mContext) + "";
LOGI(TAG, "Starting cards query: " + currentTime);
loader = getCursorLoaderInstance(mContext, ScheduleContract.Cards.CONTENT_URI, ExploreIOQueryEnum.CARDS.getProjection(), " ? > " + ScheduleContract.Cards.DISPLAY_START_DATE + " AND ? < " + ScheduleContract.Cards.DISPLAY_END_DATE + " AND " + ScheduleContract.Cards.ACTION_TYPE + " IN ('" + EventCard.ACTION_TYPE_LINK + "', '" + EventCard.ACTION_TYPE_MAP + "', '" + EventCard.ACTION_TYPE_SESSION + "')", new String[] { currentTime, currentTime }, ScheduleContract.Cards.CARD_ID);
break;
}
return loader;
}
use of android.content.CursorLoader in project iosched by google.
the class SessionDetailModelTest method createCursorLoader_TagMetadaQuery_ReturnsCursorLoader.
@Test
public void createCursorLoader_TagMetadaQuery_ReturnsCursorLoader() {
// Given a mock uri and mock cursor loader
SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
doReturn(mMockCursorLoader).when(spyModel).getTagMetadataLoader();
// When ran with mock uri and tag metadata query loader id
CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.TAG_METADATA, null);
// Then the returned cursor loader is the mock cursor loader
assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
use of android.content.CursorLoader in project iosched by google.
the class SessionDetailModelTest method createCursorLoader_SpeakersQuery_ReturnsCursor.
@Test
public void createCursorLoader_SpeakersQuery_ReturnsCursor() {
// Given a mock uri and mock cursor loader
SessionDetailModel spyModel = spy(new SessionDetailModel(mMockUri, mMockContext, mMockSessionsHelper, mMockLoaderManager));
doReturn(mMockUri).when(spyModel).getSpeakersDirUri(any(String.class));
doReturn(mMockCursorLoader).when(spyModel).getCursorLoaderInstance(any(Context.class), any(Uri.class), any(String[].class), any(String.class), any(String[].class), any(String.class));
// When ran with mock uri and speakers query loader id
CursorLoader createdCursorLoader = (CursorLoader) spyModel.createCursorLoader(SessionDetailModel.SessionDetailQueryEnum.SPEAKERS, null);
// Then the returned cursor loader is the mock cursor loader
assertThat(createdCursorLoader, sameInstance(mMockCursorLoader));
}
Aggregations