view-holder-generator


Source link: https://github.com/molikto/view-holder-generator

view holder generator for Android

Android dev is painful. for example, findViewById(). some project like butterknife try to solve it by view injection. but is this really a good solution? the ideal way is for one view, only give it a name once. but using view injection, you still need to write the name three times:

@InjectView(R.id.subtitle) TextView subtitle;
android:id="@+id/subtitle"

an alternative approach is use a uniform binding pattern between Java field names and view ids. using this tool, a layout file like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  holder="main.MainAct"
  android:id="@+id/nav">

<LinearLayout

android:id="@+id/profile"

style="@style/nav_item">

 <ImageView

 style="@style/image"

 android:id="@+id/image">

 <TextView

 style="@style/main_nav_left_item_text"/>
  </LinearLayout> </LinearLayout>

will generate code in the MainAct class which is specified in the xml holder attribute:

 LinearLayout _nav;
  LinearLayout _nav_profile;
  ImageView _nav_profile_image;

private void __find_views_main_nav_left(View view) {

_nav = ((LinearLayout)  view);

_nav_profile = ((LinearLayout) ((ViewGroup) view).getChildAt(0));

_nav_profile_image = ((VRounded) ((ViewGroup)((ViewGroup) view).getChildAt(0)).getChildAt(0));

  
}

protected View __inflate_view_main_nav_left(LayoutInflater inflater, ViewGroup parent) {

View view = inflater.inflate(com.p1.mobile.putong.R.layout.main_nav_left, parent, false);

__find_views_main_nav_left(view);

return view;
  
}

then you can use the __inflate_view_ or __find_views_ methods whatever way you want

for example, in a activity, setContentView(__inflate_view_) and in a custom view __find_views_(this) inside onInflateFinished

it will skip ( flatmap) all the views that has no id. and the field names is generated by stacking all the ids together. i use this approach because the names preserved the tree structure of the xml naturally. because in practice it is very hard to give proper names for views if it is nested too much

just a demo

  • it should be easy to support include and merge tags, but it is not done yet
  • and should be easy to support inner classes...
  • it do not support layout files for multiple folders now. i think you can do this by do not generate getChildAt calls, but view.findViewById() calls. but be careful with name collision if you want to use the stacked short name approach. alternatively, you can just do not stack them at all. then it is just a better butterknife
  • imports is not generated. but with IntelliJ IDEA, i hardly found it a inconvenience

Resources

Sherlock reports any crash that occurres in your application as a notification. You just need to initialize Sherlock at the start of your application and it will take care of the rest.

Receiving and parsing SMS messages on Android devices.

TextInputLayout and TextInputEditText merged into one class. Just for convenience and for removing some boilerplate code.

ChromeLikeTabSwitcher is an Android-library, which provides a tab switcher similar to the one, which is used in the Android version of Google's Chrome browser. It provides layouts optimized for smartphone and tablet devices.

Wrapper of StrictMode API that can be safely called on any version of Android.

Android project to experiment the VIPER approach.

Motivations

  • Tend toward the VIPER approach
  • Make it easier to test the application
  • Simplify the set up of asynchronous job with RxJava

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