This application uses your GPS to work out the speed of any moving object, Car ,Bus, Train. You can even use it to find out how fast you are walking, running or riding a bicycle.
It gives a reading
1:Kilo Meter Per Hour
2:Miles Per Hours
3:Meter Per Second
It displays your GPS latitudinal and longitudinal coordination. Also shows your Orientation using your phone compass reading.
This application uses less graphic in order to consume less battery power.
Important*
This Application is best suited for large screen mobile devices.
package com.yene.car_monitor;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Accel extends Activity implements SensorEventListener,
LocationListener {
private SensorManager sensorManager;
private int lastX = 0;
private float lastY = 0;
private float lastZ = 0;
private int lng;
private int lat;
private float speed;
private Thread t;
private Average_Speed average;
private int chooes;
private TextView xViewA = null;
/*
* private TextView yViewA = null; private TextView zViewA = null;
*
* private TextView yViewO = null; private TextView zViewO = null; private
* TextView compass= null; private Counter update; private TextView ip=null;
* private float[]gForce= new float[6]; private float[] gravity = new
* float[3]; private float[] linear_acceleration= new float[3];
*/
private TextView xViewO = null;
private PowerManager.WakeLock wl;
private TextView gps = null;
private TextView display_info= null;
private TextView display_gps=null;
private float startPoint;
private float upperLitmit = 20;
private float lowerLitmit = -20;
private SmsManager sm = SmsManager.getDefault();
private LocationManager lm;
public int getChooes(){
return chooes;
}
public void setChooes(int option){
this.chooes=option;
}
//private XYPlot mySimpleXYPlot;
public float getSpeed() {
return speed;
}
public void setSpeed(float f) {
this.speed = f;
}
public int getLng() {
return lng;
}
public void setLng(int lng) {
this.lng = lng;
}
public int getLat() {
return lat;
}
public void setLat(int lat) {
this.lat = lat;
}
public int getLastX() {
return lastX;
}
public void setLastX(int value) {
this.lastX = value;
}
public float getLastY() {
return lastY;
}
public void setLastY(float lastY) {
this.lastY = lastY;
}
public float getLastZ() {
return lastZ;
}
public void setLastZ(float lastZ) {
this.lastZ = lastZ;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// display = new Drawing(this);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
setContentView(R.layout.main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// setContentView(display);
// Lookup R.layout.main
LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, "a14dd128b5c20b4");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
// request.setTesting(true);
adView.loadAd(request);
// xViewA = (TextView) findViewById(R.id.xbox);
// yViewA = (TextView) findViewById(R.id.ybox);
// zViewA = (TextView) findViewById(R.id.zbox);
xViewO = (TextView) findViewById(R.id.xboxo);
// yViewO = (TextView) findViewById(R.id.yboxo);
// zViewO = (TextView) findViewById(R.id.zboxo);
// compass = (TextView) findViewById(R.id.compass);
display_info= (TextView) findViewById(R.id.display_info);
gps = (TextView) findViewById(R.id.gps);
display_gps = (TextView) findViewById(R.id.time);
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
// int ipAddress = wifiInfo.getIpAddress();
// ip.setText(""+wifiInfo);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager
.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this, sensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this, sensorManager
.getDefaultSensor(Sensor.TYPE_ORIENTATION),
SensorManager.SENSOR_DELAY_FASTEST);
sensorManager.registerListener(this, sensorManager
.getDefaultSensor(Sensor.TYPE_PROXIMITY),
SensorManager.SENSOR_DELAY_FASTEST);
t = new Average_Speed();
average= new Average_Speed();
/*
// initialize our XYPlot reference:
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
// add a new series
mySimpleXYPlot.addSeries(new SimpleXYSeries(), LineAndPointRenderer.class, new LineAndPointFormatter(Color.rgb(0, 200, 0), Color.rgb(200, 0, 0), lastX));
// reduce the number of range labels
mySimpleXYPlot.getGraphWidget();
mySimpleXYPlot.setDomainLabel("Time");
mySimpleXYPlot.setRangeLabel("# Speed");
// reposition the domain label to look a little cleaner:
Widget domainLabelWidget = mySimpleXYPlot.getDomainLabelWidget();
mySimpleXYPlot.position(domainLabelWidget, // the widget to position
45, // x position value, in this case 45 pixels
XLayoutStyle.ABSOLUTE_FROM_LEFT, // how the x position value is applied, in this case from the left
0, // y position value
YLayoutStyle.ABSOLUTE_FROM_BOTTOM, // how the y position is applied, in this case from the bottom
AnchorPosition.LEFT_BOTTOM); // point to use as the origin of the widget being positioned
// get rid of the visual aids for positioning:
mySimpleXYPlot.disableAllMarkup();
*/
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.speedmenu, menu);
return true;
}
public void onSensorChanged(SensorEvent event) {
/**
* float[] values = event.values; // Movement float x = values[0]; float
* y = values[1]; float z = values[2];
*
* float accelationSquareRoot = (x * x + y * y + z * z) /
* (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH); if
* (accelationSquareRoot >= 1) // twice the accelation of earth
* Toast.makeText(this, "Device was shuffed", Toast.LENGTH_SHORT)
* .show();
*
* if (gForce < accelationSquareRoot) { gForce = accelationSquareRoot; }
*
* if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { float[]
* values1 = event.values; final float alpha = (float) 0.8;
*
* gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
* gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
* gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
*
* linear_acceleration[0] = values1[0] - gravity[0];
* linear_acceleration[1] = values1[1] - gravity[1];
* linear_acceleration[2] = values1[2] - gravity[2];
*
* xViewA.setText("Accel X: " + values1[0]);
yViewA.setText("Accel Y: "+ values1[1])
zViewA.setText("Accel Z: " + values1[2]); //after cal
* result //xViewA.setText("Accel X: " + linear_acceleration[0]);
* yViewA.setText("Accel Y: " + linear_acceleration[1]);
* zViewA.setText("Accel Z: " + linear_acceleration[2]); /*
*
}