From 17b6400e9834af3a858beae3cc913d18780de4ef Mon Sep 17 00:00:00 2001 From: Kaique Ocanha Date: Sat, 13 Apr 2019 11:27:51 -0300 Subject: [PATCH 1/3] Improve of gradle performance --- app/build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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' } From 7a73bff09ecf67c8cbcb5f9ce3ad04389a10b547 Mon Sep 17 00:00:00 2001 From: Kaique Ocanha Date: Sat, 13 Apr 2019 11:35:48 -0300 Subject: [PATCH 2/3] Added permission request for location access and camera access --- .../ordermanager/sdk/sample/MainActivity.java | 47 +++++++++++++++++-- .../cielo/ordermanager/sdk/sample/Util.java | 16 +++++++ app/src/main/res/values/strings.xml | 5 ++ 3 files changed, 63 insertions(+), 5 deletions(-) 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 From f6934030a7e53e0321347824fee72af10d3c1db2 Mon Sep 17 00:00:00 2001 From: Kaique Ocanha Date: Sat, 13 Apr 2019 11:37:36 -0300 Subject: [PATCH 3/3] Added a debug toast message to instruct about the Map Box's access token --- .../sdk/sample/LocationSampleActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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