| /* |
| * Copyright (C) 2018 Google Inc. All Rights Reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package com.example.android.wifirttscan; |
| |
| import android.Manifest.permission; |
| import android.content.Intent; |
| import android.content.pm.PackageManager; |
| import android.os.Bundle; |
| import android.support.v4.app.ActivityCompat; |
| 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.TextView; |
| |
| /** |
| * Displays list of Access Points enabled with WifiRTT (to check distance). Requests location |
| * permissions if they are not approved via secondary splash screen explaining why they are needed. |
| */ |
| public class MainActivity extends AppCompatActivity { |
| |
| private static final String TAG = "MainActivity"; |
| |
| private boolean mLocationPermissionApproved = false; |
| |
| private TextView mOutputTextView; |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| setContentView(R.layout.activity_main); |
| Toolbar toolbar = findViewById(R.id.toolbar); |
| setSupportActionBar(toolbar); |
| |
| mOutputTextView = findViewById(R.id.mainOutputTextView); |
| } |
| |
| public void onClickFindDistancesToAccessPoints(View view) { |
| if (mLocationPermissionApproved) { |
| Log.d(TAG, "Location Permissions approved! Retrieving Access Points."); |
| // TODO: Implement WifiManager + WifiRTT |
| |
| } else { |
| // On 23+ (M+) devices, fine location not granted. Request permission. |
| Intent startIntent = new Intent(this, LocationPermissionRequestActivity.class); |
| startActivity(startIntent); |
| } |
| } |
| |
| @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) { |
| int id = item.getItemId(); |
| |
| if (id == R.id.action_settings) { |
| return true; |
| } |
| |
| return super.onOptionsItemSelected(item); |
| } |
| |
| @Override |
| protected void onResume() { |
| Log.d(TAG, "onResume()"); |
| super.onResume(); |
| |
| mLocationPermissionApproved = |
| ActivityCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION) |
| == PackageManager.PERMISSION_GRANTED; |
| } |
| } |