Friday 29 January 2016

Swipe Number Picker

SwipeNumberPicker

The library provides simple number picker. The number is selected with the swipe gesture, to right - increase, to left - decrease value. Also, by click NumberPickerDialog will be shown.
Demo

Usage
Just add the dependency to your build.gradle:
dependencies {
    compile 'com.github.supervital:swipenumberpicker:1.0.3'
}
In layout:
<com.vi.swipenumberpicker.SwipeNumberPicker
    android:id="@+id/number_picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    app:snp_numberColor="@android:color/white"
    app:snp_arrowColor="@android:color/white"
    app:snp_backgroundColor="@color/colorAccent"
    app:snp_max="1000"
    app:snp_min="50"
    app:snp_value="95"/>
Attributes:
    <attr name="snp_min" format="integer"/>
    <attr name="snp_max" format="integer"/>
    <attr name="snp_value" format="integer"/>
    <attr name="snp_arrowColor" format="color"/>
    <attr name="snp_backgroundColor" format="color"/>
    <attr name="snp_numberColor" format="color"/>
To set changed value implement the OnValueChangeListener listener and on onValueChange return true
    swipeNumberPicker.setOnValueChangeListener(new OnValueChangeListener() {
        @Override
        public boolean onValueChange(SwipeNumberPicker view, int oldValue, int newValue) {
            boolean isValueOk = (newValue & 1) == 0;
            if (isValueOk)
                result1.setText(Integer.toString(newValue));

            return isValueOk;
        }
    });
Also you can:
  • disable/enable SwipeNumberPicker;
  • disable/enable Showing of a NumberPicker Dialog. If the dialog disabled View.OnClickListener will be called;
  • set the dialog title;
  • set min, max values;
  • set value;
  • set intermediate mode.

Simple Arc Loader

SimpleArcLoader

  • bored of seeing the same old Android Loader ? SimpleArcLoader is one thing you should try.

Preview

 

Setup

Gradle

  dependencies {
      compile 'com.leo.simplearcloader:simplearcloader:1.0.0'
  }

Example 1

To show dialog
SimpleArcDialog mDialog = new SimpleArcDialog(this);
mDialog.setConfiguration(new ArcConfiguration(this));
mDialog.show();

Example 2

Making use of just the Loader
<com.leo.simplearcloader.SimpleArcLoader
  android:visibility="visible"
  android:id="@+id/loader"
  android:layout_centerInParent="true"
  android:layout_width="60dp"
  android:layout_height="60dp"
  custom:arc_style="simple_arc"
  custom:arc_speed="medium"
  custom:arc_margin="3dp">
</com.leo.simplearcloader.SimpleArcLoader>

Example 3

Customizing Dialog/SimpleArcLoader View using ArcConfiguration
ArcConfiguration configuration = new ArcConfiguration(context);
configuration.setLoaderStyle(SimpleArcLoader.STYLE.COMPLETE_ARC);
configuration.setText("Please wait..");

// Using this configuration with Dialog 
mDialog.setConfiguration(configuration);

// Using this configuration with ArcLoader
mSimpleArcLoader.refreshArcLoaderDrawable(configuration);
You can customize Arc/Dialog with ArcConfiguration methods -
  • setLoaderStyle(SimpleArcLoader.STYLE mLoaderStyle)
  • setArcMargin(int mArcMargin)
  • setArcWidthInPixel(int mStrokeWidth)
  • setColors(int[] colors)
  • setTypeFace(Typeface typeFace)
  • setText(String mText)
  • setTextColor(int mTextColor)
  • setTextSize(int size)
  • setAnimationSpeedWithIndex(int mAnimationIndex) Values to be passed SimpleArcLoader.SPEED_SLOW, SimpleArcLoader.SPEED_MEDIUM, SimpleArcLoader.SPEED_FAST
Please refer the examples for some of the customization.

Saturday 23 January 2016

Floating Search View


Floating Search View

Yet another floating search view implementation, also known as persistent search: that implementation fully supports menu (including submenu), logo and animated icon. Dropdown suggestions are backed by a RecyclerView and you can provide your own RecyclerView.AdapterItemDecorator or ItemAnimator. No hiding.

Usage

Add a FloatingSearchView to your view hierarchy, make sure that it takes up the full width and height:
<com.mypopsy.widget.FloatingSearchView
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="16dp"
        android:paddingRight="8dp"
        android:paddingLeft="8dp"
        android:background="#90000000"
        android:hint="@string/hint"
        app:logo="@drawable/logo"
        app:fsv_menu="@menu/search"/>
