# floatingsearchview **Repository Path**: HarmonyOS-tpc/floatingsearchview ## Basic Information - **Project Name**: floatingsearchview - **Description**: A search view that implements a floating search bar also known as persistent search. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-04-15 - **Last Updated**: 2024-11-08 ## Categories & Tags **Categories**: harmonyos-popup **Tags**: None ## README # floatingsearchview floatingsearchview : A search view that implements a floating search bar also known as persistent search. # floatingsearchview includes : * Search Suggestion list * Search Result list. * Change in the Search Hint text. * Set the margin for view from left, right, top. * Set the suggestion list item count. # Usage Instructions The following core classes are the essential interface: Create a class implement the provider, for example: FloatingSearchView floatingSearchView = new FloatingSearchView(this, null, sColorSuggestions); try { String[] coloursArray = getElement().getStringArray(); List coloursList = Arrays.asList(coloursArray); coloursNameList = new ArrayList<>(); if (!coloursList.isEmpty()) { for (String currentItem : coloursList) { currentItem = currentItem.substring(currentItem.indexOf("+") + 1); currentItem = currentItem.substring(0, currentItem.indexOf("+")); coloursNameList.add(currentItem); } } } catch (IOException | NotExistException | WrongTypeException e) { LogUtil.error(TAG, "Exception occurred - " + e.getMessage()); } FloatingSearchView.init(SUGGESTION_COUNT, new FloatingSearchView.OnSuggestionClickListener() { @Override public void onSuggestionClick(String alert) { int textlength = alert.length(); ArrayList tempArrayList = new ArrayList(); for (String currentItem : coloursNameList) { if (textlength <= coloursNameList.size()) { if (currentItem.toLowerCase(Locale.getDefault()) .contains(alert.toLowerCase(Locale.getDefault()))) { tempArrayList.add(currentItem); } } } Component searchResultListContainerComp = rootContainer.findComponentById( ResourceTable.Id_search_reult_list); if (searchResultListContainerComp instanceof ListContainer) { ListContainer searchResultListContainer = (ListContainer) searchResultListContainerComp; SearchResultsListAdapter listItemProvider = new SearchResultsListAdapter(getContext(), tempArrayList); searchResultListContainer.setItemProvider(listItemProvider); } } }); Add a floatingsearchview to your view hierarchy, and make sure that it takes up the full width and height of the screen Listen to query changes and provide suggestion items that implement SearchSuggestion. SearchResultsListAdapter provides the main search result items. # Installation Instructions 1.For using floatingsearchview module in sample app, Add the dependencies in entry/build.gradle as below : dependencies { implementation project(path: ':library') } 2.Using the library.har, make sure to add library.har file in the entry/libs folder. Modify the dependencies in the entry/build.gradle file. dependencies { implementation fileTree(dir: 'libs', include: [' *.jar', ' *.har']) } 3. For using floatingsearchview from a remote repository in separate application, add the below dependencies : Modify entry build.gradle as below : ``` dependencies { implementation 'io.openharmony.tpc.thirdlib:floatingsearchview:1.0.1' } ``` # License Copyright (C) 2015 Ari C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.