Search in sources :

Example 6 with SearchView

use of android.widget.SearchView in project android_frameworks_base by crdroidandroid.

the class SelectPrinterActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.select_printer_activity, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String searchString) {
            ((DestinationAdapter) mListView.getAdapter()).getFilter().filter(searchString);
            return true;
        }
    });
    searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

        @Override
        public void onViewAttachedToWindow(View view) {
            if (AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_shown_utterance));
            }
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            if (!isFinishing() && AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_hidden_utterance));
            }
        }
    });
    return true;
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 7 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by LineageOS.

the class SearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.search_panel, container, false);
    mResultsRecyclerView = view.findViewById(R.id.list_results);
    mResultsRecyclerView.setAdapter(mSearchAdapter);
    mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mResultsRecyclerView.addOnScrollListener(mScrollListener);
    mNoResultsView = view.findViewById(R.id.no_results_layout);
    Toolbar toolbar = view.findViewById(R.id.search_toolbar);
    getActivity().setActionBar(toolbar);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    mSearchView = toolbar.findViewById(R.id.search_view);
    mSearchView.setQuery(mQuery, false);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.requestFocus();
    // Updating internal views inside SearchView was the easiest way to get this too look right.
    // Instead of grabbing the TextView directly, we grab it as a view and do an instanceof
    // check. This ensures if we return, say, a LinearLayout in the tests, they won't fail.
    View searchText = mSearchView.findViewById(com.android.internal.R.id.search_src_text);
    if (searchText instanceof TextView) {
        TextView searchTextView = (TextView) searchText;
        searchTextView.setTextColor(getContext().getColorStateList(com.android.internal.R.color.text_color_primary));
        searchTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.search_bar_text_size));
    }
    View editFrame = mSearchView.findViewById(com.android.internal.R.id.search_edit_frame);
    if (editFrame != null) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) editFrame.getLayoutParams();
        params.setMarginStart(0);
        editFrame.setLayoutParams(params);
    }
    ActionBarShadowController.attachToRecyclerView(view.findViewById(R.id.search_bar_container), getLifecycle(), mResultsRecyclerView);
    return view;
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.widget.Toolbar)

Example 8 with SearchView

use of android.widget.SearchView in project android_packages_apps_OmniClock by omnirom.