Then, configure your instance and set your listeners to react accordingly:
mSuggestionsAdapter = new MySuggestionsAdapter(); // use a RecyclerView.Adapter
mSearchView.setAdapter(mSuggestionsAdapter);
...
mSearchView.setOnIconClickListener(...);
mSearchView.setOnSearchListener(...);  
mSearchView.addTextChangedListener(...);
mSearchView.setOnSearchFocusChangedListener(...);
Look at the sample.

Menu

The implementation fully supports menu (and submenu):
<com.mypopsy.widget.FloatingSearchView
    ...
    app:fsv_menu="@menu/search"
/>
mSearchView.setOnMenuItemClickListener(...);
Menu items can be automatically hidden when the search view gets focus depending on the value of the MenuItem'sshowAsAction:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/menu1" ... app:showAsAction="always"/> // always shown
    <item android:id="@+id/menu2" ... app:showAsAction="ifRoom"/> // will hide on focus 
    <item android:id="@+id/menu3" ... app:showAsAction="never"/>  // will go into the overflow menu
</menu>

Animated Icon

FloatingSearchView will automagically animate icons drawable, given they declare a progress property:
  • void setProgress(float)
  • float getProgress()

Other

Since the implementation tries to focus on core logic instead of business logic as much as possible, common features like"tap to clear""speech to text" or "loading progress" are voluntarily NOT built-in because they can be easily implemented using menu items as seen in the sample.

Styling

FloatingSearchView do not expose most of TextView's XML attributes (textColor,textSize...). You can style them using theme attributes by applying app:theme for example:
First, create a dedicated theme, possibly heriting from your application theme:
<!-- your custom theme -->
<style name="CustomFloatingSearchViewTheme" parent="AppTheme">
    <item name="editTextStyle">@style/searchViewEditTextStyle</item>
    <item name="android:divider">#c9c9c9</item>
    <item name="android:dividerHeight">1dp</item>
    <item name="colorControlNormal">#696969</item>
</style>

<!-- your custom search view text style --> 
<style name="searchViewEditTextStyle" parent="Widget.AppCompat.EditText">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">?android:attr/textColorPrimary</item>
    <item name="android:imeOptions">actionSearch</item>
</style>
Then, apply your custom theme through app:theme:
<com.mypopsy.widget.FloatingSearchView
    ...
    app:theme="@style/CustomFloatingSearchViewTheme"
/>
Look at the sample.

Install

This repository can be found on JitPack:
Add it in your root build.gradle at the end of repositories:
allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }
Add the dependency:
dependencies {
            compile 'com.github.renaudcerrato:FloatingSearchView:1.0.0'
    }

Collapsible Toolbar Helper



Collapsible-Toolbar-Helper


A combination of custom CollapsibleToolbar and Collapsing Text to give you the same effect as App Bar Layout from the Desgin support library sans the use of a Toolbar

ScreenShot


Screenshot

BACKGROUND :


CollapsibleToolbarHelper :

Although the new design support library allows us to do some cool stuff, the available sample code does not cover the potential that it has been built for. Most of the samples that I came across, including the cheese square example by Chris Banes, create the application so that minimum code has to be written.
But what if I want a different layout and implementation? My main requirement was that I did NOT require a Toolbar for my design. When going through the AOSP code for CollapsibleTollbarLayout in the design support library, I realized that it has a tight integration with the Toolbar. So, Initially, I decided to work around that. There are a very few blogs out there that actually go deep into the actual potential of the CollapsibleToolbarLayout.
Few of them are listed below:
  1. Thanks Grzesiek Gajewski
  2. Thanks Saul Molinero
  3. Thanks Rafa Vazquez
In a nutshell, it all boils down to a few things:
  1. Coordinator Layout controls the "behavior" of its children which implement CoordinatoLayout.Behavior Check out NestedScrollView "Behavior" or AppBarLayout "Behavior" or FAB "Behavior" for implementations
  2. AppBarLayout calls on a OnOffsetChangedListener implementation when it scrolls,
    which can be used to do stuff. Check out OnOffsetChangedListener in CollapsingToolbarLayout
Well, that was my premise of creating the CollapsibleToolbarHelper. It of course is derived heavily from the AOSP code, but with a few modifications. It supports the following collapse modes: - MOVE_ON_SCROLL = The children move when the collapsible toolbar collapses to hit the bottom of that view - PARALLAX_ON_SCROLL = THe usual parallax, move and then hide when the Toolbar collapses - PIN_ON_SCROLL = Stays at the position where it is laid out originally - HIDE_ON_COLLAPSE = Stays at its location and hides when the toolbar is collapsed - SHOW_ON_COLLAPSE = Is hidden at the location that it is supposed to and appears after the Toolbar has collapsed Note that it has to be used as a direct child of AppBarLayout since it depends on the OffsetChangedListener of the AppBarLayout to collapse and expand.

