Search in sources :

Example 1 with CursorAdapter

use of android.widget.CursorAdapter in project sugar by satyan.

the class CursorTests method testMakeAdapter.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testMakeAdapter() {
    save(new SimpleModel());
    Cursor c = Select.from(SimpleModel.class).getCursor();
    CursorAdapter adapter = new CursorAdapter(RuntimeEnvironment.application, c, true) {

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            TextView tv = new TextView(context);
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            tv.setText(s);
            return null;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            ((TextView) view).setText(s);
        }
    };
    Assert.assertNotNull(adapter);
}
Also used : SimpleModel(com.orm.model.SimpleModel) Context(android.content.Context) CursorAdapter(android.widget.CursorAdapter) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Cursor(android.database.Cursor) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 2 with CursorAdapter

use of android.widget.CursorAdapter in project NetGuard by M66B.

the class AdapterRule method onViewRecycled.

@Override
public void onViewRecycled(ViewHolder holder) {
    super.onViewRecycled(holder);
    // Context context = holder.itemView.getContext();
    // GlideApp.with(context).clear(holder.ivIcon);
    CursorAdapter adapter = (CursorAdapter) holder.lvAccess.getAdapter();
    if (adapter != null) {
        Log.i(TAG, "Closing access cursor");
        adapter.changeCursor(null);
        holder.lvAccess.setAdapter(null);
    }
}
Also used : CursorAdapter(android.widget.CursorAdapter)

Example 3 with CursorAdapter

use of android.widget.CursorAdapter in project android-aosp-mms by slvn.

the class SearchActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String searchStringParameter = getIntent().getStringExtra(SearchManager.QUERY);
    if (searchStringParameter == null) {
        searchStringParameter = getIntent().getStringExtra("intent_extra_data_key");
    }
    final String searchString = searchStringParameter != null ? searchStringParameter.trim() : searchStringParameter;
    // If we're being launched with a source_id then just go to that particular thread.
    // Work around the fact that suggestions can only launch the search activity, not some
    // arbitrary activity (such as ComposeMessageActivity).
    final Uri u = getIntent().getData();
    if (u != null && u.getQueryParameter("source_id") != null) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    long sourceId = Long.parseLong(u.getQueryParameter("source_id"));
                    long whichTable = Long.parseLong(u.getQueryParameter("which_table"));
                    long threadId = getThreadId(sourceId, whichTable);
                    final Intent onClickIntent = new Intent(SearchActivity.this, ComposeMessageActivity.class);
                    onClickIntent.putExtra("highlight", searchString);
                    onClickIntent.putExtra("select_id", sourceId);
                    onClickIntent.putExtra("thread_id", threadId);
                    startActivity(onClickIntent);
                    finish();
                    return;
                } catch (NumberFormatException ex) {
                // ok, we do not have a thread id so continue
                }
            }
        }, "Search thread");
        t.start();
        return;
    }
    setContentView(R.layout.search_activity);
    ContentResolver cr = getContentResolver();
    searchStringParameter = searchStringParameter.trim();
    final ListView listView = getListView();
    listView.setItemsCanFocus(true);
    listView.setFocusable(true);
    listView.setClickable(true);
    // I considered something like "searching..." but typically it will
    // flash on the screen briefly which I found to be more distracting
    // than beneficial.
    // This gets updated when the query completes.
    setTitle("");
    Contact.addListener(mContactListener);
    // When the query completes cons up a new adapter and set our list adapter to that.
    mQueryHandler = new AsyncQueryHandler(cr) {

        protected void onQueryComplete(int token, Object cookie, Cursor c) {
            if (c == null) {
                setTitle(getResources().getQuantityString(R.plurals.search_results_title, 0, 0, searchString));
                return;
            }
            final int threadIdPos = c.getColumnIndex("thread_id");
            final int addressPos = c.getColumnIndex("address");
            final int bodyPos = c.getColumnIndex("body");
            final int rowidPos = c.getColumnIndex("_id");
            int cursorCount = c.getCount();
            setTitle(getResources().getQuantityString(R.plurals.search_results_title, cursorCount, cursorCount, searchString));
            // Note that we're telling the CursorAdapter not to do auto-requeries. If we
            // want to dynamically respond to changes in the search results,
            // we'll have have to add a setOnDataSetChangedListener().
            setListAdapter(new CursorAdapter(SearchActivity.this, c, false) {

                /* no auto-requery */
                @Override
                public void bindView(View view, Context context, Cursor cursor) {
                    final TextView title = (TextView) (view.findViewById(R.id.title));
                    final TextViewSnippet snippet = (TextViewSnippet) (view.findViewById(R.id.subtitle));
                    String address = cursor.getString(addressPos);
                    Contact contact = address != null ? Contact.get(address, false) : null;
                    String titleString = contact != null ? contact.getNameAndNumber() : "";
                    title.setText(titleString);
                    snippet.setText(cursor.getString(bodyPos), searchString);
                    // if the user touches the item then launch the compose message
                    // activity with some extra parameters to highlight the search
                    // results and scroll to the latest part of the conversation
                    // that has a match.
                    final long threadId = cursor.getLong(threadIdPos);
                    final long rowid = cursor.getLong(rowidPos);
                    view.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            final Intent onClickIntent = new Intent(SearchActivity.this, ComposeMessageActivity.class);
                            onClickIntent.putExtra("thread_id", threadId);
                            onClickIntent.putExtra("highlight", searchString);
                            onClickIntent.putExtra("select_id", rowid);
                            startActivity(onClickIntent);
                        }
                    });
                }

                @Override
                public View newView(Context context, Cursor cursor, ViewGroup parent) {
                    LayoutInflater inflater = LayoutInflater.from(context);
                    View v = inflater.inflate(R.layout.search_item, parent, false);
                    return v;
                }
            });
            // ListView seems to want to reject the setFocusable until such time
            // as the list is not empty.  Set it here and request focus.  Without
            // this the arrow keys (and trackball) fail to move the selection.
            listView.setFocusable(true);
            listView.setFocusableInTouchMode(true);
            listView.requestFocus();
            // Remember the query if there are actual results
            if (cursorCount > 0) {
                SearchRecentSuggestions recent = ((MmsApp) getApplication()).getRecentSuggestions();
                if (recent != null) {
                    recent.saveRecentQuery(searchString, getString(R.string.search_history, cursorCount, searchString));
                }
            }
        }
    };
    // don't pass a projection since the search uri ignores it
    Uri uri = Telephony.MmsSms.SEARCH_URI.buildUpon().appendQueryParameter("pattern", searchString).build();
    // kick off a query for the threads which match the search string
    mQueryHandler.startQuery(0, null, uri, null, null, null, null);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
}
Also used : SpannableString(android.text.SpannableString) Cursor(android.database.Cursor) SearchRecentSuggestions(android.provider.SearchRecentSuggestions) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) CursorAdapter(android.widget.CursorAdapter) ListView(android.widget.ListView) TextView(android.widget.TextView) ActionBar(android.app.ActionBar) Context(android.content.Context) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) AsyncQueryHandler(android.content.AsyncQueryHandler) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) TextPaint(android.text.TextPaint) Contact(com.android.mms.data.Contact) LayoutInflater(android.view.LayoutInflater)

