Skip to content

Commit 0ade788

Browse files
committed
1. Add method for checking if GPS is enabled or not.
1 parent 81167d6 commit 0ade788

File tree

11 files changed

+111
-41
lines changed

11 files changed

+111
-41
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.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.

README.md

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,46 @@ sharedPreferenceData.getStrSetValue(key);
132132
>Before using this class first make sure to set up the apiPath into shared preference class. Shown above in **ProjectApplication** Section.
133133
134134
```java
135-
// apiName - this will the part of the api url
136-
//
137-
// requestMethod - this will GET, POST OR PUT
138-
//
139-
// parameters - this is a boolean value
140-
// if you want to send parameters in body then this should be set to true.
141-
// else it should be false.
142-
// if you don't want to pass data in body
143-
// then it should be set to false
144-
// and send data as parameters by appending it to the api name
145-
//
146-
// jsonObject - this will be the data which you want to send by body to the api.
147-
//
148-
// hasToken - this will take boolean vaule true or false.
149-
// if you have verification in your api where you are using token then
150-
// you should set it to true otherwise to false.
151-
// but set the token into sharedPreferenceData
152-
// with key as 'token' to get the token
153-
//
154-
// return - this method will return result from server in string format
155-
135+
/**
136+
* Make API Call method
137+
*
138+
* this method will handle all the api operations like GET OR POST OR PUT
139+
* parameters for this method are as follows
140+
*
141+
************************************************************************************************
142+
*
143+
*** parameter #1
144+
*** @param apiName - this parameter will contain the name of the api with some path or without any path
145+
* - FOR EXAMPLE: with path - MobileAPI/RegisterMobile
146+
* without path - RegisterMobile
147+
*
148+
*** parameter #2
149+
*** @param requestMethod - this parameter will be passed with 3 values
150+
* #1 - POST OR
151+
* #2 - PUT OR
152+
* #3 - GET
153+
*
154+
*** parameter #3
155+
*** @param parameters - this parameter will contain parameters which will be passed to the api
156+
* and required by the api to work properly
157+
*
158+
*** parameter #4
159+
*** @param values - this parameter will hold the parameters in JSON format
160+
* this will be the data which we need to pass along with the api
161+
* - FOR EXAMPLE: MobileNumber = 9999999999, OTP = 9999, etc.
162+
*
163+
*** parameter #5
164+
*** @param hasToken - this parameter should be passed with true or false
165+
* - this parameter will be used if the api requires some token to work with
166+
* - if the api requires token then this has to be true
167+
* - if the api doesn't require token then this has to be false
168+
*
169+
* @return Pair of integer and string which contains response value and response code from the server
170+
*
171+
************************************************************************************************
172+
**/
156173
ApiServices apiServices = new ApiServices(context);
157-
apiServices.makeApiCall(apiName, requestMethod, parameters, jsonObject, hasToken);
174+
apiServices.makeApiCall(apiName, requestMethod, parameters, jsonObject, hasToken).second;
158175
```
159176

