Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dabbydunkerton.alaramclock;
- import android.Manifest;
- import android.content.pm.PackageManager;
- import android.location.Location;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.net.wifi.p2p.WifiP2pManager;
- import android.provider.Settings;
- import android.support.v4.app.ActivityCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.CheckBox;
- import java.util.Timer;
- import java.util.TimerTask;
- public class AddLocatinalrm extends AppCompatActivity {
- public Button button2;
- public CheckBox checkBox2;
- LocationManager lm;
- LocationListener ll;
- boolean locationChagned= true;
- Double a;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_add_locatinalrm);
- button2 = (Button) findViewById(R.id.button2);
- checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
- lm = (LocationManager) getSystemService(LOCATION_SERVICE);
- ll = new LocationListener() {
- @Override
- public void onLocationChanged(Location location) {
- a = location.getLatitude()+location.getLongitude();
- locationChagned = true;
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- }
- @Override
- public void onProviderEnabled(String provider) {
- }
- @Override
- public void onProviderDisabled(String provider) {
- }
- };
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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;
- }
- lm.requestLocationUpdates("gps", 55000, 0, ll);
- while (checkBox2.isEnabled() == true) {
- Timer timer = new Timer();
- TimerTask myTask = new TimerTask() {
- double b =0;
- public void run(){
- if(a==b){
- //throw alarm
- }
- a = b;
- }
- };
- timer.scheduleAtFixedRate(myTask,2000,2000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement