LessCode Android Utility Library

repository·master·Indexed 21 days ago

https://github.com/openproject/lesscode

A lightweight, high-performance Android utility library designed to reduce boilerplate code. It provides helper modules including ActivityLess for window management, ViewLess for simplified view casting, HttpLess for networking, and various other utilities for image processing, shared preferences, and device information.

Tokens
792
Snippets
5
Records
6
Agent score
26%

What's inside LessCode

  1. Overview of LessCode features

    master

    LessCode is a high-performance Android utility library designed to reduce boilerplate code. Key modules include:

    • ActivityLess: Helpers for Activity tasks (no title, full screen, exit prompts, overdraw optimization).
    • AdapterLess: Base adapters for ListView, PagerAdapter, and RecyclerView.
    • AppLess: App metadata (version, name, signature) and cache cleaning.
    • BitmapLess/ImageLess: Bitmap and image processing.
    • DisplayLess: Screen utilities (dp/px conversion, status bar height, DPI).
    • HttpLess: Simple HTTP utility (not recommended for complex professional use).
    • LogLess: Advanced logging.
    • SharedPreferenceLess: Simplified SharedPreference operations.
    • ViewLess: Simplified findViewById and type casting.
    • Other modules: AlarmLess, CacheLess, DeviceLess, DrawableLess, EncodeLess, FileLess, KeyBoardLess, NetworkLess, ResourceLess, SerializeLess, StorageLess, ToastLess, and UpdateLess.
  2. Configure the LessCode instance

    master

    To use LessCode, you must initialize the singleton instance. A context is required. You can also optionally configure logging, update frequency, and HTTP timeouts.

    // Required initialization
    $.getInstance()
     .context(getApplicationContext())
     .build();
    
    // Optional configuration
    $.getInstance()
     .context(getApplicationContext())
     .log(BuildConfig.DEBUG, "LESSCODE") // LogLess - debug, tag
     .update(null, 5) // UpdateLess - null means the default value, 5 is the notification frequent
     .http(5000, 5000) // HttpLess - default connect and read timeout
     .build();
  3. Use ViewLess to simplify View casting

    master

    Instead of manually casting views using findViewById, use ViewLess.$ to find and cast a view in a single step.

    // Before
    ListView listView = (ListView) findViewById(R.id.list);
    
    // After
    ListView listView = ViewLess.$(this, R.id.list);
  4. Use ActivityLess for window management

    master

    ActivityLess provides helper methods to manage common Activity window tasks like removing titles or enabling full-screen mode.

    // Remove title and enable full screen
    ActivityLess.$noTitle(this);
    ActivityLess.$fullScreen(this);