Search in sources :

Example 1 with CursorLoader

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));
    }
}
Also used : CursorLoader(android.content.CursorLoader) Cursor(android.database.Cursor) File(java.io.File)

Example 2 with CursorLoader

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);
        }
    });
}
Also used : Cursor(android.database.Cursor) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) CursorLoader(android.content.CursorLoader) AdapterView(android.widget.AdapterView)

Example 3 with CursorLoader

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;
}
Also used : CursorLoader(android.content.CursorLoader)

Example 4 with CursorLoader

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));
}
Also used : CursorLoader(android.content.CursorLoader) SmallTest(android.test.suitebuilder.annotation.SmallTest) TagMetadataTest(com.google.samples.apps.iosched.model.TagMetadataTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with CursorLoader

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));
}
Also used : Context(android.content.Context) SettingsMockContext(com.google.samples.apps.iosched.testutils.SettingsMockContext) CursorLoader(android.content.CursorLoader) Matchers.anyString(org.mockito.Matchers.anyString) Uri(android.net.Uri) SmallTest(android.test.suitebuilder.annotation.SmallTest) TagMetadataTest(com.google.samples.apps.iosched.model.TagMetadataTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

CursorLoader (android.content.CursorLoader)30 Cursor (android.database.Cursor)12 Uri (android.net.Uri)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Test (org.junit.Test)9 TagMetadataTest (com.google.samples.apps.iosched.model.TagMetadataTest)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Context (android.content.Context)4 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SettingsMockContext (com.google.samples.apps.iosched.testutils.SettingsMockContext)3 SuppressLint (android.annotation.SuppressLint)1 Loader (android.content.Loader)1 Bundle (android.os.Bundle)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1