/** * Gets the achievement of the in the array list based on the name. * * @param name of the achievement. * @return the achievement item passed in. */ public Achievement_Item getAchievement(String name) { Iterator<Achievement_Item> iterator = this.achievementBoard.iterator(); while (iterator.hasNext()) { Achievement_Item item = iterator.next(); if (item.getGoal().equals(name)) { return item; // Stops before duplicate achievement can be added. } } return null; }
/** * Unlocks an achievement * * @param goalOfAchievement name of the achievement. * @param context of the application. */ public void AchievementUnlocked(String goalOfAchievement, Context context) { this.context = context; int id = 0; Achievement_Item compare = getAchievement(goalOfAchievement); compare.setComplete(true); id = this.achievementBoard.indexOf(getAchievement(goalOfAchievement)); if (compare != null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.relative, null); int drawableId = 0; try { Class res = R.drawable.class; Field field = res.getField("achievement_" + compare.getGoal().replace(' ', '_')); drawableId = field.getInt(null); } catch (Exception e) { Log.e("MyTag", "Failure to get drawable id.", e); } TextView text = (TextView) view.findViewById(R.id.textView1); TextView text2 = (TextView) view.findViewById(R.id.textView2); ImageView image = (ImageView) view.findViewById(R.id.imageView1); image.setImageResource(drawableId); text.setText(compare.toString()); text2.setText(compare.getExplanation()); Toast toast = new Toast(context); toast.setView(view); toast.show(); } try { Thread.currentThread().sleep(1000); // pause before updating status } catch (InterruptedException ie) { System.out.println("the sleeping thread is not working"); } if (compare.getFacebookOK()) { updateStatus(goalOfAchievement, (Activity) context); } }
/** * Adds Achievement to array list.. * * @param goal name of achievement * @param explanation how to get achievement. * @param postName * @param caption * @param description * @param link * @param postOK */ public void addAchievement( String goal, String explanation, String postName, String caption, String description, String link, boolean postOK) { Achievement_Item compare = null; Iterator<Achievement_Item> iterator = this.achievementBoard.iterator(); while (iterator.hasNext()) { compare = iterator.next(); if (compare.getGoal().equals(goal)) { return; // Stops before duplicate achievement can be added. } } this.achievementBoard.add( new Achievement_Item(goal, explanation, postName, caption, description, link, postOK)); }