FlowLayout


Source link: https://github.com/WassimBenltaief/FlowLayout

FlowLayout

A custom Layout able to display content, empty view, progress bar and network connectivity status.

  1. Why this layout
  2. Download
  3. How
  4. Connectivity Awareness
  5. Customize connectivity view (colors / text / layout)
  6. Customize empty view
  7. Customize progress view
  8. Customize error view
  9. PR
  10. TODOS

#Why this layout A very common flow of an android view is :

  • show a progress bar while fetching data from a remote service.
  • if the resut is empty : show an empty view with a custom message and hide the progressbar.
  • If not : show the content and hide the progressbar.
  • showing a notification when phone is not connected or when action requires internet connection.

FlowLayout do all of this for you with a very few code in a customized way.

#Download

compile 'com.beltaief.flowlayout:flowlayout:0.4.0'

#How

FlowLayout extends a FrameLayout. So add it to your view as a regular View and compose inside it :

in your activity_layout.xml :

<com.beltaief.flowlayout.FlowLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/flow_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

// content goes here  </com.beltaief.flowlayout.FlowLayout>

then in your Activity/Fragment :

@Override protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_layout);

 // lookup for the layout
  FlowLayout flowLayout = (FlowLayout)findViewById(R.id.flow_layout);

 //set mode progress
  flowLayout.setMode(ViewMode.PROGRESS);

 // fetch data
  ...

 // assign result to the view
  if (data.isEmpty()) {

 flowLayout.setMode(ViewMode.EMPTY);

  
}
 else {

 flowLayout.setMode(ViewMode.CONTENT);

 // show the data in the view

 ...
  
}

 ...

// or set error view
  flowLayout.setMode(ViewMode.ERROR);
 
}
content mode empty mode

#Connectivity awareness If you would like the view to notify when connectivity status changes, then add this attribute to the XML declaration of FlowLayout :

app:isConnectivityAware="true"

or programmatically

flowLayout.setConnectivityAware(true);

And the view will be able to notify whenever the status of the internet connection changes :

Customize connectivity

FlowLayout comes with several attributes to help customizing the connectivity view. Add attributes to your xml to apply customization :

to customize color and/or text in the default connectivity view

app:isConnectivityAware="true" // true, false app:connectedText="@string/connectedTextStringResource" // text to show when connected app:connectedTextColor="@color/connectedTextColorResource" // text color app:connectedBackground="@color/connectedBackgroundColorResource" // background color app:disconnectedText="@string/disconnectedTextStringResource" // text to show when disconnected app:disconnectedTextColor="@color/disconnectedTextColorResource" // text color app:disconnectedBackground="@color/disconnectedBackgroundColorResource" // background color

or i you want to provide your own layout content :

app:connectedLayout="@layout/custom_connected_layout" app:disconnectedLayout="@layout/custom_disconnected_layout"

Example :

<com.beltaief.flowlayout.FlowLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/reveLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:isConnectivityAware="true"
  app:connectedText="@string/connected_message"
  app:connectedTextColor="@color/white"
  app:connectedBackground="@color/blue_light"
  app:disconnectedBackground="@color/colorAccent">

<android.support.v7.widget.RecyclerView

android:id="@+id/recycler"

android:layout_width="match_parent"

android:layout_height="wrap_content" />  </com.beltaief.flowlayout.FlowLayout> 

or programmatically :

flowLayout.setConnectivityAware(true);
  flowLayout.setConnectedText(R.string.connected_message);
 flowLayout.setConnectedTextColor(R.color.connected_color);
 flowLayout.setConnectedBackground(R.color.connected_color);
  flowLayout.setDisconnectedText(R.string.text_disconnected);
 flowLayout.setDisconnectedTextColor(R.color.disconnected_color);
 flowLayout.setDisconnectedBackground(R.color.disconnected_color);
 

Screenshot

Customize Empty View

There's two ways to customize the empty view :

  1. custom text and color : To override the default text and colors, add a reference to your custom text/color in xml
app:emptyLayout="@layout/custom_empty" app:emptyText="@string/text_empty" app:emptyTextColor="@color/text_empty_color"

or programmatically :

flowLayout.setEmptyLayout(R.layout.layout_empty);
 flowLayout.setEmptyText(R.string.text_empty);
 // Do not combine with .setEmptyLayout() flowLayout.setEmptyTextColor(R.color.text_empty_color);
 // Do not combine with .setEmptyLayout()
  1. Custom layout : Override the empty layout by providing a reference in xml :
app:emptyLayout="@layout/custom_empty"

or programmatically :

flowLayout.setEmptyLayout(R.layout.layout_empty);

Screenshot

Customize Progress bar :

if you want to provide your own progress view :

app:progressLayout="@layout/custom_progress"

Customize Error View :

if you want to provide your own error view :

app:errorLayout="@layout/custom_error"

PR

Open.

TODOS

  • add customization to progress-bar Done
  • add error view Done
  • use @IntDef for setting view modes Done
  • Use ViewStub
  • any other idea is welcome

#Licence The MIT License (MIT)

Copyright (c) 2014 Neil Stoker

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.

Resources

Run a method once or repeat after some iterations. Super simple, One liners.

Like Button is a library that allows you to create a button with animation effects similar to Twitter's heart when you like something.

Send Button Custom View for chatting application. The custom view developed by drawing path over the coordinates of the figure. And the animation done by continuously changing the coordinates in one direction.

Base skeleton structure to start every new project, based on the design patters suggested by Robert C. Martin (aka Uncle Bob) on his clean architecture.

A simple FastScroller for Android's RecyclerView.

Supports vertical RecyclerViews using either LinearLayoutManager or GridLayoutManager (including multiple spans).

Easy to use Android Reacive Bluetooth library for communicating with microcontrollers. Tiny and simple.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes