-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into develop
- Loading branch information
Showing
20 changed files
with
357 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
WordPressUtils/src/androidTest/java/org/wordpress/android/util/JSONUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.test.InstrumentationTestCase; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
public class JSONUtilsTest extends InstrumentationTestCase { | ||
public void testQueryJSONNullSource1() { | ||
JSONUtils.queryJSON((JSONObject) null, "", ""); | ||
} | ||
|
||
public void testQueryJSONNullSource2() { | ||
JSONUtils.queryJSON((JSONArray) null, "", ""); | ||
} | ||
|
||
public void testQueryJSONNullQuery1() { | ||
JSONUtils.queryJSON(new JSONObject(), null, ""); | ||
} | ||
|
||
public void testQueryJSONNullQuery2() { | ||
JSONUtils.queryJSON(new JSONArray(), null, ""); | ||
} | ||
|
||
public void testQueryJSONNullReturnValue1() { | ||
JSONUtils.queryJSON(new JSONObject(), "", null); | ||
} | ||
|
||
public void testQueryJSONNullReturnValue2() { | ||
JSONUtils.queryJSON(new JSONArray(), "", null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.wordpress.android.util"> | ||
|
||
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
WordPressUtils/src/main/java/org/wordpress/android/util/PermissionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.wordpress.android.util; | ||
|
||
import android.Manifest.permission; | ||
import android.app.Activity; | ||
import android.content.pm.PackageManager; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PermissionUtils { | ||
/** | ||
* Check for permissions, request them if they're not granted. | ||
* | ||
* @return true if permissions are already granted, else request them and return false. | ||
*/ | ||
private static boolean checkAndRequestPermissions(Activity activity, int requestCode, String[] permissionList) { | ||
List<String> toRequest = new ArrayList<>(); | ||
for (String permission : permissionList) { | ||
if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) { | ||
toRequest.add(permission); | ||
} | ||
} | ||
if (toRequest.size() > 0) { | ||
String[] requestedPermissions = toRequest.toArray(new String[toRequest.size()]); | ||
ActivityCompat.requestPermissions(activity, requestedPermissions, requestCode); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static boolean checkAndRequestCameraAndStoragePermissions(Activity activity, int requestCode) { | ||
return checkAndRequestPermissions(activity, requestCode, new String[]{ | ||
permission.WRITE_EXTERNAL_STORAGE, | ||
permission.CAMERA | ||
}); | ||
} | ||
|
||
public static boolean checkAndRequestStoragePermission(Activity activity, int requestCode) { | ||
return checkAndRequestPermissions(activity, requestCode, new String[]{ | ||
permission.WRITE_EXTERNAL_STORAGE | ||
}); | ||
} | ||
|
||
public static boolean checkLocationPermissions(Activity activity, int requestCode) { | ||
return checkAndRequestPermissions(activity, requestCode, new String[]{ | ||
permission.ACCESS_FINE_LOCATION, | ||
permission.ACCESS_COARSE_LOCATION | ||
}); | ||
} | ||
} |
Oops, something went wrong.