@Override
 public void onStart() {
   super.onStart();
   if (mMoviesAdapter.isEmpty()) {
     updateMovieGallery();
   }
 }
 private void setAdapter(Spinner spinner, ArrayAdapter<String> adapter) {
   if (adapter.isEmpty()) {
     adapter.insert("No justification available", 0);
     spinner.setAdapter(adapter);
   } else {
     spinner.setAdapter(adapter);
   }
 }
 private void reloadHistoryItems() {
   Iterable<HistoryItem> items = historyManager.buildHistoryItems();
   adapter.clear();
   for (HistoryItem item : items) {
     adapter.add(item);
   }
   setTitle(originalTitle + " (" + adapter.getCount() + ')');
   if (adapter.isEmpty()) {
     adapter.add(new HistoryItem(null, null, null));
   }
 }
Exemple #4
0
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      if (savedInstanceState != null) position = savedInstanceState.getInt("position");
      else position = getArguments().getInt(KEYRING_POSITION);

      KeyringInfo keyring = MainActivity.mKeyringAdapter.getItem(position);
      keyring.getKeyringItems();
      items = new ArrayAdapter<ItemInfo>(getActivity(), R.layout.password_list_item, keyring.items);

      View rootView;
      if (!items.isEmpty()) {
        rootView = inflater.inflate(R.layout.fragment_password, container, false);
        ListView mPasswords = (ListView) rootView.findViewById(R.id.passwords);
        mPasswords.setAdapter(items);
        mPasswords.setOnItemClickListener(this);
      } else {
        rootView = inflater.inflate(R.layout.fragment_no_items, container, false);
      }
      getActivity().setTitle(MainActivity.mKeyringAdapter.getItem(position).getName());
      return rootView;
    }
 @Override
 public boolean isEmpty() {
   return spinnerAdapter.isEmpty();
 }
  // onPlayClick can only be executed after scanning is complete
  // then the user can get a list of the users in the area and
  // select one of them to play a game
  public void onPlayClick(final View view) {
    // Updated REST call to server (working code space)
    // try {
    // // Try to run a new thread for the REST call
    // new Thread(new Runnable() {
    // public void run() {
    // // Getting all games for now
    // String call = RESTCaller.getAllGamesCall();
    // RESTCaller caller = new RESTCaller();
    // gamesReturned = caller.executeToArray(call);
    // }
    // }).start();
    // } catch (Exception e) {
    // e.printStackTrace();
    // }

    String call = RESTCaller.getAllGamesCall();
    RESTCaller caller = new RESTCaller();
    gamesReturned = caller.executeToArray(call);
    gamesReturned = execute("getAllGames");

    // Go through the games and get the object to be displayed
    for (int i = 0; i < gamesReturned.length(); ++i) {
      try {
        JSONObject game = gamesReturned.getJSONObject(i);
        game.get("m_strName");
        String s = game.get("m_strName").toString();
        // mListGames.add(gamesReturned.getJSONObject(i).get("m_strName").toString());
        mListGames.add(s);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    // // RESTful call to server which pulls a list of all the users
    // try {
    // usersReturned = executeToArray("users");
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    //
    // // Save the MAC addresses into an ArrayAdapter for comparison
    // for (int i = 0; i < usersReturned.length(); ++i) {
    // try {
    // mListUsers.add(usersReturned.getJSONObject(i).get("m_strMac").toString());
    // } catch (JSONException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // }
    //
    // // Step through the list of common devices found in the two
    // // ArrayAdapters and save
    // // them to show the user the nearby players.
    // // TODO: OPTIMIZE THIS LOOKUP SECTION
    // for (int i = 0; i < mListUsers.getCount(); ++i) {
    // for (int j = 0; j < mScannedDevices.getCount(); ++j) {
    // // If the location in the mListUsers and mScannedDevices is a
    // // match, we have
    // // a player nearby
    // if (mListUsers
    // .getItem(i)
    // .toString()
    // .equalsIgnoreCase(mScannedDevices.getItem(j).toString())) {
    // mNearbyUsers_MAC.add(mScannedDevices.getItem(j));
    // mNearbyUsers_MAC.notifyDataSetChanged();
    // }
    // }
    // }
    //
    // // This section looks up all the users in the mNearbyUsers_MAC and
    // saves
    // // their username to
    // // be displayed to the user
    // for (int i = 0; i < mNearbyUsers_MAC.getCount(); ++i) {
    // for (int j = 0; j < usersReturned.length(); ++j) {
    // try {
    // if (mNearbyUsers_MAC
    // .getItem(i)
    // .toString()
    // .equalsIgnoreCase(
    // usersReturned.getJSONObject(j)
    // .get("m_strMac").toString()))
    // mNearbyUsers_NAME.add(usersReturned.getJSONObject(j)
    // .get("m_strUsername").toString());
    // } catch (JSONException e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    // }
    // }

    // Finally set the value of the ListView to the value of the mNeabyUsers
    listView = (ListView) findViewById(R.id.listOfPlayers);
    // If the mNearbyUsers_MAC isn't empty
    if (DEBUG) {
      listView.setAdapter(mListGames);
    } else {
      if (!mNearbyUsers_NAME.isEmpty())
        // Show the list of nearby players
        listView.setAdapter(mNearbyUsers_NAME);
      // Else alert the user there is no one around them
      else {
        // Create new AlertDialog Builder
        AlertDialog.Builder noPlayersFound = new AlertDialog.Builder(context);
        // Set the title
        noPlayersFound.setTitle("SocProx didn't find any players near you!");
        // Set the message
        noPlayersFound.setMessage(
            "Click \"Try Again\" to scan one more time or \"Cancel\" to go back.");
        // Set if the dialog box can be cancelled or not
        noPlayersFound.setCancelable(false);
        // Set what the positive button does
        noPlayersFound.setPositiveButton(
            "Try Again",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                scanForPlayers();
              }
            });
        // Set what the negative button does
        noPlayersFound.setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                // if this button is clicked, just close
                // the dialog box and do nothing
                dialog.cancel();
              }
            });
        // Create the dialog box from the builder we just used
        AlertDialog noPlayersAlert = noPlayersFound.create();
        // Show it on screen
        noPlayersAlert.show();
      }
    }
  }