當前位置: 首頁>>代碼示例>>Java>>正文


Java CursorWrapper類代碼示例

本文整理匯總了Java中android.database.CursorWrapper的典型用法代碼示例。如果您正苦於以下問題:Java CursorWrapper類的具體用法?Java CursorWrapper怎麽用?Java CursorWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CursorWrapper類屬於android.database包,在下文中一共展示了CursorWrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: provide

import android.database.CursorWrapper; //導入依賴的package包/類
public static String provide(Context context){
    String phoneNumber = null;

    SQLiteDatabase database = DatabaseProvider.provideReadableDatabase(context);
    Cursor cursor = database.query(UserTable.NAME,
            null, // Columns - null selects all columns
            null, //whereClause
            null, //whereArgs
            null, // groupBy
            null, // having
            null);  // orderBy

    if (cursor != null){
        try{
            if (cursor.moveToFirst()){
                CursorWrapper cursorWrapper = new CursorWrapper(cursor);
                phoneNumber = cursorWrapper.getString(
                        cursorWrapper.getColumnIndex(UserTable.Cols.PHONE_NUMBER));
            }
        } finally{
            cursor.close();
        }
    }
    Log.d(TAG, "Phone number retrieved from DB: " + phoneNumber);
    return phoneNumber;
}
 
開發者ID:VictorGil,項目名稱:phoneVerifier,代碼行數:27,代碼來源:NumberFromDbProvider.java

示例2: onCreateView

import android.database.CursorWrapper; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_videoitem_list, container, false);
    mGridView = (GridView) rootView.findViewById(R.id.gridview);

    mGridView.setAdapter(new MovieAdapter(getActivity()));

    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            CursorWrapper c = (CursorWrapper) parent.getAdapter().getItem(position);
            ((OnFragmentInteractionListener) getActivity()).onFragmentInteraction(c.getString(c.getColumnIndex(VideoItemContract.VideoItem._ID)), c.getString(c.getColumnIndex(VideoItemContract.VideoItem.CONTENT_URL)));
        }

    });
    getLoaderManager().initLoader(0, null, this);
    return rootView;

}
 
開發者ID:googlecodelabs,項目名稱:android-tv-leanback,代碼行數:20,代碼來源:VideoItemFragment.java

示例3: getObjectCursor

import android.database.CursorWrapper; //導入依賴的package包/類
/**
 * Convert a standard Android {@link Cursor} into a {@link org.droitateddb.cursor.ObjectCursor}.<br>
 * This is only possible for {@link Cursor}s that where queried over a {@link ContentResolver} from a
 * {@link ContentProvider} derived by {@link BaseContentProvider}.
 *
 * @param <T>    Entity class represented within the Cursor
 * @param cursor Android {@link Cursor}
 * @return The {@link org.droitateddb.cursor.ObjectCursor} representation of the given Android {@link Cursor}
 * @throws NullPointerException     When the given cursor is null
 * @throws IllegalArgumentException When the given cursor is not of the type {@link CursorWrapper}, which will be returned by a
 *                                  {@link ContentResolver}
 * @throws IllegalStateException    When the wrapped cursor within the given cursor is not of type {@link org.droitateddb.cursor.ObjectCursor}. This indicates
 *                                  that the given cursor was not queried from a derivation {@link BaseContentProvider}
 */
@SuppressWarnings("unchecked")
public static <T> ObjectCursor<T> getObjectCursor(final Cursor cursor) {
	if (cursor == null) {
		throw new NullPointerException("The given cursor is null");
	}
	if (!(cursor instanceof CursorWrapper)) {
		throw new IllegalArgumentException(
				"The given cursor is not of type " + CursorWrapper.class.getCanonicalName() + ". It has type " + cursor.getClass().getCanonicalName() +
						". Was it queried with a ContentResolver?");
	}

	CursorWrapper wrapper = (CursorWrapper) cursor;
	Cursor wrappedCursor = wrapper.getWrappedCursor();

	if (!(wrappedCursor instanceof ObjectCursor)) {
		throw new IllegalStateException(
				"The wrapped cursor of the given CursorWrapper is not of type " + ObjectCursor.class.getCanonicalName() + ". It has type " +
						wrappedCursor.getClass().getCanonicalName() +
						". Was it queried over a ContentResolver from BaseContentProvider derived ContentProvider?");
	}
	return (ObjectCursor<T>) wrappedCursor;
}
 
