Android Open Source - androidsoft-kids-memory Tile






From Project

Back to project page androidsoft-kids-memory.

License

The source code is released under:

GNU General Public License

If you think the Android project androidsoft-kids-memory 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

/* Copyright (c) 2010-2014 Pierre LEVY androidsoft.org
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version./*from  ww w . j a  v a2  s. c  o m*/
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.androidsoft.games.memory.kids.model;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author pierre
 */
public class Tile
{

    private static final String ATTR_FOUND = "Found";
    private static final String ATTR_SELECTED = "Selected";
    private static final String ATTR_RESID = "ResId";
    boolean mFound;
    boolean mSelected;
    int mResId;
    private static int mNotFoundResId;

    /**
     * Constructor
     */
    Tile()
    {
    }

    /**
     * Constructor
     */
    Tile(int nResId)
    {
        mResId = nResId;
    }

    /**
     * Constructor from a JSON object
     */
    Tile(JSONObject object)
    {
        try
        {
            mFound = object.getBoolean(ATTR_FOUND);
            mSelected = object.getBoolean(ATTR_SELECTED);
            mResId = object.getInt(ATTR_RESID);
        } catch (JSONException ex)
        {
            Logger.getLogger(Tile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void setNotFoundResId(int nNotFoundResId)
    {
        mNotFoundResId = nNotFoundResId;
    }

    boolean isFound()
    {
        return mFound;
    }

    void setFound(boolean bFound)
    {
        mFound = bFound;
    }

    public int getResId()
    {
        return (mFound || mSelected) ? mResId : mNotFoundResId;
    }

    public void select()
    {
        mSelected = true;
    }

    public void unselect()
    {
        mSelected = false;
    }

    /**
     * Build a JSONObject representing the tile
     * @return a JSONObject
     */
    JSONObject json()
    {
        JSONObject object = new JSONObject();
        try
        {
            object.accumulate(ATTR_FOUND, mFound);
            object.accumulate(ATTR_SELECTED, mSelected);
            object.accumulate(ATTR_RESID, mResId);
        } catch (JSONException ex)
        {
            Logger.getLogger(Tile.class.getName()).log(Level.SEVERE, null, ex);
        }
        return object;

    }
}




Java Source Code List

org.androidsoft.games.memory.kids.Constants.java
org.androidsoft.games.memory.kids.PreferencesService.java
org.androidsoft.games.memory.kids.Rotate3dAnimation.java
org.androidsoft.games.memory.kids.model.Memory.java
org.androidsoft.games.memory.kids.model.TileList.java
org.androidsoft.games.memory.kids.model.Tile.java
org.androidsoft.games.memory.kids.ui.AbstractMainActivity.java
org.androidsoft.games.memory.kids.ui.CreditsActivity.java
org.androidsoft.games.memory.kids.ui.ImageAdapter.java
org.androidsoft.games.memory.kids.ui.MainActivity.java
org.androidsoft.games.memory.kids.ui.MemoryGridView.java
org.androidsoft.games.memory.kids.ui.PreferencesActivity.java