Skip to content

Commit b664868

Browse files
committed
1. Updated ApiServices class.
2. Added Wifi and Mobile connection check in internet. 3. Added UiUtils class. 4. Added Utils class. 5. Added Phone read state permission.
1 parent ec809da commit b664868

File tree

9 files changed

+714
-51
lines changed

9 files changed

+714
-51
lines changed
0 Bytes
Binary file not shown.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ android {
2020
}
2121

2222
dependencies {
23-
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
implementation fileTree(include: ['*.jar'], dir: 'libs')
2424
implementation 'com.android.support:appcompat-v7:27.1.1'
25+
implementation 'com.android.support:design:27.1.1'
2526
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package="com.amit">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
56
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
67
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
78
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

app/src/main/java/com/amit/api/ApiServices.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,35 @@ public String getDeviceName()
6262

6363
if (model.startsWith(manufacturer))
6464
{
65-
return capitalize(model);
65+
return capitalizeString(model);
6666
}
6767
else
6868
{
69-
return capitalize(manufacturer + " " + model);
69+
return capitalizeString(manufacturer + " " + model);
7070
}
7171
}
7272

7373
/**
74-
* capitalize method
74+
* capitalizeString method
7575
*
76-
* this method will capitalize or set the string to upper case
76+
* this method will capitalizeString or set the string to upper case
7777
**/
78-
private String capitalize(String s)
78+
private String capitalizeString(String string)
7979
{
80-
if (s == null || s.length() == 0)
80+
if (string == null || string.length() == 0)
8181
{
8282
return "";
8383
}
8484

85-
char first = s.charAt(0);
85+
char first = string.charAt(0);
8686

8787
if (Character.isUpperCase(first))
8888
{
89-
return s;
89+
return string;
9090
}
9191
else
9292
{
93-
return Character.toUpperCase(first) + s.substring(1);
93+
return Character.toUpperCase(first) + string.substring(1);
9494
}
9595
}
9696

@@ -131,7 +131,7 @@ private String capitalize(String s)
131131
* @return String which contains result from API.
132132
*
133133
************************************************************************************************
134-
* */
134+
**/
135135
public String makeAPICall(final String apiName, final String requestMethod,
136136
final boolean parameters, final JSONObject values,
137137
final boolean hasToken)
@@ -224,7 +224,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
224224
* @param requestType - request type will be GET OR POST
225225
* @param parameter - if any information has to be sent in body then set parameters
226226
* use json object for this parameter.
227-
**/
227+
**/
228228
public Pair<Integer, Bitmap> getBitmapData(String url, String requestType, String parameter)
229229
{
230230
Bitmap resultVal = null;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.amit.utilities;
2+
3+
import android.content.Context;
4+
import android.net.ConnectivityManager;
5+
import android.net.NetworkInfo;
6+
import android.support.annotation.CheckResult;
7+
import android.util.Log;
8+
9+
import static android.content.Context.CONNECTIVITY_SERVICE;
10+
11+
/**
12+
* Created By AMIT JANGID
13+
* 2018 April 17 - Tuesday - 12:50 PM
14+
**/
15+
public class Internet
16+
{
17+
private static final String TAG = Internet.class.getSimpleName();
18+
19+
/**
20+
* isInternetConnected
21+
* this method will check for connectivity service
22+
*
23+
* @param context - context of the application
24+
* @return - returns true or false.
25+
**/
26+
@CheckResult
27+
public static boolean isInternetConnected(Context context)
28+
{
29+
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
30+
31+
if (connectivityManager != null)
32+
{
33+
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
34+
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
35+
}
36+
else
37+
{
38+
return false;
39+
}
40+
}
41+
42+
/**
43+
* isMobileNetConnected
44+
* this method helps to find out whether the user is connected to mobile internet or not
45+
*
46+
* @param context - context of the application
47+
* @return this returns true or false
48+
* true if connected or connecting
49+
* false if not connected.
50+
**/
51+
@CheckResult
52+
public static boolean isMobileNetConnected(Context context)
53+
{
54+
try
55+
{
56+
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
57+
58+
if (manager != null)
59+
{
60+
return manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
61+
}
62+
else
63+
{
64+
Log.e(TAG, "isMobileInternetAvailable: connectivity manager was null.");
65+
return false;
66+
}
67+
}
68+
catch (Exception e)
69+
{
70+
Log.e(TAG, "isMobileInternetAvailable: exception while checking for mobile internet.");
71+
return false;
72+
}
73+
}
74+
75+
/**
76+
* isWifiConnected
77+
* this method will check if the device is connected to a wifi
78+
*
79+
* @param context - context of the application
80+
* @return - this returns true or false
81+
* true if connected
82+
* false if not connected
83+
**/
84+
@CheckResult
85+
public static boolean isWifiConnected(Context context)
86+
{
87+
try
88+
{
89+
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
90+
91+
if (manager != null)
92+
{
93+
return manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
94+
}
95+
else
96+
{
97+
Log.e(TAG, "isWifiConnected: connectivity manager is null.");
98+
return false;
99+
}
100+
}
101+
catch (Exception e)
102+
{
103+
Log.e(TAG, "isWifiConnected: exception while checking for wifi connection.");
104+
e.printStackTrace();
105+
return false;
106+
}
107+
}
108+
}

app/src/main/java/com/amit/utilities/InternetConnection.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)