diff --git a/app/build.gradle b/app/build.gradle
index b81df45..038c72e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -50,10 +50,10 @@ configurations.all {
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
// ------------- DEPENDENCIAS NECESSÁRIAS PRO ORDER MANAGER SDK ------------x- //
- compile 'com.cielo.lio:order-manager:0.19.1'
+ implementation 'com.cielo.lio:order-manager:0.19.1'
// --------------------------------------------------------------------------- //
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.1') {
@@ -61,13 +61,13 @@ dependencies {
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
- compile 'com.journeyapps:zxing-android-embedded:3.5.0'
+ implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
implementation 'com.jakewharton:butterknife:9.0.0-rc2'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc2'
implementation 'com.android.support:appcompat-v7:28.0.0'
- compile 'com.android.support:design:28.0.0'
- compile 'com.android.support.constraint:constraint-layout:1.0.2'
- testCompile 'junit:junit:4.12'
+ implementation 'com.android.support:design:28.0.0'
+ implementation 'com.android.support.constraint:constraint-layout:1.0.2'
+ testImplementation 'junit:junit:4.12'
}
diff --git a/app/src/main/java/com/cielo/ordermanager/sdk/sample/LocationSampleActivity.java b/app/src/main/java/com/cielo/ordermanager/sdk/sample/LocationSampleActivity.java
index 8b5796e..14b46f5 100644
--- a/app/src/main/java/com/cielo/ordermanager/sdk/sample/LocationSampleActivity.java
+++ b/app/src/main/java/com/cielo/ordermanager/sdk/sample/LocationSampleActivity.java
@@ -1,10 +1,8 @@
package com.cielo.ordermanager.sdk.sample;
import android.Manifest;
-import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
-import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@@ -13,7 +11,9 @@
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
+import android.widget.Toast;
+import com.cielo.ordermanager.sdk.BuildConfig;
import com.cielo.ordermanager.sdk.R;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
@@ -37,8 +37,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
- locationManager =
- (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
+ if (getString(R.string.mapbox_access_token).equals("MAPBOX TOKEN") && BuildConfig.DEBUG)
+ Toast.makeText(this, getString(R.string.change_mapbox_access_token), Toast.LENGTH_LONG).show();
+
+ locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
diff --git a/app/src/main/java/com/cielo/ordermanager/sdk/sample/MainActivity.java b/app/src/main/java/com/cielo/ordermanager/sdk/sample/MainActivity.java
index 7afa351..7a647c2 100644
--- a/app/src/main/java/com/cielo/ordermanager/sdk/sample/MainActivity.java
+++ b/app/src/main/java/com/cielo/ordermanager/sdk/sample/MainActivity.java
@@ -1,13 +1,17 @@
package com.cielo.ordermanager.sdk.sample;
+import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
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.Button;
import android.widget.TextView;
+import android.widget.Toast;
import com.cielo.ordermanager.sdk.R;
@@ -22,6 +26,12 @@
public class MainActivity extends Activity {
+ private static final int REQCODE_PERM_LOCATION = 101;
+ private static final String[] LOCATION_PERMISSIONS = new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION};
+
+ private static final int REQCODE_PERM_CAMERA = 102;
+ private static final String[] CAMERA_PERMISSIONS = new String[]{Manifest.permission.CAMERA};
+
@BindView(R.id.device_model_text)
TextView deviceModelText;
@@ -135,15 +145,42 @@ public void openExample8() {
@OnClick(R.id.location_sample_button)
public void openExample9() {
- Intent intent = new Intent(this, LocationSampleActivity.class);
- startActivity(intent);
+ if (Util.checkPermissions(LOCATION_PERMISSIONS, this)) {
+ Intent intent = new Intent(this, LocationSampleActivity.class);
+ startActivity(intent);
+ } else {
+ ActivityCompat.requestPermissions(this, LOCATION_PERMISSIONS, REQCODE_PERM_LOCATION);
+ }
}
-
@OnClick(R.id.qr_code_sample)
public void openExample10() {
- Intent intent = new Intent(this, QrCodeActivity.class);
- startActivity(intent);
+ if (Util.checkPermissions(CAMERA_PERMISSIONS, this)) {
+ Intent intent = new Intent(this, QrCodeActivity.class);
+ startActivity(intent);
+ } else {
+ ActivityCompat.requestPermissions(this, CAMERA_PERMISSIONS, REQCODE_PERM_CAMERA);
+ }
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+
+ switch (requestCode) {
+ case REQCODE_PERM_LOCATION:
+ if (Util.checkPermissions(LOCATION_PERMISSIONS, this))
+ openExample9();
+ else
+ Toast.makeText(this, getString(R.string.location_permission_necessary), Toast.LENGTH_LONG).show();
+ break;
+ case REQCODE_PERM_CAMERA:
+ if (Util.checkPermissions(CAMERA_PERMISSIONS, this))
+ openExample10();
+ else
+ Toast.makeText(this, getString(R.string.camera_permission_necessary), Toast.LENGTH_LONG).show();
+ break;
+ }
+
+ }
}
diff --git a/app/src/main/java/com/cielo/ordermanager/sdk/sample/Util.java b/app/src/main/java/com/cielo/ordermanager/sdk/sample/Util.java
index 20f3906..45f76e7 100644
--- a/app/src/main/java/com/cielo/ordermanager/sdk/sample/Util.java
+++ b/app/src/main/java/com/cielo/ordermanager/sdk/sample/Util.java
@@ -1,5 +1,9 @@
package com.cielo.ordermanager.sdk.sample;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.support.v4.app.ActivityCompat;
+
import java.text.NumberFormat;
import java.util.Locale;
@@ -8,4 +12,16 @@ public class Util {
public static String getAmmount(long value) {
return NumberFormat.getCurrencyInstance(new Locale("pt", "BR")).format((value / 100));
}
+
+ public static boolean checkPermissions(String[] permissions, Context context) {
+
+ if (context != null && permissions != null) {
+ for (String permission : permissions) {
+ if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index bf3bc6c..d6fa3da 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -41,6 +41,11 @@
Main2Activity
Atualizar Lista
+
+ É necessário permitir o acesso a localização. Acesse as informações do aplicativo para dar a permissão.
+ É necessário permitir o acesso a câmera. Acesse as informações do aplicativo para dar a permissão.
+ Para ver o mapa, troque o access token do Map Box no arquivo strings.xml
+
MAPBOX TOKEN