UtilsPlus


Source link: https://github.com/rakshithsj30/UtilsPlus

UtilsPlus

Android utility library which contains usefull utility classes with simple reusable methods.

Adding to your project:

To start using this library, add these lines to the build.gradle of your project:

compile 'com.github.rrsystems:utilsplus:1.1.0' 

Initialize the libray in your application class

  UtilsPlus.initialize(getApplicationContext());
 

if you want to define name of your shared preference, intialize like below


 UtilsPlus.initialize(getApplicationContext(), "my_preference_name");
 

To toast a message, simply insert this line.

First parameter specifies message to be shown and second parameter specifies toast time in seconds



UtilsPlus.getInstance().toast("Hello World!", 5);
 

How to copy a text to clipboard?

UtilsPlus.getInstance().copyToClipboard("text to be copied");
 

How to check there is an internet connection or not?

 if (UtilsPlus.getInstance().checkNetworkState()){
  Log.d("utils plus","internet connection");
  
}
  else {

Log.d("utils plus","no internet connection");
  
}
 

How to check whether the string is a valid email id or not?

 UtilsPlus.getInstance().checkEmailIsValid("[email protected]");
 

How to check whether the string is a valid phone number or not?

// second parameter is country code UtilsPlus.getInstance().validatePhoneNumber("9480523270","91");
 

How to generate a random string?

UtilsPlus.getInstance().getRandomString();
 

How to display a simple push notification?

 /*

* Utility method which will help you to show notification in the status bar.

* @param title title of the push notification

* @param body content to be displayed in the notification

* @param small_icon small icon which will be showed in the notification. should be of following format:R.drawable.imageName

* @param large_icon Large icon which will be showed in the notification. should be of following format:R.drawable.imageName

* @param class_name The  activity which will open on clicking notification. Parameter format: activity_name.class

* @param autoCancel true or false. if set to true, notification will be disappeared after clicking it otherwise it will remain in the status bar

*/

UtilsPlus.getInstance().displaySimplePushNotification("New Mesage","new message received",R.drawable.photo,R.drawable.photo,MainActivity.class,true);
  

How to send an email using email clients installed in the device?

  UtilsPlus.getInstance().sendEmail("Intent chooser title", "Email title", "Email body", "[email protected]", "[email protected]");
 

How to encypt and decrypt a string?

encrypting a string:

UtilsPlus.getInstance().encryptIt("secret key", "string to be encrypted");
  

decrypting a string:

UtilsPlus.getInstance().decryptIt("secret key", "string to be decrypted");
 

How to get IMEI Code of the device?

To make this code work, you need to specify relevant permissions in android manifest. For mashmallow and above, user has to grant permissions.

 UtilsPlus.getInstance().getIMEICode();
 

How to get device id of the device?

To make this code work, you need to specify relevant permissions in android manifest. For mashmallow and above, user has to grant permissions.

UtilsPlus.getInstance().getDeviceID();
 

How to check whether a service created by your app is running or not?

UtilsPlus.getInstance().checkServiceIsRunning(service1.class);
 

How to convert drawable image into bitmap?

UtilsPlus.getInstance().drawableToBitmap(drawable);
 

How to use shared preference?

Save using string as a key

 UtilsPlus.getInstance().put("my_key", "some value");
  UtilsPlus.getInstance().put("my_key", 10);

UtilsPlus.getInstance().put("my_key", true);
 

Retriveing the value using key

UtilsPlus.getInstance().getString("key", "default");
  UtilsPlus.getInstance().getInt("key", 0);

 UtilsPlus.getInstance().getBoolean("key", false);
 

Removing a preference using key

 UtilsPlus.getInstance().removeKey("key");
 

Clearing shared preference

 UtilsPlus.getInstance().clear();
 

Saving an image to internal storage

bitmap --> image in the form of bitmap
image_name --> name of the image
format --> either png or jpg
image path --> path in which image to be stored
quality --> quality of the image

this method returns absolute path of the saved image.

 String path = UtilsPlus.getInstance().SaveImage(bitmap, "image_name", "png", "path/in/which/image/to/be/stored", 20,false);

  

Code Verifier

Copy verification code from SMS automatically.

Activity class should implement SMSReceiver.SMSListener.

For example,

public class MainActivity extends AppCompatActivity implements SMSReceiver.SMSListener {
  ................ .................  
}
 

Create Broadcast Receiver like this

 SMSReceiver smsReceiver = new SMSReceiver();
  

OnResume method of activty class add this line



  smsReceiver.registerReceiver(this, smsReceiver, "TM-bytwoo", "9480523270","specify 3rd phone number here");

smsReceiver.setSMSListener(this);
 

Using onSMSReceived(....) method, parse the verification code

for example, if you want to parse verification code from this sms, "201232 is your One Time Password" then we should write this code


@Override
  public void onSMSReceived(String phone_no, String message) {
  // 1st parameter ---> message // second parameter ---> position of first character of the OTP // second parameter ---> position of character after last character (includes white space) of OTP

Strng OTP = smsReceiver.extractCode(message, 0, -999);

 
}

  

Unregister BroadCast Receiver in your activities OnPause() method.

  @Override
  protected void onPause() {

super.onPause();

if (smsReceiver!=null) {

 smsReceiver.unregisterReceiver(this, smsReceiver);

}

}
  

Resources

Custom implementation of the Floating Label pattern.

MultiSelectRecyclerGalleryGridView is a custom sample application which displays the Gallery images from the device in a more organised manner by displaying images in a categorized manner and enables the MultiSelect feature to pick and share the images through various sharing options.

IconColorChanger is a custom implementation in which icons with white colors can be transformed into different colors using hex color codes.

MaterialCircleProgressBar is a custom implementation of ProgressBar dialog as similar to SwipeRefreshLayout loader. It could be used as an alternative for normal ProgressBar in android.

SpannableTextView allows to customize the styles for a single TextView (i.e., styles, size, color) rather create a separate layout.

Houdini is a simple and humane type conversion system, which allows you to prevent a lot of unnecessary code.

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