This repository offers a set of random useful classes to deal with repetitive tasks in the Android Framework. Intended to help you getting your Android applications off the ground quickly, by offering ready-to-use components and utility classes that wrap a lot of the boilerplate that’s involved when writing Android apps.
- REST - Simple REST requests and automatic parse
- Cache Magic - Easily serialize and cache your objects to disk using key/value pairs
- Async Image Loader - Image downloading and caching
Including in your project via Gradle:
dependencies{compile 'com.cesarferreira.quickutils:library:2.+' }Init the library in your Application class
publicclassSampleApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); QuickUtils.init(this)} }Simple REST requests and automatic parse
publicclassTweet{@SerializedName("title") publicStringtitle; @SerializedName("amount_of_retweets") publiclongretweetsTotal}QuickUtils.rest.connect() .GET() // POST() // PUT() .load("https://path/to/the/tweets") .as(newTypeToken<List<Tweet>>(){}) .withCallback(callback);HeaderrequestHeader = newHeader.Builder() .add("Authorization", "Bearer Jhahdau2819ajsbdkasdkasdkashjdkahs") .build(); BodyrequestBody = newBody.Builder() .add("email", "[email protected]") .build(); QuickUtils.rest.connect() .POST(requestHeader, requestBody) .load(url) .as(newTypeToken<List<Person>>(){}) .withCallback(callback);Easily serialize and cache your objects to disk using key/value pairs.
sync
QuickUtils.cacheMagic.save("somePerson", newPerson("john doe"));async
QuickUtils.cacheMagic.save("somePerson", newPerson("john doe"), newSaveToCacheCallback(){(...)});sync
QuickUtils.cacheMagic.read("somePerson", null);async
QuickUtils.cacheMagic.readAsync("somePerson", newTypeToken<Person>(){}, newReadFromCacheCallback<Person>(){(...)});QuickUtils.cacheMagic.delete("somePerson"); // deleteAsync also worksErases ALL the key/values that are stored
QuickUtils.cacheMagic.deleteAll();Check if a key/value exists
booleanpersonExists = QuickUtils.cacheMagic.existsKey("somePerson");Image downloading and caching
// SimpleQuickUtils.imageCache.load(IMAGE_URL, imageView); // or more completeQuickUtils.imageCache.load(IMAGE_URL, imageView, R.drawable.dummy, R.drawable.error);All you need to do is to specify the category and the method you want to use.
QuickUtils.__category__.__method__E.g.
// Log somethingQuickUtils.log.e("this is an error"); // Make the smartphone vibrate for the amount of time you wantQuickUtils.system.vibrate(1000); // Convert pounds to KGQuickUtils.math.poundsToKg(weight); // Does that file exists?QuickUtils.sdcard.exists(someFile); // Encode a stringQuickUtils.security.encodeBase64(someString); // Save dataQuickUtils.prefs.save(key, value); // Retrieve saved dataQuickUtils.prefs.getString(key, defaultValue); QuickUtils.prefs.getInt(key, defaultValue); // Remove saved dataQuickUtils.prefs.remove(key); // Etc. (hundreds more methods)Take a look at our wiki.
Contributions welcome via Github pull requests.
QuickUtils is available under the MIT license. See the LICENSE file for more info.
