diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/SearchManager.java | 10 | ||||
| -rw-r--r-- | core/java/android/app/SuggestionsAdapter.java | 71 | ||||
| -rw-r--r-- | core/java/android/server/search/SearchableInfo.java | 16 | ||||
| -rwxr-xr-x | core/java/android/speech/tts/TextToSpeech.java (renamed from core/java/android/speech/tts/Tts.java) | 141 | ||||
| -rw-r--r-- | core/java/android/widget/AutoCompleteTextView.java | 9 | 
5 files changed, 129 insertions, 118 deletions
| diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java index 3f0aa95..820f192 100644 --- a/core/java/android/app/SearchManager.java +++ b/core/java/android/app/SearchManager.java @@ -1402,6 +1402,16 @@ public class SearchManager       * @hide For internal use, not part of the public API.       */      public final static String SUGGEST_COLUMN_BACKGROUND_COLOR = "suggest_background_color"; +     +    /** +     * Column name for suggestions cursor. <i>Optional.</i> This column is used to specify +     * that a spinner should be shown in lieu of an icon2 while the shortcut of this suggestion +     * is being refreshed. +     *  +     * @hide Pending API council approval. +     */ +    public final static String SUGGEST_COLUMN_SPINNER_WHILE_REFRESHING = +            "suggest_spinner_while_refreshing";      /**       * Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java index 6e8bd78..8c5cee3 100644 --- a/core/java/android/app/SuggestionsAdapter.java +++ b/core/java/android/app/SuggestionsAdapter.java @@ -20,16 +20,19 @@ import android.content.ContentResolver;  import android.content.Context;  import android.content.res.Resources.NotFoundException;  import android.database.Cursor; +import android.graphics.Canvas;  import android.graphics.drawable.Drawable;  import android.net.Uri;  import android.os.Bundle;  import android.server.search.SearchableInfo;  import android.text.Html;  import android.text.TextUtils; +import android.util.DisplayMetrics;  import android.util.Log;  import android.util.TypedValue;  import android.view.View;  import android.view.ViewGroup; +import android.widget.AbsListView;  import android.widget.ImageView;  import android.widget.ResourceCursorAdapter;  import android.widget.TextView; @@ -255,7 +258,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {       */      @Override      public View newView(Context context, Cursor cursor, ViewGroup parent) { -        View v = super.newView(context, cursor, parent); +        View v = new SuggestionItemView(context, cursor);          v.setTag(new ChildViewCache(v));          return v;      } @@ -303,7 +306,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {          if (backgroundColor == 0) {              backgroundColor = mDefaultBackgroundColor;          } -        view.setBackgroundColor(backgroundColor); +        ((SuggestionItemView)view).setColor(backgroundColor);          final boolean isHtml = mFormatCol > 0 && "html".equals(cursor.getString(mFormatCol));          setViewText(cursor, views.mText1, mText1Col, isHtml); @@ -506,4 +509,68 @@ class SuggestionsAdapter extends ResourceCursorAdapter {          return cursor.getString(col);      } +    /** +     * A parent viewgroup class which holds the actual suggestion item as a child. +     * +     * The sole purpose of this class is to draw the given background color when the item is in +     * normal state and not draw the background color when it is pressed, so that when pressed the +     * list view's selection highlight will be displayed properly (if we draw our background it +     * draws on top of the list view selection highlight). +     */ +    private class SuggestionItemView extends ViewGroup { +        private int mBackgroundColor;  // the background color to draw in normal state. +        private View mView;  // the suggestion item's view. + +        protected SuggestionItemView(Context context, Cursor cursor) { +            // Initialize ourselves +            super(context); + +            // For our layout use the default list item height from the current theme. +            TypedValue lineHeight = new TypedValue(); +            context.getTheme().resolveAttribute( +                    com.android.internal.R.attr.searchResultListItemHeight, lineHeight, true); +            DisplayMetrics metrics = new DisplayMetrics(); +            metrics.setToDefaults(); +            AbsListView.LayoutParams layout = new AbsListView.LayoutParams( +                    AbsListView.LayoutParams.FILL_PARENT, +                    (int)lineHeight.getDimension(metrics)); + +            setLayoutParams(layout); + +            // Initialize the child view +            mView = SuggestionsAdapter.super.newView(context, cursor, this); +            if (mView != null) { +                addView(mView, layout.width, layout.height); +                mView.setVisibility(View.VISIBLE); +            } +        } + +        public void setColor(int backgroundColor) { +            mBackgroundColor = backgroundColor; +        } + +        @Override +        public void dispatchDraw(Canvas canvas) { +            if (!isPressed()) { +                canvas.drawColor(mBackgroundColor); +            } +            super.dispatchDraw(canvas); +        } + +        @Override +        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { +            super.onMeasure(widthMeasureSpec, heightMeasureSpec); +            if (mView != null) { +                mView.measure(widthMeasureSpec, heightMeasureSpec); +            } +        } + +        @Override +        protected void onLayout(boolean changed, int left, int top, int right, int bottom) { +            if (mView != null) { +                mView.layout(0, 0, mView.getMeasuredWidth(), mView.getMeasuredHeight()); +            } +        } +    } +  } diff --git a/core/java/android/server/search/SearchableInfo.java b/core/java/android/server/search/SearchableInfo.java index c083142..4df7368 100644 --- a/core/java/android/server/search/SearchableInfo.java +++ b/core/java/android/server/search/SearchableInfo.java @@ -66,6 +66,7 @@ public final class SearchableInfo implements Parcelable {      private final int mSearchInputType;      private final int mSearchImeOptions;      private final boolean mIncludeInGlobalSearch; +    private final boolean mQueryAfterZeroResults;      private final String mSuggestAuthority;      private final String mSuggestPath;      private final String mSuggestSelection; @@ -276,6 +277,8 @@ public final class SearchableInfo implements Parcelable {                  EditorInfo.IME_ACTION_SEARCH);          mIncludeInGlobalSearch = a.getBoolean(                  com.android.internal.R.styleable.Searchable_includeInGlobalSearch, false); +        mQueryAfterZeroResults = a.getBoolean( +                com.android.internal.R.styleable.Searchable_queryAfterZeroResults, false);          mSuggestAuthority = a.getString(                  com.android.internal.R.styleable.Searchable_searchSuggestAuthority); @@ -637,6 +640,17 @@ public final class SearchableInfo implements Parcelable {      }      /** +     * Checks whether this searchable activity should be invoked after a query returned zero +     * results. +     * +     * @return The value of the <code>queryAfterZeroResults</code> attribute, +     *         or <code>false</code> if the attribute is not set. +     */ +    public boolean queryAfterZeroResults() { +        return mQueryAfterZeroResults; +    } + +    /**       * Support for parcelable and aidl operations.       */      public static final Parcelable.Creator<SearchableInfo> CREATOR @@ -667,6 +681,7 @@ public final class SearchableInfo implements Parcelable {          mSearchInputType = in.readInt();          mSearchImeOptions = in.readInt();          mIncludeInGlobalSearch = in.readInt() != 0; +        mQueryAfterZeroResults = in.readInt() != 0;          mSuggestAuthority = in.readString();          mSuggestPath = in.readString(); @@ -702,6 +717,7 @@ public final class SearchableInfo implements Parcelable {          dest.writeInt(mSearchInputType);          dest.writeInt(mSearchImeOptions);          dest.writeInt(mIncludeInGlobalSearch ? 1 : 0); +        dest.writeInt(mQueryAfterZeroResults ? 1 : 0);          dest.writeString(mSuggestAuthority);          dest.writeString(mSuggestPath); diff --git a/core/java/android/speech/tts/Tts.java b/core/java/android/speech/tts/TextToSpeech.java index 085b030..11be75d 100755 --- a/core/java/android/speech/tts/Tts.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -28,21 +28,16 @@ import android.os.IBinder;  import android.os.RemoteException;  import android.util.Log; +import java.util.HashMap; +  /**   * - * Synthesizes speech from text. This abstracts away the complexities of using - * the TTS service such as setting up the IBinder connection and handling - * RemoteExceptions, etc. - * - * The TTS should always be safe the use; if the user does not have the - * necessary TTS apk installed, the behavior is that all calls to the TTS act as - * no-ops. + * Synthesizes speech from text.   *   * {@hide}   */ -//FIXME #TTS# review + complete javadoc -//FIXME RENAME TO TextToSpeech.java -public class Tts { +//TODO #TTS# review + complete javadoc +public class TextToSpeech {      /** @@ -82,31 +77,6 @@ public class Tts {      private OnSpeechCompletedListener speechCompletedCallback = null; -    /** -     * The constructor for the TTS. -     * -     * @param context -     *            The context -     * @param callback -     *            The InitListener that should be called when the TTS has -     *            initialized successfully. -     * @param displayInstallMessage -     *            Boolean indicating whether or not an installation prompt -     *            should be displayed to users who do not have the TTS library. -     *            If this is true, a generic alert asking the user to install -     *            the TTS will be used. If you wish to specify the exact message -     *            of that prompt, please use TTS(Context context, InitListener -     *            callback, TTSVersionAlert alert) as the constructor instead. -     */ -    public Tts(Context context, OnInitListener callback, -                boolean displayInstallMessage) { -        showInstaller = displayInstallMessage; -        ctx = context; -        cb = callback; -        if (dataFilesCheck()) { -            initTts(); -        } -    }      /**       * The constructor for the TTS. @@ -117,15 +87,13 @@ public class Tts {       *            The InitListener that should be called when the TTS has       *            initialized successfully.       */ -    public Tts(Context context, OnInitListener callback) { -        // FIXME #TTS# support TtsVersionAlert +    public TextToSpeech(Context context, OnInitListener callback) { +        // TODO #TTS# support TtsVersionAlert          //     showInstaller = true;          //     versionAlert = alert;          ctx = context;          cb = callback; -        if (dataFilesCheck()) { -            initTts(); -        } +        initTts();      } @@ -136,9 +104,9 @@ public class Tts {      private boolean dataFilesCheck() { -        // FIXME #TTS# config manager will be in settings +        // TODO #TTS# config manager will be in settings          Log.i("TTS_FIXME", "FIXME in Tts: config manager will be in settings"); -        // FIXME #TTS# implement checking of the correct installation of +        // TODO #TTS# implement checking of the correct installation of          //             the data files.          return true; @@ -193,15 +161,9 @@ public class Tts {          Intent intent = new Intent("android.intent.action.USE_TTS");          intent.addCategory("android.intent.category.TTS"); -        // Binding will fail only if the TTS doesn't exist; -        // the TTSVersionAlert will give users a chance to install -        // the needed TTS. -        if (!ctx.bindService(intent, serviceConnection, -                Context.BIND_AUTO_CREATE)) { -            if (showInstaller) { -                // FIXME #TTS# show version alert -            } -        } +        ctx.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE); +        // TODO handle case where the binding works (should always work) but +        //      the plugin fails      } @@ -316,21 +278,18 @@ public class Tts {       *            The queuing strategy to use. Use 0 for no queuing, and 1 for       *            queuing.       * @param params -     *            The array of speech parameters to be used. Currently, only -     *            params[0] is defined - it is for setting the type of voice if -     *            the engine allows it. Possible values are "VOICE_MALE", -     *            "VOICE_FEMALE", and "VOICE_ROBOT". Note that right now only -     *            the pre-recorded voice has this support - this setting has no -     *            effect on eSpeak. +     *            The hashmap of speech parameters to be used.       */ -    public void speak(String text, int queueMode, String[] params) { +    public void speak(String text, int queueMode, HashMap<String,String> params) +    {          synchronized (startLock) {              Log.i("TTS received: ", text);              if (!started) {                  return;              }              try { -                itts.speak(text, queueMode, params); +                // TODO support extra parameters, passing null for the moment +                itts.speak(text, queueMode, null);              } catch (RemoteException e) {                  // TTS died; restart it.                  started = false; @@ -357,15 +316,17 @@ public class Tts {       *            0 for no queue (interrupts all previous utterances), 1 for       *            queued       * @param params -     *            An ArrayList of parameters. +     *            The hashmap of parameters to be used.       */ -    public void playEarcon(String earcon, int queueMode, String[] params) { +    public void playEarcon(String earcon, int queueMode,  +            HashMap<String,String> params) {          synchronized (startLock) {              if (!started) {                  return;              }              try { -                itts.playEarcon(earcon, queueMode, params); +                // TODO support extra parameters, passing null for the moment +                itts.playEarcon(earcon, queueMode, null);              } catch (RemoteException e) {                  // TTS died; restart it.                  started = false; @@ -381,6 +342,11 @@ public class Tts {              }          }      } +     +     +    public void playSilence(long durationInMs, int queueMode) { +        // TODO implement, already present in TTS service +    }      /** @@ -440,17 +406,6 @@ public class Tts {      } -    /** -     * Returns the version number of the TTS library that the user has -     * installed. -     * -     * @return The version number of the TTS library that the user has -     *         installed. -     */ -    public int getVersion() { -        return version; -    } -      /**       * Sets the speech rate for the TTS engine. @@ -519,21 +474,21 @@ public class Tts {       * @param text       *            The String of text that should be synthesized       * @param params -     *            An ArrayList of parameters. The first element of this array -     *            controls the type of voice to use. +     *            A hashmap of parameters.       * @param filename       *            The string that gives the full output filename; it should be       *            something like "/sdcard/myappsounds/mysound.wav".       * @return A boolean that indicates if the synthesis succeeded       */ -    public boolean synthesizeToFile(String text, String[] params, +    public boolean synthesizeToFile(String text, HashMap<String,String> params,              String filename) {          synchronized (startLock) {              if (!started) {                  return false;              }              try { -                return itts.synthesizeToFile(text, params, filename); +                // TODO support extra parameters, passing null for the moment +                return itts.synthesizeToFile(text, null, filename);              } catch (RemoteException e) {                  // TTS died; restart it.                  started = false; @@ -552,36 +507,4 @@ public class Tts {      } -    /** -     * Displays an alert that prompts users to install the TTS engine. -     * This is useful if the application expects a newer version -     * of the TTS than what the user has. -     */ -    public void showVersionAlert() { -        if (!started) { -            return; -        } -        // FIXME #TTS# implement show version alert -    } - - -    /** -     * Checks if the TTS service is installed or not -     * -     * @return A boolean that indicates whether the TTS service is installed -     */ -    // TODO: TTS Service itself will always be installed. Factor this out -    // (may need to add another method to see if there are any working -    // TTS engines on the device). -    public static boolean isInstalled(Context ctx) { -        PackageManager pm = ctx.getPackageManager(); -        Intent intent = new Intent("android.intent.action.USE_TTS"); -        intent.addCategory("android.intent.category.TTS"); -        ResolveInfo info = pm.resolveService(intent, 0); -        if (info == null) { -            return false; -        } -        return true; -    } -  } diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index f376ce5..585ce3d 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -123,10 +123,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe      private AutoCompleteTextView.ListSelectorHider mHideSelector; -    // Indicates whether this AutoCompleteTextView is attached to a window or not -    // The widget is attached to a window when mAttachCount > 0 -    private int mAttachCount; -      private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;      public AutoCompleteTextView(Context context) { @@ -960,7 +956,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe      /** {@inheritDoc} */      public void onFilterComplete(int count) { -        if (mAttachCount <= 0) return; +        // Not attached to window, don't update drop-down +        if (getWindowVisibility() == View.GONE) return;          /*           * This checks enoughToFilter() again because filtering requests @@ -999,13 +996,11 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe      @Override      protected void onAttachedToWindow() {          super.onAttachedToWindow(); -        mAttachCount++;      }      @Override      protected void onDetachedFromWindow() {          dismissDropDown(); -        mAttachCount--;          super.onDetachedFromWindow();      } | 
