arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Some suggestions #8

Closed Pabloku closed 8 years ago

Pabloku commented 8 years ago

Hi again @arimorty!

Just 2 suggestions for some common uses:

Thanks very much!

arimorty commented 8 years ago

For the first one, I'll take it into consideration in the next release. For the second one, after the release I was waiting for such a request, and here it comes.... So, I'll think about if it fits with my vision for the library at this stage and will added it to release 1.1.0 if it does.

Pabloku commented 8 years ago

Ok! Thanks very much!

manjunathc23 commented 8 years ago

+1 for point one. I was wondering how to set the search text

Pabloku commented 8 years ago

Hi @arimorty! Just to confirm: point one has not been implemented yet in version 1.1.0, right?

Thanks!

arimorty commented 8 years ago

Hi @Pabloku,

My understanding is that you suggest that the search view remain focused when a suggestion item is selected, right? The problem is that even if the search remains focused and the suggestions are closed, there is still that shadow that will shadow your views beneath it, so what's the point? Which leads us to your point 2, but again, I am not sure that this is a good idea for now, and here is why:

The library at its current state is aiming on implementing a search like you can see in the Google Play app where when the search view is clicked, the search shadows the other content, and a suggestion click will confirm the search and return focus to the main content that will process the search.

If all you want is to show the last search in the search view after it lost focus, you can use https://github.com/arimorty/floatingsearchview/blob/master/library/src/main/java/com/arlib/floatingsearchview/FloatingSearchView.java#L958 to set the bar's text to the searched text in onSearch listener.

Use the new version 1.1.2 that also fixed minor bugs.

Thanks, Ari

Pabloku commented 8 years ago

Thanks!

setSearchText was what I needed, but now, it would be grate to be able to show the X button on the right side ;) Let me show you a capture of what I am trying:

device-2015-12-09-185216

I am trying to do it using the _app:floatingSearch_menu="@menu/menusearchbox" but icon is not showing. It just shows the 3 point icon menu.

Hope you understand me. Sorry about my poor english.

Thanks!

arimorty commented 8 years ago

@Pabloku First, I don't see any problem in your English. Second, the three dots will show if your menu_searchbox contains more than one item and there isn't enough room to show them or they are set to app:showAsAction="never". You can refer to the README for details.

The main point is that you can achieve one of the following depending on your situation:

  1. If you have multiple menu items, set app:showAsAction="always" for the X menu item, and app:showAsAction="never" for the rest. But, you will still see the dots as there are more items that have to be accessed through the popup menu.
  2. If the X menu item is your only item, simply set it with app:showAsAction="always" and the dots won't show.

If you go with one of the approaches, you are left with one problem: The X that comes with the library will show when the user types in addition to the X of your menu item. So your are now stuck with two Xs ): But, wait, there is a workaround. Use mSearchView.setClearBtnColor(Color.TRANSPARENT); and you won't see the clear button that comes with the view, and then handle search clear yourself by calling setSearchText("").

Let me know the results. BTW, I loved that you made use of a menu item for showing the X. I simply didn't think about it :)

Pabloku commented 8 years ago

I am glad my feedback helps! Just some comment. I am not able to make app:showAsAction="always" work. I have just one item in my menu and it is always showing the three dots icon...

arimorty commented 8 years ago

Hey, @Pabloku The below works for me.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" >

    <item
        android:id="@+id/action_clear"
        android:orderInCategory="1"
        android:title="@string/action_clear"
        android:icon="@drawable/ic_clear_black_24dp"
        app:showAsAction="always" />

  </menu>

However, if you set app:floatingSearch_searchBarWidth="" to a very small width, or if the screen width is small, there won't be room for the icon, so it will display as dots. "always" really means: show the icon always, search focused or not, if there is room; otherwise, show the menu item in the overflow menu.

Hope it helps.

All the best, Ari

Pabloku commented 8 years ago

Not working for me :S It is really strange. In designer, I see the icon, but not when executing the app on the device....

arimorty commented 8 years ago

I is not strange at all, if you read my previous answer, the view decides if there is enough room for icons and then puts dots if there isn't any. Now, currently, this is measured by screenW - 225dp (min that is assumed to be needed for input and left icon to fit) and looking if the result will leave room for icons.

The reason you see different results in the designer is that the screen width when in designer mode is set to 360dp which when applying the above will leave room for icons. (I should changed that when I get a chance though).

I will reopen the issue to make all of these points more flexible by providing a method to set the min width that is needed for input and left icon to fit. I will include it in next release (probably week or two).

Pabloku commented 8 years ago

Ok thanks!

feifeierchampy commented 8 years ago

It works well in mobile phone, but in the android tv, it can't get the focus when the key up,down pressed. Hope it could be compatible in android tv.

arimorty commented 8 years ago

This lib is not intended and was not tested on Android TV.