Splashpage

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Slpsh page

package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SeekBar;

import java.util.Timer;
import java.util.TimerTask;

public class SlapshActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_slapsh);

Intent ihome= new Intent(SlapshActivity.this,MainActivity.class);

new Handler().postDelayed(new Runnable() {


@Override
public void run() {
startActivity(ihome);

}
},4000);

}
activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#77673AB7"
tools:context=".MainActivity2">

<Button android:id="@+id/buttonstartprog1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start"
android:layout_marginTop="50dp" />

<Button android:id="@+id/buttonstopprog1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop"/>

<TextView android:id="@+id/textViewtimer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textSize="34sp"/>

<ImageView
android:layout_width="400dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"

android:src="@mipmap/image8" />

</LinearLayout>

activity_mani.java

package com.example.myapplication;

import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity2 extends AppCompatActivity {

Button b1, b2;


TextView e1;

Timer timer;
MyTimerTask myTimerTask;
int a=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//EdgeToEdge.enable(this);
setContentView(R.layout.activity_main2);

b1 =(Button) findViewById(R.id.buttonstartprog1);
b2 =(Button) findViewById(R.id.buttonstopprog1);
e1 =(TextView) findViewById(R.id.textViewtimer1);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//create method
getlocation();

try
{
a=0;
timer = new Timer();
myTimerTask = new MyTimerTask();
timer.schedule(myTimerTask, 1000, 1000);
}
catch(Exception w){
Toast.makeText(getApplication(),
w.toString() ,Toast.LENGTH_LONG).show();
}
}

private void getlocation() {


}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timer.cancel();
}
});

class MyTimerTask extends TimerTask {


@Override
public void run() {
runOnUiThread(new Runnable(){
@Override
public void run() {
getval();
}});
}
}

void getval()
{
a=a+1;

if(a>=60)
{
a=0;

GPSTracker gps = new GPSTracker(this);

if( gps.canGetLocation()){
try {
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
double Speedval = gps.getSpeed();
String latitudestr = Double.toString(latitude);
String longitudestr = Double.toString(longitude);
String Speedudestr = Double.toString(Speedval);

Toast.makeText(getBaseContext(),latitudestr+",
"+longitudestr+", "+Speedudestr,Toast.LENGTH_LONG).show();

String SMSval = "Vehical At Location


http://maps.google.com/maps?q=" + Double.toString(latitude) + "," +
Double.toString(longitude);
SmsManager SM = SmsManager.getDefault();
SM.sendTextMessage("7666838311" , null, SMSval, null,
null);

//(t1.getText().toString(), SMSval);

}
catch(Exception ee)
{
Toast.makeText(getApplicationContext(),
"GPS faild, please try again later!",
Toast.LENGTH_LONG).show();
}
}

e1.setText(Integer.toString(a));
}
}

GPS Tracker ,,package com.example.myapplication;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

public class GPSTracker extends Service implements LocationListener {

private static final long MIN_TIME_BW_UPDATES = 1000 * 60 ; // 1 minute

private final Context mContext;


public GPSTracker gps;
// flag for GPS status
boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
// flag for GPS status
boolean canGetLocation = false;

Location location; // location


double latitude; // latitude
double longitude; // longitude
double Speedval; // longitude

// The minimum distance to change Updates in meters


private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10
meters

// The minimum time between updates in milliseconds

// Declaring a Location Manager


protected LocationManager locationManager;

GPSTracker(Context context) {

this.mContext = context;
getLocation();
}

public Location getLocation() {


try {

//bind service
locationManager = (LocationManager)
mContext.getSystemService(LOCATION_SERVICE);

// getting GPS status


isGPSEnabled =
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

// getting network status


isNetworkEnabled =
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) {


// no network provider is enabled
} else {
this.canGetLocation = true;

if (isNetworkEnabled) {
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then
overriding
// public void onRequestPermissionsResult(int
requestCode, String[] permissions,
// int[]
grantResults)
// to handle the case where the user grants the permission.
See the documentation
// for ActivityCompat#requestPermissions for more details.
return location;
}

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

if (locationManager != null) {
if (ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {

}
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
Speedval=location.getSpeed();
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

return location;
}

/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
* */
public void stopUsingGPS(){
if( locationManager != null){
locationManager.removeUpdates(GPSTracker.this);
}
}

/**
* Function to get latitude
* */
public double getLatitude(){
if( location != null){
latitude = location.getLatitude();
}
return latitude;
}

/**
* Function to get longitude
* */
public double getLongitude(){
if(location != null){

longitude = gps.getLongitude();
}
return longitude;
}

/**
* Function to get longitude
*/
public double getSpeed(){
if(location != null){

double Speedval = gps.getSpeed();


}
return Speedval;
}

/**
* Function to check GPS/wifi enabled
* @return boolean
* */
public boolean canGetLocation() {

return this.canGetLocation;
}

@Override
public void onLocationChanged(Location location) {

@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public IBinder onBind(Intent arg0) {
return null;
}

You might also like