Skip to content

Commit 5d0e033

Browse files
committed
1. Updated README.md
2. Modified SwitchButton 3. Modified SharedPreferenceData
1 parent bac43e6 commit 5d0e033

File tree

4 files changed

+475
-9
lines changed

4 files changed

+475
-9
lines changed

README.md

Lines changed: 272 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Setup
44

55
#### 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:**
77
```
88
allprojects{
99
repositories {
@@ -37,3 +37,274 @@ dependencies {
3737
version>v1.1.2</version>
3838
dependency>
3939
```
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+
```

app/src/main/java/com/amit/db/DBHelper.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
/**
1313
* Created by AMIT JANGID
14+
* 2018 Feb 01 - Thursday - 02:55 PM
15+
*
1416
* this class has method for executing db queries
1517
* like: creating table, inserting into table, deleting table, dropping table
1618
*/
@@ -128,8 +130,10 @@ public DBHelper(Context context)
128130
**/
129131

130132
// endregion
131-
public boolean executeDatabaseOperations(String tableName, String operations,
132-
LinkedHashMap<String, String> values, boolean hasConditions,
133+
public boolean executeDatabaseOperations(String tableName,
134+
String operations,
135+
LinkedHashMap<String, String> values,
136+
boolean hasConditions,
133137
LinkedHashMap<String, String> conditionalValues)
134138
{
135139
try
@@ -324,6 +328,8 @@ public boolean executeDatabaseOperations(String tableName, String operations,
324328
}
325329
}
326330

331+
// region COMMENTS FOR executeSelectQuery method
332+
327333
/**
328334
* 2018 Feb 01 - Thursday - 03:52 PM
329335
* Execute Select Query
@@ -351,7 +357,11 @@ public boolean executeDatabaseOperations(String tableName, String operations,
351357
* when you want to select one or multiple columns from the table
352358
* no matter condition is there or not
353359
**/
354-
public Cursor executeSelectQuery(String tableName, String values, boolean hasConditions,
360+
361+
// endregion COMMENTS FOR executeSelectQuery method
362+
public Cursor executeSelectQuery(String tableName,
363+
String values,
364+
boolean hasConditions,
355365
LinkedHashMap<String, String> conditionalValues)
356366
{
357367
try
@@ -422,6 +432,8 @@ public Cursor executeSelectQuery(String tableName, String values, boolean hasCon
422432
}
423433
}
424434

435+
// region COMMENTS FOR getRecordCount method
436+
425437
/**
426438
* 2018 Feb 02 - Friday - 01:36 PM
427439
* Get Record Count
@@ -450,6 +462,8 @@ public Cursor executeSelectQuery(String tableName, String values, boolean hasCon
450462
*
451463
*** @return this method will return the count of the record in the table
452464
* */
465+
466+
// endregion COMMENTS FOR getRecordCount method
453467
public int getRecordCount(String tableName,
454468
String values,
455469
boolean hasConditions,

app/src/main/java/com/amit/ui/SwitchButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SwitchButton extends View
2525
private String[] mTabTexts = {"Male", "Female"};
2626
private int mNumOfTabs = mTabTexts.length;
2727

28-
private static final float TEXT_SIZE = 14;
28+
private static final float TEXT_SIZE = 50; // changed text size to 30 from 14
2929
private static final float STROKE_WIDTH = 2;
3030
private static final float STROKE_RADIUS = 0;
3131

0 commit comments

Comments
 (0)