当前位置: 首页>>代码示例>>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;未经允许,请勿转载。