This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from opendatakit/demo
merge demo to master
- Loading branch information
Showing
14 changed files
with
96 additions
and
32 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
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,6 +1,6 @@ | ||
#Thu Mar 29 16:05:43 PDT 2018 | ||
#Thu Sep 27 16:04:41 PDT 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,22 @@ | |
*/ | ||
package org.opendatakit.sensors.ui.activity; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
import org.opendatakit.sensors.Constants; | ||
import org.opendatakit.sensors.R; | ||
import org.opendatakit.sensors.SensorsSingleton; | ||
import org.opendatakit.sensors.ServiceConstants; | ||
import org.opendatakit.utilities.RuntimePermissionUtils; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -33,6 +40,15 @@ public class AddSensorActivity extends Activity { | |
|
||
private static final String LOGTAG = AddSensorActivity.class.getSimpleName(); | ||
|
||
protected static final String[] REQUIRED_PERMISSIONS = new String[] { | ||
Manifest.permission.BLUETOOTH_ADMIN, | ||
Manifest.permission.BLUETOOTH, | ||
Manifest.permission.WRITE_EXTERNAL_STORAGE, | ||
Manifest.permission.ACCESS_COARSE_LOCATION | ||
}; | ||
|
||
protected static final int PERMISSION_REQ_CODE = 5; | ||
|
||
private static final int RESULT_OK_BT = 1; | ||
private static final int RESULT_OK_USB = 2; | ||
|
||
|
@@ -41,6 +57,14 @@ public class AddSensorActivity extends Activity { | |
@Override public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
if (!RuntimePermissionUtils.checkSelfAllPermission(this, REQUIRED_PERMISSIONS)) { | ||
ActivityCompat.requestPermissions( | ||
this, | ||
REQUIRED_PERMISSIONS, | ||
PERMISSION_REQ_CODE | ||
); | ||
} | ||
|
||
Intent intent = getIntent(); | ||
String tmpAppName = intent.getStringExtra(ServiceConstants.APP_NAME_KEY); | ||
if (tmpAppName == null) { | ||
|
@@ -92,4 +116,39 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
} | ||
} | ||
|
||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
if (requestCode != PERMISSION_REQ_CODE) { | ||
return; | ||
} | ||
|
||
boolean granted = true; | ||
if (grantResults.length > 0) { | ||
for (int i = 0; i < grantResults.length; i++) { | ||
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { | ||
granted = false; | ||
} | ||
} | ||
|
||
if (granted) | ||
return; | ||
|
||
if (RuntimePermissionUtils.shouldShowAnyPermissionRationale(this, permissions)) { | ||
RuntimePermissionUtils.createPermissionRationaleDialog(this, requestCode, permissions).setMessage(R.string.write_external_storage_rationale) | ||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { | ||
@Override public void onClick(DialogInterface dialog, int which) { | ||
dialog.cancel(); | ||
setResult(Activity.RESULT_CANCELED); | ||
finish(); | ||
} | ||
}).show(); | ||
} else { | ||
Toast.makeText(this, R.string.write_external_perm_denied, Toast.LENGTH_LONG).show(); | ||
setResult(Activity.RESULT_CANCELED); | ||
finish(); | ||
} | ||
} | ||
} | ||
} |
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
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