開發者ID:arconsis,項目名稱:droitatedDB,代碼行數:37,代碼來源:CursorUtil.java

示例4: closeWithCursor

import android.database.CursorWrapper; //導入依賴的package包/類
protected CursorWrapper closeWithCursor(final Closeable closeable, Cursor cursor) {
    return new CursorWrapper(cursor) {
        @Override
        public void close() {
            super.close();
            if (closeable != null) {
                try {
                    closeable.close();
                } catch (IOException ignored) {
                }
            }
        }
    };
}
 
開發者ID:requery,項目名稱:requery,代碼行數:15,代碼來源:SqliteMetaData.java

示例5: ForwardVerifier

import android.database.CursorWrapper; //導入依賴的package包/類
public ForwardVerifier() {
  mockCursor = mock(Cursor.class);
  cursorWrapper = new CursorWrapper(mockCursor);
  cursorMethod = new HashMap<String, Method>();

  // This works because no two methods in the Cursor interface have the same name
  for (Method m : Cursor.class.getMethods()) {
    cursorMethod.put(m.getName(), m);
  }
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:11,代碼來源:CursorWrapperTest.java

示例6: getWrappedCursor

import android.database.CursorWrapper; //導入依賴的package包/類
@Test
public void getWrappedCursor() {
  Cursor mockCursor = mock(Cursor.class);
  CursorWrapper cursorWrapper = new CursorWrapper(mockCursor);
  ShadowCursorWrapper shadow = Robolectric.shadowOf(cursorWrapper);

  assertThat(shadow.getWrappedCursor()).isSameAs(mockCursor);
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:9,代碼來源:CursorWrapperTest.java

示例7: getMasterCursor

import android.database.CursorWrapper; //導入依賴的package包/類
/** Returns the first non-CursorWrapper instance contained within this object. */
public Cursor getMasterCursor() {
  Cursor cursor = mCursor;

  while (cursor instanceof CursorWrapper) {
    cursor = ((CursorWrapper) cursor).getWrappedCursor();
  }

  return cursor;
}
 
開發者ID:clover,項目名稱:android-filteredcursor,代碼行數:11,代碼來源:FilteredCursor.java

示例8: unwrapFilteredCursor

import android.database.CursorWrapper; //導入依賴的package包/類
/** Returns the first FilteredCursor wrapped by the provided cursor or null if no FilteredCursor is found. */
public static FilteredCursor unwrapFilteredCursor(Cursor cursor) {
  while (cursor instanceof CursorWrapper) {
    if (cursor instanceof FilteredCursor) {
      return (FilteredCursor)cursor;
    } else {
      cursor = ((CursorWrapper) cursor).getWrappedCursor();
    }
  }

  return null;
}
 
開發者ID:clover,項目名稱:android-filteredcursor,代碼行數:13,代碼來源:FilteredCursor.java

示例9: onListItemClick

import android.database.CursorWrapper; //導入依賴的package包/類
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
	Cursor c = new CursorWrapper(searchResults);
	c.moveToPosition(position);
	String path = c.getString(c.getColumnIndex(SearchResultsProvider.COLUMN_PATH));
	
	browse(Uri.parse(path));
}
 
開發者ID:msafin,項目名稱:wmc,代碼行數:9,代碼來源:SearchableActivity.java

示例10: shadowOf

import android.database.CursorWrapper; //導入依賴的package包/類
public static ShadowCursorWrapper shadowOf(CursorWrapper instance) {
  return (ShadowCursorWrapper) shadowOf_(instance);
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:4,代碼來源:Robolectric.java

示例11: getType1

import android.database.CursorWrapper; //導入依賴的package包/類
@Test
@Config(manifest = Config.NONE, shadows = ShadowCursorWrapper1.class)
public void getType1() {
  assertThat(new CursorWrapper(null).getType(expectedType)).isEqualTo(1);
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:6,代碼來源:ParameterizedRobolectricTestRunnerConfigTest.java

示例12: getTypeEcho

import android.database.CursorWrapper; //導入依賴的package包/類
@Test
@Config(manifest = Config.NONE, shadows = ShadowCursorWrapperEcho.class)
public void getTypeEcho() {
  assertThat(new CursorWrapper(null).getType(expectedType)).isEqualTo(expectedType);
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:6,代碼來源:ParameterizedRobolectricTestRunnerConfigTest.java

示例13: crudTest

import android.database.CursorWrapper; //導入依賴的package包/類
@Test
public void crudTest() {

    ContentResolver resolver = context.getContentResolver();
    Comment c1 = new Comment("asdf");
    EntityService<Comment> entityService = entityService(Comment.class);

    entityService.save(c1);
    assertThat(entityService.get()).hasSize(1);
    Uri uri = CommentContentProvider.uri(DB.CommentTable.TABLE_NAME);

    // create
    ContentValues values = new ContentValues();
    values.put("name", "aName");
    Uri itemLocation = resolver.insert(uri, values);
    assertThat("content://org.droitateddb.test.data.generated.provider.comment/comment/2").isEqualTo(itemLocation.toString());
    assertThat(entityService.get()).hasSize(2);
    assertThat(entityService.get(2).getName()).isEqualTo("aName");

    // update
    values.put("name", "otherName");
    int update = resolver.update(itemLocation, values, null, null);
    assertThat(1).isEqualTo(update);
    assertThat(entityService.get(2).getName()).isEqualTo("otherName");

    // read
    Cursor cursor = resolver.query(itemLocation, DB.CommentTable.PROJECTION, null, null, null);
    assertThat(cursor).isNotNull();
    // Wrap to unwrap ... this is a bit strange, normally Android wraps the Cursor but robolectric doesn't!
    CursorWrapper wrapped = new CursorWrapper(cursor);
    ObjectCursor<Comment> objectCursor = CursorUtil.getObjectCursor(wrapped);

    assertThat(objectCursor.size()).isEqualTo(1);
    Comment curserloadedObject = objectCursor.getOne();
    assertThat(curserloadedObject.getName()).isEqualTo("otherName");
    assertSameFields(curserloadedObject, entityService.get(curserloadedObject.getId()));

    // read all
    Cursor nextCursor = resolver.query(uri, DB.CommentTable.PROJECTION, null, null, null);
    assertThat(nextCursor).isNotNull();
    // Wrap to unwrap ... this is a bit strange, normally Android wraps the Cursor but robolectric doesn't!
    CursorWrapper nextWrapped = new CursorWrapper(nextCursor);
    ObjectCursor<Comment> allObjectCursor = CursorUtil.getObjectCursor(nextWrapped);

    assertThat(allObjectCursor.size()).isEqualTo(2);

    // delete
    int delete = resolver.delete(itemLocation, null, null);
    assertThat(entityService.get()).hasSize(1);
    assertThat(1).isEqualTo(delete);

}
 
開發者ID:arconsis,項目名稱:droitatedDB,代碼行數:53,代碼來源:ContentProviderTest.java

示例14: getSingleCursor

import android.database.CursorWrapper; //導入依賴的package包/類
private Cursor getSingleCursor() {
    Cursor cursor = context.getContentResolver().query(CommentContentProvider.uri(DB.SingleTable.TABLE_NAME), DB.SingleTable.PROJECTION, null, null, null);
    // Wrap to unwrap ... this is a bit strange, normally Android wraps the Cursor but robolectric doesn't!
    CursorWrapper wrapped = new CursorWrapper(cursor);
    return wrapped;
}
 
開發者ID:arconsis,項目名稱:droitatedDB,代碼行數:7,代碼來源:ContentProviderTest.java

示例15: throwsIllegalArgumentExceptionForWrongWrappedCursor

import android.database.CursorWrapper; //導入依賴的package包/類
@Test(expected = IllegalStateException.class)
public void throwsIllegalArgumentExceptionForWrongWrappedCursor() throws Exception {
	CursorUtil.getObjectCursor(new CursorWrapper(new CursorDummy()));
}
 
開發者ID:arconsis,項目名稱:droitatedDB,代碼行數:5,代碼來源:CursorUtilTest.java


注:本文中的android.database.CursorWrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。