Git Product home page Git Product logo

materialsearchbar's Introduction

Mansur's GitHub stats

Top Langs

trophy

materialsearchbar's People

Contributors

cirnoftw avatar gituser4732 avatar mancj avatar pavel163 avatar ruijiepan avatar vbauer avatar voghdev avatar wax911 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialsearchbar's Issues

Not work on SDK 16

Hi, thanks for this library.
this library minSDK has 16, but when running on SDK 16 and 17, when click on EditText for write text not show me any text!!! but and sdk 18 and above its ok and not bug!!
please check this and fix it, i really need this

Thanks man

Compile exception

"Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 16 declared in library [com.github.mancj:MaterialSearchBar:0.1.1]
Suggestion: use tools:overrideLibrary="com.mancj.materialsearchbar" to force usage"
Can I force usage ?

BUTTON_BACK not available

Hi, I used the available example, there is

MaterialSearchBar.BUTTON_BACK

It is not available in the library that on "jitpack" 0.7.1
But i see it in the latest version of code here, i didn't know how to implement the library in my app manually, when will the jitpack library get updated?

Thanks,

resource not found when compile, solved by adding a android name space.

Hi mancj, Thanks for the nice searchBar.

I encounered a small issue when i use AS 3.0 beta 6, gradle 4.1 with the code

<com.mancj.materialsearchbar.MaterialSearchBar
    style="@style/MaterialSearchBarLight"
    app:mt_speechMode="true"
    app:mt_hint="Custom hint"
    app:mt_maxSuggestionsCount="10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchBar" />

I got an err, can't resolve the symbol or when compile Error:resource style/MaterialSearchBarLight (aka com.dm.package:style/MaterialSearchBarLight) not found

Changing second line to :

 style="android:@style/MaterialSearchBarLight"

solve the issue

Size of Search Icon

Hello,
I set the layout height of MaterialSearchBar to 56dp (size of action bar) and this causes the search/voice icon to be relatively small.
Is it possible to resize this icon to better match size of navigation icon?

I included image of the icons replaced with a color to show size relative to one another along with one with the default icons.
iconsizedifferencemsb

Once the number of items in the CustomSuggestionAdapter decreases, the list view shrinks.

Once the number of items in the CustomSuggestionAdapter decreases, the list view shrinks.
Even if i add the items into the list agiain. It never increases.

Steps to reproduce :

  1. Try to initialize the CustomSuggestionAdapter with zero items.
  2. Now increase the number of items in the CustomSuggestionAdapter during runtime.
  3. We can never see the list view of suggestions coming up.

I was trying to do a predictive search by calling a webservice. The number of items increases and decreases based on the search key.

"I have done some workaround to fix the issue for me for now", but its a temporary fix.

My further steps would be to combine recent searches when user hasn't typed anything, and once the user starts typing i will call the webservice and get the results and show in this suggestions area. i will write an article on the Material Search bar once I complete my implementation.

Thanks,
Adarsh

Resource not found exception

I am getting exception when i tried to change text color using setTextColor() method
01-03 16:46:03.757 15355-15355/com.onlineshopping.deals.browser.shopping E/AndroidRuntime: FATAL EXCEPTION: main Process: com.onlineshopping.deals.browser.shopping, PID: 15355 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.onlineshopping.deals.browser.shopping/nudimelabs.com.browser.NavigationActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xff000000 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2394) at android.app.ActivityThread.access$800(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5276) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) Caused by: android.content.res.Resources$NotFoundException: Resource ID #0xff000000 at android.content.res.Resources.getValue(Resources.java:1284) at android.content.res.MiuiResources.getValue(MiuiResources.java:145) at android.content.res.Resources.getColor(Resources.java:938) at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:434) at com.mancj.materialsearchbar.MaterialSearchBar.setupTextColors(MaterialSearchBar.java:179) at com.mancj.materialsearchbar.MaterialSearchBar.setTextColor(MaterialSearchBar.java:356) at nudimelabs.com.browser.NavigationActivity.onCreate(NavigationActivity.java:84) at android.app.Activity.performCreate(Activity.java:6041) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1109) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2285) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2394)  at android.app.ActivityThread.access$800(ActivityThread.java:154)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5276)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 

Here is my code snippet
MaterialSearchBar searchBar= (MaterialSearchBar) findViewById(R.id.searchBar); searchBar.setHint("Search..."); searchBar.setTextColor(Color.BLACK); searchBar.setOnSearchActionListener(this);
I am using com.github.mancj:MaterialSearchBar:0.3.5 version

