Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some gradle performance and user experience improvements #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ 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') {
exclude group: 'com.android.support'
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'
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/cielo/ordermanager/sdk/sample/Util.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<string name="title_activity_main2">Main2Activity</string>
<string name="refresh_list">Atualizar Lista</string>


<string name="location_permission_necessary">É necessário permitir o acesso a localização. Acesse as informações do aplicativo para dar a permissão.</string>
<string name="camera_permission_necessary">É necessário permitir o acesso a câmera. Acesse as informações do aplicativo para dar a permissão.</string>
<string name="change_mapbox_access_token">Para ver o mapa, troque o access token do Map Box no arquivo strings.xml</string>

<string name="mapbox_access_token">MAPBOX TOKEN</string>

</resources>