binding-tc


Source link: https://github.com/OleksandrKucherenko/binding-tc

binding-tc

First Name: ArtfulBits Binding Second Name: Android Easy Binding (AEB)

Android View properties binding to the Business Objects (POJO).

Why TC suffix? TC - Take Care!

State

Active development, started at: 2014-05-15

Changes: Changes Log

Roadmap (v1.0.0 - v2.0.0): Road Map

Compare to Android Binding: Comparison

Goals

  • High performance,
  • easy syntax,
  • minimalistic approach,
  • highly customizable,
  • hamcrest validation syntax,
  • serializable binding configuration
  • 100% covered by unit tests, TDD

#Binding In Details

Example of Usage

Typical Business Object declared in POJO way (with Observable pattern):

public class Pin extends Observable {

private String mPassword;
private String mConfirmPassword;
 /** Calculated message based on state of instance. */
public int getMessage() {

  if (TextUtils.isEmpty(mPassword) || TextUtils.isEmpty(mConfirmPassword))

 return R.string.msgPasswordPatternFail;

if (mPassword.length() < 4 || mPassword.length() > 6)

 return R.string.msgPasswordPatternFail;

if (mConfirmPassword.length() < 4 || mConfirmPassword.length() > 6)

 return R.string.msgPasswordPatternFail;

return mPassword.equals(mConfirmPassword) ?

R.string.msgPasswordOK :

R.string.msgPasswordFail;

}

 public String getConfirmPassword() {

  return mConfirmPassword;

}

 public void setConfirmPassword(final String confirmPassword) {

  mConfirmPassword = confirmPassword;

setChanged();

  notifyObservers("ConfirmPassword");

}

 public String getPassword() {

  return mPassword;

}

 public void setPassword(final String password) {

  mPassword = password;

setChanged();

  notifyObservers("Password");

}
 
}

Fragment binding:

import com.artfulbits.binding.*;  import static com.artfulbits.binding.toolbox.Binders.*; import static com.artfulbits.binding.toolbox.Listeners.*; import static com.artfulbits.binding.toolbox.Models.*; import static com.artfulbits.binding.toolbox.Molds.*; import static com.artfulbits.binding.toolbox.Views.*; import static org.hamcrest.core.IsAnything.anything;  /** Login fragment with simplest UI. */ public class PinFragment extends BindingFragment {

 private final Pin mPin = new Pin();

 public PlaceholderFragment() {

}

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

  return inflater.inflate(R.layout.fragment_pin, container, false);

}

 @Override
public void onCreateBinding(final BindingManager bm) {

  /** 
  * EXPLANATION: 
  * - we listen to user input in et_password and et_confirm_password 
  * - during update of the model instance by entered text we expect Observable callbacks 
  * - observable callback force Binding update of UI label - tv_feedback 
  * 
  * USE CASE: 
  * - on wrong password display Error message 
  * - on correct password display OK message, 
  * - Correct pattern: pin contains at least 4 digits and not more than 6 
  */

// do binding only from UI side, only PUSH
  Binders.strings(bm) // <CharSequence - to - String>

.view(editText(getView(), R.id.et_password))

.onView(anyOf(onTextChanged(), onFocusLost()))

.model(pojo(mPin, text("Password")))

.format(onlyPush(fromCharsToString()))

.validate(Matchers.anyOf(blankString(), matchesPattern("[0-9]{
4,6
}
")));

Binders.strings(bm) // <CharSequence - to - String>

.view(editText(getView(), R.id.et_confirm_password))

.onView(anyOf(onTextChanged(), onFocusLost()))

.model(pojo(mPin, text("ConfirmPassword")))

.setTag(R.id.tag_test, "test");

// POP message from model to View only, do that on model state change
  Binders.numeric(bm) // <CharSequence - to - Integer>

.view(textView(getView(), R.id.tv_feedback))

.model(pojo(mPin, integer("Message")))

.onModel(onObservable())

.format(onlyPop(new ToView<CharSequence, Integer>() {

  @Override

  public CharSequence toView(final Integer value) {

 return getString(value);

  
}

}
));

}
 
}

Extended lifecycle

AEB adding a new step into lifecycle onCreateBinding() it executed after the onAttachedToWindow() and before onCreateOptionsMenu().

Generic Concept Overview

Binding Concept

Abstractions

Abstractions and Responsibilities

License

The MIT License (MIT) Copyright (c) 2014-2015 Oleksandr Kucherenko, ArtfulBits Inc. 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

AirMapView is a view abstraction that enables interactive maps for devices with and without Google Play Services. AirMapView is built to support multiple native map providers.

Java client for the Thumbor image service which allows you to build URIs in an expressive fashion using a fluent API.

Android Library Finder

An Android library that allows you to figure out the quality of the current user's internet connection. The connection gets classified into several "Connection Classes" that make it easy to develop against. The library does this by listening to the existing internet traffic done by your app and notifying you when the user's connection quality changes. Developers can then use this Connection Class information and adjust the application's behavior.

Android APT Plugin for Gradle. Makes sources generated by annotation processors visible in Android Studio.

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