Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

AndroidBaseUtils

> 编程语言
Open source

Context free and basic utils to build Android project conveniently

658 stars0 likes1 views
WebsiteGitHub

About

Context free and basic utils to build Android project conveniently

AndroidBaseUtils

Context free and basic utils to build Android project conveniently

Any kinds of contributions including pull requests, registering new issues, sending me personal emails are always welcome. Let me know if you have any idea about basic utils for Android development.

Table of Contents

  1. Get started
  2. Utils
    1. Base
    2. LogUtil (L)
    3. LogHelper
    4. ContextUtil (Ctx)
    5. ResourcesUtil (Res)
    6. PreferencesUtil (Pref)
    7. ExtrasBinder
    8. UnitConverter (Unit)
    9. KeyboardUtil (Keyboard)
    10. APILevel
    11. DisplayUtil
    12. ViewUtil
    13. ServiceUtil
    14. ThemeUtil
    15. ActivityBuilder
    16. BundleBuilder
    17. PackageUtil
    18. VibratorUtil
    19. ClipboardManagerUtil
    20. TypedValueUtil
    21. WindowManagerUtil
    22. IntArrayUtil
    23. SparseArrayUtil
    24. ThreadUtil
  3. Contributors
  4. License

Get started

Gradle Dependency (jcenter)

Release is in process...

java
buildscript {
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
    compile 'com.thefinestartist:utils:0.9.5'
    apt 'com.thefinestartist:compilers:0.9.5'
}

Initialization (Application)

Call Base.initialize(context) within your Application onCreate() method.

java
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Base.initialize(this);
    }
}

Utils

Base

Base helps to get Context, Resources, Assets, Configuration and DisplayMetrics in any class.

java
void            Base.initialize(Context context);

Context         Base.getContext();
Resources       Base.getResources();
Theme           Base.getTheme();
AssetManager    Base.getAssets();
Configuration   Base.getConfiguration();
DisplayMetrics  Base.getDisplayMetrics();

LogUtil (L)

LogUtil helps to deal with Log conveniently.
L is abbreviation class of LogUtil. You can extends LogUtil to create your own L.

…
java
// Set default settings at your Application.
L.getDefaultSettings()
        .setTag(LogUtil.class)
        .setShowThreadInfo(false)
        .setStackTraceCount(0)
        .setLogLevel(LogLevel.FULL)
        .setShowDivider(false)
        .setLogPrinter(new AndroidLogPrinter());
        
L.v("Hello World");
L.tag("Tag").e(12.0f);
L.showThreadInfo(true).i(new int[]{1, 2, 3});
L.stackTraceCount(3).showDivider(true).json("{\"name\":\"Leonardo Taehwan Kim\",\"email\":\"[email protected]\"}");

LogHelper

LogHelper helps to deal with Log conveniently.

…
java
// Set default settings at any Class.
LogHelper logHelper = new LogHelper(MainActivity.class).showThreadInfo(true);

logHelper.v("Hello World");
logHelper.e(12.0f);
logHelper.json("{\"name\":\"Leonardo Taehwan Kim\",\"email\":\"[email protected]\"}");

ContextUtil (Ctx)

ContextUtil helps to use Context conveniently.
Ctx is abbreviation class of ContextUtil. You can extends ContextUtil to create your own Ctx.

…

ResourcesUtil (Res)

ResourcesUtil helps to use Resources conveniently.
Res is abbreviation class of ResourcesUtil. You can extends ResourcesUtil to create your own Res.

…

PreferencesUtil (Pref)

PreferencesUtil helps to manage application-wide preferences conveniently.
Pref is abbreviation class of PreferencesUtil. You can extends PreferencesUtil to create your own Pref.

…

ExtrasBinder

Simply call ExtrasBinder.bind(this) in your Activity or Fragment. ExtrasBinder binds data from Intent or Bundle to matching variable. ExtrasBinder will consider annotation variable as key. If there is no annotation variable, it will consider variable name as key.

java
// Start YourActivity with extras
Intent intent = new Intent(this, YourActivity.class);
intent.putExtra(YourActivity.EXTRA_TITLE, "Activity title");
intent.putExtra("ids", new ArrayList());
startActivity(intent);
java
public class YourActivity extends AppCompatActivity {

    public static final String EXTRA_TITLE = "TITLE";

    @Extra(EXTRA_TITLE) String title;
    @Extra ArrayList ids;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ExtrasBinder.bind(this);
        // do something...
    }
}
java
// Show YourFragment with extras
YourFragment fragment = new YourFragment();
Bundle bundle = new Bundle();
bundle.putString("Name", "Fragment name");
fragment.setArguments(bundle);
java
public class YourFragment extends Fragment {