CollapsibleTextLayout :

Since I was designing the CollapsibleToolbar, I required a CollapsibleText as well. But the default CollapsibleTextHelper is coupled too tightly with the CollapsingToolbarLayout and not public to be modified. So, taking inspirations from AOSP, Chris banes' Philm and Nick Butchers Plaid, I wrote my own CollapsingTextlayout.
I know that there is a lot of room for improvement and that there are obvious optimizations and feature enhancements, but the main objective of re-writing these widgets was learning. I have collected all the ideas from the given references and tried to simplify the implementation as much as possible. The code is commented and should be self explanatory.
Interested? Well go ahead, download and use the widgets.

Usage

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:paddingBottom="30dp"
        android:theme="@style/AppTheme.AppBarOverlay"
        >

        <abysmel.com.collapsibletoolbarhelper.widgets.CollapsibleToolbarHelper
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:gravity="center_vertical"
            android:layout_marginTop="10dp"
            android:background="@android:color/transparent"
            >

            <!--Note that the position has to be set with respect to the collapsed toolbar. So,
                aligning it in center initially (centerInParent="true") will NOT work as it will remain
                at its position even after the Toolbar collapses. Also note that the initially set the
                alpha of the view to zero and NOT the visibility to gone, as the view will then have never
                been drawn which will throw all calculations haywire for show_on_collapse. Wish there
                was a better way to do this-->
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hello.img"
                android:src="@mipmap/hello"
                android:layout_marginLeft="10dp"
                android:alpha="0"
                app:layout_marginTopPercent = "3%"
                app:collapseMode="show_on_collapse"/>

            <!-- Title -->
            <abysmel.com.collapsibletoolbarhelper.widgets.CollapsibleTextLayout
                android:id="@+id/hello.text"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                app:layout_widthPercent="59%"
                android:layout_alignParentLeft="true"
                app:layout_marginTopPercent = "1%"
                app:layout_marginBottomPercent = "1%"
                app:layout_marginLeftPercent="5%"
                android:textColor="@android:color/white"
                app:collapseMode="pin_on_scroll"
                app:textToShow = "Hello World"
                app:expandedTextColor = "@android:color/white"
                app:collapsedTextColor = "@android:color/white"
                app:typefaceFamilyPrimary = "sans-serif-light"
                app:typefaceFamilySecondary = "sans-serif-medium"
                app:isMultiFaceted="true"
                app:typefaceSplitPosition="5"
                app:expandedTextSize = "62dp"
                app:collapsedTextSize = "32dp"
                app:maxExpandedTextSize = "62dp"
                />

            <!-- The hello number edit button -->
            <ImageView
                android:id="@+id/hello.edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                app:layout_marginTopPercent = "3%"
                app:layout_marginBottomPercent = "1%"
                app:layout_marginRightPercent = "4%"
                android:layout_marginLeft="10dp"
                android:src="@mipmap/pencil"
                app:collapseMode="hide_on_collapse"/>

            <!-- The hello Number -->
            <TextView
                android:id="@+id/hello.number"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                app:layout_widthPercent="40%"
                app:layout_marginTopPercent = "1%"
                app:layout_marginBottomPercent = "1%"
                app:layout_marginRightPercent = "1%"
                android:layout_toLeftOf="@id/hello.edit"
                android:layout_toRightOf="@id/hello.text"
                android:gravity="end"
                android:text="@string/hello_no_sign"
                android:textColor="@android:color/white"
                android:textSize="@dimen/hello_no_size"
                app:collapseMode="pin_on_scroll"/>



            <!-- Version -->
            <TextView
                android:id="@+id/version"
                app:layout_widthPercent="40%"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_below="@id/hello.text"
                android:layout_marginTop="5dp"
                android:layout_alignParentLeft="true"
                app:layout_marginLeftPercent="5%"
                android:text="@string/version"
                android:textColor="@android:color/white"
                android:textSize="@dimen/version_no_size"
                app:collapseMode="parallax_on_scroll"
                 />

            <!-- E-mail Address -->
            <TextView
                android:id="@+id/hello.address"
                app:layout_widthPercent="40%"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:layout_below="@id/hello.number"
                android:layout_alignParentRight="true"
                android:gravity="end"
                app:layout_marginRightPercent="5%"
                android:text="@string/emailaddress"
                android:textColor="@android:color/white"
                android:textSize="@dimen/mail_address_size"
                app:collapseMode="parallax_on_scroll"
                 />
        </abysmel.com.collapsibletoolbarhelper.widgets.CollapsibleToolbarHelper>
    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>