Search in sources :

Example 1 with OKAchievement

use of io.openkit.OKAchievement in project openkit-android by OpenKit.

the class OKAchievementsFragment method getAchievements.

private void getAchievements() {
    spinnerBar.setVisibility(View.VISIBLE);
    OKAchievement.getAchievements(new OKAchievementsListResponseHandler() {

        @Override
        public void onSuccess(List<OKAchievement> achievementList) {
            listAdapter = new OKAchievementsListAdapter(OKAchievementsFragment.this.getActivity(), android.R.layout.simple_list_item_1, achievementList);
            numAchievements = achievementList.size();
            listHeaderTextView.setText(numAchievements + " Achievements");
            OKAchievementsFragment.this.setListAdapter(listAdapter);
            listView.setVisibility(View.VISIBLE);
            spinnerBar.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            spinnerBar.setVisibility(View.INVISIBLE);
            if (OKAchievementsFragment.this.getActivity() != null) {
                Toast toast = Toast.makeText(OKAchievementsFragment.this.getActivity(), "Couldn't connect to server to get achivements", Toast.LENGTH_LONG);
                toast.show();
            }
        }
    });
    startedAchievementsRequest = true;
}
Also used : JSONObject(org.json.JSONObject) Toast(android.widget.Toast) OKAchievementsListResponseHandler(io.openkit.OKAchievementsListResponseHandler) OKAchievement(io.openkit.OKAchievement)

Example 2 with OKAchievement

use of io.openkit.OKAchievement in project openkit-android by OpenKit.

the class OKAchievementsListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    int text1id = getContext().getResources().getIdentifier("text1", "id", getContext().getPackageName());
    int text2id = getContext().getResources().getIdentifier("text2", "id", getContext().getPackageName());
    int progressID = getContext().getResources().getIdentifier("io_openkit_achievement_progress", "id", getContext().getPackageName());
    int smartImageViewID = getContext().getResources().getIdentifier("smartImageView", "id", getContext().getPackageName());
    int leaderboardRowID = getContext().getResources().getIdentifier("io_openkit_row_okachievement", "layout", getContext().getPackageName());
    if (row == null) {
        LayoutInflater inflater = LayoutInflater.from(this.getContext());
        row = inflater.inflate(leaderboardRowID, parent, false);
    }
    TextView label1 = (TextView) row.findViewById(text1id);
    TextView label2 = (TextView) row.findViewById(text2id);
    SmartImageView imageView = (SmartImageView) row.findViewById(smartImageViewID);
    ProgressBar progressBar = (ProgressBar) row.findViewById(progressID);
    OKAchievement currentAchievement = this.getItem(position);
    row.setTag(position);
    label1.setText(currentAchievement.getName());
    label2.setText(currentAchievement.getDescription());
    progressBar.setMax(currentAchievement.getGoal());
    progressBar.setProgress(currentAchievement.getProgress());
    if (currentAchievement.getProgress() >= currentAchievement.getGoal()) {
        imageView.setImageUrl(currentAchievement.getUnlockedIconURL());
    } else {
        imageView.setImageUrl(currentAchievement.getLockedIconURL());
    }
    return row;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) SmartImageView(io.openkit.smartimageview.SmartImageView) TextView(android.widget.TextView) View(android.view.View) SmartImageView(io.openkit.smartimageview.SmartImageView) ProgressBar(android.widget.ProgressBar) OKAchievement(io.openkit.OKAchievement)

Aggregations

OKAchievement (io.openkit.OKAchievement)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 OKAchievementsListResponseHandler (io.openkit.OKAchievementsListResponseHandler)1 SmartImageView (io.openkit.smartimageview.SmartImageView)1 JSONObject (org.json.JSONObject)1