AttributesDispatcher


Source link: https://github.com/pavel163/AttributesDispatcher

AttributesDispatcher

It is a lightweight library which helps to create a custom view.

The library is 100% reflection-free.

Usage

AttributesDispatcher introduces a few annotations:

NOTE: Annotated methods and fields must not be private.

Annotation Required Description
@CustomView ? Register Custom View. Annotation @CustomView require package name of application
@Attribute Annotate a method which performs the action that requires one or more attributes
@BooleanAttr Annotate fields or parameters with @BooleanAttr and a custom boolean format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default false.
@ColorAttr Annotate fields or parameters with @ColorAttr and a custom color format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default 0.
@DimenAttr Annotate fields or parameters with @DimenAttr and a custom dimension format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default 0f.
@FloatAttr Annotate fields or parameters with @FloatAttr and a custom float format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default 0f.
@IntAttr Annotate fields or parameters with @IntAttr and a custom integer format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default -1.
@ReferenceAttr Annotate fields or parameters with @ReferenceAttr and a custom reference format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default -1.
@StringAttr Annotate fields or parameters with @StringAttr and a custom string format attribute for Attribute to find and automatically cast the corresponding attribute in your view. By default ""

Example

1. Create custom declare-styleable

<resources>
  <declare-styleable name="MyCustomView">

<attr name="custom_text" format="string" />

<attr name="custom_color" format="color" />
  </declare-styleable> </resources>

2. In your layout

 <com.ebr163.android.attributesdispatcher.view.MyCustomView

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:custom_text="Text1"

app:custom_color="@android:color/holo_blue_light" />

3. Attach annotations

@CustomView("com.ebr163.android.attributesdispatcher") public class MyCustomView extends EditText {

@StringAttr("custom_text")
  protected String text;

 @ColorAttr(value = "custom_color", defaultValue = Color.GREEN)
  public int color;

public MyCustomView(Context context) {

super(context);

  
}

 @Attribute
  protected void setCustomAttr(@ColorAttr("custom_color") int color) {

this.setTextColor(color);

  
}
 
}

4. Delegate to generated class

 public MyCustomView(Context context, AttributeSet attrs) {

super(context, attrs);

MyCustomViewAttribute.init(this, attrs);

  
}

public MyCustomView(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

MyCustomViewAttribute.init(this, attrs);

  
}

Note

  • The name of the custom view and the name of the declare-styleable should be the same
  • The parameters of the method with @Attribute must be annotated with

Installation

To add it to your project, include the following in your build.gradle file:

allprojects {

repositories {

 ...
 maven {
 url 'https://jitpack.io' 
}

}
  
}

And on your app module build.gradle:

  compile 'com.github.pavel163.AttributesDispatcher:library:1.1.1'
annotationProcessor 'com.github.pavel163.AttributesDispatcher:compiler:1.1.1'

Licence

Copyright 2016 Ergashev Bakht.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

CircleMenu is a simple, elegant menu with a circular layout.

A fast, light-weight and powerful Play Store information fetcher for Android.

This library allows you to fetch various live information from Play Store of your app or any other app of your choice. With just a few lines of code, you can get access to a lot of useful app data fetched fresh from the Play Store.

An Android Library to load your GIF files directly

PermissionsManager library that has base activity and fragment that extend from AppCompatActivity to ease with the handling of runtime permissions.

It's a simple MVP implementation. With this library every developer can integration pattern MVP in him project. To add presenter to Activity or Fragment, the developer need write only one row - setPreseter(ExamplePresenter.class);

This library does support MVP pattern for Activities, Fragments and RecyclerViewAdapter.

Android View Styleable Attribute Binding

Easily obtain and bind styleable attribute values. Annotate your styleable fields:

java @Styleable(R.styleable.CustomView_showText) boolean showText; @ColorInt @Styleable(value = R.styleable.CustomView_textColor, defaultRes = R.color.default_text_color) int textColor;

Then call the static obtain method providing the View object instance as the target, the AttributeSet containing the values, and any additional parameters:

java Glimpse.obtain(this, attrs);

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