    @Extra("NAME") String name;
    
    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ExtrasBinder.bind(this);
        // do something...
    }
}

Proguard

java
-keep class com.thefinestartist.annotations.** { *; }
-keep class **$$ExtraBinder { *; }
-keepclasseswithmembernames class * {
    @com.thefinestartist.annotations.Extra ;
}

UnitConverter (Unit)

UnitConverter helps to convert dp or sp size into pixel.
Unit is abbreviation class of UnitConverter. You can extends UnitConverter to create your own Unit.

java
float   Unit.dpToPx(float dp);
int     Unit.dpToPx(int dp);
float   Unit.pxToDp(float px);
int     Unit.pxToDp(int px);
float   Unit.spToPx(float sp);
int     Unit.spToPx(int sp);
float   Unit.pxToSp(float px);
int     Unit.pxToSp(int px);

KeyboardUtil (Keyboard)

KeyboardUtil helps to show and hide keyboard conveniently.
Keyboard is abbreviation class of KeyboardUtil. You can extends KeyboardUtil to create your own Keyboard.

java
void    Keyboard.show(View);
void    Keyboard.showImmediately(View); // Call this method if your activity or fragment is resumed.

void    Keyboard.hide(View);
void    Keyboard.hide(View, clearFocus);
void    Keyboard.hide(Activity);
void    Keyboard.hide(Activity, clearFocus);
void    Keyboard.hide(Fragment);
void    Keyboard.hide(Fragment, clearFocus);
void    Keyboard.hide(Dialog);
void    Keyboard.hide(Dialog, clearFocus);

APILevel

APILevel helps to check device API Build.VERSION conveniently.

  • Update your Android Studio lint option before you use this class. Show Image
java
→ Android Studio  
→ Preferences...  
→ Editor  
→ Inspections  
→ Android Lint  
→ Calling new methods on older versions
→ Set Severity as Warning.
…
java
new ActivityBuilder(YourActivity.class)
    .set(YourActivity.TITLE, "Title")
    .set(YourActivity.CONTENT, 1)
    .set("values", new int[]{1, 2, 3})
    .set(YourActivity.ARRAY_LIST, list)
    .start();

BundleBuilder

BundleBuilder helps to build Bundle conveniently.

java
BundleBuilder   BundleBuilder.set(String key, T value);
T               BundleBuilder.get(String key);
Bundle          BundleBuilder.build();
java
Bundle bundle = new BundleBuilder()
                    .set("values", new int[]{1, 2, 3})
                    .build();

PackageUtil

PackageUtil helps to handle methods related to package.

java
boolean     PackageUtil.isInstalled(String packageName);
String      PackageUtil.getPackageName();
void        PackageUtil.openPlayStore();
void        PackageUtil.openPlayStore(String packageName);

VibratorUtil

VibratorUtil helps to use Vibrator conveniently.

java
void    VibratorUtil.vibrate(); // vibrate device for 200 milliseconds
void    VibratorUtil.vibrate(milliseconds);
// and more...

ClipboardManagerUtil

ClipboardManagerUtil helps to use ClipboardManager conveniently.

java
void            ClipboardManagerUtil.setText(CharSequence text);
boolean         ClipboardManagerUtil.hasText();
CharSequence    ClipboardManagerUtil.getText();

TypedValueUtil

TypedValueUtil helps to use TypedValue class conveniently.

java
float   TypedValueUtil.applyDimension(int unit, float value);
float   TypedValueUtil.complexToDimension(int data);
int     TypedValueUtil.complexToDimensionPixelOffset(int data);
int     TypedValueUtil.complexToDimensionPixelSize(int data);

WindowManagerUtil

WindowManagerUtil helps to use WindowManager conveniently.

java
Display     WindowManagerUtil.getDefaultDisplay();
void        WindowManagerUtil.removeViewImmediate(View view);

IntArrayUtil

IntArrayUtil helps to deal with IntArray conveniently.

java
boolean     IntArrayUtil.contains(int[] array, int value);
int[]       IntArrayUtil.add(int[] array, int value);

SparseArrayUtil

SparseArrayUtil helps to deal with SparseArray conveniently.

java
ArrayList    SparseArrayUtil.asArrayList(SparseArray sparseArray);

ThreadUtil

ThreadUtil helps to deal with thread conveniently.

java
boolean     ThreadUtil.isMain();

Contributors

Leonardo Taehwan Kim
Min Kim
Robin Gustafsson
Marcos Trujillo

License

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Java

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言