package com.nickdroid.niket.projectmaw; import android.Manifest; 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.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends AppCompatActivity implements LocationListener{ private LocationManager locationManager; private GoogleApiClient mGoogleApiClient = null; private Location location=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,3000,10,this); /*if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); }*/ Log.v("pemission check",String.valueOf(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)); /*if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this,new String[]{ android.Manifest.permission.ACCESS_FINE_LOCATION },LocationService.ACCESS_FINE_LOCATION); location=LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); }*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); /* FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } });*/ Log.v("TAG", "MainOnCreate"); Button searchButton = (Button) findViewById(R.id.restCall); Log.v("TAG", "Button Created"); searchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.v("pemission check",String.valueOf(ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)); if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { //mMap.setMyLocationEnabled(true); Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); Log.v("Something 1",mLastLocation.toString()); if (mLastLocation != null) { // mMap.addMarker(new MarkerOptions().position(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude())).title("Me")); Log.v("Something", "weird going on"); double latitude = mLastLocation.getLatitude(); double longitude = mLastLocation.getLongitude(); LatLng myLoc = new LatLng(latitude, longitude); //mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLoc, 15)); Log.v("Location123","Lat"+latitude+"Lon"+longitude); //populateListView(); } } search(); } }); } public void search() { Log.v("TAG", "search"); Intent intent = new Intent("android.intent.action.YELPSEARCH"); startActivity(intent); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onLocationChanged(Location location) { String loc = "Latitude "+location.getLatitude()+"Longitude "+location.getLongitude(); Toast.makeText(getBaseContext(),loc,Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { Toast.makeText(getBaseContext(),"GPS turned ON",Toast.LENGTH_SHORT).show(); } @Override public void onProviderDisabled(String provider) { } /*@Override public void onConnected(@Nullable Bundle bundle) { if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { //mMap.setMyLocationEnabled(true); Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (mLastLocation != null) { // mMap.addMarker(new MarkerOptions().position(new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude())).title("Me")); Log.v("Something", "weird going on"); double latitude = mLastLocation.getLatitude(); double longitude = mLastLocation.getLongitude(); LatLng myLoc = new LatLng(latitude, longitude); //mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLoc, 15)); Log.v("Location","Lat"+latitude+"Lon"+longitude); //populateListView(); } } search(); } @Override public void onConnectionSuspended(int i) { } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { }*/ }/* End of MainActivity Activity */