Skip to content
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
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: android

android:
components:
- tools
- platform-tools
- extra-android-support
- extra-android-m2repository

jdk:
- oraclejdk8

branches:
except:
- gh-pages

before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55\nd56f5187479451eabf01fb78af6dfcb131a6481e\nd56f5187479451eabf01fb78af6dfcb131a6481e\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license"

licenses:
- android-sdk-license-.+
- '.+'

script:
./gradlew clean build

cache:
directories:
- $HOME/.m2
49 changes: 27 additions & 22 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ copper {
projectName = "AskSample"

publications {
genSourcesForVariant = {false}
artiConfig = project.hasProperty('artiServer')?project.artiServer:"arti01"
genSourcesForVariant = { false }
artiConfig = project.hasProperty('artiServer') ? project.artiServer : "arti01"
}
}

Expand All @@ -25,7 +25,7 @@ android {
targetSdkVersion 28
versionCode versioning.info.versionCode
versionName versioning.info.display
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -39,36 +39,41 @@ android {
exclude 'META-INF/main.kotlin_module'
exclude 'META-INF/lib_release.kotlin_module'
}

// Butterknife requires Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.media:media:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.preference:preference:1.1.0'
implementation 'com.takisoft.preferencex:preferencex:1.1.0'

// Coppernic
implementation 'fr.coppernic.sdk.ask:CpcAsk:3.5.2'
implementation 'fr.coppernic.sdk.core:CpcCore:1.8.14'
implementation'fr.coppernic.sdk.cpcutils:CpcUtilsLib:6.18.4'
implementation 'fr.coppernic.sdk.ask:CpcAsk:chasse'
implementation 'fr.coppernic.sdk.core:CpcCore:1.9.0'
implementation 'fr.coppernic.sdk.cpcutils:CpcUtilsLib:6.19.0'

// Butter knife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.jakewharton:butterknife:10.2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'

// Timber
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'fr.bipi.treessence:treessence:0.3.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package fr.coppernic.samples.ask;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.SystemClock;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.widget.TextView;

Expand All @@ -23,11 +12,20 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.*;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* Instrumentation test, which will execute on an Android device.
Expand All @@ -42,9 +40,9 @@ public class HuntInstrumentedTest {
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<> (MainActivity.class);

@Test
public void useAppContext() throws Exception {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
Context appContext = ApplicationProvider.getApplicationContext();

assertEquals("fr.coppernic.samples.ask", appContext.getPackageName());
}
Expand Down Expand Up @@ -84,7 +82,7 @@ public void stabilityTest() {
clickOnEnterHuntPhase();
SystemClock.sleep(500);
String result = getText(ViewMatchers.withId(R.id.tvAtrValue));
assertTrue(result.compareTo(initialValue) == 0);
assertEquals(0, result.compareTo(initialValue));
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
android:roundIcon="@drawable/rfid_blue"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".settings.SettingsActivity"
android:label="@string/title_activity_settings"></activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/fr/coppernic/samples/ask/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.coppernic.samples.ask;

import android.app.Application;
import android.view.Window;
import android.view.WindowManager;

import timber.log.Timber;

Expand Down
60 changes: 55 additions & 5 deletions app/src/main/java/fr/coppernic/samples/ask/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package fr.coppernic.samples.ask;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
import androidx.appcompat.widget.Toolbar;
import androidx.preference.PreferenceManager;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import fr.coppernic.samples.ask.settings.SettingsActivity;
import fr.coppernic.sdk.ask.Defines;
import fr.coppernic.sdk.ask.Reader;
import fr.coppernic.sdk.ask.ReaderListener;
Expand All @@ -30,6 +37,7 @@
import fr.coppernic.sdk.utils.io.InstanceListener;
import timber.log.Timber;

@SuppressWarnings("Convert2Lambda")
public class MainActivity extends AppCompatActivity implements PowerListener, InstanceListener<Reader> {
// RFID reader
private Reader reader;
Expand All @@ -46,6 +54,8 @@ public class MainActivity extends AppCompatActivity implements PowerListener, In
TextView tvAtrValue;
@BindView(R.id.btnSamGetAtr)
Button btnGetSamAtr;
//Settings
private SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -56,6 +66,8 @@ protected void onCreate(Bundle savedInstanceState) {

ButterKnife.bind(this);

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

PowerManager.get().registerListener(this);
}

Expand All @@ -69,6 +81,22 @@ protected void onDestroy() {

// InstanceListener implementation

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onCreated(Reader reader) {
this.reader = reader;
Expand Down Expand Up @@ -135,6 +163,7 @@ public void onSwCardDetectionCheckedChanged(final CompoundButton buttonView, boo
if (checked) {
// Clears Tag data
showTag(null);

// Sets the card detection
sCARD_SearchExt search = new sCARD_SearchExt();
search.OTH = 1;
Expand All @@ -148,7 +177,8 @@ public void onSwCardDetectionCheckedChanged(final CompoundButton buttonView, boo
search.MV5k = 1;
search.TICK = 1;
int mask = Defines.SEARCH_MASK_INNO | Defines.SEARCH_MASK_ISOA | Defines.SEARCH_MASK_ISOB | Defines.SEARCH_MASK_MIFARE | Defines.SEARCH_MASK_MONO | Defines.SEARCH_MASK_MV4K | Defines.SEARCH_MASK_MV5K | Defines.SEARCH_MASK_TICK | Defines.SEARCH_MASK_OTH;
SearchParameters parameters = new SearchParameters(search, mask, (byte) 0x01, (byte) 0x00);
SearchParameters parameters =
new SearchParameters(search, mask, (byte) 0x01, getTimeout(), getRfOffTimeout());
// Starts card detection
reader.startDiscovery(parameters, new ReaderListener() {
@Override
Expand Down Expand Up @@ -330,4 +360,24 @@ public void onPowerUp(CpcResult.RESULT result, Peripheral peripheral) {
public void onPowerDown(CpcResult.RESULT result, Peripheral peripheral) {
enableUiAfterReaderInstantiation(false);
}

private byte getTimeout() {

String s = sharedPreferences.getString(SettingsActivity.KEY_SEARCH_TIMEOUT, "200");
if (s == null) {
s = "200";
}

int i = Integer.parseInt(s);

return (byte) (i / 10);
}

private long getRfOffTimeout() {
String s = sharedPreferences.getString(SettingsActivity.KEY_RF_OFF_TIMEOUT, "0");
if (s == null) {
s = "0";
}
return Long.parseLong(s);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.coppernic.samples.ask.settings;

import android.os.Bundle;

import com.takisoft.preferencex.PreferenceFragmentCompat;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import fr.coppernic.samples.ask.R;

public class SettingsActivity extends AppCompatActivity {

public static final String KEY_SEARCH_TIMEOUT = "search_timeout";
public static final String KEY_RF_OFF_TIMEOUT = "rf_off_timeout";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/ic_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- drawable/settings.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z"
tools:ignore="VectorPath" />
</vector>
Loading