@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.about: Intent mainIntent = new Intent(MainActivity.this, AboutActivity.class); MainActivity.this.startActivityForResult(mainIntent, -1); return true; case R.id.listcards: Intent mainIntent2 = new Intent(MainActivity.this, ListCardsActivity.class); mainIntent2.putExtra("USERID", game.getPlayer().getUserId()); MainActivity.this.startActivityForResult(mainIntent2, -1); return true; case R.id.statistics: Intent mainIntent3 = new Intent(MainActivity.this, StatisticsActivity.class); MainActivity.this.startActivityForResult(mainIntent3, -1); return true; case R.id.refresh: // Refreshing stuff! // New owner? Card lc = dbc.loadCard(game.getCurrentCard().getId()); // Load the new card from db if (lc != null) { Log.d(TAG, Integer.toString(lc.getOwnerId())); game.setCurrentCard(lc); game.getCurrentCard().setOwner(dbc.loadUserName(lc.getOwnerId())); game.getCurrentCard() .setLocationData(this.getBaseContext(), game.getCurrentCard().getPosition()); } // Cash syncAllCash(true); updateMainContent(game.getCurrentCard()); Toast.makeText(this, "Refresh Complete!", Toast.LENGTH_SHORT).show(); return true; case R.id.logout: // Log out Facebook Log.d(TAG, "Logout Facebook"); prefsEditor = prefsPrivate.edit(); prefsEditor.putString("access_token", null); prefsEditor.putLong("access_expires", 0); prefsEditor.putString("user", null); prefsEditor.putString("pass", null); prefsEditor.putString("email", null); prefsEditor.putInt("userid", 0); prefsEditor.putInt("cash", 0); prefsEditor.commit(); String method = "DELETE"; Bundle params = new Bundle(); /* * this will revoke 'publish_stream' permission * Note: If you don't specify a permission then this will de-authorize the application completely. */ params.putString("permission", ""); mAsyncRunner.request( "/me/permissions", params, method, new RequestListener() { @Override public void onComplete(String response, Object state) {} @Override public void onIOException(IOException e, Object state) {} @Override public void onFileNotFoundException(FileNotFoundException e, Object state) {} @Override public void onMalformedURLException(MalformedURLException e, Object state) {} @Override public void onFacebookError(FacebookError e, Object state) {} }, null); mAsyncRunner.logout( this.getBaseContext(), new RequestListener() { @Override public void onMalformedURLException(MalformedURLException e, Object state) {} @Override public void onIOException(IOException e, Object state) {} @Override public void onFileNotFoundException(FileNotFoundException e, Object state) {} @Override public void onFacebookError(FacebookError e, Object state) {} @Override public void onComplete(String response, Object state) {} }); return true; default: return super.onOptionsItemSelected(item); } }
@Override public void onLocationChanged(Location location) { Log.v(TAG, "Location Changed"); nofixes++; StringBuilder sb = new StringBuilder(); // Get some cash on each fix and make sound game.foundCash(); mp.get(0).start(); // vib.vibrate(100); try { sb.append( game.getPlayer().getUserId() + ", " + game.getPlayer().getUser() + ", " + game.getPlayer().getEmail() + "\n"); sb.append(nofixes + ", "); // Decode point address List<Address> listan = new LinkedList<Address>(); Geocoder adam = new Geocoder(this.getBaseContext()); listan.addAll(adam.getFromLocation(location.getLatitude(), location.getLongitude(), 9)); Log.v(TAG, Integer.toString(nofixes)); sb.append(location.getProvider()); // Conversion to UTM CoordinateConversion bertil = new CoordinateConversion(); String cesar = bertil.latLon2UTM(location.getLatitude(), location.getLongitude()); String[] david = cesar.split(" "); // if new square - update! String newid = david[0] + Character.getNumericValue(david[1].toCharArray()[0]) + david[2].substring(0, 3) + david[3].substring(0, 4); if (!newid.matches(game.getCurrentCard().getId()) && game.getPlayer().getUserId() != 0) { Log.v(TAG, "NEW AREA!!!"); if (!dbc.existsCard(newid)) { Log.v(TAG, "NEW CARD! (Insert card)"); game.setCurrentCard(new Card(cesar, "", "", 0, GameMechanics.DEFAULT_OWNER, 0, 0)); game.getCurrentCard().setLocationData(this.getBaseContext(), cesar); dbc.insertCard(game.getCurrentCard()); } else { Log.v(TAG, "CARD EXISTS! (Load card)"); Card lc = dbc.loadCard(newid); // Load the new card from db if (lc != null) { Log.d(TAG, Integer.toString(lc.getOwnerId())); game.setCurrentCard(lc); game.getCurrentCard().setOwner(dbc.loadUserName(lc.getOwnerId())); game.getCurrentCard().setLocationData(this.getBaseContext(), cesar); } // potential owner / disable button issue? or will it be fixed in the update views?.... // yes probably // pay taxes! if (game.getPlayer().getUserId() != lc.getOwnerId() && lc.getOwnerId() != 0) dbc.insertTransfer( game.getPlayer().getUserId(), lc.getOwnerId(), lc.getId(), lc.getTax(), 0); // 0 = tax } syncAllCash(true); // make a new sound mp.get(2).start(); } else { Log.v(TAG, "SAME OLD AREA!"); game.getCurrentCard().setLocationData(this.getBaseContext(), cesar); syncAllCash(false); } // Update current card and funds updateMainContent(game.getCurrentCard()); sb.append(cesar + ", "); sb.append(game.getCurrentCard().getId() + "\n"); sb.append("\n"); sb.append(location.getProvider() + ", "); sb.append(location.getAccuracy() + "\n"); /*for(int i = 0; i < listan.size(); i++){ sb.append(listan.get(i).getThoroughfare() + ", " + listan.get(i).getLocality() + "\n"); }*/ // Debug text if (DEBUG) tw.setText(sb.toString()); } catch (Exception e) { e.printStackTrace(); } if (game.getAddedCash() > 100) mp.get(3).start(); }