Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uk.ac.ncl.b5027438.CEG3799;
- import android.Manifest;
- import android.content.pm.PackageManager;
- import android.hardware.SensorManager;
- import android.location.LocationProvider;
- import android.support.v4.app.ActivityCompat;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.webkit.WebView;
- import android.location.Location;
- import android.location.LocationListener;
- import android.widget.Toast;
- import com.google.android.gms.location.FusedLocationProviderClient;
- import com.google.android.gms.location.LocationServices;
- import com.google.android.gms.tasks.OnSuccessListener;
- import com.wikitude.architect.ArchitectStartupConfiguration;
- import com.wikitude.architect.ArchitectView;
- import com.wikitude.tools.location.LocationService;
- public class AR extends AppCompatActivity implements LocationListener {
- public static final String INTENT_EXTRAS_KEY_SAMPLE = "sampleData";
- private static final String TAG = SimpleArActivity.class.getSimpleName();
- /** Root directory of the sample AR-Experiences in the assets dir. */
- private static final String SAMPLES_ROOT = "samples/";
- protected ArchitectView architectView;
- /** The path to the AR-Experience. This is usually the path to its index.html. */
- private String arExperience = "AR.html";
- private LocationProvider locationProvider;
- /** private WebView mWebView; */
- private FusedLocationProviderClient mFusedLocationClient;
- private void startLocationUpdates() {
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, },
- LocationService.MY_PERMISSION_ACCESS_COARSE_LOCATION);
- ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
- LocationService.MY_PERMISSION_ACCESS_FINE_LOCATION);
- }
- mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
- }
- private final LocationProvider.ErrorCallback errorCallback = new LocationProvider.ErrorCallback() {
- @Override
- public void noProvidersEnabled() {
- Toast.makeText(AR.this, R.string.no_location_provider, Toast.LENGTH_LONG).show();
- }
- };
- private final ArchitectView.SensorAccuracyChangeListener sensorAccuracyChangeListener = new ArchitectView.SensorAccuracyChangeListener() {
- @Override
- public void onCompassAccuracyChanged(int accuracy) {
- if ( accuracy < SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // UNRELIABLE = 0, LOW = 1, MEDIUM = 2, HIGH = 3
- Toast.makeText(AR.this, R.string.compass_accuracy_low, Toast.LENGTH_LONG ).show();
- }
- }
- };
- @Override
- protected void onResume() {
- super.onResume();
- if (mRequestingLocationUpdates) {
- startLocationUpdates();
- }
- locationProvider.onResume();
- architectView.registerSensorAccuracyChangeListener(sensorAccuracyChangeListener);
- }
- @Override
- protected void onPause() {
- locationProvider.onPause();
- super.onPause();
- architectView.unregisterSensorAccuracyChangeListener(sensorAccuracyChangeListener);
- }
- @Override
- public void onLocationChanged(Location location) {
- float accuracy = location.hasAccuracy() ? location.getAccuracy() : 1000;
- if (location.hasAltitude()) {
- architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), accuracy);
- } else {
- architectView.setLocation(location.getLatitude(), location.getLongitude(), accuracy);
- }
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {}
- @Override
- public void onProviderEnabled(String provider) {}
- @Override
- public void onProviderDisabled(String provider) {}
- protected void onCreate(ArchitectStartupConfiguration) {}
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
- super.onCreate(savedInstanceState);
- // Used to enabled remote debugging of the ArExperience with google chrome https://developers.google.com/web/tools/chrome-devtools/remote-debugging
- WebView.setWebContentsDebuggingEnabled(true);
- locationProvider = new LocationProvider(this, this, errorCallback);
- setContentView(R.layout.activity_ar);
- this.architectView = (ArchitectView)this.findViewById( R.id.architectView );
- final ArchitectStartupConfiguration config = new ArchitectStartupConfiguration();
- config.setLicenseKey(getString(R.string.wikitude_license_key));
- architectView = new ArchitectView(this);
- architectView.onCreate(config); // create ArchitectView with configuration
- setContentView(architectView);
- this.architectView.onPostCreate();
- this.architectView.load( "assets/AR.html" );
- /** mWebView = (WebView) findViewById(R.id.architectView); */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement