Android Open Source - Keep-score Krata Score Activity






From Project

Back to project page Keep-score.

License

The source code is released under:

MIT License

If you think the Android project Keep-score 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 gr.sv1jsb.kratascore;
/* w  ww. j  av  a2 s .  co  m*/
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.Calendar;

import gr.sv1jsb.kratascore.persistance.KrataScoreContract;
import gr.sv1jsb.utils.ImageUtils;


public class KrataScoreActivity extends Activity implements
        DeleteConfirmDialog.DeleteListener,
        EndConfirmDialog.EndListener {

    private GameListFragment mGameListFrag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kratascore_main);
        if (savedInstanceState == null) {
            ImageUtils.addImageCache(getFragmentManager(), 0.1f);
            mGameListFrag = GameListFragment.newInstance();
            getFragmentManager().beginTransaction()
                    .add(R.id.container, mGameListFrag)
                    .commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch(id){
            case R.id.action_help:
                getFragmentManager().beginTransaction()
                        .replace(R.id.container, new HelpFragment(), HelpFragment.TAG)
                        .addToBackStack(HelpFragment.TAG)
                        .commit();
                break;
            case R.id.action_about:
                getFragmentManager().beginTransaction()
                        .replace(R.id.container, new AboutFragment(), AboutFragment.TAG)
                        .addToBackStack(AboutFragment.TAG)
                        .commit();
                break;
            case android.R.id.home:
                getFragmentManager().popBackStack();
                break;
            default:
                break;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDeletePositiveClick(long lineID) {
        ContentResolver cr = getContentResolver();
        Uri uri = Uri.withAppendedPath(KrataScoreContract.GameEntry.CONTENT_URI, String.valueOf(lineID));
        cr.delete(uri,null,null);
        Toast.makeText(this, R.string.game_deleted, Toast.LENGTH_SHORT).show();
        getFragmentManager().popBackStack();
    }

    @Override
    public void onEndPositiveClick(long gameID, String gameMethod) {
        ContentResolver cr = getContentResolver();
        Uri uri = KrataScoreContract.ScoreEntry.CONTENT_URI;
        String minOrMax;
        int count = 0;
        if(gameMethod.equals(KrataScoreContract.GameEntry.METHOD_MAX)){
            minOrMax = KrataScoreContract.ScoreEntry.SORT_SCORE_DESC;
        } else {
            minOrMax = KrataScoreContract.ScoreEntry.SORT_SCORE_ASC;
        }
        Cursor cursor = cr.query(uri, KrataScoreContract.ScoreEntry.PROJECTION_JOINED,
                KrataScoreContract.ScoreEntry.SELECTION_GAME_ID,
                new String[] {String.valueOf(gameID)},
                minOrMax);
        if(cursor.getCount() >= 1) {
            cursor.moveToFirst();
            String winner = cursor.getString(KrataScoreContract.ScoreEntry.NUM_PLAYER);
            cursor.close();
            ContentValues values = new ContentValues();
            Calendar cal = Calendar.getInstance();
            long dt = cal.getTimeInMillis();
            values.put(KrataScoreContract.GameEntry.COL_ENDED, String.valueOf(dt));
            values.put(KrataScoreContract.GameEntry.COL_WINNER, winner);
            uri = Uri.withAppendedPath(KrataScoreContract.GameEntry.CONTENT_URI, String.valueOf(gameID));
            count = cr.update(uri, values, null, null);
        }
        getFragmentManager().popBackStack();
        if(count>0) {
            Toast.makeText(getBaseContext(), getString(R.string.game_ended), Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getBaseContext(), getString(R.string.game_not_updated), Toast.LENGTH_SHORT).show();
        }
    }
}




Java Source Code List

gr.sv1jsb.cropimage.ApplicationTest.java
gr.sv1jsb.cropimage.BitmapManager.java
gr.sv1jsb.cropimage.CropImageView.java
gr.sv1jsb.cropimage.CropImage.java
gr.sv1jsb.cropimage.HighlightView.java
gr.sv1jsb.cropimage.ImageViewTouchBase.java
gr.sv1jsb.cropimage.MonitoredActivity.java
gr.sv1jsb.cropimage.RotateBitmap.java
gr.sv1jsb.cropimage.Util.java
gr.sv1jsb.kratascore.AboutFragment.java
gr.sv1jsb.kratascore.AddScoreDialog.java
gr.sv1jsb.kratascore.ApplicationTest.java
gr.sv1jsb.kratascore.Constants.java
gr.sv1jsb.kratascore.DateFragment.java
gr.sv1jsb.kratascore.DeleteConfirmDialog.java
gr.sv1jsb.kratascore.EndConfirmDialog.java
gr.sv1jsb.kratascore.GameFragment.java
gr.sv1jsb.kratascore.GameListFragment.java
gr.sv1jsb.kratascore.GenericAlertDialog.java
gr.sv1jsb.kratascore.HelpFragment.java
gr.sv1jsb.kratascore.KrataScoreActivity.java
gr.sv1jsb.kratascore.NewGameActivity.java
gr.sv1jsb.kratascore.PhotoPickDialog.java
gr.sv1jsb.kratascore.PlayerActivity.java
gr.sv1jsb.kratascore.PlayerListActivity.java
gr.sv1jsb.kratascore.SearchActivity.java
gr.sv1jsb.kratascore.SortDialog.java
gr.sv1jsb.kratascore.adapters.BaseCursorAdapter.java
gr.sv1jsb.kratascore.adapters.GameAdapter.java
gr.sv1jsb.kratascore.adapters.GameListAdapter.java
gr.sv1jsb.kratascore.adapters.PlayerListAdapter.java
gr.sv1jsb.kratascore.persistance.KrataScoreContract.java
gr.sv1jsb.kratascore.persistance.KrataScoreDB.java
gr.sv1jsb.kratascore.persistance.Player.java
gr.sv1jsb.kratascore.provider.KrataScoreProvider.java
gr.sv1jsb.utils.ImageCache.java
gr.sv1jsb.utils.ImageUtils.java
gr.sv1jsb.utils.RandomStringUtils.java