Android Open Source - game_guess_lib Levels Adapter






From Project

Back to project page game_guess_lib.

License

The source code is released under:

MIT License

If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wkmf.guess.lib.screen.adapter;
//  ww w.  j  a v  a  2 s.  com
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.wkmf.guess.lib.R;
import com.wkmf.guess.lib.structure.GuessConfig;
import com.wkmf.guess.lib.structure.GuessLevel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ernestofndz on 21/02/14.
 */
public class LevelsAdapter extends BaseAdapter {

    private GuessConfig config;
    private Context context;
    private List<GuessLevel> levels;
    private LayoutInflater inflater;

    // constructor
    public LevelsAdapter(Context context, GuessConfig config, List<GuessLevel> levels){
        this.context = context;
        this.config = config;
        this.levels = levels;
    }

    @Override
    public int getCount() {
        return this.levels.size();
    }

    @Override
    public Object getItem(int i) {
        return this.levels.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        // asignamos el layout que deseamos
        this.inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v;
        if (view == null) v = this.inflater.inflate(R.layout.item_level, viewGroup, false);
        else v = view;
        // recuperamos el elemento
        final GuessLevel level = (GuessLevel) getItem(i);
        if (level != null) {
            // inicializamos los datos
            final TextView levelNumber = (TextView) v.findViewById(R.id.level_number);
            levelNumber.setText(level.getStage());
            // damos color de fondo
            if(level.isCompleted()){
                // nivel completado
                v.findViewById(R.id.level_root).setBackgroundColor(Color.parseColor(this.config.getTagDoneBackgroundColor()));
                levelNumber.setTextColor(Color.parseColor(this.config.getTagDoneTextColor()));
            }else{
                // no completado
                v.findViewById(R.id.level_root).setBackgroundColor(Color.parseColor(this.config.getTagBackgroundColor()));
                levelNumber.setTextColor(Color.parseColor(this.config.getTagTextColor()));
            }
            // dificultad del nivel
            final RatingBar levelDifficulty = (RatingBar) v.findViewById(R.id.level_difficulty);
            levelDifficulty.setNumStars(level.getDifficulty());
            levelDifficulty.setRating(level.getDifficulty());
            // lo aadimos al tag
            v.setTag(level);
        }
        // devolvemos la vista
        return v;
    }
}




Java Source Code List

com.android.vending.billing.util.Base64DecoderException.java
com.android.vending.billing.util.Base64.java
com.android.vending.billing.util.IabException.java
com.android.vending.billing.util.IabHelper.java
com.android.vending.billing.util.IabResult.java
com.android.vending.billing.util.Inventory.java
com.android.vending.billing.util.Purchase.java
com.android.vending.billing.util.Security.java
com.android.vending.billing.util.SkuDetails.java
com.wkmf.guess.lib.common.Constants.java
com.wkmf.guess.lib.common.ads.GuessGameAdsListener.java
com.wkmf.guess.lib.common.ads.GuessGameAds.java
com.wkmf.guess.lib.common.api.GuessApi.java
com.wkmf.guess.lib.common.api.GuessRestApi.java
com.wkmf.guess.lib.common.async.DownloadTask.java
com.wkmf.guess.lib.common.dialog.DialogElement.java
com.wkmf.guess.lib.common.dialog.DialogModalListAdapter.java
com.wkmf.guess.lib.common.dialog.DialogModal.java
com.wkmf.guess.lib.data.GuessGameBDDHandler.java
com.wkmf.guess.lib.data.GuessSQL.java
com.wkmf.guess.lib.impl.GuessGameBaseApp.java
com.wkmf.guess.lib.impl.GuessGameImageDownload.java
com.wkmf.guess.lib.impl.GuessGameInterface.java
com.wkmf.guess.lib.purchase.items.GuessGameItems.java
com.wkmf.guess.lib.screen.GuessLevelScreen.java
com.wkmf.guess.lib.screen.GuessMainScreen.java
com.wkmf.guess.lib.screen.GuessQuestionScreen.java
com.wkmf.guess.lib.screen.adapter.LevelsAdapter.java
com.wkmf.guess.lib.screen.adapter.QuestionsAdapter.java
com.wkmf.guess.lib.service.GuessGameService.java
com.wkmf.guess.lib.service.GuessGameUpdater.java
com.wkmf.guess.lib.service.ServiceStarter.java
com.wkmf.guess.lib.structure.GuessConfig.java
com.wkmf.guess.lib.structure.GuessDrawable.java
com.wkmf.guess.lib.structure.GuessGame.java
com.wkmf.guess.lib.structure.GuessLevelType.java
com.wkmf.guess.lib.structure.GuessLevel.java
com.wkmf.guess.lib.structure.GuessQuestion.java