Android Open Source - GasTracker Add Entry






From Project

Back to project page GasTracker.

License

The source code is released under:

Copyright 2014 kurtzy317

If you think the Android project GasTracker 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 com.mindalsoblown.gastracker;
/* w ww .  java 2 s.c o  m*/
import java.io.FileNotFoundException;
import java.sql.Date;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class AddEntry extends ActionBarActivity {

  DatabaseConnector connection;
  EditText txtTotalMiles;
  EditText txtTripMiles;
  EditText txtCarMPGs;
  EditText txtGallons;
  TextView lblCarMPG;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_entry);
    
    //intialize database connection
    try {
      connection = new DatabaseConnector(openFileInput("ID"));
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    
    txtGallons = (EditText)findViewById(R.id.txtGallons);
    txtCarMPGs = (EditText)findViewById(R.id.txtMPG);
    txtTripMiles = (EditText)findViewById(R.id.txtTrip);
    txtTotalMiles = (EditText)findViewById(R.id.txtOdometer);
    lblCarMPG = (TextView)findViewById(R.id.lblCarMPG);
    
    if (!connection.GetUserSetting("CarMPG"))
    {
      lblCarMPG.setVisibility(View.GONE);
      txtCarMPGs.setVisibility(View.GONE);
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.add_entry, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      return true;
    }
    return super.onOptionsItemSelected(item);
  }
  
  @SuppressWarnings({ "deprecation" })
  public void addEntry(View view)
  {
    //get todays date and entry text boxes
    java.util.Date today = new java.util.Date();
    
    //add new entry
    double dblCarMPGs;
    try
    {
      dblCarMPGs =  Double.valueOf(txtCarMPGs.getText().toString());
    }
    catch (Exception ex)
    {
      dblCarMPGs = 0;
    }
    connection.AddEntry(new Date(today.getYear(), today.getMonth(), today.getDate()), Integer.valueOf(txtTotalMiles.getText().toString()), Double.valueOf(txtTripMiles.getText().toString()), dblCarMPGs, Double.valueOf(txtGallons.getText().toString()));
    finish();
  }
}




Java Source Code List

com.mindalsoblown.gastracker.AddEntry.java
com.mindalsoblown.gastracker.DatabaseConnector.java
com.mindalsoblown.gastracker.Entry.java
com.mindalsoblown.gastracker.FillUpDetail.java
com.mindalsoblown.gastracker.History.java
com.mindalsoblown.gastracker.Login.java
com.mindalsoblown.gastracker.MainMenu.java
com.mindalsoblown.gastracker.Register.java
com.mindalsoblown.gastracker.Stats.java
com.mindalsoblown.gastracker.User.java