implements NavigationView. OnNavigationItemSelectedListener, BeyondarSensorListener, LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient. OnConnectionFailedListener {


private BeyondarFragmentSupport mBeyondarFragment;

private World mWorld;

private RadarView mRadarView;

private RadarWorldPlugin mRadarPlugin;


private Location mCurrentLocation;

private Context context;


GoogleApiClient mGoogleApiClient;

LocationRequest mLocationRequest;


private float [] mLastAccelerometer = new float [3];

private float [] mLastMagnetometer = new float [3];

private float [] mR = new float [9];

private float [] mOrientation = new float [3];


private static boolean flagLocationUpdate=true;

private static SharedPreferences mSettings;

private Set boLat=new LinkedHashSet ();

private Set boLon=new LinkedHashSet ();


private static ProgressBar spinner;


@Override

protected void onCreate (Bundle savedInstanceState) {

super. onCreate (savedInstanceState);

setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar (toolbar);


spinner = (ProgressBar)findViewById(R.id.progressBar);

spinner.setVisibility (View. GONE);


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (

this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

drawer.addDrawerListener (toggle);

toggle.syncState ();


NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

navigationView.setNavigationItemSelectedListener (this);


final NestedScrollView nestedScrollView = (NestedScrollView)findViewById(R.id.content_main);

nestedScrollView.getViewTreeObserver().addOnGlobalLayoutListener (

new ViewTreeObserver. OnGlobalLayoutListener () {


@Override

public void onGlobalLayout () {

int height = nestedScrollView.getHeight ();

int width = nestedScrollView.getWidth ();

if (height> width) height=width;

if (width> height) width=height;

ViewGroup.LayoutParams params = nestedScrollView.getLayoutParams ();

params. width=width;

params. height=height;

nestedScrollView.setLayoutParams (params);

nestedScrollView.getViewTreeObserver().removeGlobalOnLayoutListener (this);

}

});


context = this;

mSettings = getSharedPreferences («APP_PREFERENCES», Context.MODE_PRIVATE);


if (!mSettings.contains («BOLAT»)) {

SharedPreferences. Editor editor = mSettings. edit ();

editor. putStringSet («BOLAT», boLat);

editor.commit ();

}


if(!mSettings.contains («BOLON»)) {

SharedPreferences. Editor editor = mSettings. edit ();

editor. putStringSet («BOLON», boLon);

editor.commit ();

}


if(!mSettings.contains («CREATURES»)) {

JSONArray creatures = new JSONArray ();

SharedPreferences. Editor editor = mSettings. edit ();

editor.putString("CREATURES",creatures.toString ());

editor.commit ();

}


if(!mSettings.contains («USERLON»)) {

SharedPreferences. Editor editor = mSettings. edit ();

editor. putString («USERLON», «82.9346»);

editor.commit ();

}

if(!mSettings.contains («USERLAT»)) {

SharedPreferences. Editor editor = mSettings. edit ();

editor. putString («USERLAT», «55.0415»);

editor.commit ();

}


checkPermissions ();


mBeyondarFragment = (BeyondarFragmentSupport) getSupportFragmentManager().findFragmentById(R.id.beyondarFragment);


mRadarView = (RadarView) findViewById(R.id.radarView);

mRadarPlugin = new RadarWorldPlugin (this);

mRadarPlugin.setRadarView (mRadarView);

mRadarPlugin.setMaxDistance (100);


CustomWorldHelper.setActivity (this);

mWorld = CustomWorldHelper.generateObjects (this);

mWorld.addPlugin (mRadarPlugin);