Skip to content

Commit c04e1c9

Browse files
committed
Projects - remove reconnection callback
1 parent bf28339 commit c04e1c9

File tree

1 file changed

+70
-66
lines changed

1 file changed

+70
-66
lines changed

app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ public class ProjectActivity extends Activity implements View.OnClickListener, B
148148
private BroadcastReceiver connectionChangedReceiver = BLEConnectionHandler.bleConnectionChangedReceiver(this);
149149

150150
private Handler handler = new Handler();
151-
private int countOfReconnecting;
152-
private boolean sentPause;
153151

154-
private boolean notAValidFlashHexFile;
152+
// // REMOVE tryToConnectAgain
153+
// private int countOfReconnecting;
154+
// private boolean sentPause;
155+
// private boolean notAValidFlashHexFile;
155156

156157
private boolean minimumPermissionsGranted;
157158

@@ -186,44 +187,45 @@ public void onClick(View v) {
186187
}
187188
};
188189

189-
private final Runnable tryToConnectAgain = new Runnable() {
190-
191-
@Override
192-
public void run() {
193-
if(sentPause) {
194-
countOfReconnecting++;
195-
}
196-
197-
final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager
198-
.getInstance(ProjectActivity.this);
199-
200-
if(countOfReconnecting == Constants.MAX_COUNT_OF_RE_CONNECTIONS_FOR_DFU) {
201-
countOfReconnecting = 0;
202-
Intent intent = new Intent(DfuService.BROADCAST_ACTION);
203-
intent.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_ABORT);
204-
localBroadcastManager.sendBroadcast(intent);
205-
} else {
206-
final int nextAction;
207-
final long delayForNewlyBroadcast;
208-
209-
if(sentPause) {
210-
nextAction = DfuService.ACTION_RESUME;
211-
delayForNewlyBroadcast = Constants.TIME_FOR_CONNECTION_COMPLETED;
212-
} else {
213-
nextAction = DfuService.ACTION_PAUSE;
214-
delayForNewlyBroadcast = Constants.DELAY_BETWEEN_PAUSE_AND_RESUME;
215-
}
216-
217-
sentPause = !sentPause;
218-
219-
Intent intent = new Intent(DfuService.BROADCAST_ACTION);
220-
intent.putExtra(DfuService.EXTRA_ACTION, nextAction);
221-
localBroadcastManager.sendBroadcast(intent);
222-
223-
handler.postDelayed(this, delayForNewlyBroadcast);
224-
}
225-
}
226-
};
190+
// // REMOVE tryToConnectAgain
191+
// private final Runnable tryToConnectAgain = new Runnable() {
192+
//
193+
// @Override
194+
// public void run() {
195+
// if (sentPause) {
196+
// countOfReconnecting++;
197+
// }
198+
//
199+
// final LocalBroadcastManager localBroadcastManager = LocalBroadcastManager
200+
// .getInstance(ProjectActivity.this);
201+
//
202+
// if (countOfReconnecting == Constants.MAX_COUNT_OF_RE_CONNECTIONS_FOR_DFU) {
203+
// countOfReconnecting = 0;
204+
// Intent intent = new Intent(DfuService.BROADCAST_ACTION);
205+
// intent.putExtra(DfuService.EXTRA_ACTION, DfuService.ACTION_ABORT);
206+
// localBroadcastManager.sendBroadcast(intent);
207+
// } else {
208+
// final int nextAction;
209+
// final long delayForNewlyBroadcast;
210+
//
211+
// if (sentPause) {
212+
// nextAction = DfuService.ACTION_RESUME;
213+
// delayForNewlyBroadcast = Constants.TIME_FOR_CONNECTION_COMPLETED;
214+
// } else {
215+
// nextAction = DfuService.ACTION_PAUSE;
216+
// delayForNewlyBroadcast = Constants.DELAY_BETWEEN_PAUSE_AND_RESUME;
217+
// }
218+
//
219+
// sentPause = !sentPause;
220+
//
221+
// Intent intent = new Intent(DfuService.BROADCAST_ACTION);
222+
// intent.putExtra(DfuService.EXTRA_ACTION, nextAction);
223+
// localBroadcastManager.sendBroadcast(intent);
224+
//
225+
// handler.postDelayed(this, delayForNewlyBroadcast);
226+
// }
227+
// }
228+
// };
227229