Example 4 with CursorAdapter

use of android.widget.CursorAdapter in project assertj-android by square.

the class SearchViewAssert method hasSuggestionsAdapter.

public SearchViewAssert hasSuggestionsAdapter(CursorAdapter adapter) {
    isNotNull();
    CursorAdapter actualAdapter = actual.getSuggestionsAdapter();
    // 
    assertThat(actualAdapter).overridingErrorMessage("Expected suggestions adapter <%s> but was <%s>.", adapter, // 
    actualAdapter).isSameAs(adapter);
    return this;
}
Also used : CursorAdapter(android.widget.CursorAdapter)

Example 5 with CursorAdapter

use of android.widget.CursorAdapter in project cw-omnibus by commonsguy.

the class VideosFragment method onListItemClick.

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    CursorAdapter adapter = (CursorAdapter) getListAdapter();
    Cursor c = (Cursor) adapter.getItem(position);
    int uriColumn = c.getColumnIndex(MediaStore.Video.Media.DATA);
    int mimeTypeColumn = c.getColumnIndex(MediaStore.Video.Media.MIME_TYPE);
    getContract().onVideoSelected(c.getString(uriColumn), c.getString(mimeTypeColumn));
}
Also used : SimpleCursorAdapter(android.widget.SimpleCursorAdapter) CursorAdapter(android.widget.CursorAdapter) Cursor(android.database.Cursor)

Aggregations

CursorAdapter (android.widget.CursorAdapter)5 Cursor (android.database.Cursor)3 Context (android.content.Context)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 TargetApi (android.annotation.TargetApi)1 ActionBar (android.app.ActionBar)1 AsyncQueryHandler (android.content.AsyncQueryHandler)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 SearchRecentSuggestions (android.provider.SearchRecentSuggestions)1 SpannableString (android.text.SpannableString)1 TextPaint (android.text.TextPaint)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 SimpleCursorAdapter (android.widget.SimpleCursorAdapter)1 Contact (com.android.mms.data.Contact)1 SimpleModel (com.orm.model.SimpleModel)1