/** * Recalculate camera per row preference for the following situations: 1. If it won't influence * others and the current user only has one or two cameras, reset the value to be 1. 2. If current * user only has one or two cameras, but the device has other accounts logged in, keep the value * as it was without overriding it. 3. If the current user has more than two cameras, adjust the * value of camera per row to be a proper number based on screen size. * * @return The recalculated value of camera per row */ public int recalculateCameraPerRow() { int totalCameras = AppData.evercamCameraList.size(); boolean isInfluencingOtherUser = false; ArrayList<AppUser> userList = new EvercamAccount(this).retrieveUserList(); if (userList.size() > 1) { isInfluencingOtherUser = true; } if (totalCameras != 0 && totalCameras <= 2) { if (!isInfluencingOtherUser) { PrefsManager.setCameraPerRow(this, 1); return 1; } else { return PrefsManager.getCameraPerRow(this, 2); } } else { int screenWidth = readScreenWidth(this); int maxCamerasPerRow = 3; int minCamerasPerRow = 1; if (screenWidth != 0) { maxCamerasPerRow = screenWidth / 350; } int oldCamerasPerRow = PrefsManager.getCameraPerRow(this, 2); if (maxCamerasPerRow < oldCamerasPerRow && maxCamerasPerRow != 0) { PrefsManager.setCameraPerRow(this, maxCamerasPerRow); return maxCamerasPerRow; } else if (maxCamerasPerRow == 0) { return minCamerasPerRow; } return oldCamerasPerRow; } }