Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. package com.example.dabbydunkerton.alaramclock;
  2.  
  3. import android.Manifest;
  4. import android.content.pm.PackageManager;
  5. import android.location.Location;
  6. import android.location.LocationListener;
  7. import android.location.LocationManager;
  8. import android.net.wifi.p2p.WifiP2pManager;
  9. import android.provider.Settings;
  10. import android.support.v4.app.ActivityCompat;
  11. import android.support.v7.app.AppCompatActivity;
  12. import android.os.Bundle;
  13. import android.widget.Button;
  14. import android.widget.CheckBox;
  15.  
  16. import java.util.Timer;
  17. import java.util.TimerTask;
  18.  
  19. public class AddLocatinalrm extends AppCompatActivity {
  20.     public Button button2;
  21.     public CheckBox checkBox2;
  22.     LocationManager lm;
  23.     LocationListener ll;
  24.     boolean locationChagned= true;
  25.     Double a;
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_add_locatinalrm);
  30.        
  31.         button2 = (Button) findViewById(R.id.button2);
  32.         checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
  33.         lm = (LocationManager) getSystemService(LOCATION_SERVICE);
  34.         ll = new LocationListener() {
  35.             @Override
  36.             public void onLocationChanged(Location location) {
  37.                 a = location.getLatitude()+location.getLongitude();
  38.                 locationChagned = true;
  39.              
  40.             }
  41.  
  42.             @Override
  43.             public void onStatusChanged(String provider, int status, Bundle extras) {
  44.  
  45.             }
  46.  
  47.             @Override
  48.             public void onProviderEnabled(String provider) {
  49.  
  50.             }
  51.  
  52.             @Override
  53.             public void onProviderDisabled(String provider) {
  54.  
  55.             }
  56.            
  57.            
  58.         };
  59.         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  60.             // TODO: Consider calling
  61.             //    ActivityCompat#requestPermissions
  62.             // here to request the missing permissions, and then overriding
  63.             //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
  64.             //                                          int[] grantResults)
  65.             // to handle the case where the user grants the permission. See the documentation
  66.             // for ActivityCompat#requestPermissions for more details.
  67.             return;
  68.         }
  69.         lm.requestLocationUpdates("gps", 55000, 0, ll);
  70.        
  71.         while (checkBox2.isEnabled() == true) {
  72.             Timer timer = new Timer();
  73.  
  74.  
  75.             TimerTask myTask = new TimerTask() {
  76.                
  77.                  double b =0;
  78.                 public void run(){
  79.                     if(a==b){
  80.                         //throw alarm
  81.                     }
  82.                     a = b;
  83.                 }
  84.             };
  85.             timer.scheduleAtFixedRate(myTask,2000,2000);
  86.  
  87.  
  88.  
  89.  
  90.  
  91.         }
  92.  
  93.  
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement