Coder Social home page Coder Social logo

huyanghu / reel-search-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from forkachild/reel-search-android

0.0 2.0 0.0 12.86 MB

Reel Search for Android is a UI/UX design for autocomplete action. It is a beautiful minimalistic addition to any use case.

License: MIT License

Kotlin 2.76% Java 97.24%

reel-search-android's Introduction

Reel Search for Android

Release

Watch it in action

Screencast

Add to Gradle

Add this to your project level build.gradle file

repositories {
    maven { url "https://jitpack.io" }
}

And then add this to your module level build.gradle file

dependencies {
    implementation "com.github.forkachild:reel-search-android:${latest-version}"
}

How it works

The design is highly inspired from RAMReel by @Ramotion, brilliant work guys.

It is based around a custom LayoutManager named CenteredLayoutManager which provides top and bottom offsets for the scrolling suggestions in a RecyclerView. All of it is conveniently enclosed in the ReelSearchView which coordinates with its children to realise the reel effect.

A detailed blog on the making of this is available at Reel Search and LayoutManager: An Android journey.

How to setup

The ReelSearchView is a ViewGroup and it can contain exactly 2 views. The first being a RecyclerView or any subclass of it, and the second being an EditText or any subclass of it.

Add it to a layout

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    tools:context=".SuggestionsActivity">

    <com.suhel.library.ReelSearchView
        android:id="@+id/reelSearch"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  
        <android.support.v7.widget.RecyclerView
            android:id="@+id/lstSuggestions"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            android:paddingStart="8dp"
            android:paddingEnd="8dp" />
  
        <EditText
            android:id="@+id/txtQuery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/colorTransparent"
            android:fontFamily="sans-serif-light"
            android:hint="Start typing"
            android:paddingStart="16dp"
            android:paddingEnd="16dp"
            android:textColor="@color/colorBlack"
            android:textColorHint="@color/colorGrey"
            android:textSize="32sp" />

    </com.suhel.library.ReelSearchView>

</android.support.design.widget.CoordinatorLayout>

Create a layout for an item for the RecyclerView

<TextView
    android:id="@+id/tvSuggestion"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif-light"
    android:paddingStart="8dp"
    android:paddingTop="2dp"
    android:paddingEnd="8dp"
    android:paddingBottom="2dp"
    android:textColor="@color/colorGrey"
    android:textSize="32sp" />

Create an adapter

I am not going to guide through this part as it is out of scope. Please refer to SuggestionsAdapter or google.

Use it in the Activity

ReelSearchView reelSearch = findViewById(R.id.reelSearch);
RecyclerView lstSuggestions = findViewById(R.id.lstSuggestions);
EditText txtQuery = findViewById(R.id.txtQuery);

SuggestionsAdapter adapter = new SuggestionsAdapter(this);
TextWatcher textWatcher = new TextWatcher() {

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // Fetch list here and assign data to adapter
    }
    
    @Override
    public void afterTextChanged(Editable s) {
    }

}

txtQuery.addTextChangedListener(textWatcher);
lstSuggestions.setAdapter(adapter);

Features

Get current selected position

The item selected, in the middle underlying the query EditText, can be found through a simple method

int position = ReelSearchView.getSelection()

Set OnSelectionChangedListener

ReelSearchView.setOnSelectionChangedListener(listener);

Child transformer

What if I told you that the soft gradient of alpha is configurable. ChildTransformer is an interface settable through setChildTransformer() call.

It contains a method

void onApplyTransform(@NonNull View child,
                              @IntRange(from = 0, to = Integer.MAX_VALUE) int index,
                              @IntRange(from = 0, to = Integer.MAX_VALUE) int screenPosition,
                              @FloatRange(from = -1.0f, to = 1.0f) float centerOffset);

which gets called on each child when they are laid out. AlphaChildTransformer is already attached as a ChildTransformer which accomplishes the alpha gradient. You are only limited by your imagination

Thanks!

P.S You can always buy me a beer or a coffee through PayPal

LICENSE

MIT License

Copyright (c) 2019 Suhel Chakraborty

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

reel-search-android's People

Contributors

forkachild avatar

Watchers

James Cloos avatar xiongxiaolong avatar

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.