Android Open Source - androidsoft-kids-memory Preferences Activity






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 w ww  . j av  a 2s .co  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.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;

import org.androidsoft.games.memory.kids.PreferencesService;
import org.silo.games.memory.kids.R;
import org.androidsoft.utils.ui.BasicActivity;

import com.fairket.sdk.android.FairketApiClient;
import com.fairket.sdk.android.FairketHelperForGingerbread;

/**
 *
 * @author pierre
 */
public class PreferencesActivity extends BasicActivity implements OnClickListener
{

    private TextView mTvHiScore;
    private Button mButtonResetHiScore;
    private Button mButtonSupport;
    private CompoundButton mCbSoundEnabled;
    private Spinner mSpinner;
    private int mIconSet;
  private FairketApiClient mFaiirketApiClient;

    /**
     * {@inheritDoc }
     */
    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);

        setContentView(R.layout.preferences);

        mTvHiScore = (TextView) findViewById(R.id.hiscore);
        updateHiScore();

        mButtonResetHiScore = (Button) findViewById(R.id.button_reset_hiscore);
        mButtonResetHiScore.setOnClickListener(this);

        mSpinner = (Spinner) findViewById(R.id.spinner_theme);

        mIconSet = PreferencesService.instance().getIconsSet();
        mSpinner.setSelection( mIconSet );

        mSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                setIconSet(position);
            }

            public void onNothingSelected(AdapterView<?> parent)
            {
                setIconSet( 0 );
            }

        });


        mCbSoundEnabled = (CompoundButton) findViewById(R.id.checkbox_sound);
        mCbSoundEnabled.setOnClickListener(this);
        mCbSoundEnabled.setChecked(PreferencesService.instance().isSoundEnabled());

        mButtonSupport = (Button) findViewById(R.id.button_support);
        mButtonSupport.setOnClickListener(this);
        
    mFaiirketApiClient = FairketHelperForGingerbread.onCreate(this,
        MainActivity.FAIRKET_APP_PUBLIC_KEY,
        MainActivity.FAIRKET_LOG_TAG);

    }

    /**
     * {@inheritDoc }
     */
    @Override
    public int getMenuResource()
    {
        return R.menu.menu_close;
    }

    /**
     * {@inheritDoc }
     */
    @Override
    public int getMenuCloseId()
    {
        return R.id.menu_close;
    }

    /**
     * {@inheritDoc }
     */
    public void onClick(View view)
    {
        if (view == mButtonResetHiScore)
        {
            PreferencesService.instance().resetHiScore();
            updateHiScore();
        }
        else if (view == mCbSoundEnabled)
        {
            PreferencesService.instance().saveSoundEnabled(mCbSoundEnabled.isChecked());
        }
        else if (view == mButtonSupport)
        {
            openGooglePlay();
        }
    }

    private void updateHiScore()
    {
        int hiscore = PreferencesService.instance().getHiScore();
        if (hiscore == PreferencesService.HISCORE_DEFAULT)
        {
            mTvHiScore.setText(" - ");
        }
        else
        {
            mTvHiScore.setText(" " + hiscore);
        }
    }
    
    private void setIconSet(int iconSet)
    {
        if( iconSet != mIconSet )
        {
            PreferencesService.instance().saveIconsSet( iconSet );
            Toast.makeText(this, R.string.message_effect_new_game, Toast.LENGTH_LONG).show();
            mIconSet = iconSet;
        }
    }

    /**
     * Open the market
     */
    private void openGooglePlay()
    {
        String uri = "market://details?id=org.androidsoft.games.memory.kids";
        Intent intentGoToGooglePlay = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        startActivity(intentGoToGooglePlay);
    }
    
  @Override
  protected void onResume() {
    super.onResume();

    FairketHelperForGingerbread.onResume(mFaiirketApiClient);
  }

  @Override
  protected void onPause() {
    super.onPause();
    FairketHelperForGingerbread.onPause(mFaiirketApiClient);
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    FairketHelperForGingerbread.onDestroy(mFaiirketApiClient);
  }


}




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