public void recordingStopped() { endTime_ = now(); mDb.open(); mDb.updateTripStatus(tripid, STATUS_RECORDING_COMPLETE); mDb.setEndTime(tripid, endTime_); mDb.close(); }
private void loadJourney() { // Otherwise, we need to query DB and build points from scratch. gpspoints = new ArrayList<>(); mDb.openReadOnly(); Cursor points = mDb.fetchAllCoordsForTrip(tripid); int COL_LAT = points.getColumnIndex("lat"); int COL_LGT = points.getColumnIndex("lgt"); int COL_TIME = points.getColumnIndex("time"); int COL_ACC = points.getColumnIndex(DbAdapter.K_POINT_ACC); int COL_SPEED = points.getColumnIndex(DbAdapter.K_POINT_SPEED); int COL_ALT = points.getColumnIndex(DbAdapter.K_POINT_ALT); while (!points.isAfterLast()) { int lat = points.getInt(COL_LAT); int lgt = points.getInt(COL_LGT); long time = points.getInt(COL_TIME); double altitude = points.getDouble(COL_ALT); float speed = (float) points.getDouble(COL_SPEED); float acc = (float) points.getDouble(COL_ACC); gpspoints.add(new CyclePoint(lat, lgt, time, acc, altitude, speed)); points.moveToNext(); } // while points.close(); mDb.close(); } // loadJourney
public void addPointNow(Location loc) { int lat = (int) (loc.getLatitude() * 1E6); int lgt = (int) (loc.getLongitude() * 1E6); float accuracy = loc.getAccuracy(); double altitude = loc.getAltitude(); float speed = loc.getSpeed(); endTime_ = (loc.getTime() / 1000); CyclePoint pt = new CyclePoint(lat, lgt, endTime_, accuracy, altitude, speed); if (gpspoints.size() > 1) { CyclePoint gp = gpspoints.get(gpspoints.size() - 1); float segmentDistance = gp.distanceTo(pt); if (segmentDistance == 0) return; // we haven't gone anywhere distance += segmentDistance; } // if ... gpspoints.add(pt); mDb.open(); mDb.addCoordToTrip(tripid, pt); mDb.setDistance(tripid, distance); mDb.close(); return; } // addPointNow
private void setMessages() { dbHelper.open(); for (Message message : dbHelper.getMessages()) { addMessageToLayout(message); } dbHelper.close(); messagesScroll.fullScroll(ScrollView.FOCUS_DOWN); }
private Message createMessage() { dbHelper.open(); Message message = dbHelper.createMessage( settings.getUsername(), content.getText().toString(), Calendar.getInstance().getTimeInMillis()); TransportConfiguration tc = new TransportConfiguration(); dbHelper.close(); return message; }
private void initializeData() { startTime_ = now(); endTime_ = now(); distance = 0; purp_ = fancystart_ = info_ = ""; gpspoints = new ArrayList<>(); mDb.open(); mDb.setStartTime(tripid, startTime_); mDb.close(); }
/** * Constructor for creating "fresh" new track. Use this for new measurements that were captured * from the OBD-II adapter. */ private Track(DbAdapter dbAdapter) { this.name = ""; this.description = ""; this.measurements = new ArrayList<Measurement>(); this.id = dbAdapter.insertTrack(this); this.dbAdapter = dbAdapter; }
// Método ejecutado al iniciar la aplicación. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Establece main.xml como vista actual. setContentView(R.layout.main); // Obtiene el elemento btnInsertar de main.xml Button btnInsertar = (Button) this.findViewById(R.id.btnInsertar); // Le asigna un evento de clase BtnInsertarClick. btnInsertar.setOnClickListener(new BtnInsertarClick(this)); // Obtiene el elemento btnCancelar de main.xml Button btnCancelar = (Button) this.findViewById(R.id.btnCancelar); // Le asigna un evento de clase BtnCancelarClick. btnCancelar.setOnClickListener(new BtnCancelarClick(this)); // Crea un objeto manipulador de base de datos y abre una conexión. db = new DbAdapter(this); db.open(); // Rellena el elemento ListView con los registros de la tabla notas. this.rellenarListView(); }
// open the database, put something in it when Add is clicked. public void onCreate(Bundle bundle) { mDb = new DbAdapter(this); mDb.open(); mRowId = 0; Bundle extras = getIntent().getExtras(); mRowId = extras.getInt(DbAdapter.KEY_TEAM_ID); super.onCreate(bundle); setContentView(R.layout.player); playerName = (EditText) findViewById(R.id.name_player); btnAdd = (Button) findViewById(R.id.add_player); btnCancel = (Button) findViewById(R.id.close_player); btnAdd.setOnClickListener( new OnClickListener() { public void onClick(View v) { // TODO add the record and return to the main screen mDb.addPlayer(playerName.getText().toString(), mRowId); setResult(RESULT_OK); finish(); } }); btnCancel.setOnClickListener( new OnClickListener() { public void onClick(View v) { finish(); } }); }
@Override protected String doInBackground(String... args) { // TODO Auto-generated method stub int success; try { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("fname", fname)); params.add(new BasicNameValuePair("password", password)); params.add(new BasicNameValuePair("phone", phone)); params.add(new BasicNameValuePair("email", email)); ContentValues contents = new ContentValues(); contents.put(DbHelper.USER_NAME, fname); contents.put(DbHelper.USER_PHONE_NUMBER, phone); contents.put(DbHelper.USER_EMAIL, email); contents.put(DbHelper.USER_PASSWORD, password); DbAdapter adapter = new DbAdapter(getBaseContext()); adapter.addUser(contents); Log.d("request!", "starting"); JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params); // Log.d("Login attempt", json.toString()); // success = json.getInt(TAG_SUCCESS); success = 1; if (success == 1) { Log.d("User Created!", json.toString()); Intent intent = new Intent(Register.this, Login.class); startActivity(intent); finish(); return "Succssfully registered!"; // return json.getString(TAG_MESSAGE); } else { Log.d("Login Failure!", json.getString(TAG_MESSAGE)); return json.getString(TAG_MESSAGE); } } catch (Exception e) { e.printStackTrace(); } return null; }
public void onDestroy() { try { db.close(); } catch (Exception e) { } super.onDestroy(); }
/** * updates the tracks metadata. if there is already metadata, the properties are merged. the * provided object overrides existing keys. * * @param newMetadata */ public void updateMetadata(TrackMetadata newMetadata) { if (this.metadata != null) { this.metadata.merge(newMetadata); } else { setMetadata(newMetadata); } dbAdapter.updateTrack(this); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mDbHelper = new DbAdapter(this); mDbHelper.open(); fillData(); }
/** @return the measurements */ public List<Measurement> getMeasurements() { if ((measurements == null || measurements.isEmpty()) && dbAdapter != null) { try { this.measurements = dbAdapter.getAllMeasurementsForTrack(this); } catch (TrackWithoutMeasurementsException e) { logger.warn(e.getMessage(), e); } } return measurements; }
public void updateTrip( String purpose, String fancyStart, String fancyInfo, String notes, String age, String gender, String experience) { // Save the trip details to the phone database. W00t! mDb.open(); mDb.updateNotes(tripid, purpose, fancyStart, fancyInfo, notes, age, gender, experience); mDb.close(); purp_ = purpose; note_ = notes; age_ = age; gender_ = gender; experience_ = experience; } // updateTrip
public static PokemonSpecies[] createSpeciesArray() { PokemonSpecies[] speciesArray = new PokemonSpecies[668]; PokemonSpecies base_poke = null; ResultSet info = null; ResultSet moves = null; DbAdapter adapter; try { System.out.print("Loading Pokedex."); adapter = new DbAdapter(); for (int i = 1; i < 668; i++) { if (i % 50 == 0) { System.out.print('.'); } info = null; info = adapter.makeQuery("SELECT * FROM pokemon WHERE id = '" + i + "'"); if (info.next()) { base_poke = new PokemonSpecies(info); } speciesArray[i] = base_poke; } info.close(); for (int i = 1; i < 668; i++) { if (i % 50 == 0) { System.out.print('.'); } moves = null; moves = adapter.makeQuery("SELECT * FROM pokemon_moves WHERE pokemon_id = '" + i + "'"); speciesArray[i].setMoves(moves); } moves.close(); adapter.close(); } catch (Exception e) { e.printStackTrace(); } return speciesArray; }
// Get lat/long extremes, etc, from trip record private void populateDetails() { mDb.openReadOnly(); Cursor tripdetails = mDb.fetchTrip(tripid); startTime_ = tripdetails.getInt(tripdetails.getColumnIndex("start")); status = tripdetails.getInt(tripdetails.getColumnIndex("status")); endTime_ = tripdetails.getInt(tripdetails.getColumnIndex("endtime")); distance = tripdetails.getFloat(tripdetails.getColumnIndex("distance")); purp_ = tripdetails.getString(tripdetails.getColumnIndex("purp")); fancystart_ = tripdetails.getString(tripdetails.getColumnIndex("fancystart")); info_ = tripdetails.getString(tripdetails.getColumnIndex("fancyinfo")); note_ = tripdetails.getString(tripdetails.getColumnIndex("note")); age_ = tripdetails.getString(tripdetails.getColumnIndex("age")); gender_ = tripdetails.getString(tripdetails.getColumnIndex("gender")); experience_ = tripdetails.getString(tripdetails.getColumnIndex("experience")); tripdetails.close(); mDb.close(); loadJourney(); }
private void fillData() { // TODO Auto-generated method stub // Get all of the notes from the database and create the item list Cursor c = mDbHelper.getAllNotes(); startManagingCursor(c); String[] from = new String[] {DbAdapter.KEY_TITLE}; int[] to = new int[] {R.id.text1}; // Now create an array adapter and set it to display using our row SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to); Log.d("AAAAAAAMMMMMMMMM=", "" + c + "===" + from + "====" + to); setListAdapter(notes); }
/** Método para rellenar el elemento ListView con los registros de la base de datos. */ void rellenarListView() { // Variable que contiene los registros. Cursor c = db.obtenerNotas(); // Prepara el cursor para su uso. startManagingCursor(c); // Indica los campos a proyectar. String[] desde = new String[] {SqLiteHelper.KEY_ID, SqLiteHelper.KEY_TITULO, SqLiteHelper.KEY_CUERPO}; // Indica dónde se mostrarán los campos. int[] hasta = new int[] {R.id.tvId, R.id.tvTitulo, R.id.tvCuerpo}; // Crea un adaptador para poder mostrar los datos en el ListView. SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.listview_item, c, desde, hasta); // Asigna el adaptador al ListView. setListAdapter(notes); }
private void setSettings() { dbHelper.open(); settings = dbHelper.getSettings(); dbHelper.close(); }
private void updateTripStatus(int tripStatus) { mDb.open(); mDb.updateTripStatus(tripid, tripStatus); mDb.close(); }
public void finish() { mDb.close(); super.finish(); }
void dropTrip() { mDb.open(); mDb.deleteAllCoordsForTrip(tripid); mDb.deleteTrip(tripid); mDb.close(); }
private void createTripInDatabase(Context c) { mDb.open(); tripid = mDb.createTrip(); mDb.close(); }