package com.android.browser;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.PaintDrawable;
import android.os.Handler;
import android.os.Message;
+import android.speech.RecognizerIntent;
import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.LayoutInflater;
private ImageView mLockIcon;
private Drawable mStopDrawable;
private Drawable mBookmarkDrawable;
+ private Drawable mVoiceDrawable;
private boolean mInLoad;
private BrowserActivity mBrowserActivity;
private Drawable mGenericFavicon;
private int mIconDimension;
private View mTitleBg;
private MyHandler mHandler;
+ private Intent mVoiceSearchIntent;
+ private boolean mInVoiceMode;
private static int LONG_PRESS = 1;
R.id.progress_horizontal);
mGenericFavicon = context.getResources().getDrawable(
R.drawable.app_web_browser_sm);
+ mVoiceSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
+ mVoiceSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
+ RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
+ PackageManager pm = context.getPackageManager();
+ ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ if (ri == null) {
+ mVoiceSearchIntent = null;
+ } else {
+ mVoiceDrawable = resources.getDrawable(
+ android.R.drawable.ic_btn_speak_now);
+ }
+ mStopDrawable = resources.getDrawable(R.drawable.ic_btn_stop_v2);
+ mBookmarkDrawable = mRtButton.getDrawable();
}
private class MyHandler extends Handler {
break;
case MotionEvent.ACTION_UP:
if (mRtButton.isPressed()) {
- if (mInLoad) {
+ if (mInVoiceMode) {
+ mBrowserActivity.startActivity(mVoiceSearchIntent);
+ } else if (mInLoad) {
mBrowserActivity.stopLoading();
} else {
mBrowserActivity.bookmarksOrHistoryPicker(false);
}
/**
- * Return whether the associated WebView is currently loading. Needed to
- * determine whether a click should stop the load or close the tab.
- */
- /* package */ boolean isInLoad() {
- return mInLoad;
- }
-
- /**
* Set a new Bitmap for the Favicon.
*/
/* package */ void setFavicon(Bitmap icon) {
}
/**
+ * Change the TitleBar to or from voice mode. If there is no package to
+ * handle voice search, the TitleBar cannot be set to voice mode.
+ */
+ /* package */ void setInVoiceMode(boolean inVoiceMode) {
+ if (mInVoiceMode == inVoiceMode) return;
+ mInVoiceMode = inVoiceMode && mVoiceSearchIntent != null;
+ if (mInVoiceMode) {
+ mRtButton.setImageDrawable(mVoiceDrawable);
+ } else if (mInLoad) {
+ mRtButton.setImageDrawable(mStopDrawable);
+ } else {
+ mRtButton.setImageDrawable(mBookmarkDrawable);
+ }
+ }
+
+ /**
* Set the Drawable for the lock icon, or null to hide it.
*/
/* package */ void setLock(Drawable d) {
mTitle.setCompoundDrawables(null, null, null, null);
((Animatable) mCircularProgress).stop();
mHorizontalProgress.setVisibility(View.INVISIBLE);
- if (mBookmarkDrawable != null) {
+ if (!mInVoiceMode) {
mRtButton.setImageDrawable(mBookmarkDrawable);
}
mInLoad = false;
null);
((Animatable) mCircularProgress).start();
mHorizontalProgress.setVisibility(View.VISIBLE);
- if (mBookmarkDrawable == null) {
- mBookmarkDrawable = mRtButton.getDrawable();
- }
- if (mStopDrawable == null) {
- mRtButton.setImageResource(R.drawable.ic_btn_stop_v2);
- mStopDrawable = mRtButton.getDrawable();
- } else {
+ if (!mInVoiceMode) {
mRtButton.setImageDrawable(mStopDrawable);
}
mInLoad = true;