Skip to content

Commit

Permalink
Configurable read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Galambos Máté authored and frankmorgner committed Oct 22, 2018
1 parent 5082ab0 commit 2c7a8e5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onClick(DialogInterface dialog, int id) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
int timeout = Integer.parseInt(SP.getString("delay", Integer.toString(NFCReader.TIMEOUT)));
int timeout = Integer.parseInt(SP.getString("delay", "500"));
Bundle bundle = new Bundle();
bundle.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, timeout * 10);
adapter.enableReaderMode(this, this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void onCreate(Bundle savedInstanceState) {
bindPreferenceSummaryToValue(findPreference("hostname"));
bindPreferenceSummaryToValue(findPreference("port"));
bindPreferenceSummaryToValue(findPreference("delay"));
bindPreferenceSummaryToValue(findPreference("timeout"));

Preference nfcSettings = findPreference("nfcSettings");
nfcSettings.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.WindowManager;

Expand All @@ -42,7 +44,10 @@ public class NFCReader implements SCReader {
private NFCReader(IsoDep sc, Activity activity) throws IOException {
this.card = sc;
sc.connect();
card.setTimeout(TIMEOUT);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(activity);
int timeout = Integer.parseInt(SP.getString("timeout", "500"));
card.setTimeout(timeout);
com.example.android.common.logger.Log.i(getClass().getName(), "Timeout set to " + Integer.toString(timeout));
this.activity = activity;
avoidScreenTimeout();
}
Expand Down Expand Up @@ -81,7 +86,6 @@ public void eject() throws IOException {
resetScreenTimeout();
}

public static final int TIMEOUT = 500;
@Override
public void powerOn() {
/* should already be connected... */
Expand Down
18 changes: 18 additions & 0 deletions remote-reader/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
<item>1000</item>
<item>2000</item>
</string-array>
<string-array name="strTimeouts">
<item>125 milliseconds</item>
<item>250 milliseconds</item>
<item>500 milliseconds</item>
<item>1 second</item>
<item>2 seconds</item>
<item>3 seconds</item>
<item>4 seconds</item>
</string-array>
<string-array name="intTimeouts">
<item>125</item>
<item>250</item>
<item>500</item>
<item>1000</item>
<item>2000</item>
<item>3000</item>
<item>4000</item>
</string-array>

<string name="action_settings">Settings</string>
<string name="action_copy">Copy Log</string>
Expand Down
7 changes: 7 additions & 0 deletions remote-reader/app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
android:entries="@array/strDelays"
android:entryValues="@array/intDelays" />

<ListPreference
android:key="timeout"
android:defaultValue="500"
android:title="Delay for Card Response"
android:entries="@array/strTimeouts"
android:entryValues="@array/intTimeouts" />

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 2c7a8e5

Please sign in to comment.