Sunday , November 28 2021

Android SpeedoMeter Tutorial using Google Location Service – Android Coding by DMTechnolab

The package Pinch.Bitman.With.Speedometer;

Import Android.App.AlertDialog;

Import Android.App.Progressressialog;

Import Android.Content.Component Name;

Import Android.Content.Dialog interface;

Import Android.Content.Intent;

Import Android.Content.Serviceconnect;

Import Android.place.location manager;

Import Android..Bundle;

Import Android..IBinder;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.Opinion.Opinion;

Import Android.Widget.switch;

Import Android.Widget.ImageView;

Import Android.Widget.text view;

public class Main activity Is spread AppCompatActivity {{

location service myService;

Fixed Boolean Event;

location manager location manager;

Fixed text view away, Time, Speed;

switch Start, Stay, Stop;

Fixed long Start time, Last Time;

ImageView The image;

Fixed Progressressialog Find out;

Fixed int P = 0;

Private Serviceconnect sc = New Serviceconnect()) {{

@Override

public Zero onServiceConnected()Component Name Name, IBinder Service) {{

location service.Local binder Bookbinder = ()location service.Local binder) Service;

myService = Bookbinder.getService());

Event = True;

}

@Override

public Zero onServiceDisconnected()Component Name Name) {{

Event = false;

}

};

Zero bindService()) {{

If ()Event == True)

The return;

Intent I am = New Intent()getApplicationContext()), location service.class);

bindService()I am, sc, BIND_AUTO_CREATE);

Event = True;

Start time = system.currentTimeMillis());

}

Zero Unbundled service()) {{

If ()Event == false)

The return;

Intent I am = New Intent()getApplicationContext()), location service.class);

Unbundled service()sc);

Event = false;

}

@Override

Protected Zero on resume()) {{

Super.on resume());

}

@Override

Protected Zero onStart()) {{

Super.onStart());

}

@Override

Protected Zero onDestroy()) {{

Super.onDestroy());

If ()Event == True)

Unbundled service());

}

@Override

public Zero onBackPressed()) {{

If ()Event == false)

Super.onBackPressed());

other

MoveTaskToBack()True);

}

@Override

Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);

setContentView()R.Layout.activity_main);

away = ()text view) findViewById()R.Id.nooks and crannies);

Time = ()text view) findViewById()R.Id.time limit);

Speed = ()text view) findViewById()R.Id.Speedtext);

Start = ()switch) findViewById()R.Id.Start);

Stay = ()switch) findViewById()R.Id.Stay);

Stop = ()switch) findViewById()R.Id.Stop);

The image = ()ImageView) findViewById()R.Id.The image);

Start.setOnClickListener()New Opinion.OnClickListener()) {{

@Override

public Zero on click()Opinion v) {{

// The method below checks whether the location is enabled on the device. If not, a warning dialog box appears with the option

// To enable GPS.

Checkgaps());

location manager = ()location manager) getSystemService()location service);

If ()!location manager.isProviderEnabled()location manager.GPS_PROVIDER)) {{

The return;

}

If ()Event == false)

// Here, the location service is tied up and the GPS speedometer becomes active.

bindService());

Find out = New Progressressialog()Main activity.this);

Find out.setIndeterminate()True);

Find out.Setable()false);

Find out.Setmessage()“Getting location …”);

Find out.Display());

Start.Instability()Opinion.Gone);

Stay.Instability()Opinion.View);

Stay.Settext()“Pause”);

Stop.Instability()Opinion.View);

}

});

Stay.setOnClickListener()New Opinion.OnClickListener()) {{

@Override

public Zero on click()Opinion v) {{

If ()Stay.Gettext()).Wire()).equalsIgnoreCase()“Pause”)) {{

Stay.Settext()“Biodata”);

P = Have 1;

} other If ()Stay.Gettext()).Wire()).equalsIgnoreCase()“Biodata”)) {{

Checkgaps());

location manager = ()location manager) getSystemService()location service);

If ()!location manager.isProviderEnabled()location manager.GPS_PROVIDER)) {{

//Toast.makeText(this, “GPS is enabled in your divide”, Toast.LENGTH .SHORT) .show ();

The return;

}

Stay.Settext()“Pause”);

P = 0;

}

}

});

Stop.setOnClickListener()New Opinion.OnClickListener()) {{

@Override

public Zero on click()Opinion v) {{

If ()Event == True)

Unbundled service());

Start.Instability()Opinion.View);

Stay.Settext()“Pause”);

Stay.Instability()Opinion.Gone);

Stop.Instability()Opinion.Gone);

P = 0;

}

});

}

// This method takes you to the warning dialog box.

Zero Checkgaps()) {{

location manager = ()location manager) getSystemService()location service);

If ()!location manager.isProviderEnabled()location manager.GPS_PROVIDER)) {{

showGPSDisabledAlertToUser());

}

}

// This method configures the alert dialog box.

Private Zero showGPSDisabledAlertToUser()) {{

AlertDialog.Builder AlertDialogular = New AlertDialog.Builder()this);

AlertDialogular.Setmessage()“Enable GPS to use the application”)

.Setable()false)

.setPositiveButton()“Enable GPS”,

New Dialog interface.OnClickListener()) {{

public Zero on click()Dialog interface conversation, int Id) {{

Intent callGPSSettingIntent = New Intent()

Android.the provider.Adjustment.ACTION_LOCATION_SOURCE_SETTINGS);

Beginning()callGPSSettingIntent);

}

});

AlertDialogular.setNegativeButton()“To cancel”,

New Dialog interface.OnClickListener()) {{

public Zero on click()Dialog interface conversation, int Id) {{

conversation.To cancel());

}

});

AlertDialog Cautious = AlertDialogular.To create());

Cautious.Display());

}

}


Source link

About dmtechnolab

Check Also

Simplified Coding

Android Espresso Tutorial – Testing Fragment in Isolation – Android Coding by DMTechnolab

Welcome to another tutorial in the Android test series. And this post is called Android …

Leave a Reply

Your email address will not be published. Required fields are marked *