Adding Theme/Style Support

Submitted Pull Request

I have been adding theme/style support to Material SearchBar, along with some other stuff
What I have so far. The Min SDK is still 16

  • Animated Hamburger/Back Arrow Icon
  • Change Color Of SearchBar
  • Change Color Of Hint And Text
  • Custom Drawable For All Icons Including Menu Icon
  • Change Tint Of Each Icon Separately From One Another Or Use Default Drawable Color
  • Change Drawables For Text Selection Tabs
  • Change Color Of Text Selection Tabs/Text Highlight/Cursor Independently From One Another And Separate From color/accentColor
  • Menu Divider To Separate Menu Icon From Search Icon (Toggle On And Off)
  • (v21+) Capsule Shaped Searchbar Reverts To Default Shape Due To Odd Behavior On Lower Versions
  • (v21+) Enable Borderless Icon Pressed Ripple, Reverts To Bordered On Lower Versions Due To Not Being Supported.

Other

  • Changed Sizing To Match That Of The SearchBar In GooglePlay

If you are interested in this or want anything added theme/style related let me know!
msbar_themesupport
darktheme

Color

Is there anyway to change the color of the search bar?
Also when I set the placeholder, the words are overlapping the search icon

suggestion bar won't show

hi all

sometimes i see suggestion bar, and some time i don't.. the showSuggestions(); hideSuggestions(); isn't working for me either.. can someone shed some light on it?

thank you

error no find OnSearchActionListener

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.mancj.materialsearchbar.MaterialSearchBar;
public class MainActivity extends AppCompatActivity  {

private MaterialSearchBar search_bar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    init();
}

private void init() {
    search_bar = (MaterialSearchBar) findViewById(R.id.search_bar);
    search_bar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
        @Override
        public void onSearchBarClicked() {

        }

        @Override
        public void onSearchEnabled() {

        }

        @Override
        public void onSearchDisabled() {

        }

        @Override
        public void onSearch(CharSequence charSequence) {

        }

        @Override
        public void onSpeechSelected() {

        }
    });
}

Why no find OnSearchActionListener error

1.add maven { url "https://jitpack.io" } to project level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:2.1.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2.add 'com.github.mancj:MaterialSearchBar:0.1.0' to app build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.github.mancj:MaterialSearchBar:0.1.0'
}

help!!!

Latest release does not contain updates made to SuggestionsAdapter

Some changes made to the library's SuggestionsAdapter such as this:

//changing the suggestions list to protected
protected List<S> suggestions = new ArrayList<>();

..were not included in the latest 0.7.1 release. Please make a new release with these changes as we can't use the CustomSuggestionsAdapter implementation without the newly committed changes. Thanks!

Result list not shown

Hi Guys,

My search won't return a resultlist. I see my results in the monitor but the resultlist from the searchView won't open. Do you guys have any idea what can be the issue?

` mSearchView = (MaterialSearchBar) view.findViewById(R.id.kvk_floating_search_view);

    mSearchView.setOnSearchActionListener(this);

    mSearchView.setTextColor(R.color.colorPrimary);
    mSearchView.setBackgroundColor(getActivity().getResources().getColor(R.color.colorBackground));

    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSearchAdapter = new KvkSearchAdapter(inflater);
    mSearchAdapter.setSuggestions(mCompanyList);
    mSearchView.setCustomSuggestionAdapter(mSearchAdapter);`

`

<com.mancj.materialsearchbar.MaterialSearchBar
    android:id="@+id/kvk_floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:mt_hint="Naam, Adres of KvK"
    app:mt_maxSuggestionsCount="10"
    app:mt_placeholder="Naam, Adres of KvK"
    app:mt_speechMode="false"/>

`

Click of the Custom Suggestion Adapter doesn't return on the callback setSuggstionsClickListener

Your Material Search bar implementation is awesome, but there is slight problem when i try to use it.

When I give the customSuggestionAdapter, setSuggstionsClickListener is not working. Can you please change the implementation to give call back to the click listener.

MaterialSearchBar.java

"if (adapter instanceof DefaultSuggestionsAdapter)
((DefaultSuggestionsAdapter) adapter).setListener(this);"

OR
Can you please give methods to hide the image and the cross mark in the suggestions.

I am showing a predictive search after hitting a server. So the clock image and the cross image in the view is not relevant for my implementation.

