Context free and basic utils to build Android project conveniently
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.
Release is in process...
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'
}Call Base.initialize(context) within your Application onCreate() method.
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Base.initialize(this);
}
}Base helps to get Context, Resources, Assets, Configuration and DisplayMetrics in any class.
void Base.initialize(Context context);
Context Base.getContext();
Resources Base.getResources();
Theme Base.getTheme();
AssetManager Base.getAssets();
Configuration Base.getConfiguration();
DisplayMetrics Base.getDisplayMetrics();LogUtil helps to deal with Log conveniently.L is abbreviation class of LogUtil. You can extends LogUtil to create your own L.
…// 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 helps to deal with Log conveniently.
…// 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 helps to use Context conveniently.Ctx is abbreviation class of ContextUtil. You can extends ContextUtil to create your own Ctx.
…ResourcesUtil helps to use Resources conveniently.Res is abbreviation class of ResourcesUtil. You can extends ResourcesUtil to create your own Res.
…PreferencesUtil helps to manage application-wide preferences conveniently.Pref is abbreviation class of PreferencesUtil. You can extends PreferencesUtil to create your own Pref.
…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.
// 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);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...
}
}// Show YourFragment with extras
YourFragment fragment = new YourFragment();
Bundle bundle = new Bundle();
bundle.putString("Name", "Fragment name");
fragment.setArguments(bundle);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
-keep class com.thefinestartist.annotations.** { *; }
-keep class **$$ExtraBinder { *; }
-keepclasseswithmembernames class * {
@com.thefinestartist.annotations.Extra ;
}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.
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 helps to show and hide keyboard conveniently.Keyboard is abbreviation class of KeyboardUtil. You can extends KeyboardUtil to create your own Keyboard.
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 helps to check device API Build.VERSION conveniently.
→ Android Studio
→ Preferences...
→ Editor
→ Inspections
→ Android Lint
→ Calling new methods on older versions
→ Set Severity as Warning.…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 helps to build Bundle conveniently.
BundleBuilder BundleBuilder.set(String key, T value);
T BundleBuilder.get(String key);
Bundle BundleBuilder.build();Bundle bundle = new BundleBuilder()
.set("values", new int[]{1, 2, 3})
.build();PackageUtil helps to handle methods related to package.
boolean PackageUtil.isInstalled(String packageName);
String PackageUtil.getPackageName();
void PackageUtil.openPlayStore();
void PackageUtil.openPlayStore(String packageName);VibratorUtil helps to use Vibrator conveniently.
void VibratorUtil.vibrate(); // vibrate device for 200 milliseconds
void VibratorUtil.vibrate(milliseconds);
// and more...ClipboardManagerUtil helps to use ClipboardManager conveniently.
void ClipboardManagerUtil.setText(CharSequence text);
boolean ClipboardManagerUtil.hasText();
CharSequence ClipboardManagerUtil.getText();TypedValueUtil helps to use TypedValue class conveniently.
float TypedValueUtil.applyDimension(int unit, float value);
float TypedValueUtil.complexToDimension(int data);
int TypedValueUtil.complexToDimensionPixelOffset(int data);
int TypedValueUtil.complexToDimensionPixelSize(int data);WindowManagerUtil helps to use WindowManager conveniently.
Display WindowManagerUtil.getDefaultDisplay();
void WindowManagerUtil.removeViewImmediate(View view);IntArrayUtil helps to deal with IntArray conveniently.
boolean IntArrayUtil.contains(int[] array, int value);
int[] IntArrayUtil.add(int[] array, int value);SparseArrayUtil helps to deal with SparseArray conveniently.
ArrayList SparseArrayUtil.asArrayList(SparseArray sparseArray);ThreadUtil helps to deal with thread conveniently.
boolean ThreadUtil.isMain();Leonardo Taehwan Kim
Min Kim
Robin Gustafsson
Marcos Trujillo
…No open issues yet, or sync has not completed.