From 4340f18e97bd8b3443f3e6eab80fb27b63175d9f Mon Sep 17 00:00:00 2001 From: Chris Kitching Date: Sun, 12 Oct 2014 01:41:42 +0100 Subject: [PATCH] Bug 1081597: Refactor some branches. r=rnewman * * * Bug 1081597: Refactor some branches. r=rnewman --- mobile/android/base/ANRReporter.java | 3 +- .../android/base/AndroidGamepadManager.java | 4 +- mobile/android/base/ContactService.java | 66 +++++++++------- mobile/android/base/GeckoNetworkManager.java | 5 +- .../android/base/GeckoScreenOrientation.java | 31 ++++---- .../favicons/cache/FaviconCacheElement.java | 4 +- .../activities/FxAccountStatusActivity.java | 4 +- mobile/android/base/home/BrowserSearch.java | 4 +- .../RemoteTabsExpandableListFragment.java | 9 ++- .../base/mozglue/DirectBufferAllocator.java | 4 +- .../preferences/MultiChoicePreference.java | 4 +- mobile/android/base/prompts/PromptInput.java | 50 ++++++------ ...roidBrowserBookmarksRepositorySession.java | 4 +- .../android/base/tabs/TabStripItemView.java | 3 +- .../base/tests/helpers/JavascriptBridge.java | 79 ++++++++++--------- .../android/base/toolbar/ToolbarEditText.java | 4 +- .../android/base/webapp/InstallListener.java | 3 +- mobile/android/base/webapp/WebappImpl.java | 4 +- mobile/android/base/widget/TwoWayView.java | 66 ++++++++-------- .../service/stumblerthread/Reporter.java | 24 +++--- 20 files changed, 208 insertions(+), 167 deletions(-) diff --git a/mobile/android/base/ANRReporter.java b/mobile/android/base/ANRReporter.java index cf9da781c417..c34173a46543 100644 --- a/mobile/android/base/ANRReporter.java +++ b/mobile/android/base/ANRReporter.java @@ -250,7 +250,8 @@ public final class ANRReporter extends BroadcastReceiver Log.d(LOGTAG, "uptime " + String.valueOf(uptimeMins)); } return uptimeMins; - } else if (DEBUG) { + } + if (DEBUG) { Log.d(LOGTAG, "could not get uptime"); } return 0L; diff --git a/mobile/android/base/AndroidGamepadManager.java b/mobile/android/base/AndroidGamepadManager.java index 557723b4186d..435c1f050eba 100644 --- a/mobile/android/base/AndroidGamepadManager.java +++ b/mobile/android/base/AndroidGamepadManager.java @@ -258,7 +258,9 @@ public class AndroidGamepadManager { // Queue up key events for pending devices. sPendingGamepads.get(deviceId).add(ev); return true; - } else if (!sGamepads.containsKey(deviceId)) { + } + + if (!sGamepads.containsKey(deviceId)) { InputDevice device = ev.getDevice(); if (device != null && (device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) { diff --git a/mobile/android/base/ContactService.java b/mobile/android/base/ContactService.java index 6ad6e2b5bad9..5d380253ec1d 100644 --- a/mobile/android/base/ContactService.java +++ b/mobile/android/base/ContactService.java @@ -402,41 +402,47 @@ public class ContactService implements GeckoEventListener { filterValue = filterValue.toLowerCase(); databaseValue = databaseValue.toLowerCase(); - if ("match".equals(filterOp)) { - // If substring matching is a positive number, only pay attention to the last X characters - // of both the filter and database values - if (substringMatching > 0) { - databaseValue = substringStartFromEnd(cleanPhoneNumber(databaseValue), substringMatching); - filterValue = substringStartFromEnd(cleanPhoneNumber(filterValue), substringMatching); - return databaseValue.startsWith(filterValue); - } - return databaseValue.equals(filterValue); - } else if ("equals".equals(filterOp)) { - if (isPhone) { - return PhoneNumberUtils.compare(filterValue, databaseValue); - } - return databaseValue.equals(filterValue); - } else if ("contains".equals(filterOp)) { - if (isPhone) { - filterValue = cleanPhoneNumber(filterValue); - databaseValue = cleanPhoneNumber(databaseValue); - } - return databaseValue.contains(filterValue); - } else if ("startsWith".equals(filterOp)) { - // If a phone number, remove non-dialable characters and then only pay attention to - // the last X digits given by the substring matching values (see bug 877302) - if (isPhone) { - String cleanedDatabasePhone = cleanPhoneNumber(databaseValue); + switch (filterOp) { + case "match": + // If substring matching is a positive number, only pay attention to the last X characters + // of both the filter and database values if (substringMatching > 0) { - cleanedDatabasePhone = substringStartFromEnd(cleanedDatabasePhone, substringMatching); + databaseValue = substringStartFromEnd(cleanPhoneNumber(databaseValue), substringMatching); + filterValue = substringStartFromEnd(cleanPhoneNumber(filterValue), substringMatching); + return databaseValue.startsWith(filterValue); } - if (cleanedDatabasePhone.startsWith(filterValue)) { - return true; + return databaseValue.equals(filterValue); + case "equals": + if (isPhone) { + return PhoneNumberUtils.compare(filterValue, databaseValue); } - } - return databaseValue.startsWith(filterValue); + + return databaseValue.equals(filterValue); + case "contains": + if (isPhone) { + filterValue = cleanPhoneNumber(filterValue); + databaseValue = cleanPhoneNumber(databaseValue); + } + + return databaseValue.contains(filterValue); + case "startsWith": + // If a phone number, remove non-dialable characters and then only pay attention to + // the last X digits given by the substring matching values (see bug 877302) + if (isPhone) { + String cleanedDatabasePhone = cleanPhoneNumber(databaseValue); + if (substringMatching > 0) { + cleanedDatabasePhone = substringStartFromEnd(cleanedDatabasePhone, substringMatching); + } + + if (cleanedDatabasePhone.startsWith(filterValue)) { + return true; + } + } + + return databaseValue.startsWith(filterValue); } + return false; } diff --git a/mobile/android/base/GeckoNetworkManager.java b/mobile/android/base/GeckoNetworkManager.java index 70c658da73a5..048cf26a3c1c 100644 --- a/mobile/android/base/GeckoNetworkManager.java +++ b/mobile/android/base/GeckoNetworkManager.java @@ -280,9 +280,12 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven if (networkOperator == null || networkOperator.length() <= 3) { return -1; } + if (type == InfoType.MNC) { return Integer.parseInt(networkOperator.substring(3)); - } else if (type == InfoType.MCC) { + } + + if (type == InfoType.MCC) { return Integer.parseInt(networkOperator.substring(0, 3)); } diff --git a/mobile/android/base/GeckoScreenOrientation.java b/mobile/android/base/GeckoScreenOrientation.java index f4bd71dacee3..77dbc8b071c1 100644 --- a/mobile/android/base/GeckoScreenOrientation.java +++ b/mobile/android/base/GeckoScreenOrientation.java @@ -298,24 +298,21 @@ public class GeckoScreenOrientation { * otherwise. */ public static ScreenOrientation screenOrientationFromString(String aStr) { - if ("portrait".equals(aStr)) { - return ScreenOrientation.PORTRAIT_PRIMARY; - } - else if ("landscape".equals(aStr)) { - return ScreenOrientation.LANDSCAPE_PRIMARY; - } - else if ("portrait-primary".equals(aStr)) { - return ScreenOrientation.PORTRAIT_PRIMARY; - } - else if ("portrait-secondary".equals(aStr)) { - return ScreenOrientation.PORTRAIT_SECONDARY; - } - else if ("landscape-primary".equals(aStr)) { - return ScreenOrientation.LANDSCAPE_PRIMARY; - } - else if ("landscape-secondary".equals(aStr)) { - return ScreenOrientation.LANDSCAPE_SECONDARY; + switch (aStr) { + case "portrait": + return ScreenOrientation.PORTRAIT_PRIMARY; + case "landscape": + return ScreenOrientation.LANDSCAPE_PRIMARY; + case "portrait-primary": + return ScreenOrientation.PORTRAIT_PRIMARY; + case "portrait-secondary": + return ScreenOrientation.PORTRAIT_SECONDARY; + case "landscape-primary": + return ScreenOrientation.LANDSCAPE_PRIMARY; + case "landscape-secondary": + return ScreenOrientation.LANDSCAPE_SECONDARY; } + Log.w(LOGTAG, "screenOrientationFromString: unknown orientation string"); return DEFAULT_SCREEN_ORIENTATION; } diff --git a/mobile/android/base/favicons/cache/FaviconCacheElement.java b/mobile/android/base/favicons/cache/FaviconCacheElement.java index f0d313df15e9..a6aa3af029d4 100644 --- a/mobile/android/base/favicons/cache/FaviconCacheElement.java +++ b/mobile/android/base/favicons/cache/FaviconCacheElement.java @@ -84,7 +84,9 @@ public class FaviconCacheElement implements Comparable { final int w2 = another.imageSize; if (w1 > w2) { return 1; - } else if (w2 > w1) { + } + + if (w2 > w1) { return -1; } return 0; diff --git a/mobile/android/base/fxa/activities/FxAccountStatusActivity.java b/mobile/android/base/fxa/activities/FxAccountStatusActivity.java index c8c2d47015e7..ca672a1d7570 100644 --- a/mobile/android/base/fxa/activities/FxAccountStatusActivity.java +++ b/mobile/android/base/fxa/activities/FxAccountStatusActivity.java @@ -171,7 +171,9 @@ public class FxAccountStatusActivity extends LocaleAwareFragmentActivity { if (itemId == android.R.id.home) { finish(); return true; - } else if (itemId == R.id.remove_account) { + } + + if (itemId == R.id.remove_account) { maybeDeleteAndroidAccount(FirefoxAccounts.getFirefoxAccount(this)); return true; } diff --git a/mobile/android/base/home/BrowserSearch.java b/mobile/android/base/home/BrowserSearch.java index 506a71886d17..1465a0efbeb8 100644 --- a/mobile/android/base/home/BrowserSearch.java +++ b/mobile/android/base/home/BrowserSearch.java @@ -822,7 +822,9 @@ public class BrowserSearch extends HomeFragment if (engine == -1) { return ROW_STANDARD; - } else if (engine == 0 && mSuggestionsEnabled) { + } + + if (engine == 0 && mSuggestionsEnabled) { // Give suggestion views their own type to prevent them from // sharing other recycled search engine views. Using other // recycled views for the suggestion row can break animations diff --git a/mobile/android/base/home/RemoteTabsExpandableListFragment.java b/mobile/android/base/home/RemoteTabsExpandableListFragment.java index 834856f20cf5..45259aeab341 100644 --- a/mobile/android/base/home/RemoteTabsExpandableListFragment.java +++ b/mobile/android/base/home/RemoteTabsExpandableListFragment.java @@ -168,7 +168,9 @@ public class RemoteTabsExpandableListFragment extends HomeFragment implements Re info.url = tab.url; info.title = tab.title; return info; - } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { + } + + if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { final RemoteClient client = (RemoteClient) adapter.getGroup(groupPosition); final RemoteTabsClientContextMenuInfo info = new RemoteTabsClientContextMenuInfo(view, position, id, client); return info; @@ -288,11 +290,14 @@ public class RemoteTabsExpandableListFragment extends HomeFragment implements Re sState.setClientHidden(info.client.guid, true); getLoaderManager().restartLoader(LOADER_ID_REMOTE_TABS, null, mCursorLoaderCallbacks); return true; - } else if (itemId == R.id.home_remote_tabs_show_client) { + } + + if (itemId == R.id.home_remote_tabs_show_client) { sState.setClientHidden(info.client.guid, false); getLoaderManager().restartLoader(LOADER_ID_REMOTE_TABS, null, mCursorLoaderCallbacks); return true; } + return false; } diff --git a/mobile/android/base/mozglue/DirectBufferAllocator.java b/mobile/android/base/mozglue/DirectBufferAllocator.java index 90c60775d7a1..b3fb24291e0c 100644 --- a/mobile/android/base/mozglue/DirectBufferAllocator.java +++ b/mobile/android/base/mozglue/DirectBufferAllocator.java @@ -24,7 +24,9 @@ public final class DirectBufferAllocator { ByteBuffer directBuffer = nativeAllocateDirectBuffer(size); if (directBuffer == null) { throw new OutOfMemoryError("allocateDirectBuffer() returned null"); - } else if (!directBuffer.isDirect()) { + } + + if (!directBuffer.isDirect()) { throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); } diff --git a/mobile/android/base/preferences/MultiChoicePreference.java b/mobile/android/base/preferences/MultiChoicePreference.java index 375f402e7088..c0e69305e8e8 100644 --- a/mobile/android/base/preferences/MultiChoicePreference.java +++ b/mobile/android/base/preferences/MultiChoicePreference.java @@ -192,10 +192,10 @@ class MultiChoicePreference extends DialogPreference implements DialogInterface. // user cancelled; reset checkbox values to their previous state mValues = mPrevValues.clone(); return; - } else { - mPrevValues = mValues.clone(); } + mPrevValues = mValues.clone(); + if (!callChangeListener(getValues())) { return; } diff --git a/mobile/android/base/prompts/PromptInput.java b/mobile/android/base/prompts/PromptInput.java index 93df92d33dd0..a7a1cf326fff 100644 --- a/mobile/android/base/prompts/PromptInput.java +++ b/mobile/android/base/prompts/PromptInput.java @@ -347,31 +347,35 @@ public class PromptInput { public static PromptInput getInput(JSONObject obj) { String type = obj.optString("type"); - if (EditInput.INPUT_TYPE.equals(type)) { - return new EditInput(obj); - } else if (NumberInput.INPUT_TYPE.equals(type)) { - return new NumberInput(obj); - } else if (PasswordInput.INPUT_TYPE.equals(type)) { - return new PasswordInput(obj); - } else if (CheckboxInput.INPUT_TYPE.equals(type)) { - return new CheckboxInput(obj); - } else if (MenulistInput.INPUT_TYPE.equals(type)) { - return new MenulistInput(obj); - } else if (LabelInput.INPUT_TYPE.equals(type)) { - return new LabelInput(obj); - } else if (IconGridInput.INPUT_TYPE.equals(type)) { - return new IconGridInput(obj); - } else if (ColorPickerInput.INPUT_TYPE.equals(type)) { - return new ColorPickerInput(obj); - } else if (TabInput.INPUT_TYPE.equals(type)) { - return new TabInput(obj); - } else { - for (String dtType : DateTimeInput.INPUT_TYPES) { - if (dtType.equals(type)) { - return new DateTimeInput(obj); + switch (type) { + case EditInput.INPUT_TYPE: + return new EditInput(obj); + case NumberInput.INPUT_TYPE: + return new NumberInput(obj); + case PasswordInput.INPUT_TYPE: + return new PasswordInput(obj); + case CheckboxInput.INPUT_TYPE: + return new CheckboxInput(obj); + case MenulistInput.INPUT_TYPE: + return new MenulistInput(obj); + case LabelInput.INPUT_TYPE: + return new LabelInput(obj); + case IconGridInput.INPUT_TYPE: + return new IconGridInput(obj); + case ColorPickerInput.INPUT_TYPE: + return new ColorPickerInput(obj); + case TabInput.INPUT_TYPE: + return new TabInput(obj); + default: + for (String dtType : DateTimeInput.INPUT_TYPES) { + if (dtType.equals(type)) { + return new DateTimeInput(obj); + } } - } + + break; } + return null; } diff --git a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java index fb3533e849dc..63e8da94ffc2 100644 --- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java @@ -1086,10 +1086,10 @@ public class AndroidBrowserBookmarksRepositorySession extends AndroidBrowserRepo if (typeString == null) { Logger.warn(LOG_TAG, "Unsupported type code " + rowType); return null; - } else { - Logger.trace(LOG_TAG, "Record " + guid + " has type " + typeString); } + Logger.trace(LOG_TAG, "Record " + guid + " has type " + typeString); + rec.type = typeString; rec.title = RepoUtils.getStringFromCursor(cur, BrowserContract.Bookmarks.TITLE); rec.bookmarkURI = RepoUtils.getStringFromCursor(cur, BrowserContract.Bookmarks.URL); diff --git a/mobile/android/base/tabs/TabStripItemView.java b/mobile/android/base/tabs/TabStripItemView.java index c695666724de..c7b7de1db7e8 100644 --- a/mobile/android/base/tabs/TabStripItemView.java +++ b/mobile/android/base/tabs/TabStripItemView.java @@ -207,7 +207,8 @@ public class TabStripItemView extends ThemedLinearLayout lastFavicon = null; faviconView.setImageResource(R.drawable.new_tablet_default_favicon); return; - } else if (favicon == lastFavicon) { + } + if (favicon == lastFavicon) { return; } diff --git a/mobile/android/base/tests/helpers/JavascriptBridge.java b/mobile/android/base/tests/helpers/JavascriptBridge.java index aa6299e1e4ac..1b0ece1cd200 100644 --- a/mobile/android/base/tests/helpers/JavascriptBridge.java +++ b/mobile/android/base/tests/helpers/JavascriptBridge.java @@ -256,52 +256,55 @@ public final class JavascriptBridge { } type = message.getString("innerType"); - if ("progress".equals(type)) { - // Javascript harness message - mLogParser.logMessage(message.getString("message")); - return MessageStatus.PROCESSED; + switch (type) { + case "progress": + // Javascript harness message + mLogParser.logMessage(message.getString("message")); + return MessageStatus.PROCESSED; - } else if ("notify-loaded".equals(type)) { - mJavaBridgeLoaded = true; - return MessageStatus.PROCESSED; + case "notify-loaded": + mJavaBridgeLoaded = true; + return MessageStatus.PROCESSED; - } else if ("sync-reply".equals(type)) { - // Reply to Java-to-Javascript sync call - return MessageStatus.REPLIED; + case "sync-reply": + // Reply to Java-to-Javascript sync call + return MessageStatus.REPLIED; - } else if ("sync-call".equals(type) || "async-call".equals(type)) { + case "sync-call": + case "async-call": - if ("async-call".equals(type)) { - // Save this async message until another async message arrives, then we - // process the saved message and save the new one. This is done as a - // form of tail call optimization, by making sync-replies come before - // async-calls. On the other hand, if (message == mSavedAsyncMessage), - // it means we're currently processing the saved message and should clear - // mSavedAsyncMessage. - final JSONObject newSavedMessage = - (message != mSavedAsyncMessage ? message : null); - message = mSavedAsyncMessage; - mSavedAsyncMessage = newSavedMessage; - if (message == null) { - // Saved current message and there wasn't an already saved one. - return MessageStatus.SAVED; + if ("async-call".equals(type)) { + // Save this async message until another async message arrives, then we + // process the saved message and save the new one. This is done as a + // form of tail call optimization, by making sync-replies come before + // async-calls. On the other hand, if (message == mSavedAsyncMessage), + // it means we're currently processing the saved message and should clear + // mSavedAsyncMessage. + final JSONObject newSavedMessage = + (message != mSavedAsyncMessage ? message : null); + message = mSavedAsyncMessage; + mSavedAsyncMessage = newSavedMessage; + if (message == null) { + // Saved current message and there wasn't an already saved one. + return MessageStatus.SAVED; + } } - } - methodName = message.getString("method"); - argsArray = message.getJSONArray("args"); - args = new Object[argsArray.length()]; - for (int i = 0; i < args.length; i++) { - args[i] = convertFromJSONValue(argsArray.get(i)); - } - invokeMethod(methodName, args); + methodName = message.getString("method"); + argsArray = message.getJSONArray("args"); + args = new Object[argsArray.length()]; + for (int i = 0; i < args.length; i++) { + args[i] = convertFromJSONValue(argsArray.get(i)); + } + invokeMethod(methodName, args); - if ("sync-call".equals(type)) { - // Reply for sync messages - sendMessage("sync-reply", methodName, null); - } - return MessageStatus.PROCESSED; + if ("sync-call".equals(type)) { + // Reply for sync messages + sendMessage("sync-reply", methodName, null); + } + return MessageStatus.PROCESSED; } + throw new IllegalStateException("Message type is unexpected"); } catch (final JSONException e) { diff --git a/mobile/android/base/toolbar/ToolbarEditText.java b/mobile/android/base/toolbar/ToolbarEditText.java index c039674c18bb..0342e6b2aaa2 100644 --- a/mobile/android/base/toolbar/ToolbarEditText.java +++ b/mobile/android/base/toolbar/ToolbarEditText.java @@ -556,7 +556,9 @@ public class ToolbarEditText extends CustomEditText } return true; - } else if (GamepadUtils.isBackKey(event)) { + } + + if (GamepadUtils.isBackKey(event)) { if (mDismissListener != null) { mDismissListener.onDismiss(); } diff --git a/mobile/android/base/webapp/InstallListener.java b/mobile/android/base/webapp/InstallListener.java index 6914efd4c7c2..a9fc7492441b 100644 --- a/mobile/android/base/webapp/InstallListener.java +++ b/mobile/android/base/webapp/InstallListener.java @@ -61,7 +61,8 @@ public class InstallListener extends BroadcastReceiver { if (TextUtils.isEmpty(manifestUrl)) { Log.i(LOGTAG, "No manifest URL present in metadata"); return; - } else if (!isCorrectManifest(manifestUrl)) { + } + if (!isCorrectManifest(manifestUrl)) { // This happens when the updater triggers installation of multiple // APK updates simultaneously. If we're the receiver for another // update, then simply ignore this intent by returning early. diff --git a/mobile/android/base/webapp/WebappImpl.java b/mobile/android/base/webapp/WebappImpl.java index 6154cae81ed1..cb1d32976338 100644 --- a/mobile/android/base/webapp/WebappImpl.java +++ b/mobile/android/base/webapp/WebappImpl.java @@ -149,10 +149,10 @@ public class WebappImpl extends GeckoApp implements InstallCallback { installHelper.registerGeckoListener(); } return; - } else { - launchWebapp(origin); } + launchWebapp(origin); + setTitle(mAppName); } diff --git a/mobile/android/base/widget/TwoWayView.java b/mobile/android/base/widget/TwoWayView.java index 54672de9c6f0..c6677f6cd2a6 100644 --- a/mobile/android/base/widget/TwoWayView.java +++ b/mobile/android/base/widget/TwoWayView.java @@ -1276,7 +1276,9 @@ public class TwoWayView extends AdapterView implements if (mTouchMode == TOUCH_MODE_FLINGING) { return true; - } else if (motionPosition >= 0) { + } + + if (motionPosition >= 0) { mMotionPosition = motionPosition; mTouchMode = TOUCH_MODE_DOWN; } @@ -1376,7 +1378,9 @@ public class TwoWayView extends AdapterView implements reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); motionPosition = findMotionRowOrColumn((int) mLastTouchPos); return true; - } else if (mMotionPosition >= 0 && mAdapter.isEnabled(mMotionPosition)) { + } + + if (mMotionPosition >= 0 && mAdapter.isEnabled(mMotionPosition)) { mTouchMode = TOUCH_MODE_DOWN; triggerCheckForTap(); } @@ -3849,7 +3853,9 @@ public class TwoWayView extends AdapterView implements if (mItemCount == 0) { resetState(); return; - } else if (mItemCount != mAdapter.getCount()) { + } + + if (mItemCount != mAdapter.getCount()) { throw new IllegalStateException("The content of the adapter has changed but " + "TwoWayView did not receive a notification. Make sure the content of " + "your adapter is not modified from a background thread, but only " @@ -4274,31 +4280,30 @@ public class TwoWayView extends AdapterView implements mSyncPosition = Math.min(Math.max(0, mSyncPosition), itemCount - 1); return; - } else { - // See if we can find a position in the new data with the same - // id as the old selection. This will change mSyncPosition. - newPos = findSyncPosition(); - if (newPos >= 0) { - // Found it. Now verify that new selection is still selectable - selectablePos = lookForSelectablePosition(newPos, true); - if (selectablePos == newPos) { - // Same row id is selected - mSyncPosition = newPos; + } + // See if we can find a position in the new data with the same + // id as the old selection. This will change mSyncPosition. + newPos = findSyncPosition(); + if (newPos >= 0) { + // Found it. Now verify that new selection is still selectable + selectablePos = lookForSelectablePosition(newPos, true); + if (selectablePos == newPos) { + // Same row id is selected + mSyncPosition = newPos; - if (mSyncHeight == getHeight()) { - // If we are at the same height as when we saved state, try - // to restore the scroll position too. - mLayoutMode = LAYOUT_SYNC; - } else { - // We are not the same height as when the selection was saved, so - // don't try to restore the exact position - mLayoutMode = LAYOUT_SET_SELECTION; - } - - // Restore selection - setNextSelectedPositionInt(newPos); - return; + if (mSyncHeight == getHeight()) { + // If we are at the same height as when we saved state, try + // to restore the scroll position too. + mLayoutMode = LAYOUT_SYNC; + } else { + // We are not the same height as when the selection was saved, so + // don't try to restore the exact position + mLayoutMode = LAYOUT_SET_SELECTION; } + + // Restore selection + setNextSelectedPositionInt(newPos); + return; } } break; @@ -5787,11 +5792,10 @@ public class TwoWayView extends AdapterView implements View getScrapView(int position) { if (mViewTypeCount == 1) { return retrieveFromScrap(mCurrentScrap, position); - } else { - int whichScrap = mAdapter.getItemViewType(position); - if (whichScrap >= 0 && whichScrap < mScrapViews.length) { - return retrieveFromScrap(mScrapViews[whichScrap], position); - } + } + int whichScrap = mAdapter.getItemViewType(position); + if (whichScrap >= 0 && whichScrap < mScrapViews.length) { + return retrieveFromScrap(mScrapViews[whichScrap], position); } return null; diff --git a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/Reporter.java b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/Reporter.java index c9d23edf07ab..823033ec0ec8 100644 --- a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/Reporter.java +++ b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/Reporter.java @@ -111,16 +111,20 @@ public final class Reporter extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (action.equals(ACTION_FLUSH_TO_BUNDLE)) { - flush(); - return; - } else if (action.equals(WifiScanner.ACTION_WIFIS_SCANNED)) { - receivedWifiMessage(intent); - } else if (action.equals(CellScanner.ACTION_CELLS_SCANNED)) { - receivedCellMessage(intent); - } else if (action.equals(GPSScanner.ACTION_GPS_UPDATED)) { - // Calls reportCollectedLocation, this is the ideal case - receivedGpsMessage(intent); + switch (action) { + case ACTION_FLUSH_TO_BUNDLE: + flush(); + return; + case WifiScanner.ACTION_WIFIS_SCANNED: + receivedWifiMessage(intent); + break; + case CellScanner.ACTION_CELLS_SCANNED: + receivedCellMessage(intent); + break; + case GPSScanner.ACTION_GPS_UPDATED: + // Calls reportCollectedLocation, this is the ideal case + receivedGpsMessage(intent); + break; } if (mBundle != null &&