Thanks,
Adarsh

PlaceHolderText bug

Добрый день. Столкнулся с такой проблемой: placeHolderText отображается по разному в зависимости от mt_navIconEnabled. Когда app:mt_navIconEnabled="true" то все работает корректно, но когда app:mt_navIconEnabled="false" то placeHolderText уезжает к правому краю. Я посмотрел верстку и самое простое решение которое я увидел, это переверстать на ConstrainLayout

(Question) How change PopupMenu Style!

Hi there, I've tried to change SearchBar Menu style by using style, but does not work!
I'm using search bar in fragment, my parent activity style is like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:itemTextAppearance">@style/itemTextStyle.AppTheme</item>

    <item name="android:popupMenuStyle">@style/PopupMenu</item>
    <item name="android:textAppearanceLargePopupMenu">@style/PopupMenuTextAppearanceLarge</item>
    <item name="android:textAppearanceSmallPopupMenu">@style/PopupMenuTextAppearanceSmall</item>

</style>

<style name="itemTextStyle.AppTheme" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">@color/iconColor</item>
    <item name="android:textSize">@dimen/h3</item>
</style>

<!-- Popup Menu Style -->
<style name="PopupMenu" parent="@style/Widget.AppCompat.Light.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
    <item name="android:textColor">@color/iconColor</item>
    <item name="android:textSize">@dimen/h3</item>
</style>
<style name="PopupMenuTextAppearanceSmall" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
    <item name="android:textColor">@color/iconColor</item>
    <item name="android:textSize">@dimen/h3</item>
</style>
<style name="PopupMenuTextAppearanceLarge" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
    <item name="android:textColor">@color/iconColor</item>
    <item name="android:textSize">@dimen/h0</item>
</style>
<!-- Popup Menu Style -->

How can do that?

Controlling the Arrow icon

Hi there! i've tried to reach the arrow icon by

implementing the listener:
searchBar.setOnSearchActionListener(this);

and using
@OverRide
// public void onButtonClicked(int buttonCode)

can anyone tell me how i interact with the left arrow icon?

How can store and restore last word?

Hi, Thanks for this library ❤️
How can i write loadSearchSuggestionFromDisk and saveSearchSuggestionToDisk this code and use it?

can you help me my bro? Thanks

Not able to check if the suggestion list is shown or not.

  1. You have a method to check to show suggestions and hide suggestions but you don't have a method to check if the Suggestion list is currently hidden or shown.
    searchBar.showSuggestionsList();
    searchBar.hideSuggestionsList();

It will be very helpful if there was a method to check if the list was open or closed. isSuggestionsListOpen().
This is because of the fact that you close the list when user clicks the keyboard button submit. Then after than whenever I try to search again, the list never comes up until i explicitly do searchBar.showSuggestionsList();. I cannot call this method always as the list flickers when i call this.
A method such as isSuggestionsListOpen() will surely help in knowing if list is present or not on the screen.

Exception

The following classes could not be instantiated:
- com.mancj.materialsearchbar.MaterialSearchBar (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details android.content.res.Resources$NotFoundException: Could not resolve resource value: 0xFFFAFAFA.   at android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:932)   at android.content.res.Resources_Delegate.throwException(Resources_Delegate.java:919)   at android.content.res.Resources_Delegate.getColorStateList(Resources_Delegate.java:226)   at android.content.res.Resources_Delegate.getColor(Resources_Delegate.java:203)   at android.content.res.Resources.getColor(Resources.java:915)   at android.content.Context.getColor(Context.java:508)   at android.support.v4.content.ContextCompatApi23.getColor(ContextCompatApi23.java:32)   at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:432)   at com.mancj.materialsearchbar.MaterialSearchBar.setupTextColors(MaterialSearchBar.java:186)   at com.mancj.materialsearchbar.MaterialSearchBar.postSetup(MaterialSearchBar.java:176)   at com.mancj.materialsearchbar.MaterialSearchBar.init(MaterialSearchBar.java:135)   at com.mancj.materialsearchbar.MaterialSearchBar.(MaterialSearchBar.java:78)   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)   at android.view.LayoutInflater.inflate(LayoutInflater.java:518)   at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

[Feature request] Search on typing

For now, the search action can only be trigger manually. I'd like trigger the search after some delay during typing. Unfortunately, with current implementation, I cannot call the listener from my subclass.

onSearchConfirmed executed twice

When I hit the magnifying glass on the keyboard, the onSearchConfirmed method (from OnSearchActionListener) is executed two times.
Simply with :

