Esempio n. 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());
   }
 }
Esempio n. 2
0
 public void run() {
   try {
     Transport.send(message);
   } catch (Exception e) {
     Log.v("Internet connectionless", e.toString());
   }
 }
Esempio n. 3
0
 public void startNewAchievementActivity(Achievement achievement) {
   try {
     Intent intent = new Intent();
     intent.putExtra("display_name", achievement.getDisplayName());
     intent.putExtra("pic", achievement.getPictureLink());
     intent.putExtra("desc", achievement.getDescription());
     intent.setClass(activity, NewAchievementActivity.class);
     activity.startActivity(intent);
     finishBackgroundProcess();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 public synchronized void sendMail(String subject, String body, String sender, String recipients)
     throws Exception {
   try {
     message = new MimeMessage(session);
     DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
     message.setSender(new InternetAddress(sender));
     message.setSubject(subject);
     message.setDataHandler(handler);
     if (recipients.indexOf(',') > 0)
       message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
     else message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
     Thread Subthread = new Thread(mutiThread); // 開一個新的線程,去執行網路連線
     Subthread.start();
   } catch (Exception e) {
     Log.v("ErrorMail", e.toString());
   }
 }
Esempio n. 5
0
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_splash);
   TextView tv = (TextView) findViewById(R.id.textView);
   try {
     Typeface tf = Typeface.createFromAsset(this.getAssets(), "fonts/gillsansmt.ttf");
     tv.setTypeface(tf);
   } catch (Exception e) {
     Log.e("ERROR", e.toString());
   }
   new Handler()
       .postDelayed(
           new Runnable() {
             @Override
             public void run() {
               checkUser();
             }
           },
           SPLASH_TIME);
 }
Esempio n. 6
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());
   }
 }
Esempio n. 7
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;
  }