13e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/*
23e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Copyright (C) 2009 The Android Open Source Project
33e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
43e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
53e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * you may not use this file except in compliance with the License.
63e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * You may obtain a copy of the License at
73e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
83e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *      http://www.apache.org/licenses/LICENSE-2.0
93e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert *
103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * See the License for the specific language governing permissions and
143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * limitations under the License.
153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */
163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpackage com.android.quicksearchbox;
173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
18b42184f1e6a1b7bb22797ff92cae696753aca770Bjorn Bringertimport com.android.quicksearchbox.util.QuietlyCloseable;
19b42184f1e6a1b7bb22797ff92cae696753aca770Bjorn Bringert
2094e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinneyimport android.database.DataSetObserver;
213e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
225229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwoodimport java.util.Collection;
235229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood
24fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert/**
25fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * A sequence of suggestions, with a current position.
26fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert */
27b42184f1e6a1b7bb22797ff92cae696753aca770Bjorn Bringertpublic interface SuggestionCursor extends Suggestion, QuietlyCloseable {
2893bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert
2993bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert    /**
3093bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert     * Gets the query that the user typed to get this suggestion.
3193bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert     */
3293bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert    String getUserQuery();
333e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
343e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
35fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Gets the number of suggestions in this result.
36fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     *
37fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * @return The number of suggestions, or {@code 0} if this result represents a failed query.
383e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
39fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    int getCount();
403e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
413e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
42fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Moves to a given suggestion.
43fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     *
44fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * @param pos The position to move to.
45fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * @throws IndexOutOfBoundsException if {@code pos < 0} or {@code pos >= getCount()}.
463e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
47fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    void moveTo(int pos);
483e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
493e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
5087e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert     * Moves to the next suggestion, if there is one.
5187e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert     *
5287e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert     * @return {@code false} if there is no next suggestion.
5387e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert     */
5487e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert    boolean moveToNext();
5587e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert
5687e947cbd9f279a83337900ff8bbd5ab0a8dc455Bjorn Bringert    /**
57fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Gets the current position within the cursor.
583e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
59fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    int getPosition();
603e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
613e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
62fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Frees any resources used by this cursor.
633e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert     */
64ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood    @Override
653e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    void close();
663e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert
673e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert    /**
68fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Register an observer that is called when changes happen to this data set.
6994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney     *
70fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * @param observer gets notified when the data set changes.
7194e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney     */
72fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    void registerDataSetObserver(DataSetObserver observer);
7394e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney
7494e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney    /**
75fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * Unregister an observer that has previously been registered with
76fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * {@link #registerDataSetObserver(DataSetObserver)}
7794e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney     *
78fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert     * @param observer the observer to unregister.
7994e8a2be78530170f50e7895a558bf8011bbf8e8Bryan Mawhinney     */
80fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert    void unregisterDataSetObserver(DataSetObserver observer);
815229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood
825229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood    /**
835229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood     * Return the extra columns present in this cursor, or null if none exist.
845229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood     */
855229b06f00d20aac76cd8519b37f2a579d61c54fMathew Inwood    Collection<String> getExtraColumns();
863e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert}
87