@Override
public void onSearchConfirmed(CharSequence charSequence) {
    Log.d("SEARCHED",charSequence.toString());
}

Please prefix attrs with component name

Please can you add a namespace to your attributes. app:textcolor is not unique and causes clashes with other components. eg app:materialsearchbar_textcolor

I am currently getting clashes with https://github.com/GwonHyeok/StickySwitch when compiling with the following error Error:(449) Attribute "textColor" already defined with incompatible format.

I have posted the same issue against the other component.

Hide Menu Item

Hi,

Is there a way to remove the 3 dots (Menu Icon) when not been used?

How to update the suggestions list while typing in the searchbar?

I can't figure out how to update the suggestions list in the searchbar when typing in it. Could you help me please?

I have a TextWatcher on the searchbar and when the user types in the text the database is queried in the background, in AsyncTask, and then creates the list of suggestions. Then, it executes the method of my Activity which sets the suggestions to the searchbox.

Here is what that method does:

public void updateSearch(List<Suggestion> suggestions) {
        customSuggestionsAdapter.setSuggestions(suggestions);
        searchBar.setCustomSuggestionAdapter(customSuggestionsAdapter);
}

But nothing happens in the searchbox. That is, the suggestion list does not appear. If I press the back button on the searchbar and disable the search and then enable it again, that is, I press on the search bar, then the suggestion list appears, so I gather it was actually set to the searhbar but did not refresh on the screen. But what should I do to make it appear and change while typing in the searchbox?
As a stupid hack I can get it around by automatic disable and enable of the seachBar right after I set the suggestion adapter, but that update doesn't look good visually, and I suppose I just missed something simple.

EditText cursor color

Currently the cursor for the EditText box for me is defaulting to white due to our apps theme but I want to set the color of the cursor in the search bar specifically so it can actually appear clearly over its white background. Any chance of getting access to the textCursorDrawable() method or something similar to the Hint and Text color methods?

Missing IME option

The IME option actionSearch is not working (there's not search icon in the keyboard) because you're missing the inputType. Just add android:inputType="text" to the EditText within searchbar.xml and it will work (tested on some device)

PlaceHolder BUG?

Hi,thanks for the library.And I may find a bug.
When I disable NavButton,set placeholder and set optionMenu like:

searchBar.setNavButtonEnabled(false); searchBar.setPlaceHolder("Google Play"); searchBar.inflateMenu(R.menu.main);

The placeholder move to right next to the three dot(menu icon).
Here's the screen short: link.
I don't know if it's a bug or I use it in a wrong way.
Thanks.

cannot use search and history suggestion fiture

package com.mancj.example;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.Gravity;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import com.mancj.materialsearchbar.MaterialSearchBar;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, MaterialSearchBar.OnSearchActionListener {
MaterialSearchBar searchBar;
private DrawerLayout drawer;
private RecyclerView recyclerView;
private ArrayList data;
private DataAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initViews();

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    searchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
    searchBar.setOnSearchActionListener(this);
    searchBar.inflateMenu(R.menu.main);
}

private void initViews(){
    recyclerView = (RecyclerView)findViewById(R.id.card_recycler_view);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    loadJSON();
}

private void loadJSON(){
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    client.readTimeout(60, TimeUnit.SECONDS);
    client.connectTimeout(60, TimeUnit.SECONDS);
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://192.168.1.16")
            .client(client.build())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    RequestInterface request = retrofit.create(RequestInterface.class);
    Call<JSONResponse> call = request.getJSON();
    call.enqueue(new Callback<JSONResponse>() {
        @Override

        public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
            JSONResponse jsonResponse = response.body();
            data = new ArrayList<>(Arrays.asList(jsonResponse.getPerson()));
            adapter = new DataAdapter(data);
            recyclerView.setAdapter(adapter);
        }

        @Override
        public void onFailure(Call<JSONResponse> call, Throwable t) {
            Log.d("Error",t.getMessage());
        }
    });
}


@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

@Override
public void onSearchStateChanged(boolean enabled) {

}

@Override
public void onSearchConfirmed(CharSequence text) {

}

@Override
public void onButtonClicked(int buttonCode) {
    switch (buttonCode){
        case MaterialSearchBar.BUTTON_NAVIGATION:
            drawer.openDrawer(Gravity.LEFT);
            break;
        case MaterialSearchBar.BUTTON_SPEECH:
    }
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.