├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── libraries
│ ├── animated_vector_drawable_24_2_1.xml
│ ├── appcompat_v7_24_2_1.xml
│ ├── design_24_2_1.xml
│ ├── firebase_analytics_9_0_0.xml
│ ├── firebase_analytics_impl_9_0_0.xml
│ ├── firebase_client_android_2_4_0.xml
│ ├── firebase_client_jvm_2_4_0.xml
│ ├── firebase_common_9_0_0.xml
│ ├── firebase_core_9_0_0.xml
│ ├── firebase_iid_9_0_0.xml
│ ├── jackson_annotations_2_2_2.xml
│ ├── jackson_core_2_2_2.xml
│ ├── jackson_databind_2_2_2.xml
│ ├── libphonenumber_android_8_1_0.xml
│ ├── play_services_base_9_0_0.xml
│ ├── play_services_basement_9_0_0.xml
│ ├── play_services_tasks_9_0_0.xml
│ ├── recyclerview_v7_24_2_1.xml
│ ├── support_annotations_24_2_1.xml
│ ├── support_compat_24_2_1.xml
│ ├── support_core_ui_24_2_1.xml
│ ├── support_core_utils_24_2_1.xml
│ ├── support_fragment_24_2_1.xml
│ ├── support_media_compat_24_2_1.xml
│ ├── support_v4_24_2_1.xml
│ ├── support_vector_drawable_24_2_1.xml
│ └── tubesock_0_0_12.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
├── vcs.xml
└── workspace.xml
├── README.md
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── google-services.json
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── clearbits
│ │ └── bitcricket
│ │ └── android
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── sampleapp
│ │ │ └── android
│ │ │ ├── MainActivity.java
│ │ │ └── MyApplication.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── content_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── clearbits
│ └── bitcricket
│ └── android
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── settings.gradle
└── utilsplus
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── src
├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── rrsystems
│ │ └── utilsplus
│ │ └── android
│ │ └── ApplicationTest.java
├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── rrsystems
│ │ │ └── utilsplus
│ │ │ └── android
│ │ │ ├── SMSReceiver.java
│ │ │ └── UtilsPlus.java
│ └── res
│ │ └── values
│ │ └── strings.xml
└── test
│ └── java
│ └── com
│ └── github
│ └── rrsystems
│ └── utilsplus
│ └── android
│ └── ExampleUnitTest.java
└── utilsplus.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Bit Cricket
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/libraries/animated_vector_drawable_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/design_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_analytics_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_analytics_impl_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_client_android_2_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_client_jvm_2_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_common_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_core_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/firebase_iid_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/jackson_annotations_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/jackson_core_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/jackson_databind_2_2_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/libphonenumber_android_8_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/play_services_base_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/play_services_basement_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/play_services_tasks_9_0_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/recyclerview_v7_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_compat_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/support_core_ui_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/support_core_utils_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/support_fragment_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/support_media_compat_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/support_vector_drawable_24_2_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/tubesock_0_0_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UtilsPlus
2 | Android utility library which contains usefull utility classes with simple reusable methods.
3 |
4 | ## Adding to your project:
5 | To start using this library, add these lines to the build.gradle of your project:
6 | ```
7 | compile 'com.github.rrsystems:utilsplus:1.1.0'
8 | ```
9 |
10 | ### Initialize the libray in your application class
11 | ```
12 | UtilsPlus.initialize(getApplicationContext());
13 | ```
14 | if you want to define name of your shared preference, intialize like below
15 | ```
16 | UtilsPlus.initialize(getApplicationContext(), "my_preference_name");
17 | ```
18 | ### To toast a message, simply insert this line.
19 | First parameter specifies message to be shown and second parameter specifies toast time in seconds
20 | ```
21 | UtilsPlus.getInstance().toast("Hello World!", 5);
22 | ```
23 | ### How to copy a text to clipboard?
24 | ```
25 | UtilsPlus.getInstance().copyToClipboard("text to be copied");
26 | ```
27 |
28 | ### How to check there is an internet connection or not?
29 | ```
30 | if (UtilsPlus.getInstance().checkNetworkState()){
31 | Log.d("utils plus","internet connection");
32 | }
33 | else {
34 | Log.d("utils plus","no internet connection");
35 | }
36 | ```
37 | ### How to check whether the string is a valid email id or not?
38 | ```
39 | UtilsPlus.getInstance().checkEmailIsValid("rakshithsj30@gmail.com");
40 | ```
41 | ### How to check whether the string is a valid phone number or not?
42 | ```
43 | // second parameter is country code
44 | UtilsPlus.getInstance().validatePhoneNumber("9480523270","91");
45 | ```
46 | ### How to generate a random string?
47 | ```
48 | UtilsPlus.getInstance().getRandomString();
49 | ```
50 |
51 | ### How to display a simple push notification?
52 | ```
53 | /*
54 | * Utility method which will help you to show notification in the status bar.
55 | * @param title title of the push notification
56 | * @param body content to be displayed in the notification
57 | * @param small_icon small icon which will be showed in the notification. should be of following format:R.drawable.imageName
58 | * @param large_icon Large icon which will be showed in the notification. should be of following format:R.drawable.imageName
59 | * @param class_name The activity which will open on clicking notification. Parameter format: activity_name.class
60 | * @param autoCancel true or false. if set to true, notification will be disappeared after clicking it otherwise it will remain in the status bar
61 | */
62 |
63 |
64 | UtilsPlus.getInstance().displaySimplePushNotification("New Mesage","new message received",R.drawable.photo,R.drawable.photo,MainActivity.class,true);
65 |
66 | ```
67 | ### How to send an email using email clients installed in the device?
68 | ```
69 | UtilsPlus.getInstance().sendEmail("Intent chooser title", "Email title", "Email body", "recipient1@xyz.com", "recipient2@abc.com");
70 | ```
71 | ### How to encypt and decrypt a string?
72 | encrypting a string:
73 | ```
74 | UtilsPlus.getInstance().encryptIt("secret key", "string to be encrypted");
75 |
76 | ```
77 | decrypting a string:
78 | ```
79 | UtilsPlus.getInstance().decryptIt("secret key", "string to be decrypted");
80 | ```
81 | ### How to get IMEI Code of the device?
82 | To make this code work, you need to specify relevant permissions in android manifest. For mashmallow and above, user has to grant permissions.
83 | ```
84 | UtilsPlus.getInstance().getIMEICode();
85 | ```
86 | ### How to get device id of the device?
87 | To make this code work, you need to specify relevant permissions in android manifest. For mashmallow and above, user has to grant permissions.
88 | ```
89 | UtilsPlus.getInstance().getDeviceID();
90 | ```
91 | ### How to check whether a service created by your app is running or not?
92 | ```
93 | UtilsPlus.getInstance().checkServiceIsRunning(service1.class);
94 | ```
95 |
96 | ### How to convert drawable image into bitmap?
97 | ```
98 | UtilsPlus.getInstance().drawableToBitmap(drawable);
99 | ```
100 |
101 | ### How to use shared preference?
102 |
103 | Save using string as a key
104 | ```
105 | UtilsPlus.getInstance().put("my_key", "some value");
106 | UtilsPlus.getInstance().put("my_key", 10);
107 | UtilsPlus.getInstance().put("my_key", true);
108 | ```
109 | Retriveing the value using key
110 | ```
111 | UtilsPlus.getInstance().getString("key", "default");
112 | UtilsPlus.getInstance().getInt("key", 0);
113 | UtilsPlus.getInstance().getBoolean("key", false);
114 | ```
115 | Removing a preference using key
116 | ```
117 | UtilsPlus.getInstance().removeKey("key");
118 | ```
119 | Clearing shared preference
120 | ```
121 | UtilsPlus.getInstance().clear();
122 | ```
123 |
124 | ### Saving an image to internal storage
125 |
126 |
127 | bitmap --> image in the form of bitmap
128 | image_name --> name of the image
129 | format --> either png or jpg
130 | image path --> path in which image to be stored
131 | quality --> quality of the image
132 |
133 | this method returns absolute path of the saved image.
134 |
135 | ```
136 | String path = UtilsPlus.getInstance().SaveImage(bitmap, "image_name", "png", "path/in/which/image/to/be/stored", 20,false);
137 |
138 |
139 | ```
140 |
141 | ### Code Verifier
142 | Copy verification code from SMS automatically.
143 |
144 | Activity class should implement SMSReceiver.SMSListener.
145 |
146 | For example,
147 | ```
148 | public class MainActivity extends AppCompatActivity implements SMSReceiver.SMSListener {
149 |
150 | ................
151 | .................
152 |
153 | }
154 | ```
155 |
156 | Create Broadcast Receiver like this
157 | ```
158 |
159 | SMSReceiver smsReceiver = new SMSReceiver();
160 |
161 | ```
162 | OnResume method of activty class add this line
163 |
164 | ```
165 | smsReceiver.registerReceiver(this, smsReceiver, "TM-bytwoo", "9480523270","specify 3rd phone number here");
166 | smsReceiver.setSMSListener(this);
167 | ```
168 |
169 | Using onSMSReceived(....) method, parse the verification code
170 |
171 | for example, if you want to parse verification code from this sms, "201232 is your One Time Password" then we should write this code
172 |
173 | ```
174 | @Override
175 | public void onSMSReceived(String phone_no, String message) {
176 |
177 | // 1st parameter ---> message
178 | // second parameter ---> position of first character of the OTP
179 | // second parameter ---> position of character after last character (includes white space) of OTP
180 |
181 | Strng OTP = smsReceiver.extractCode(message, 0, -999);
182 |
183 | }
184 |
185 | ```
186 |
187 | Unregister BroadCast Receiver in your activities OnPause() method.
188 |
189 | ```
190 | @Override
191 | protected void onPause() {
192 | super.onPause();
193 | if (smsReceiver!=null) {
194 | smsReceiver.unregisterReceiver(this, smsReceiver);
195 | }
196 |
197 | }
198 |
199 | ```
200 |
201 |
202 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | packagingOptions {
5 | exclude 'META-INF/DEPENDENCIES.txt'
6 | exclude 'META-INF/LICENSE.txt'
7 | exclude 'META-INF/NOTICE.txt'
8 | exclude 'META-INF/NOTICE'
9 | exclude 'META-INF/LICENSE'
10 | exclude 'META-INF/DEPENDENCIES'
11 | exclude 'META-INF/notice.txt'
12 | exclude 'META-INF/license.txt'
13 | exclude 'META-INF/dependencies.txt'
14 | exclude 'META-INF/LGPL2.1'
15 | }
16 | compileSdkVersion 24
17 | buildToolsVersion "23.0.3"
18 |
19 | defaultConfig {
20 | applicationId "com.sampleapp.android"
21 | minSdkVersion 15
22 | targetSdkVersion 24
23 | versionCode 1
24 | versionName "1.0"
25 | }
26 | buildTypes {
27 | release {
28 | minifyEnabled false
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | }
33 |
34 | dependencies {
35 | compile fileTree(dir: 'libs', include: ['*.jar'])
36 | testCompile 'junit:junit:4.12'
37 | compile 'com.android.support:appcompat-v7:24.2.1'
38 | compile 'com.android.support:design:24.2.1'
39 | compile 'com.firebase:firebase-client-android:2.4.0'
40 | compile project(':utilsplus')
41 |
42 |
43 | }
44 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "979459244103",
4 | "firebase_url": "https://bit-cricket.firebaseio.com",
5 | "project_id": "bit-cricket",
6 | "storage_bucket": "bit-cricket.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:979459244103:android:7ada952a65e57099",
12 | "android_client_info": {
13 | "package_name": "com.sampleapp.android"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "979459244103-oo5e242bdnpo1l1e3mhp9idb77cvshl7.apps.googleusercontent.com",
19 | "client_type": 3
20 | }
21 | ],
22 | "api_key": [
23 | {
24 | "current_key": "AIzaSyA2wW8Yu0FfFt4jIT4gTWqCzUYI9YsyimA"
25 | }
26 | ],
27 | "services": {
28 | "analytics_service": {
29 | "status": 1
30 | },
31 | "appinvite_service": {
32 | "status": 1,
33 | "other_platform_oauth_client": []
34 | },
35 | "ads_service": {
36 | "status": 2
37 | }
38 | }
39 | }
40 | ],
41 | "configuration_version": "1"
42 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\Android SDK\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/clearbits/bitcricket/android/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.android;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
22 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/android/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.android;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.BitmapDrawable;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.Toolbar;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import java.io.IOException;
15 | import java.util.Iterator;
16 | import java.util.Map;
17 |
18 | import com.sampleapp.android.R;
19 |
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 |
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
30 | setSupportActionBar(toolbar);
31 |
32 |
33 |
34 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
35 |
36 |
37 |
38 |
39 | fab.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View view) {
42 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
43 | .setAction("Action", null).show();
44 | }
45 | });
46 |
47 |
48 |
49 | }
50 |
51 | @Override
52 | public boolean onCreateOptionsMenu(Menu menu) {
53 | // Inflate the menu; this adds items to the action bar if it is present.
54 | getMenuInflater().inflate(R.menu.menu_main, menu);
55 | return true;
56 | }
57 |
58 | @Override
59 | public boolean onOptionsItemSelected(MenuItem item) {
60 | // Handle action bar item clicks here. The action bar will
61 | // automatically handle clicks on the Home/Up button, so long
62 | // as you specify a parent activity in AndroidManifest.xml.
63 | int id = item.getItemId();
64 |
65 | //noinspection SimplifiableIfStatement
66 | if (id == R.id.action_settings) {
67 | return true;
68 | }
69 |
70 | return super.onOptionsItemSelected(item);
71 | }
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/sampleapp/android/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.android;
2 |
3 | import android.app.Application;
4 | import android.content.res.Configuration;
5 |
6 | import com.github.rrsystems.utilsplus.android.UtilsPlus;
7 |
8 | /**
9 | * Created by Clear Bits on 4/21/2017.
10 | */
11 | public class MyApplication extends Application {
12 |
13 | @Override
14 | public void onConfigurationChanged(Configuration newConfig) {
15 | super.onConfigurationChanged(newConfig);
16 | }
17 |
18 | @Override
19 | public void onCreate() {
20 | super.onCreate();
21 | UtilsPlus.initialize(getApplicationContext(), "myapp");
22 | }
23 |
24 | @Override
25 | public void onLowMemory() {
26 | super.onLowMemory();
27 | }
28 |
29 | @Override
30 | public void onTerminate() {
31 | super.onTerminate();
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Bit Cricket
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/clearbits/bitcricket/android/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.sampleapp.android;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 |
10 | // Add this line
11 | classpath 'com.google.gms:google-services:3.0.0'
12 |
13 | classpath 'com.android.tools.build:gradle:1.2.3'
14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
15 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
16 |
17 |
18 |
19 |
20 | // NOTE: Do not place your application dependencies here; they belong
21 | // in the individual module build.gradle files
22 | }
23 | }
24 |
25 | allprojects {
26 | repositories {
27 | jcenter()
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rakshithsj30/UtilsPlus/54e8e88bf1aef669fa7a30abc398e69475e1eb83/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file should *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':utilsplus'
2 |
--------------------------------------------------------------------------------
/utilsplus/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/utilsplus/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:24.2.1'
25 | compile 'io.michaelrocks:libphonenumber-android:8.1.0'
26 | }
27 |
28 | ext {
29 | bintrayRepo = 'android-libraries'
30 | bintrayName = 'utils-plus'
31 |
32 | publishedGroupId = 'com.github.rrsystems'
33 | libraryName = 'utilsplus'
34 | artifact = 'utilsplus'
35 |
36 | libraryDescription = 'A libary which contains usefull utility tools.'
37 |
38 | siteUrl = 'https://github.com/rakshithsj30/UtilsPlus'
39 | gitUrl = 'https://github.com/rakshithsj30/UtilsPlus.git'
40 |
41 | libraryVersion = '1.0.0'
42 |
43 | developerId = 'rakshithsj30'
44 | developerName = 'Rakshith Shetty'
45 | developerEmail = 'rakshithsj30@gmail.com'
46 |
47 | licenseName = 'The Apache Software License, Version 2.0'
48 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
49 | allLicenses = ["Apache-2.0"]
50 | }
51 | // Place it at the end of the file
52 | apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/installv.gradle'
53 | apply from: 'https://raw.githubusercontent.com/numetriclabz/jcenter/master/bintrayv.gradle'
54 |
--------------------------------------------------------------------------------
/utilsplus/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in F:\Android SDK\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/utilsplus/src/androidTest/java/com/github/rrsystems/utilsplus/android/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.rrsystems.utilsplus.android;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/utilsplus/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/utilsplus/src/main/java/com/github/rrsystems/utilsplus/android/SMSReceiver.java:
--------------------------------------------------------------------------------
1 | package com.github.rrsystems.utilsplus.android;
2 |
3 | import android.app.Activity;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.os.Bundle;
9 | import android.telephony.SmsManager;
10 | import android.telephony.SmsMessage;
11 | import android.util.Log;
12 | import android.widget.Toast;
13 |
14 | import java.util.ArrayList;
15 | import java.util.Arrays;
16 | import java.util.Collections;
17 | import java.util.List;
18 |
19 |
20 | /**
21 | * Created by Clear Bits on 4/28/2017.
22 | */
23 | public class SMSReceiver extends BroadcastReceiver {
24 | SMSListener smsListener;
25 | String[] phoneNos;
26 | // Get the object of SmsManager
27 | final SmsManager sms = SmsManager.getDefault();
28 |
29 | public interface SMSListener {
30 |
31 | public void onSMSReceived(String phone_no, String message);
32 | }
33 |
34 | public void registerReceiver(Activity activity, SMSReceiver smsReceiver, String... phoneNumbers) {
35 | IntentFilter mIntentFilter;
36 | mIntentFilter = new IntentFilter();
37 | mIntentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
38 | mIntentFilter.setPriority(2147483647);
39 | activity.registerReceiver(smsReceiver, mIntentFilter);
40 | phoneNos = phoneNumbers;
41 |
42 |
43 | }
44 |
45 | public void unregisterReceiver(Activity activity, SMSReceiver smsReceiver) {
46 | activity.unregisterReceiver(smsReceiver);
47 |
48 | }
49 |
50 | public String extractCode(String message, int firstIndex, int lastIndex) {
51 | if (message == null || message.isEmpty()) {
52 | return "";
53 | } else {
54 | try {
55 | if (lastIndex == -999) {
56 | return message.substring(firstIndex);
57 | } else {
58 | return message.substring(firstIndex, lastIndex);
59 | }
60 | } catch (Exception e) {
61 | e.printStackTrace();
62 | return "";
63 | }
64 | }
65 |
66 |
67 | }
68 |
69 |
70 | public void setSMSListener(SMSListener listener) {
71 | this.smsListener = listener;
72 | }
73 |
74 |
75 | public void onReceive(Context context, Intent intent) {
76 |
77 | // Retrieves a map of extended data from the intent.
78 | final Bundle bundle = intent.getExtras();
79 |
80 | try {
81 |
82 | if (bundle != null) {
83 |
84 | final Object[] pdusObj = (Object[]) bundle.get("pdus");
85 |
86 | for (int i = 0; i < pdusObj.length; i++) {
87 |
88 | SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
89 | String phoneNumber = currentMessage.getDisplayOriginatingAddress();
90 |
91 | String senderNum = phoneNumber;
92 | String message = currentMessage.getDisplayMessageBody();
93 |
94 | if (smsListener != null) {
95 |
96 | List phone_nos = Arrays.asList(phoneNos);
97 | for (int j = 0; j < phone_nos.size(); j++) {
98 | if (phone_nos.get(i).equals(senderNum)) {
99 | smsListener.onSMSReceived(phoneNumber, message);
100 | }
101 | }
102 |
103 |
104 | }
105 | Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message);
106 | } // end for loop
107 | }
108 |
109 | } catch (Exception e) {
110 |
111 |
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/utilsplus/src/main/java/com/github/rrsystems/utilsplus/android/UtilsPlus.java:
--------------------------------------------------------------------------------
1 | package com.github.rrsystems.utilsplus.android;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.ActivityManager;
5 | import android.app.Notification;
6 | import android.app.NotificationManager;
7 | import android.app.PendingIntent;
8 | import android.content.Context;
9 | import android.content.ContextWrapper;
10 | import android.content.Intent;
11 | import android.content.SharedPreferences;
12 | import android.graphics.Bitmap;
13 | import android.graphics.BitmapFactory;
14 | import android.graphics.Canvas;
15 | import android.graphics.drawable.BitmapDrawable;
16 | import android.graphics.drawable.Drawable;
17 | import android.net.ConnectivityManager;
18 | import android.os.Build;
19 | import android.os.CountDownTimer;
20 | import android.provider.Settings;
21 | import android.telephony.TelephonyManager;
22 | import android.text.TextUtils;
23 | import android.util.Base64;
24 | import android.util.Log;
25 | import android.view.Gravity;
26 | import android.widget.Toast;
27 |
28 | import java.io.File;
29 | import java.io.FileOutputStream;
30 | import java.io.IOException;
31 | import java.io.UnsupportedEncodingException;
32 | import java.security.InvalidKeyException;
33 | import java.security.NoSuchAlgorithmException;
34 | import java.security.spec.InvalidKeySpecException;
35 | import java.util.Random;
36 | import java.util.Set;
37 | import java.util.UUID;
38 | import java.util.regex.Matcher;
39 | import java.util.regex.Pattern;
40 |
41 | import javax.crypto.BadPaddingException;
42 | import javax.crypto.Cipher;
43 | import javax.crypto.IllegalBlockSizeException;
44 | import javax.crypto.NoSuchPaddingException;
45 | import javax.crypto.SecretKey;
46 | import javax.crypto.SecretKeyFactory;
47 | import javax.crypto.spec.DESKeySpec;
48 |
49 | import io.michaelrocks.libphonenumber.android.NumberParseException;
50 | import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
51 | import io.michaelrocks.libphonenumber.android.Phonenumber.PhoneNumber;
52 |
53 | /**
54 | * Created by Clear Bits on 4/12/2017.
55 | */
56 | public class UtilsPlus {
57 |
58 |
59 | static String DEFAULT_SHARED_PREFS_NAME = "app_preferences";
60 |
61 | static SharedPreferences preference;
62 |
63 | static SharedPreferences.Editor editor;
64 |
65 | public static UtilsPlus instance;
66 |
67 | public static Context mcontext;
68 |
69 |
70 | public final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
71 | "[a-zA-Z0-9+._%-+]{1,256}" +
72 | "@" +
73 | "[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
74 | "(" +
75 | "." +
76 | "[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" +
77 | ")+"
78 | );
79 |
80 | /**
81 | * initialize utils plus library
82 | * @param context
83 | * @param prefs_name
84 | */
85 | public static void initialize(Context context, String prefs_name) {
86 |
87 | if (prefs_name == null) {
88 | throw new IllegalArgumentException("Preference name can not be null");
89 | }
90 | if (prefs_name.isEmpty()) {
91 | throw new IllegalArgumentException("Preference name can not be empty");
92 | }
93 | if (context == null) {
94 | throw new IllegalArgumentException("Preference name can not be null");
95 | }
96 | mcontext = context;
97 | preference = context.getSharedPreferences(prefs_name, context.MODE_PRIVATE);
98 | editor = preference.edit();
99 |
100 |
101 | }
102 |
103 | /**
104 | * initialize Utils Plus Library
105 | * @param context
106 | */
107 | public static void initialize(Context context) {
108 |
109 | if (context == null) {
110 | throw new IllegalArgumentException("Preference name can not be null");
111 | }
112 | preference = context.getSharedPreferences(DEFAULT_SHARED_PREFS_NAME, context.MODE_PRIVATE);
113 | editor = preference.edit();
114 | mcontext = context;
115 |
116 | }
117 |
118 |
119 | public static synchronized UtilsPlus getInstance() {
120 | if (instance == null) {
121 | return instance = new UtilsPlus();
122 | }
123 | return instance;
124 | }
125 |
126 | public UtilsPlus put(String key, Object obj) {
127 | // if(obj instanceof Float)
128 |
129 | if (obj instanceof String) {
130 | editor.putString(key, (String) obj);
131 | editor.commit();
132 | return this;
133 |
134 | } else if (obj instanceof Boolean) {
135 |
136 | editor.putBoolean(key, (Boolean) obj);
137 | editor.commit();
138 | return this;
139 |
140 |
141 | } else if (obj instanceof Integer) {
142 |
143 | editor.putInt(key, (Integer) obj);
144 | editor.commit();
145 | return this;
146 |
147 |
148 | } else if (obj instanceof Long) {
149 | editor.putLong(key, (Long) obj);
150 | editor.commit();
151 | return this;
152 |
153 |
154 | } else if (obj instanceof Float) {
155 | editor.putFloat(key, (Float) obj);
156 | editor.commit();
157 | return this;
158 |
159 | } else {
160 | throw new ClassCastException(obj.getClass().getName() + " is not allowed type of object.");
161 |
162 | }
163 |
164 | }
165 |
166 |
167 | public UtilsPlus insertStringSet(String key, Set values) {
168 | editor.putStringSet(key, values);
169 | return this;
170 | }
171 |
172 | public Set retrievetStringSet(String key, Set defaultValue) {
173 | return preference.getStringSet(key, defaultValue);
174 | }
175 |
176 |
177 | public boolean getBoolean(String key, boolean defalutValue) {
178 | return preference.getBoolean(key, defalutValue);
179 | }
180 |
181 | public String getString(String key, String defalutValue) {
182 | return preference.getString(key, defalutValue);
183 | }
184 |
185 | public int getInt(String key, int defalutValue) {
186 | return preference.getInt(key, defalutValue);
187 | }
188 |
189 | public float getFloat(String key, float defalutValue) {
190 | return preference.getFloat(key, defalutValue);
191 | }
192 |
193 | public long getLong(String key, long defalutValue) {
194 | return preference.getLong(key, defalutValue);
195 | }
196 |
197 | /**
198 | * removes specified preference using its name
199 | * @param key name of the key
200 | * @return object
201 | */
202 | public UtilsPlus removeKey(String key) {
203 | editor.remove(key);
204 | editor.commit();
205 | return this;
206 | }
207 |
208 | /**
209 | * this utlity method clears all preferences
210 | * @return object
211 | */
212 | public UtilsPlus clear() {
213 | editor.clear();
214 | editor.commit();
215 | return this;
216 | }
217 |
218 | /**
219 | * this utility method helps to save images in internal memory. Since the image is saved in the internal memory, the image is private
220 | * @param bitmap image in bitmap form
221 | * @param name name of the file
222 | * @param type format of the image. only png and jpg formats are allowed. parameter should be of following format. "png" or "jpg"
223 | * @param path path of the folder in which image to be saved. sample path format: /folder1/folder2/folder3/
224 | * @param quality quality of the image
225 | * @param isPrivate
226 | * @return path in which image is saved
227 | */
228 | public String SaveImage(Bitmap bitmap, String name, String type, String path, int quality, boolean isPrivate) {
229 | File file_path = null;
230 | File dir2 = null;
231 |
232 | String a = File.separator;
233 |
234 |
235 | if (path == null || path.isEmpty() || path.length() <= 3 || !path.contains("/")) {
236 | Log.e("Utils Plus", "Folder path seems to be incorrect. Please correct the path");
237 |
238 | }
239 | if (type == null || type.isEmpty()) {
240 |
241 | Log.e("Utils Plus", "Image type can not be null or empty.");
242 | }
243 | if (name == null || name.isEmpty()) {
244 |
245 | Log.e("Utils Plus", "Image name can not be null or empty.");
246 | }
247 | if (quality < 0 || quality > 100) {
248 |
249 | Log.e("Utils Plus", "Quality must be greater than 0 and less than 100");
250 | }
251 |
252 | if (type != null) {
253 | if (!type.equalsIgnoreCase("PNG") && !type.equalsIgnoreCase("JPG")) {
254 | Log.e("Utils Plus", "format not supported except png and jpg");
255 | }
256 | }
257 |
258 | if (type.equalsIgnoreCase("PNG")) {
259 | name = name + ".png";
260 | } else if (type.equalsIgnoreCase("JPG")) {
261 | name = name + ".jpg";
262 | }
263 |
264 | if (!isPrivate) {
265 | File rootDir = null;
266 | path = path.replaceAll("//*", "/");
267 | String[] folders = path.split("/");
268 | for (int i = 0; i < folders.length; i++) {
269 | if (i == 0) {
270 | rootDir = mcontext.getDir(folders[i], Context.MODE_APPEND); //Creating an internal dir;
271 | if (!rootDir.exists()) {
272 | rootDir.mkdirs();
273 | }
274 | } else {
275 | rootDir = new File(rootDir, folders[i]);
276 | rootDir.mkdir();
277 |
278 | }
279 |
280 | }
281 | return rootDir.getAbsolutePath();
282 |
283 | }
284 | ContextWrapper cw = new ContextWrapper(mcontext);
285 | File dir = cw.getFilesDir();
286 | dir2 = new File(dir, path);
287 | dir2.mkdirs();
288 |
289 | file_path = new File(dir2, name);
290 | FileOutputStream fos = null;
291 | try {
292 | fos = new FileOutputStream(file_path);
293 | // Use the compress method on the BitMap object to write image to the OutputStream
294 | if (type.equalsIgnoreCase("PNG")) {
295 | bitmap.compress(Bitmap.CompressFormat.PNG, quality, fos);
296 | } else if (type.equalsIgnoreCase("JPG")) {
297 | bitmap.compress(Bitmap.CompressFormat.JPEG, quality, fos);
298 | }
299 | } catch (Exception e) {
300 | e.printStackTrace();
301 | } finally {
302 | try {
303 | fos.close();
304 | } catch (IOException e) {
305 | e.printStackTrace();
306 | }
307 | }
308 |
309 |
310 |
311 | return dir2.getAbsolutePath();
312 | }
313 |
314 | /**
315 | * Checks whether there is an active network connection or not
316 | * @return true or false
317 | */
318 | public boolean checkNetworkState() {
319 | final ConnectivityManager connectivityManager = ((ConnectivityManager) mcontext.getSystemService(Context.CONNECTIVITY_SERVICE));
320 | return connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnected();
321 | }
322 |
323 | /**
324 | * utlity method used to toast the message
325 | * @param message message to be displayed in the toast
326 | * @param seconds duration of time that message is to be shown
327 | */
328 | public void toast(String message, int seconds) {
329 |
330 | if (message == null) {
331 |
332 | Log.d("Utils Plus", "message can not be null");
333 | return;
334 |
335 | }
336 |
337 | if (seconds <= 0) {
338 | Log.d("Utils Plus", "Time in seconds can not be <= 0");
339 | return;
340 | }
341 | long milliseconds;
342 | milliseconds = seconds * 1000;
343 | final Toast toast = Toast.makeText(mcontext, message, Toast.LENGTH_SHORT);
344 | toast.show();
345 |
346 | new CountDownTimer(milliseconds, 1000) {
347 | public void onTick(long millisUntilFinished) {
348 | toast.show();
349 | }
350 |
351 | public void onFinish() {
352 | toast.cancel();
353 | }
354 | }.start();
355 |
356 |
357 | }
358 |
359 | /**
360 | * this utility method is used to encrypt the information
361 | * @param encryptKey secret key which is used to encrypt the information
362 | * @param value information to be encrypted
363 | * @return encrypted information
364 | */
365 | public String encryptIt(String encryptKey, String value) {
366 | try {
367 | DESKeySpec keySpec = new DESKeySpec(encryptKey.getBytes("UTF8"));
368 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
369 | SecretKey key = keyFactory.generateSecret(keySpec);
370 |
371 | byte[] clearText = value.getBytes("UTF8");
372 | // Cipher is not thread safe
373 | Cipher cipher = Cipher.getInstance("DES");
374 | cipher.init(Cipher.ENCRYPT_MODE, key);
375 |
376 | String encrypedValue = Base64.encodeToString(cipher.doFinal(clearText), Base64.DEFAULT);
377 | return encrypedValue;
378 |
379 | } catch (InvalidKeyException e) {
380 | e.printStackTrace();
381 | } catch (UnsupportedEncodingException e) {
382 | e.printStackTrace();
383 | } catch (InvalidKeySpecException e) {
384 | e.printStackTrace();
385 | } catch (NoSuchAlgorithmException e) {
386 | e.printStackTrace();
387 | } catch (BadPaddingException e) {
388 | e.printStackTrace();
389 | } catch (NoSuchPaddingException e) {
390 | e.printStackTrace();
391 | } catch (IllegalBlockSizeException e) {
392 | e.printStackTrace();
393 | }
394 | return value;
395 | }
396 |
397 | /**
398 | * this utility method is used to decrypt the encrypted information.
399 | * @param decryptKey secret key which is required to decrypt the information
400 | * @param value information which is to be decrypted
401 | * @return decrypted information
402 | */
403 | public String decryptIt(String decryptKey, String value) {
404 | try {
405 | DESKeySpec keySpec = new DESKeySpec(decryptKey.getBytes("UTF8"));
406 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
407 | SecretKey key = keyFactory.generateSecret(keySpec);
408 |
409 | byte[] encrypedPwdBytes = Base64.decode(value, Base64.DEFAULT);
410 | // cipher is not thread safe
411 | Cipher cipher = Cipher.getInstance("DES");
412 | cipher.init(Cipher.DECRYPT_MODE, key);
413 | byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));
414 |
415 | String decrypedValue = new String(decrypedValueBytes);
416 | return decrypedValue;
417 |
418 | } catch (InvalidKeyException e) {
419 | e.printStackTrace();
420 | } catch (UnsupportedEncodingException e) {
421 | e.printStackTrace();
422 | } catch (InvalidKeySpecException e) {
423 | e.printStackTrace();
424 | } catch (NoSuchAlgorithmException e) {
425 | e.printStackTrace();
426 | } catch (BadPaddingException e) {
427 | e.printStackTrace();
428 | } catch (NoSuchPaddingException e) {
429 | e.printStackTrace();
430 | } catch (IllegalBlockSizeException e) {
431 | e.printStackTrace();
432 | }
433 | return value;
434 | }
435 |
436 | /**
437 | * generates random string
438 | * @return random string
439 | */
440 | private String getRandomString() {
441 | return UUID.randomUUID().toString();
442 |
443 | }
444 |
445 | /**
446 | * converts image of the form "drawable" to "bitmap"
447 | * @param drawable drawable resource
448 | * @return bitmap obtained from drawable
449 | */
450 | private Bitmap drawableToBitmap(Drawable drawable) {
451 | if (drawable instanceof BitmapDrawable) {
452 | return ((BitmapDrawable) drawable).getBitmap();
453 | }
454 |
455 | int width = drawable.getIntrinsicWidth();
456 | width = width > 0 ? width : 1;
457 | int height = drawable.getIntrinsicHeight();
458 | height = height > 0 ? height : 1;
459 |
460 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
461 | Canvas canvas = new Canvas(bitmap);
462 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
463 | drawable.draw(canvas);
464 |
465 | return bitmap;
466 | }
467 |
468 | /**
469 | * validates email
470 | * @param email email address
471 | * @return true or false.
472 | */
473 | public boolean checkEmailIsValid(String email) {
474 | if (email != null && !email.isEmpty()) {
475 | return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
476 | } else {
477 | Log.e("Utils Plus", "email can not be null or empty.");
478 | return false;
479 | }
480 | }
481 |
482 | /**
483 | * validates the phone number with country code
484 | * @param phone_no phone number
485 | * @param country_code country code for example: +91,+1,+93 etc
486 | * @return true or false. whether the given phone no is valid or not.
487 | */
488 | public boolean validatePhoneNumber(String phone_no, String country_code) {
489 | PhoneNumber phoneNumber = null;
490 | PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.createInstance(mcontext);
491 | String finalNumber = null;
492 | String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(country_code));
493 | boolean isValid = false;
494 | PhoneNumberUtil.PhoneNumberType isMobile = null;
495 | try {
496 | phoneNumber = phoneNumberUtil.parse(phone_no, isoCode);
497 | isValid = phoneNumberUtil.isValidNumber(phoneNumber);
498 | if (isValid) return true;
499 | if (!isValid) return false;
500 | } catch (NumberParseException e) {
501 | e.printStackTrace();
502 | } catch (NullPointerException e) {
503 | e.printStackTrace();
504 | }
505 |
506 | return false;
507 | }
508 |
509 | /**
510 | * returns device id of the device. User should grant "android.permission.READ_PHONE_STATE" permission
511 | * @return
512 | */
513 | public String getDeviceID() {
514 | return Settings.Secure.getString(mcontext.getContentResolver(),
515 | Settings.Secure.ANDROID_ID);
516 |
517 | }
518 |
519 | /**
520 | * returns the IMEI Code of the device. proper permission to be granted inorder to make this method work.
521 | * @return IMEI code of the device.
522 | */
523 | public String getIMEICode() {
524 | TelephonyManager telephonyManager = (TelephonyManager) mcontext
525 | .getSystemService(Context.TELEPHONY_SERVICE);
526 | return telephonyManager.getDeviceId();
527 | }
528 |
529 | /**
530 | * Copies specified text to the clipboard
531 | * @param text text to be copied to the clipboard.
532 | */
533 | public String copyToClipboard(String text) {
534 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
535 | android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mcontext.getSystemService(Context.CLIPBOARD_SERVICE);
536 | clipboard.setText(text);
537 | toast("Copied to Clipboard",3);
538 | return text;
539 | } else {
540 | android.content.ClipboardManager clipboard = (android.content.ClipboardManager) mcontext.getSystemService(Context.CLIPBOARD_SERVICE);
541 | android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", text);
542 | clipboard.setPrimaryClip(clip);
543 | toast("Copied to Clipboard",3);
544 | return text;
545 | }
546 | }
547 |
548 | /**
549 | * this utility method checks whether particular service is running or not
550 | * @param serviceClass name of the service class. for example: myservice.class
551 | * @return true or false. whether the given service is running or not
552 | */
553 | private boolean checkServiceIsRunning(Class> serviceClass) {
554 | ActivityManager manager = (ActivityManager) mcontext.getSystemService(Context.ACTIVITY_SERVICE);
555 | for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
556 | if (serviceClass.getName().equals(service.service.getClassName())) {
557 | return true;
558 | }
559 | }
560 | return false;
561 | }
562 |
563 | /**
564 | * Utility method which will help you to show notification in the status bar.
565 | * @param title title of the push notification
566 | * @param body content to be displayed in the notification
567 | * @param small_icon small icon which will be showed in the notification. should be of following format:R.drawable.imageName
568 | * @param large_icon Large icon which will be showed in the notification. should be of following format:R.drawable.imageName
569 | * @param class_name The activity which will open on clicking notification. Parameter format: activity_name.class
570 | * @param autoCancel true or false. if set to true, notification will be disappeared after clicking it otherwise it will remain in the status bar
571 | */
572 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
573 | public void displaySimplePushNotification(String title, String body, int small_icon, int large_icon, Class> class_name, boolean autoCancel) {
574 | NotificationManager notificationManager;
575 | Notification notification;
576 | boolean autoCancelValue = autoCancel;
577 | Intent intent = new Intent(mcontext, class_name);
578 | PendingIntent pIntent = PendingIntent.getActivity(mcontext, (int) System.currentTimeMillis(), intent, 0);
579 |
580 | notification = new Notification.Builder(mcontext)
581 | .setContentTitle(title)
582 | .setContentText(body)
583 | .setContentIntent(pIntent)
584 | .setDefaults(Notification.DEFAULT_SOUND)
585 | .setAutoCancel(autoCancelValue)
586 | .setSmallIcon(small_icon)
587 | .setLargeIcon(BitmapFactory.decodeResource(mcontext.getResources(), large_icon))
588 | .build();
589 |
590 | notificationManager =
591 | (NotificationManager) mcontext.getSystemService(mcontext.NOTIFICATION_SERVICE);
592 |
593 | int maximum=9999, minimum=0;
594 | Random rn = new Random();
595 | int n = maximum - minimum + 1;
596 | int i = rn.nextInt() % n;
597 | notificationManager.notify(minimum + i, notification);
598 |
599 | }
600 |
601 | /**
602 | * sendEmail method is used to send email from available email clients installed in the app
603 | * @param chooserTitle title of the client. Can not be null
604 | * @param subject email subject. Can not be null.
605 | * @param body body of the email. Can not be null
606 | * @param recipients list of recipients. For example, "abc@xyz.com, xyz@dfc.com". this parameter can not be null
607 | */
608 | public void sendEmail(String chooserTitle,String subject, String body, String... recipients){
609 |
610 | checkNull("chooserTitle not allowed to be null", chooserTitle);
611 | checkNull("subject not allowed to be null", subject);
612 | checkNull("body not allowed to be null", body);
613 | checkNull("recipients not allowed to be null", recipients);
614 |
615 | Intent intent = new Intent(Intent.ACTION_SEND);
616 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
617 | intent.setType("message/rfc822");
618 | intent.putExtra(Intent.EXTRA_EMAIL, recipients);
619 | intent.putExtra(Intent.EXTRA_SUBJECT, subject);
620 | intent.putExtra(Intent.EXTRA_TEXT, body);
621 | try {
622 | Intent chooserIntent= Intent.createChooser(intent, chooserTitle);
623 | chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
624 | mcontext.startActivity(chooserIntent);
625 | } catch (android.content.ActivityNotFoundException ex) {
626 | Log.d("Utils Plus", "Activity Not Found");
627 | }
628 | }
629 |
630 | public static T checkNull(String message, T object) {
631 | if(object == null) {
632 | throw new NullPointerException(message);
633 | }
634 | return object;
635 | }
636 |
637 | }
--------------------------------------------------------------------------------
/utilsplus/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Utils Plus
3 |
4 |
--------------------------------------------------------------------------------
/utilsplus/src/test/java/com/github/rrsystems/utilsplus/android/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.rrsystems.utilsplus.android;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/utilsplus/utilsplus.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------