Skip to content

Commit

Permalink
Added check to wakelock methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Silva committed Apr 10, 2012
1 parent 2fdce63 commit 26a20f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions source/src/ca/idi/tekla/TeclaApp.java
Expand Up @@ -366,8 +366,12 @@ public void holdWakeLock(long length) {
}

public void releaseWakeLock () {
if (DEBUG) Log.d(TeclaApp.TAG, "Releasing wake lock...");
mWakeLock.release();
if (mWakeLock.isHeld()) {
if (DEBUG) Log.d(TeclaApp.TAG, "Releasing wake lock...");
mWakeLock.release();
} else {
if (DEBUG) Log.d(TeclaApp.TAG, "Wake lock not held, so not releasing");
}
}

/**
Expand Down
10 changes: 5 additions & 5 deletions source/src/ca/idi/tekla/TeclaPrefs.java
Expand Up @@ -198,12 +198,11 @@ public void onReceive(Context context, Intent intent) {
if ((dev.getName() != null) && (
dev.getName().startsWith(SwitchEventProvider.SHIELD_PREFIX_2) ||
dev.getName().startsWith(SwitchEventProvider.SHIELD_PREFIX_3) )) {
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Found a Tecla Access Shield candidate");
mShieldFound = true;
mShieldAddress = dev.getAddress();
mShieldName = dev.getName();
if (mBluetoothAdapter.isDiscovering())
mBluetoothAdapter.cancelDiscovery();
if (mBluetoothAdapter.isDiscovering()) mBluetoothAdapter.cancelDiscovery();
if (TeclaApp.DEBUG) Log.d(TeclaApp.TAG, CLASS_TAG + "Found a Tecla Access Shield candidate");
}
}

Expand All @@ -212,8 +211,6 @@ public void onReceive(Context context, Intent intent) {
// Shield found, try to connect
mProgressDialog.setMessage(getString(R.string.connecting_tecla_shield) +
" " + mShieldName);
if (!mProgressDialog.isShowing())
mProgressDialog.show();
if(!SepManager.start(TeclaPrefs.this, mShieldAddress)) {
// Could not connect to Shield
dismissDialog();
Expand Down Expand Up @@ -377,18 +374,21 @@ public void onCancel(DialogInterface arg0) {
}
});
mProgressDialog.show();
TeclaApp.getInstance().holdWakeLock();
}

private void cancelDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.cancel();
}
TeclaApp.getInstance().releaseWakeLock();
}

private void dismissDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
TeclaApp.getInstance().releaseWakeLock();
}

}

0 comments on commit 26a20f4

Please sign in to comment.