/** * This method is used to get a new default category that doesn't exist in the list of categories * that the method is supplied with * * @param categories The category list that needs more categories to be added * @return The new category * @throws Exception If there are no new categories left from the list of default categories or if * the default category list is null, the system would find */ public Category getNewCategory(List<Category> categories) throws Exception { if (defaultCategories == null) defaultCategories = _default.getAllDefaultCategories(); if (defaultCategories == null) { throw new Exception("The default category list is null"); } int count = 0; // Check if there are any more categories that can be loaded into the list to keep the lesson // plan running, if not throw an exception for (Category defaultCategory : defaultCategories) { if (!categories.contains(defaultCategory)) break; else count++; } if (count == defaultCategories.size()) { AlertMessage alert = new AlertMessage(); alert.showAlertMessage( "You’ve gone through all the default categories of words. This is a contextual vocabulary learning app. Please use the passive mode for a while, to help the app learn more about your vocabulary. You may return back after you’ve done so"); // TODO: Set states as end of mode as soon s this is // encountered------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ } Category cat = new Category(); Random rand = new Random(); // Return a new category while (!categories.contains(cat)) { cat = defaultCategories.get(rand.nextInt(defaultCategories.size())); } return cat; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.friend_list_view); AlertMessage.setActivity(this); dbHelper = new DataBaseHelper(getApplicationContext()); appUsersId = getAppUsersId(); Session session = Session.getActiveSession(); if (session.isOpened()) { // Fetch friends from Facebook FacebookFriendsTask fbFriends = new FacebookFriendsTask(this, this); String token = session.getAccessToken(); String url = "https://graph.facebook.com/me/friends"; fbFriends.execute(new String[] {token, url}); } // Extract location is passed in Bundle extras = getIntent().getExtras(); if (extras != null) location = (Location) extras.getParcelable("location"); }