the class CitiesActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(org.omnirom.deskclock.R.menu.cities_menu, menu);
    MenuItem search = menu.findItem(org.omnirom.deskclock.R.id.menu_item_search);
    if (search != null) {
        search.setOnActionExpandListener(new SearchActionExpandListener(menu));
    }
    MenuItem searchMenu = menu.findItem(org.omnirom.deskclock.R.id.menu_item_search);
    mSearchView = (SearchView) searchMenu.getActionView();
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_DONE);
    mSearchView.setOnSearchClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            mSearchMode = true;
        }
    });
    mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            mSearchMode = false;
            return false;
        }
    });
    if (mSearchView != null) {
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setQuery(mQueryTextBuffer.toString(), false);
        if (mSearchMode) {
            mSearchView.requestFocus();
            mSearchView.setIconified(false);
        }
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : SearchView(android.widget.SearchView) OnClickListener(android.view.View.OnClickListener) MenuItem(android.view.MenuItem) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchView(android.widget.SearchView)

Example 9 with SearchView

use of android.widget.SearchView in project android_packages_apps_OmniClock by omnirom.

the class BrowseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (getIntent().hasExtra(AlarmConstants.DATA_COLOR_THEME_ID)) {
        int themeId = getIntent().getIntExtra(AlarmConstants.DATA_COLOR_THEME_ID, 0);
        setTheme(Utils.getThemeResourceId(this, themeId));
    } else if (getIntent().hasExtra(AlarmConstants.DATA_COLOR_THEME_LIGHT)) {
        boolean lightTheme = getIntent().getBooleanExtra(AlarmConstants.DATA_COLOR_THEME_LIGHT, true);
        setTheme(Utils.getThemeResourceId(this, lightTheme ? 0 : 1));
    } else {
        setTheme(Utils.getThemeResourceId(this));
    }
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    mPrimaryColor = getResources().getColor(android.R.color.white);
    mPrimaryColorDisabled = Utils.setColorAlpha(mPrimaryColor, getResources().getInteger(org.omnirom.deskclock.R.integer.disabled_text_alpha));
    if (getIntent().hasExtra(AlarmConstants.DATA_ALARM_EXTRA)) {
        mAlarm = getIntent().getParcelableExtra(AlarmConstants.DATA_ALARM_EXTRA);
        if (mAlarm != null) {
            mSelectedUri = mAlarm.alert.toString();
            mPreAlarm = mAlarm.preAlarm;
        }
    }
    if (mAlarm == null) {
        mAlarm = new Alarm();
        mPreAlarm = false;
    }
    if (getIntent().hasExtra(AlarmConstants.DATA_ALARM_EXTRA_URI)) {
        mSelectedUri = getIntent().getStringExtra(AlarmConstants.DATA_ALARM_EXTRA_URI);
        if (mSelectedUri != null) {
            mAlarm.alert = Uri.parse(mSelectedUri);
        }
    }
    if (getIntent().hasExtra(AlarmConstants.DATA_BROWSE_EXTRA_FALLBACK)) {
        mLimitedMode = getIntent().getBooleanExtra(AlarmConstants.DATA_BROWSE_EXTRA_FALLBACK, false);
    }
    setContentView(R.layout.browse_activity);
    mCurrentUri = findViewById(R.id.current_uri);
    mSearchView = (SearchView) findViewById(R.id.query_pattern);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setSubmitButtonEnabled(false);
    mSearchView.setVisibility(View.INVISIBLE);
    mQueryTypeText = (TextView) findViewById(R.id.query_type_string);
    mQueryList = (ListView) findViewById(R.id.query_result);
    mFooterView = getLayoutInflater().inflate(R.layout.browse_footer_item, mQueryList, false);
    mProgress = (ProgressBar) mFooterView.findViewById(R.id.query_progressbar);
    mPasteUrl = findViewById(R.id.query_paste_url);
    mPasteUrlText = (EditText) findViewById(R.id.query_paste_url_field);
    ImageView pasteUrlButton = (ImageView) findViewById(R.id.query_paste_url_add);
    pasteUrlButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!TextUtils.isEmpty(mPasteUrlText.getText().toString())) {
                showPlaylistDialog();
            }
        }
    });
    mQueryList.addFooterView(mFooterView, null, false);
    mQueryType = QUERY_TYPE_RECENT;
    mQueryTypeText.setText(R.string.local_query_recent);
    mChooseFolder = (TextView) findViewById(R.id.query_folder_button);
    mChooseFolder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            launchStoragePicker();
        }
    });
    mAdapter = createListAdapter();
    mQueryList.setAdapter(mAdapter);
    mAlarmsTab = findViewById(R.id.tab_alarms);
    ((ImageView) mAlarmsTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_alarm_white);
    ((TextView) mAlarmsTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_alarm);
    mAlarmsTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.INVISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_ALARM;
            mQueryTypeText.setText(R.string.local_query_alarm_ringtones);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mRecentTab = findViewById(R.id.tab_recent);
    ((ImageView) mRecentTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_star_white);
    ((TextView) mRecentTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_recent);
    mRecentTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.INVISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_RECENT;
            mQueryTypeText.setText(R.string.local_query_recent);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mArtistTab = findViewById(R.id.tab_artist);
    ((ImageView) mArtistTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_artist_white);
    ((TextView) mArtistTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_artist);
    mArtistTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.VISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_ARTIST;
            mQueryTypeText.setText(R.string.local_query_artist);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mAlbumTab = findViewById(R.id.tab_album);
    ((ImageView) mAlbumTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_album_white);
    ((TextView) mAlbumTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_album);
    mAlbumTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.VISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_ALBUM;
            mQueryTypeText.setText(R.string.local_query_album);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mTrackTab = findViewById(R.id.tab_track);
    ((ImageView) mTrackTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_track_white);
    ((TextView) mTrackTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_track);
    mTrackTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.VISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_TRACK;
            mQueryTypeText.setText(R.string.local_query_track);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mFolderTab = findViewById(R.id.tab_folder);
    ((ImageView) mFolderTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_folder_white);
    ((TextView) mFolderTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_folder);
    mFolderTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.INVISIBLE);
            mChooseFolder.setVisibility(View.VISIBLE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_FOLDER;
            mQueryTypeText.setText(R.string.local_query_folder);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mPlaylistTab = findViewById(R.id.tab_playlist);
    ((ImageView) mPlaylistTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_playlist_white);
    ((TextView) mPlaylistTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_playlist);
    mPlaylistTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.VISIBLE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.GONE);
            mQueryType = QUERY_TYPE_PLAYLIST;
            mQueryTypeText.setText(R.string.local_query_playlist);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    mStreamTab = findViewById(R.id.tab_stream);
    ((ImageView) mStreamTab.findViewById(R.id.tab_strip_image)).setImageResource(R.drawable.ic_earth_white);
    ((TextView) mStreamTab.findViewById(R.id.tab_strip_title)).setText(R.string.local_query_stream);
    mStreamTab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mSearchView.setVisibility(View.GONE);
            mChooseFolder.setVisibility(View.GONE);
            mPasteUrl.setVisibility(View.VISIBLE);
            mQueryType = QUERY_TYPE_STREAM;
            mQueryTypeText.setText(R.string.local_query_stream);
            clearList();
            updateTabs();
            doQuery(mCurrentQueryText, 0);
        }
    });
    if (mLimitedMode) {
        mStreamTab.setVisibility(View.GONE);
        mPlaylistTab.setVisibility(View.GONE);
    }
    mFolderTab.setVisibility(View.GONE);
    updateTabs();
    mQueryList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            QueryItem queryItem = mAdapter.getItem(position);
            if (queryItem.mQueryType != QUERY_TYPE_UNKNOWN) {
                mSelectedUri = queryItem.mUri;
                addToRecents(mSelectedUri);
                Intent intent = new Intent();
                intent.putExtra(AlarmConstants.DATA_ALARM_EXTRA_URI, mSelectedUri);
                intent.putExtra(AlarmConstants.DATA_ALARM_EXTRA_NAME, queryItem.mName);
                intent.putExtra(AlarmConstants.DATA_ALARM_EXTRA_TYPE, queryItem.mQueryType);
                setResult(Activity.RESULT_OK, intent);
                finish();
            }
        }
    });
    mQueryList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            QueryItem queryItem = mAdapter.getItem(position);
            // TODO export as spotify open URL
            return true;
        }
    });
    cacheAlarmTones();
    cacheRingtones();
    View queryArea = findViewById(R.id.query_area);
    queryArea.setVisibility(View.VISIBLE);
    checkStoragePermissions();
}
Also used : Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) Alarm(org.omnirom.deskclock.provider.Alarm) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView)