160177
### DBHelper
@@ -386,6 +403,11 @@ switchButton.setOnSwitchListener(new SwitchButton.OnSwitchListener()
386403
>**This class will get the current location of the user.**
387404
388405
```java
406+
407+
// this will check whether gps is enabled or not
408+
MyLocation.isGPSEnabled(Context context); // returns true or false
409+
410+
// following code is for getting latitude and longitude
389411
// Declare this class globally inside your activity or class.
390412
private double latitude = 0.0, longitude = 0.0;
391413
private MyLocation myLocation = new MyLocation();

app/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ android {
1313
versionCode 29 // this indicates the number of releases of library
1414
versionName "1.3.1" // this indicates the current version of library
1515
}
16+
1617
buildTypes {
1718
release {
1819
minifyEnabled true
@@ -23,6 +24,11 @@ android {
2324
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2425
}
2526
}
27+
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
2632
}
2733

2834
repositories {

app/src/main/java/com/amit/drawables/CircularAnimDrawable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void stop()
128128
/**
129129
* Method the inform if the animation is in process
130130
*
131-
* @return
131+
* @return true or false
132132
*/
133133
@Override
134134
public boolean isRunning()
@@ -138,7 +138,7 @@ public boolean isRunning()
138138

139139
/**
140140
* Method called when the drawable is going to draw itself.
141-
* @param canvas
141+
* @param canvas - canvas object
142142
*/
143143
@Override
144144
public void draw(Canvas canvas)

app/src/main/java/com/amit/location/MyLocation.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,31 @@
66
import android.location.Location;
77
import android.location.LocationListener;
88
import android.location.LocationManager;
9+
import android.os.Build;
910
import android.os.Bundle;
11+
import android.provider.Settings;
1012
import android.support.v4.app.ActivityCompat;
13+
import android.text.TextUtils;
1114
import android.util.Log;
1215

1316
import java.util.Timer;
1417
import java.util.TimerTask;
1518

1619
/**
1720
* Created by RAMCHANDRA SINGH on 10-03-2017.
18-
*/
21+
**/
22+
@SuppressWarnings("unused")
1923
public class MyLocation
2024
{
25+
private static final String TAG = MyLocation.class.getSimpleName();
26+
2127
private Timer timer1;
2228
private LocationManager locationManager;
2329
private LocationResult locationResult;
2430
private boolean gps_enabled = false;
2531
private boolean network_enabled = false;
2632
private Context mContext;
2733

28-
private String TAG = "MyLocation";
29-
private int REQUEST_CHECK_SETTINGS = 1;
30-
3134
private LocationListener locationListenerNetwork = new LocationListener()
3235
{
3336
public void onLocationChanged(Location location)
@@ -162,6 +165,7 @@ public boolean getLocation(Context context, LocationResult result)
162165
return true;
163166
}
164167

168+
@SuppressWarnings("WeakerAccess")
165169
public static abstract class LocationResult
166170
{
167171
public abstract void gotLocation(Location location);
@@ -223,4 +227,41 @@ public void run()
223227
locationResult.gotLocation(null);
224228
}
225229
}
230+
231+
/**
232+
* 2018 October 17 - Wednesday - 02:50 PM
233+
* is gps enabled method
234+
*
235+
* this method will check if gps is enabled or not
236+
*
237+
* @param context - context of the application
238+
*
239+
* @return true if enabled, false if not enabled.
240+
**/
241+
@SuppressWarnings("deprecation")
242+
public static boolean isGPSEnabled(Context context)
243+
{
244+
int locationMode;
245+
String locationProviders;
246+
247+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
248+
{
249+
try
250+
{
251+
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
252+
}
253+
catch (Settings.SettingNotFoundException e)
254+
{
255+
e.printStackTrace();
256+
return false;
257+
}
258+
259+
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
260+
}
261+
else
262+
{
263+
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
264+
return !TextUtils.isEmpty(locationProviders);
265+
}
266+
}
226267
}

app/src/main/java/com/amit/shinebtn/ShineButton.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.amit.R;
2121

22+
@SuppressWarnings({"unused", "WeakerAccess"})
2223
public class ShineButton extends PorterShapeImageView
2324
{
2425
private static final String TAG = "ShineButton";
@@ -27,10 +28,7 @@ public class ShineButton extends PorterShapeImageView
2728
private int btnColor;
2829
private int btnFillColor;
2930

30-
int DEFAULT_WIDTH = 50;
31-
int DEFAULT_HEIGHT = 50;
32-
33-
DisplayMetrics metrics = new DisplayMetrics();
31+
private DisplayMetrics metrics = new DisplayMetrics();
3432

3533
Activity activity;
3634
ShineView shineView;
@@ -284,7 +282,7 @@ public void showAnim()
284282
{
285283
if (activity != null)
286284
{
287-
final ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
285+
final ViewGroup rootView = activity.findViewById(Window.ID_ANDROID_CONTENT);
288286
shineView = new ShineView(activity, this, shineParams);
289287
rootView.addView(shineView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
290288
doShareAnim();
@@ -299,7 +297,7 @@ public void removeView(View view)
299297
{
300298
if (activity != null)
301299
{
302-
final ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
300+
final ViewGroup rootView = activity.findViewById(Window.ID_ANDROID_CONTENT);
303301
rootView.removeView(view);
304302
}
305303
else

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.graphics.Bitmap;
88
import android.graphics.Canvas;
99
import android.graphics.Color;
10-
import android.graphics.Point;
1110
import android.graphics.Typeface;
1211
import android.graphics.drawable.BitmapDrawable;
1312
import android.graphics.drawable.Drawable;
@@ -24,15 +23,13 @@
2423
import android.util.Base64;
2524
import android.util.DisplayMetrics;
2625
import android.util.Log;
27-
import android.view.WindowManager;
2826
import android.view.inputmethod.InputMethodManager;
2927

3028
import java.net.MalformedURLException;
3129
import java.net.URISyntaxException;
3230
import java.net.URL;
3331
import java.security.MessageDigest;
3432
import java.security.NoSuchAlgorithmException;
35-
import java.util.Locale;
3633

3734
/**
3835
* https://github.com/jaydeepw/android-utils/tree/master/Utils

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.1.3'
9+
classpath 'com.android.tools.build:gradle:3.2.1'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri May 04 17:41:03 IST 2018
1+
#Sat Oct 20 10:27:15 IST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 commit comments

Comments
 (0)