228230
/**
229231
* Allows to handle forced closing of the bluetooth service and
@@ -618,7 +620,7 @@ protected void onResume() {
618620
@Override
619621
protected void onDestroy() {
620622

621-
handler.removeCallbacks(tryToConnectAgain);
623+
// handler.removeCallbacks(tryToConnectAgain); // REMOVE tryToConnectAgain
622624

623625
MBApp application = MBApp.getApp();
624626

@@ -2069,17 +2071,18 @@ public void onClick(View v) {
20692071
},//override click listener for ok button
20702072
null);//pass null to use default listener
20712073

2072-
countOfReconnecting = 0;
2073-
sentPause = false;
2074-
2075-
long delayForCheckOnConnection = Constants.TIME_FOR_CONNECTION_COMPLETED;
2076-
2077-
if (notAValidFlashHexFile) {
2078-
notAValidFlashHexFile = false;
2079-
delayForCheckOnConnection += Constants.JUST_PAIRED_DELAY_ON_CONNECTION;
2080-
}
2081-
2082-
handler.postDelayed(tryToConnectAgain, delayForCheckOnConnection);
2074+
// // REMOVE tryToConnectAgain
2075+
// countOfReconnecting = 0;
2076+
// sentPause = false;
2077+
//
2078+
// long delayForCheckOnConnection = Constants.TIME_FOR_CONNECTION_COMPLETED;
2079+
//
2080+
// if (notAValidFlashHexFile) {
2081+
// notAValidFlashHexFile = false;
2082+
// delayForCheckOnConnection += Constants.JUST_PAIRED_DELAY_ON_CONNECTION;
2083+
// }
2084+
//
2085+
// handler.postDelayed(tryToConnectAgain, delayForCheckOnConnection);
20832086
}
20842087

20852088
inInit = true;
@@ -2163,7 +2166,7 @@ public void onClick(View v) {
21632166
popupOkHandler);//pass null to use default listener
21642167

21652168
dfuUnregister();
2166-
removeReconnectionRunnable();
2169+
// removeReconnectionRunnable(); // REMOVE tryToConnectAgain
21672170
onFlashComplete();
21682171
break;
21692172
/*
@@ -2188,7 +2191,7 @@ public void onClick(View v) {
21882191
popupOkHandler);//pass null to use default listener
21892192
21902193
dfuUnregister();
2191-
removeReconnectionRunnable();
2194+
// removeReconnectionRunnable();// REMOVE tryToConnectAgain
21922195
break;
21932196
*/
21942197
default:
@@ -2209,8 +2212,7 @@ public void onClick(View v) {
22092212
TYPE_PROGRESS_NOT_CANCELABLE, null, null);
22102213

22112214
inProgress = true;
2212-
2213-
removeReconnectionRunnable();
2215+
// removeReconnectionRunnable(); // REMOVE tryToConnectAgain
22142216
}
22152217

22162218
if ( state != progressState) {
@@ -2221,9 +2223,10 @@ public void onClick(View v) {
22212223
} else if(intent.getAction().equals(DfuService.BROADCAST_ERROR)) {
22222224
int errorCode = intent.getIntExtra(DfuService.EXTRA_DATA, 0);
22232225

2224-
if(errorCode == DfuService.ERROR_FILE_INVALID) {
2225-
notAValidFlashHexFile = true;
2226-
}
2226+
// // REMOVE tryToConnectAgain
2227+
// if(errorCode == DfuService.ERROR_FILE_INVALID) {
2228+
// notAValidFlashHexFile = true;
2229+
// }
22272230

22282231
String error_message = GattError.parse(errorCode);
22292232

@@ -2239,7 +2242,7 @@ public void onClick(View v) {
22392242
MBApp application = MBApp.getApp();
22402243

22412244
dfuUnregister();
2242-
removeReconnectionRunnable();
2245+
// removeReconnectionRunnable(); // REMOVE tryToConnectAgain
22432246
//Update Stats
22442247
/*
22452248
GoogleAnalyticsManager.getInstance().sendFlashStats(
@@ -2300,11 +2303,12 @@ public void onClick(View v) {
23002303

23012304
}
23022305

2303-
private void removeReconnectionRunnable() {
2304-
handler.removeCallbacks(tryToConnectAgain);
2305-
countOfReconnecting = 0;
2306-
sentPause = false;
2307-
}
2306+
// // REMOVE tryToConnectAgain
2307+
// private void removeReconnectionRunnable() {
2308+
// handler.removeCallbacks(tryToConnectAgain);
2309+
// countOfReconnecting = 0;
2310+
// sentPause = false;
2311+
// }
23082312

23092313
@Override
23102314
public boolean onCreateOptionsMenu(Menu menu) {

0 commit comments

Comments
 (0)