Example #1
0
 public void getAchievements(String playerId) throws IOException {
   try {
     JSONObject json = new JSONObject();
     json.put("access_token", "8e6b3a7b47c3346cb7e4db42c88519bc");
     json.put("player_id", playerId);
     json.put("project_id", "50d78a38d870307e9b000002");
     JSONArray jsonArray =
         new JSONArray(
             WebUtil.postData("http://www.itsbeta.com/s/info/achievements.json", json, "UTF-8"));
     if (jsonArray.length() != 1) {
       return;
     }
     JSONArray projects = jsonArray.getJSONObject(0).getJSONArray("projects");
     for (int i = 0; i < projects.length(); i++) {
       JSONObject currentProject = projects.getJSONObject(i);
       Log.d("donor", currentProject.getString("api_name"));
       JSONArray achievements = currentProject.getJSONArray("achievements");
       for (int j = 0; j < achievements.length(); j++) {
         JSONObject currentAchievement = achievements.getJSONObject(i);
         Log.d("donor", currentAchievement.getString("badge_name"));
         Achievement achievement = new Achievement();
         achievement.setDisplayName(currentAchievement.getString("display_name"));
         achievement.setPictureLink(currentAchievement.getString("pic"));
         achievement.setDescription(currentAchievement.getString("desc"));
         achievementsList.add(achievement);
       }
     }
   } catch (Exception e) {
     throw new RuntimeException(e.getMessage());
   }
 }
Example #2
0
 public void getPlayerId(String facebookId) {
   try {
     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
     nameValuePairs.add(
         new BasicNameValuePair("access_token", "059db4f010c5f40bf4a73a28222dd3e3"));
     nameValuePairs.add(new BasicNameValuePair("type", "fb_user_id"));
     nameValuePairs.add(new BasicNameValuePair("id", facebookId));
     String result =
         WebUtil.postData("http://www.itsbeta.com/s/info/playerid.json", nameValuePairs, "UTF-8");
     JSONObject jsonObject = new JSONObject(result);
     if (jsonObject.has("player_id")) {
       playerId = jsonObject.getString("player_id");
       Log.d("donor", "player_id " + playerId);
     } else {
       playerId = null;
     }
   } catch (Exception e) {
     throw new RuntimeException(e.getMessage());
   }
 }
Example #3
0
  @Override
  public View getItemView(SingleWorkout workout, View convertView, ViewGroup parent) {
    super.getItemView(workout, convertView, parent);
    final ViewHolder holder;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.list_item_cards, parent, false);
      holder = new ViewHolder();
      holder.ivImage = (ImageView) convertView.findViewById(R.id.imageViewProfilePic);
      holder.ivPeek1 = (ImageView) convertView.findViewById(R.id.imageViewPeek1);
      holder.ivPeek2 = (ImageView) convertView.findViewById(R.id.imageViewPeek2);
      holder.ivPeek3 = (ImageView) convertView.findViewById(R.id.imageViewPeek3);
      holder.tvTitle = (TextView) convertView.findViewById(R.id.textViewTitle);
      holder.tvDifficulty = (TextView) convertView.findViewById(R.id.textViewDifficulty);
      holder.tvTime = (TextView) convertView.findViewById(R.id.textViewTime);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    holder.tvTitle.setText(workout.get_title());
    holder.tvTime.setText(workout.get_time());
    holder.tvDifficulty.setText(workout.get_difficulty());

    try {
      JSONArray mJsonArray = new JSONArray(workout.get_pictureArrayJSON());
      String pictureVal1 = "w" + mJsonArray.getString(0);
      String pictureVal2 = "w" + mJsonArray.getString(1);
      String pictureVal3 = "w" + mJsonArray.getString(2);

      holder.ivPeek1.setImageResource(
          getContext()
              .getResources()
              .getIdentifier(pictureVal1, "drawable", getContext().getPackageName()));
      holder.ivPeek2.setImageResource(
          getContext()
              .getResources()
              .getIdentifier(pictureVal2, "drawable", getContext().getPackageName()));
      holder.ivPeek3.setImageResource(
          getContext()
              .getResources()
              .getIdentifier(pictureVal3, "drawable", getContext().getPackageName()));

    } catch (JSONException e) {
      e.printStackTrace();
    }

    // needed to get User profile pic for parse feed
    try {
      ParseUser mUser = workout.getParseUser("user");
      mUser.fetchInBackground(
          new GetCallback<ParseObject>() {
            @Override
            public void done(ParseObject parseObject, ParseException e) {
              try {
                final byte[] mBytes = parseObject.getBytes("photo");
                if (mBytes != null) {
                  new Handler()
                      .post(
                          new Runnable() {
                            @Override
                            public void run() {
                              Bitmap bitmap =
                                  BitmapFactory.decodeByteArray(mBytes, 0, mBytes.length);
                              holder.ivImage.setImageBitmap(bitmap);
                            }
                          });
                }
              } catch (Exception f) {
                Log.e(TAG, f.getMessage());
              }
            }
          });
    } catch (Exception e) {
      Log.e(TAG, e.getMessage());
    }

    // still need to populate the ivPeek with icons

    return convertView;
  }