Android Open Source - OneSearch Word Search Grid Adapter






From Project

Back to project page OneSearch.

License

The source code is released under:

MIT License

If you think the Android project OneSearch 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 chrisjluc.funsearch.adapters;
/*from  w  ww . j  a v  a2s . co  m*/
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.TextView;

import java.util.List;

import chrisjluc.funsearch.R;
import chrisjluc.funsearch.WordSearchManager;
import chrisjluc.funsearch.wordSearchGenerator.models.Node;

public class WordSearchGridAdapter extends BaseAdapter {

    private Context mContext;
    private List<Node> mNodes;
    private int mColumnWidth;
    private int mWordSearchDimension;
    private LayoutInflater mInflater;

    public WordSearchGridAdapter(Context context, List<Node> nodes, int columnWidth, int wordSearchDimension) {
        this.mContext = context;
        this.mNodes = nodes;
        this.mColumnWidth = columnWidth;
        this.mWordSearchDimension = wordSearchDimension;
        this.mInflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public View getView(final int pos, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.grid_item, null);
        }
        Node n = mNodes.get(pos);
        TextView tv = (TextView) convertView;
        tv.setText("" + n.getLetter());
        tv.setHeight(mColumnWidth);

        int difference = ((WordSearchManager.ADVANCED_MAX_WORDLENGTH + WordSearchManager.ADVANCED_MAX_DIMENSION_OFFSET - WordSearchManager.EASY_MIN_WORDLENGTH) / 3);
        if (WordSearchManager.EASY_MIN_WORDLENGTH <= mWordSearchDimension && mWordSearchDimension < (WordSearchManager.EASY_MIN_WORDLENGTH + difference))
            tv.setTextSize(22);
        else if ((WordSearchManager.EASY_MIN_WORDLENGTH + difference) <= mWordSearchDimension && mWordSearchDimension < (WordSearchManager.EASY_MIN_WORDLENGTH + difference * 2))
            tv.setTextSize(18);
        else
            tv.setTextSize(14);

        int color;
        if (n.isHighlighted())
            color = Color.BLUE;
        else if ((pos / mWordSearchDimension) % 2 == 0)
            color = mContext.getResources().getColor(pos % 2 == 0 ? R.color.blue : R.color.green);
        else
            color = mContext.getResources().getColor((pos - mWordSearchDimension) % 2 == 0 ? R.color.green : R.color.blue);
        tv.setTextColor(color);

        return convertView;
    }

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

    @Override
    public Object getItem(int pos) {
        return mNodes.get(pos);
    }

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




Java Source Code List

chrisjluc.funsearch.ApplicationTest.java
chrisjluc.funsearch.WordSearchManager.java
chrisjluc.funsearch.adapters.WordSearchGridAdapter.java
chrisjluc.funsearch.adapters.WordSearchPagerAdapter.java
chrisjluc.funsearch.base.BaseActivity.java
chrisjluc.funsearch.models.GameDifficulty.java
chrisjluc.funsearch.models.GameMode.java
chrisjluc.funsearch.models.GameType.java
chrisjluc.funsearch.ui.MenuActivity.java
chrisjluc.funsearch.ui.ResultsActivity.java
chrisjluc.funsearch.ui.components.GameButton.java
chrisjluc.funsearch.ui.components.GameTextView.java
chrisjluc.funsearch.ui.gameplay.PauseDialogFragment.java
chrisjluc.funsearch.ui.gameplay.WordSearchActivity.java
chrisjluc.funsearch.ui.gameplay.WordSearchFragment.java
chrisjluc.funsearch.ui.gameplay.WordSearchGridView.java
chrisjluc.funsearch.ui.gameplay.WordSearchViewPager.java
chrisjluc.funsearch.wordSearchGenerator.generators.DistinctRandomGenerator.java
chrisjluc.funsearch.wordSearchGenerator.generators.WordSearchGenerator.java
chrisjluc.funsearch.wordSearchGenerator.models.Node.java
chrisjluc.funsearch.wordSearchGenerator.models.Point.java
chrisjluc.funsearch.wordSearchGenerator.models.PossibleInstance.java