|
3 | 3 | ## Setup |
4 | 4 |
|
5 | 5 | #### Step 1. Add the JitPack repository to your build file |
6 | | -##### Add it in your root build.gradle at the end of repositories: |
| 6 | +>**Add it in your root build.gradle at the end of repositories:** |
7 | 7 | ``` |
8 | 8 | allprojects{ |
9 | 9 | repositories { |
@@ -37,3 +37,274 @@ dependencies { |
37 | 37 | version>v1.1.2</version> |
38 | 38 | dependency> |
39 | 39 | ``` |
| 40 | + |
| 41 | +## Usage |
| 42 | +### ProjectApplication Class |
| 43 | +>**You can create an Application class for your project if you want and set up some utils there.** |
| 44 | +
|
| 45 | +```java |
| 46 | +public class ProjectApplication extends Application |
| 47 | +{ |
| 48 | + @Override |
| 49 | + public void onCreate() |
| 50 | + { |
| 51 | + super.onCreate(); |
| 52 | + |
| 53 | + // Set up SharedPreferenceData |
| 54 | + // the key in the shared preference should be of same name as given below. |
| 55 | + // these two are the constant values which will be used in the entire application |
| 56 | + String apiPath = "https://www.example.com/api/"; |
| 57 | + |
| 58 | + SharedPreferenceData sharedPreferenceData = new SharedPreferenceData(this); |
| 59 | + sharedPreferenceData.setValue("apiPath", apiPath); |
| 60 | + sharedPreferenceData.setValue("dbName", "YourDatabaseName"); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### SharedPreferenceData |
| 66 | + |
| 67 | +``` |
| 68 | +// use it in the activity or class you want to. |
| 69 | +SharedPreferenceData sharedPreferenceData = new SharedPreferenceData(context); |
| 70 | +sharedPreferenceData.setValue("keyname", "value for that keyname"); |
| 71 | +``` |
| 72 | + |
| 73 | +### ApiServices |
| 74 | + |
| 75 | +>Before using this class first make sure to set up the apiPath into shared preference class. Shown above in **ProjectApplication** Section. |
| 76 | +
|
| 77 | +``` |
| 78 | +// apiName - this will the part of the api url |
| 79 | +// |
| 80 | +// requestMethod - this will GET, POST OR PUT |
| 81 | +// |
| 82 | +// parameters - this is a boolean value |
| 83 | +// if you want to send parameters in body then this should be set to true. |
| 84 | +// else it should be false. |
| 85 | +// if you don't want to pass data in body |
| 86 | +// then it should be set to false |
| 87 | +// and send data as parameters by appending it to the api name |
| 88 | +// |
| 89 | +// jsonObject - this will be the data which you want to send by body to the api. |
| 90 | +// |
| 91 | +// hasToken - this will take boolean vaule true or false. |
| 92 | +// if you have verification in your api where you are using token then |
| 93 | +// you should set it to true otherwise to false. |
| 94 | +// but set the token into sharedPreferenceData |
| 95 | +// with key as 'token' to get the token |
| 96 | +// |
| 97 | +// return - this method will return result from server in string format |
| 98 | +// |
| 99 | +ApiServices apiServices = new ApiServices(context); |
| 100 | +apiServices.makeApiCall(apiName, requestMethod, parameters, jsonObject, hasToken); |
| 101 | +``` |
| 102 | + |
| 103 | +### DBHelper |
| 104 | + |
| 105 | +>Set the dbName in sharedPreferenceData with key name **'dbName'**. Shown above in **ProjectApplication** section. |
| 106 | +
|
| 107 | +``` |
| 108 | +// parameters to be passed are as follows: |
| 109 | +// |
| 110 | +// tableName - table on which query should be performed. |
| 111 | +// |
| 112 | +// operation - c for creating table, |
| 113 | +// i - for inserting records in table |
| 114 | +// d - for deleting records in table |
| 115 | +// u - for updating records in table |
| 116 | +// dr - for droping the table |
| 117 | +// |
| 118 | +// values - it is of type LinkedHashMap<String, String> |
| 119 | +// declaration as below |
| 120 | +// LinkedHashMap<String, String> vauels = new LinkedHashMap<>(); |
| 121 | +// now just add your column name and values or data types |
| 122 | +// |
| 123 | +// example: values.put("ID", "INTEGER PRIMARY KEY AUTOINCREMENT"); |
| 124 | +// values.put("firstName", "TEXT"); |
| 125 | +// |
| 126 | +// use this way when creating a table. |
| 127 | +// when inserting a record in the table |
| 128 | +// example: value.put("firstName", "'Amit'"); |
| 129 | +// notice the single quotes inside the double quotes where name is written. |
| 130 | +// for string value you should pass with single quotes and integer value can be passed directly |
| 131 | +// |
| 132 | +// hasConditions - set this value as true or false |
| 133 | +// if you are setting this parameter as true |
| 134 | +// then you must also pass the conditionalValues parameter as well |
| 135 | +// else the query won't work |
| 136 | +// |
| 137 | +// this parameter is useful when using conditional queries like update or delete |
| 138 | +// where you create another linked hash map like the one above can just pass the coloumn name or conditions with values |
| 139 | +// the values should be passed the way we pass in insert query. |
| 140 | +// |
| 141 | +// conditionalValues - when passing this parameter make sure |
| 142 | +// |
| 143 | +// return - the method will return true or false if the operation is successful or failed. |
| 144 | +// |
| 145 | + |
| 146 | +DBHelper dbHelper = new DBHelper(context); |
| 147 | +dbHelper.executeDatabaseOperation(tableName, operation, values, hasConditions, conditionalValues); |
| 148 | +``` |
| 149 | +``` |
| 150 | +// for select query use this method |
| 151 | +// |
| 152 | +// parameters to be passed are as follows: |
| 153 | +// |
| 154 | +// tableName - table on which query should be performed. |
| 155 | +// |
| 156 | +// values - values will be of type string, |
| 157 | +// you can pass * or name of the columns saperated by , |
| 158 | +// |
| 159 | +// hasConditions - hasConditions is of type boolean |
| 160 | +// pass true or false to this parameter |
| 161 | +// if true then you must pass conditoinalValues parameter |
| 162 | +// else if it's false then conditionalValues can be passed as null |
| 163 | +// |
| 164 | +// conditionalValues - if hasConditions value is true or false |
| 165 | +// then pass this parameter as linked hash map |
| 166 | +// it is similar as in executeDatabaseOperation method's conditionalValues parameter. |
| 167 | +// |
| 168 | +// return - this method wull return Cursor with values or will return null |
| 169 | +// |
| 170 | +dbHelper.executeSelectQuery(tableName, values, hasConditions, conditionalValues); |
| 171 | +``` |
| 172 | +``` |
| 173 | +// for select query use this method |
| 174 | +// |
| 175 | +// parameters to be passed are as follows: |
| 176 | +// |
| 177 | +// tableName - table on which query should be performed. |
| 178 | +// |
| 179 | +// values - values will be of type string, |
| 180 | +// you can pass * or name of the column |
| 181 | +// |
| 182 | +// hasConditions - hasConditions is of type boolean |
| 183 | +// pass true or false to this parameter |
| 184 | +// if true then you must pass conditoinalValues parameter |
| 185 | +// else if it's false then conditionalValues can be passed as null |
| 186 | +// |
| 187 | +// conditionalValues - if hasConditions value is true or false |
| 188 | +// then pass this parameter as linked hash map |
| 189 | +// it is similar as in executeDatabaseOperation method's conditionalValues parameter. |
| 190 | +// |
| 191 | +// return - this method wull return count of records in the table |
| 192 | +// either for entire table or for a single column |
| 193 | +// |
| 194 | +dbHelper.getRecordCount(tableName, values, hasConditions, conditionalValues); |
| 195 | +``` |
| 196 | + |
| 197 | +### SquareImageView |
| 198 | +>**Use it the way you use ImageView in android. This makes your image in a perfect square shape.** |
| 199 | +
|
| 200 | +```xml |
| 201 | +<com.amit.imgview.SquareImageView |
| 202 | + android:id="@+id/squareImageView" |
| 203 | + android:layout_width="match_parent" |
| 204 | + android:layout_height="wrap_content" |
| 205 | + android:scaleType="centerCrop" |
| 206 | + android:src="@drawable/no_image" /> |
| 207 | +``` |
| 208 | + |
| 209 | + |
| 210 | +### CircularImageView |
| 211 | +>**Use it the way you use ImageView in android. Attributes for this image view are as follows:** |
| 212 | +
|
| 213 | +**1. highlightEnable - true/false** |
| 214 | + |
| 215 | +**2. highlightColor** |
| 216 | + |
| 217 | +**3. imgStrokeWidth** |
| 218 | + |
| 219 | +**4. strokeColor** |
| 220 | + |
| 221 | +>**example code:** |
| 222 | +
|
| 223 | +```xml |
| 224 | +<com.amit.imgview.CircularImageView |
| 225 | + android:id="@+id/circularImageView" |
| 226 | + android:layout_width="match_parent" |
| 227 | + android:layout_height="wrap_content" |
| 228 | + android:scaleType="centerCrop" |
| 229 | + android:src="@drawable/no_image" |
| 230 | + app:highlightColor="@color/colorPrimary" |
| 231 | + app:highlightEnable="true" |
| 232 | + app:imgStrokeWidth="2dp" |
| 233 | + app:strokeColor="#000000" /> |
| 234 | +``` |
| 235 | + |
| 236 | +### AvatarImageView |
| 237 | +>**Use it the way you use ImageView in android** |
| 238 | +
|
| 239 | +**1. imgStrokeWidth** |
| 240 | + |
| 241 | +**2. strokeColor** |
| 242 | + |
| 243 | +**3. avatar_backgroundColor** |
| 244 | + |
| 245 | +**4. avatar_text** |
| 246 | + |
| 247 | +**5. avatar_textColor** |
| 248 | + |
| 249 | +**6. avatar_textSize** |
| 250 | + |
| 251 | +**7. avatar_state - IMAGE/INITIAL - use image if you want to show image or use initial if you want to show initial letter of a word.** |
| 252 | + |
| 253 | +>**example code:** |
| 254 | +
|
| 255 | +```xml |
| 256 | +<com.amit.imgview.AvatarImageView |
| 257 | + android:id="@+id/avatarImageView" |
| 258 | + android:layout_width="match_parent" |
| 259 | + android:layout_height="wrap_content" |
| 260 | + android:scaleType="centerCrop" |
| 261 | + android:src="@drawable/no_image" |
| 262 | + app:avatar_backgroundColor="@color/colorAccent" |
| 263 | + app:avatar_state="INITIAL" |
| 264 | + app:avatar_text="A" |
| 265 | + app:avatar_textColor="#FFFFFF" |
| 266 | + app:avatar_textSize="30sp" |
| 267 | + app:imgStrokeWidth="5dp" |
| 268 | + app:strokeColor="@color/colorPrimary" /> |
| 269 | +``` |
| 270 | + |
| 271 | +### TouchImageView |
| 272 | +>**Use it the way you use ImageView in android. This is helpful when you have to add zoom in or zoom out functionality to the imageView with additional code.** |
| 273 | +
|
| 274 | + |
| 275 | +```xml |
| 276 | +<com.amit.imgview.TouchImageView |
| 277 | + android:id="@+id/imageView" |
| 278 | + android:layout_width="match_parent" |
| 279 | + android:layout_height="match_parent" |
| 280 | + android:src="@drawable/no_image" /> |
| 281 | +``` |
| 282 | + |
| 283 | +### SwitchButton |
| 284 | +>**Use it in the xml file like this.** |
| 285 | +
|
| 286 | +**If you are using typeface then add the font file into assets folder, inside assets folder create another folder named 'fonts'. And then just use the name of your font file like the one in below example.** |
| 287 | + |
| 288 | +```xml |
| 289 | +<com.amit.ui.SwitchButton |
| 290 | + android:id="@+id/switchButton" |
| 291 | + android:layout_width="wrap_content" |
| 292 | + android:layout_height="wrap_content" |
| 293 | + android:layout_margin="10dp" |
| 294 | + android:padding="10dp" |
| 295 | + app:selectedColor="@color/colorPrimary" |
| 296 | + app:selectedTab="0" |
| 297 | + app:strokeRadius="5dp" |
| 298 | + app:strokeWidth="2dp" |
| 299 | + app:switchTabs="@array/gender" |
| 300 | + app:textSize="20sp" |
| 301 | + app:typeface="QuattrocentoSans-Regular.ttf" /> |
| 302 | +``` |
| 303 | + |
| 304 | +### ToastMsg |
| 305 | + |
| 306 | +>**If you want to use a custom toast message then you can use this class.** |
| 307 | +
|
| 308 | +``` |
| 309 | +
|
| 310 | +``` |
0 commit comments