Example 10 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by crdroidandroid.

the class PrintServiceSettingsFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.print_service_settings, menu);
    MenuItem addPrinters = menu.findItem(R.id.print_menu_item_add_printer);
    if (mServiceEnabled && mAddPrintersIntent != null) {
        addPrinters.setIntent(mAddPrintersIntent);
    } else {
        menu.removeItem(R.id.print_menu_item_add_printer);
    }
    MenuItem settings = menu.findItem(R.id.print_menu_item_settings);
    if (mServiceEnabled && mSettingsIntent != null) {
        settings.setIntent(mSettingsIntent);
    } else {
        menu.removeItem(R.id.print_menu_item_settings);
    }
    MenuItem searchItem = menu.findItem(R.id.print_menu_item_search);
    if (mServiceEnabled && mPrintersAdapter.getUnfilteredCount() > 0) {
        mSearchView = (SearchView) searchItem.getActionView();
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String searchString) {
                mPrintersAdapter.getFilter().filter(searchString);
                return true;
            }
        });
        mSearchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

            @Override
            public void onViewAttachedToWindow(View view) {
                if (AccessibilityManager.getInstance(getActivity()).isEnabled()) {
                    view.announceForAccessibility(getString(R.string.print_search_box_shown_utterance));
                }
            }

            @Override
            public void onViewDetachedFromWindow(View view) {
                Activity activity = getActivity();
                if (activity != null && !activity.isFinishing() && AccessibilityManager.getInstance(activity).isEnabled()) {
                    view.announceForAccessibility(getString(R.string.print_search_box_hidden_utterance));
                }
            }
        });
    } else {
        menu.removeItem(R.id.print_menu_item_search);
    }
}
Also used : SearchView(android.widget.SearchView) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchView(android.widget.SearchView)

Aggregations

SearchView (android.widget.SearchView)67 View (android.view.View)35 TextView (android.widget.TextView)30 MenuItem (android.view.MenuItem)26 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)13 SearchManager (android.app.SearchManager)11 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 SettingsActivity (com.android.settings.SettingsActivity)7 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 MenuInflater (android.view.MenuInflater)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Nullable (android.support.annotation.Nullable)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)3