List of usage examples for android.speech RecognizerIntent ACTION_WEB_SEARCH
String ACTION_WEB_SEARCH
To view the source code for android.speech RecognizerIntent ACTION_WEB_SEARCH.
Click Source Link
From source file:com.glabs.homegenie.util.VoiceControl.java
public VoiceControl(StartActivity hgactivity) { _hgcontext = hgactivity;/* w w w .j av a 2s .c o m*/ //find out whether speech recognition is supported PackageManager packManager = _hgcontext.getPackageManager(); List<ResolveInfo> intActivities = packManager .queryIntentActivities(new Intent(RecognizerIntent.ACTION_WEB_SEARCH), 0); if (intActivities.size() != 0) { // TODO ok speech recognition supported } else { //speech recognition not supported, disable button and output message Toast.makeText(_hgcontext, "Oops - Speech recognition not supported!", Toast.LENGTH_LONG).show(); } _lingodata = new LingoData(); new RetrieveLingoDataTask().execute(); }
From source file:com.delexus.imitationzhihu.MySearchView.java
public MySearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.MySearchView, defStyleAttr, 0);// w ww .j av a2 s.com final LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.search_view, this); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.my_search_src_text); mSearchSrcTextView.setSearchView(this); mNavigationButton = (ImageView) findViewById(R.id.my_search_button); mGoButton = (ImageView) findViewById(R.id.my_search_go_btn); mCloseButton = (ImageView) findViewById(R.id.my_search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.my_search_voice_btn); // Set up icons and backgrounds. mNavigationButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_navigateIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_voiceIcon)); mSearchHintIcon = a.getDrawable(R.styleable.MySearchView_searchHintIcon); mNavigationButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(MySearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.MySearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.MySearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } mDefaultQueryHint = a.getText(R.styleable.MySearchView_defaultQueryHint); mQueryHint = a.getText(R.styleable.MySearchView_queryHint); final int imeOptions = a.getInt(R.styleable.MySearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.MySearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.MySearchView_android_inputType, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:io.github.vomitcuddle.SearchViewAllowEmpty.SearchView.java
public SearchView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.cba_search_view, this, true); mSearchButton = findViewById(R.id.search_button); mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mQueryTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSubmitButton = findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = findViewById(R.id.search_voice_btn); mSearchHintIcon = (ImageView) findViewById(R.id.search_mag_icon); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); }/*from www . j a v a2 s . c o m*/ } }); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } a.recycle(); boolean focusable = true; a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); focusable = a.getBoolean(R.styleable.View_android_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs) { super(context, attrs); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) { throw new IllegalStateException("SearchView is API 8+ only."); }//from w w w . j a va 2 s . c o m LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.abs__search_view, this, true); mSearchButton = findViewById(R.id.abs__search_button); mQueryTextView = (SearchAutoComplete) findViewById(R.id.abs__search_src_text); mQueryTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.abs__search_edit_frame); mSearchPlate = findViewById(R.id.abs__search_plate); mSubmitArea = findViewById(R.id.abs__submit_area); mSubmitButton = findViewById(R.id.abs__search_go_btn); mCloseButton = (ImageView) findViewById(R.id.abs__search_close_btn); mVoiceButton = findViewById(R.id.abs__search_voice_btn); mSearchHintIcon = (ImageView) findViewById(R.id.abs__search_mag_icon); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockSearchView, 0, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SherlockSearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SherlockSearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } CharSequence queryHint = a.getText(R.styleable.SherlockSearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } int imeOptions = a.getInt(R.styleable.SherlockSearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } int inputType = a.getInt(R.styleable.SherlockSearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } a.recycle(); boolean focusable = true; a = context.obtainStyledAttributes(attrs, R.styleable.SherlockView, 0, 0); focusable = a.getBoolean(R.styleable.SherlockView_android_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mDropDownAnchor.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { adjustDropDownSizeAndPosition(); } }); } else { mDropDownAnchor.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { adjustDropDownSizeAndPosition(); } }); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:lewa.support.v7.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.abc_search_view, this, true); mSearchButton = findViewById(R.id.search_button); mQueryTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mQueryTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSubmitButton = findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = findViewById(R.id.search_voice_btn); mSearchHintIcon = (ImageView) findViewById(R.id.search_mag_icon); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); }//w w w. j a v a2 s.c o m } }); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0); mSearchIconResId = a.getResourceId(R.styleable.SearchView_searchIcon, 0); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } a.recycle(); boolean focusable = true; a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0); focusable = a.getBoolean(R.styleable.View_android_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:android.support.v7ox.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDrawableManager = AppCompatDrawableManager.get(); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);// w w w . j a v a 2 s .co m final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view); inflater.inflate(layoutResId, this, true); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // Set up icons and backgrounds. mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground)); mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground)); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } mDefaultQueryHint = a.getText(R.styleable.SearchView_defaultQueryHint); mQueryHint = a.getText(R.styleable.SearchView_queryHint); final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:android.support.v7.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);/*from w w w . j a v a2 s. c om*/ // Keep the TintManager in case we need it later mTintManager = a.getTintManager(); final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view); inflater.inflate(layoutResId, this, true); mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // Set up icons and backgrounds. mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground)); mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground)); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:com.example.navigationsearchview.NavigationSearchView.java
public NavigationSearchView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView, defStyleAttr, 0);//www . j a va 2 s .c o m // Keep the TintManager in case we need it later mTintManager = a.getTintManager(); final LayoutInflater inflater = LayoutInflater.from(context); final int layoutResId = com.example.navigationsearchview.R.layout.abc_search_view; inflater.inflate(layoutResId, this, true);// original true mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text); mSearchSrcTextView.setSearchView(this); mSearchEditFrame = findViewById(R.id.search_edit_frame); mSearchPlate = findViewById(R.id.search_plate); mSubmitArea = findViewById(R.id.submit_area); mSearchButton = (ImageView) findViewById(R.id.search_button); mGoButton = (ImageView) findViewById(R.id.search_go_btn); mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn); mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon); // next and previous mNextButton = (ImageView) findViewById(R.id.search_next_btn); mPrevButton = (ImageView) findViewById(R.id.search_previous_btn); // Set up icons and backgrounds. mSearchPlate.setBackground(a.getDrawable((R.styleable.SearchView_queryBackground))); mSubmitArea.setBackground(a.getDrawable((R.styleable.SearchView_submitBackground))); mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon)); mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon)); mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon)); mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon)); // next and previous mNextButton.setImageResource(R.drawable.arrow_right); mPrevButton.setImageResource(R.drawable.arrow_left); mSearchHintIcon = a.getDrawable(R.styleable.SearchView_iconifiedByDefault); // Extract dropdown layout resource IDs for later use. mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout, R.layout.abc_search_dropdown_item_icons_2line); mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mGoButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.setOnClickListener(mOnClickListener); // next and previous button mNextButton.setOnClickListener(mOnClickListener); mPrevButton.setOnClickListener(mOnClickListener); mSearchSrcTextView.addTextChangedListener(mTextWatcher); mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener); mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener); mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener); mSearchSrcTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(NavigationSearchView.this, hasFocus); } } }); setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true)); final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } boolean focusable = true; focusable = a.getBoolean(0, focusable); setFocusable(focusable); a.recycle(); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { addOnLayoutChangeListenerToDropDownAnchorSDK11(); } else { addOnLayoutChangeListenerToDropDownAnchorBase(); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:com.tandong.sa.sherlock.widget.SearchView.java
public SearchView(Context context, AttributeSet attrs) { super(context, attrs); this.c = context; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) { throw new IllegalStateException("SearchView is API 8+ only."); }/* w w w . ja va 2s .com*/ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(getResources().getIdentifier("abs__search_view", "layout", context.getPackageName()), this, true); // inflater.inflate(R.layout.abs__search_view, this, true); mSearchButton = findViewById( getResources().getIdentifier("abs__search_button", "id", context.getPackageName())); // mSearchButton = findViewById(R.id.abs__search_button); mQueryTextView = (SearchAutoComplete) findViewById( getResources().getIdentifier("abs__search_src_text", "id", context.getPackageName())); // mQueryTextView = (SearchAutoComplete) // findViewById(R.id.abs__search_src_text); mQueryTextView.setSearchView(this); mSearchEditFrame = findViewById( getResources().getIdentifier("abs__search_edit_frame", "id", context.getPackageName())); // mSearchEditFrame = findViewById(R.id.abs__search_edit_frame); mSearchPlate = findViewById( getResources().getIdentifier("abs__search_plate", "id", context.getPackageName())); // mSearchPlate = findViewById(R.id.abs__search_plate); mSubmitArea = findViewById( getResources().getIdentifier("abs__submit_area", "id", context.getPackageName())); // mSubmitArea = findViewById(R.id.abs__submit_area); mSubmitButton = findViewById( getResources().getIdentifier("abs__search_go_btn", "id", context.getPackageName())); // mSubmitButton = findViewById(R.id.abs__search_go_btn); mCloseButton = (ImageView) findViewById( getResources().getIdentifier("abs__search_close_btn", "id", context.getPackageName())); // mCloseButton = (ImageView) findViewById(R.id.abs__search_close_btn); mVoiceButton = findViewById( getResources().getIdentifier("abs__search_voice_btn", "id", context.getPackageName())); // mVoiceButton = findViewById(R.id.abs__search_voice_btn); mSearchHintIcon = (ImageView) findViewById( getResources().getIdentifier("abs__search_mag_icon", "id", context.getPackageName())); // mSearchHintIcon = (ImageView) // findViewById(R.id.abs__search_mag_icon); mSearchButton.setOnClickListener(mOnClickListener); mCloseButton.setOnClickListener(mOnClickListener); mSubmitButton.setOnClickListener(mOnClickListener); mVoiceButton.setOnClickListener(mOnClickListener); mQueryTextView.setOnClickListener(mOnClickListener); mQueryTextView.addTextChangedListener(mTextWatcher); mQueryTextView.setOnEditorActionListener(mOnEditorActionListener); mQueryTextView.setOnItemClickListener(mOnItemClickListener); mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener); mQueryTextView.setOnKeyListener(mTextKeyListener); // Inform any listener of focus changes mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (mOnQueryTextFocusChangeListener != null) { mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus); } } }); TypedArray a = context.obtainStyledAttributes(attrs, new int[] { getResources().getIdentifier("SherlockSearchView", "styleable", context.getPackageName()) }, 0, 0); // R.styleable.SherlockSearchView, 0, 0); setIconifiedByDefault(a.getBoolean(getResources().getIdentifier("SherlockSearchView_iconifiedByDefault", "styleable", context.getPackageName()), true)); // R.styleable.SherlockSearchView_iconifiedByDefault, true)); int maxWidth = a.getDimensionPixelSize(getResources().getIdentifier("SherlockSearchView_android_maxWidth", "styleable", context.getPackageName()), -1); // R.styleable.SherlockSearchView_android_maxWidth, -1); if (maxWidth != -1) { setMaxWidth(maxWidth); } CharSequence queryHint = a.getText(getResources().getIdentifier("SherlockSearchView_queryHint", "styleable", context.getPackageName())); // .getText(R.styleable.SherlockSearchView_queryHint); if (!TextUtils.isEmpty(queryHint)) { setQueryHint(queryHint); } int imeOptions = a.getInt(getResources().getIdentifier("SherlockSearchView_android_imeOptions", "styleable", context.getPackageName()), -1); // R.styleable.SherlockSearchView_android_imeOptions, -1); if (imeOptions != -1) { setImeOptions(imeOptions); } int inputType = a.getInt(getResources().getIdentifier("SherlockSearchView_android_inputType", "styleable", context.getPackageName()), -1); // R.styleable.SherlockSearchView_android_inputType, -1); if (inputType != -1) { setInputType(inputType); } a.recycle(); boolean focusable = true; a = context.obtainStyledAttributes(attrs, new int[] { getResources().getIdentifier("SherlockView", "styleable", context.getPackageName()) }, 0, // a = context.obtainStyledAttributes(attrs, // R.styleable.SherlockView, 0, 0); focusable = a.getBoolean( getResources().getIdentifier("SherlockView_android_focusable", "styleable", context.getPackageName()), // focusable = // a.getBoolean(R.styleable.SherlockView_android_focusable, focusable); a.recycle(); setFocusable(focusable); // Save voice intent for later queries/launching mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor()); if (mDropDownAnchor != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mDropDownAnchor.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { adjustDropDownSizeAndPosition(); } }); } else { mDropDownAnchor.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { adjustDropDownSizeAndPosition(); } }); } } updateViewsVisibility(mIconifiedByDefault); updateQueryHint(); }
From source file:com.android.launcher2.Launcher.java
/** * Event handler for the voice button/* ww w . jav a2 s.co m*/ * * @param v The view that was clicked. */ public void onClickVoiceButton(View v) { v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); try { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName activityName = searchManager.getGlobalSearchActivity(); Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (activityName != null) { intent.setPackage(activityName.getPackageName()); } startActivity(null, intent, "onClickVoiceButton"); } catch (ActivityNotFoundException e) { Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivitySafely(null, intent, "onClickVoiceButton"); } }