android-commons


Source link: https://github.com/darko1002001/android-commons

android-commons

This library provides some common classes that i have used in a lot of my projects so far and have decided to move them to a reusable library.

#Features

Working with application context

One of the most common things that you need is access to application context from anywhere. The way i use Application context has never caused any issues in development or production applications. The key thing to remember is not to use the application context inside static initialization blocks or static initialization for variables in general.

Commons.getContext();
 

To set it up you need to initialize Commons inside your application class. See the example project for details

Working with Shared Preferences

This library offers what i consider a great practice when it comes to working with shared preferences. A good pattern to manage all the access to shared preferences with a single point of contact where you manage all the keys and access to setting, getting or deleting values from preferences.

You need to create a class extending from BasePreferenceUtil and define all your preference values there.

public class PreferenceUtil extends BasePreferenceUtil {

 public static BooleanPreference getRememberMePreference() {

  return booleanPreference("key_remember_me");

}
 
}
 

The operations to change this key for example would be used this way:

boolean b = PreferenceUtil.getRememberMePreference().get();
  PreferenceUtil.getRememberMePreference().set(true);
  PreferenceUtil.getRememberMePreference().delete();
 

You can also use the helper methods to serialize whole objects or lists

PreferenceUtil.modelPreference("test_model", TestModel.class).set(new TestModel("darko", "G"));
  ListPreference<TestModel> testList = PreferenceUtil.listPreference("test_list", TestModel.class);
 List<TestModel> list = new ArrayList<TestModel>();
 list.add(new TestModel("one", "two"));
 list.add(new TestModel("three", "four"));
 testList.set(list);
 

The model serialization uses google GSON to convert the objects. Also keep in mind that you should avoid using this for more complex scenarios due to the issues that happen with backwards compatibility and the inability to version the serialized models.

Working with Intents

A good practice when working with intents is to have a central location where one manages all the operations with intents

This library offers a simple BaseIntentUtil class which one should extend and define their own methods and use the helpers provided

public class IntentUtil extends BaseIntentUtil {

 public static void startMainActivity(Activity context) {

  startActivity(context, MainActivity.class);

}
 
}
 

Working with fragments and progress dialog

BaseFragmentUtl provides a few shortcuts when working with fragments and also a way to show and hide a progress dialog for the blocking progress for long running operations.

To show a progress dialog

BaseFragmentUtil.showProgressDialog(fragmentManager);
 

To hide it

BaseFragmentUtil.clearProgressDialog(fragmentManager);
 

Offers an Alert Dialog fragment for showing standard alert messages through a fragmentDialog which is a good way to show dialogs in new android releases

These API's works for Android 4.0+

Working with notifications

A good practice for the app is to have a central place from which you show Toast messages or any custom toast notifications

just create a class extending BaseNotificationUtil

it provides a way to show toasts without the hassle of adding all the parameters and calling show()

public static void makeToast(String message) public static void makeToast(int resId) 

ViewUtil

Some common operations for changing view visibility and a shortcut to convert dp to pixels

ViewUtil.makeGone(v1,v2,v3,v4,....);
 ViewUtil.makeVisible(v1,v2,v3,v4,....);
 ViewUtil.makeInvisible(v1,v2,v3,v4,....);
  public static int dpToPixels(int dp) 

IOUtils

The most common usages for manipulation with streams, convert to a string, copy from one to another with a buffer etc...

public static String toString(InputStream input) throws IOException public static int copy(Reader input, Writer output) throws IOException 

Network Util

Shortcuts for network connectivity checks

UDID Generator

Changelog

1.1.3

Updated samples Small tweaks Edited readme.md

1.1.2

Added More options to preference utils added IO Utils Added UDID Generator

1.0.0

Initial release

Features

Some common classes for use in your android projects.

Minimum SDK version / API level

The minimum API version is set to 11 because of FragmentUtils

Include in your own project

As Maven dependency

<dependency>
  <groupId>com.aranea-apps.android.libs</groupId>
  <artifactId>android-commons</artifactId>
  <version>1.1.2</version>
  <type>aar</type> </dependency>

As Gradle dependency

dependencies {

  compile 'com.aranea-apps.android.libs:android-commons:1.1.2' 
}
 

Packaging

This project is packaged as AAR

Contributors

License

Copyright 2014 Darko Grozdanovski  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

An RxJava2 binding for android Animator.

Android kotlin clean architecture rxjava2 + dagger2 + retrofit2 + realm.

Transform any method to an Rx Observable!

Super simple and fast (on RenderScript opt.) blurred ImageView.

DecleX is an open source framework that aims to get closer to a fully Declarative Language for Android Development. It facilitates the writing and the maintenance of applications, reducing the amount of code that should be written. It uses a clean Pseudo Java Code and Java Annotations, getting rid of the verbosity of the Java Language itself.

Selecting a particular section of text and highlighting with different color and add notes to them.

Watch it in action here

go to this link to see integration

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