Skip to content

Commit

Permalink
prevent nfc to initialize every script launch
Browse files Browse the repository at this point in the history
  • Loading branch information
victordiaz committed Jul 4, 2020
1 parent e49149b commit a1e7258
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
}

project.ext {
versionCode = 124
versionName = "1.2.4"
versionCode = 126
versionName = "1.2.6-alpha"
}

task hello {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected void onResume() {
super.onResume();

// NFC
if (nfcSupported) mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
if (isNFCInitialized) mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);

// broadcast to start/stop the activity
startStopActivityBroadcastReceiver();
Expand All @@ -215,16 +215,16 @@ protected void onResume() {
protected void onPause() {
super.onPause();

MLog.d(TAG, "onPause 1");
MLog.d(TAG, "onPause");

if (nfcSupported) mAdapter.disableForegroundDispatch(this);
if (isNFCInitialized) mAdapter.disableForegroundDispatch(this);
unregisterReceiver(stopActivitiyBroadcastReceiver);
unregisterReceiver(executeCodeActivitiyBroadcastReceiver);
}

@Override
public void onStop() {
MLog.d(TAG, "onStop 1");
MLog.d(TAG, "onStop");
super.onStop();
}

Expand Down Expand Up @@ -294,18 +294,16 @@ private void removeDebugFragment() {
private IntentFilter[] mFilters;
private String[][] mTechLists;
private boolean nfcSupported;
private boolean nfcInit = false;
private boolean isNFCInitialized = false;
public boolean isCodeExecutedShown;

public void initializeNFC() {

if (nfcInit == false) {
if (isNFCInitialized == false) {
PackageManager pm = getPackageManager();
nfcSupported = pm.hasSystemFeature(PackageManager.FEATURE_NFC);

if (nfcSupported == false) {
return;
}
if (!nfcSupported) return;

// when is in foreground
MLog.d(TAG, "starting NFC");
Expand All @@ -325,7 +323,7 @@ public void initializeNFC() {

// Setup a tech list for all NfcF tags
mTechLists = new String[][]{new String[]{NfcF.class.getName()}};
nfcInit = true;
isNFCInitialized = true;
}
}

Expand Down Expand Up @@ -443,7 +441,6 @@ public boolean onKeyShortcut(int keyCode, KeyEvent event) {
return super.onKeyShortcut(keyCode, event);
}


/**
* Menu
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ public void onActivityCreated(Bundle savedInstanceState) {

mAppRunner.initProject();

// nfc
mActivity.initializeNFC();

// file observer will notify project file changes
startFileObserver();

Expand Down Expand Up @@ -174,6 +171,7 @@ public void onDestroy() {
super.onDestroy();
MLog.d(TAG, "onDestroy");
if (mAppRunner.interp != null) mAppRunner.interp.callJsFunction("onDestroy");
fileObserver.stopWatching();
mAppRunner.byebye();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import okhttp3.RequestBody;
import okhttp3.Response;


@PhonkObject
public class PNetwork extends ProtoBase {

Expand Down Expand Up @@ -115,6 +114,10 @@ public void initForParentFragment(AppRunnerFragment fragment) {
}
}

/**
* Initializes NFC
*/
@PhonkMethod
public PNfc startNFC() {
PNfc nfc = new PNfc(getAppRunner());
nfc.initForParentFragment(getFragment());
Expand Down

0 comments on commit a1e7258

Please sign in to comment.