- val secureFromStingrayImageView = findViewById<ImageView>(R.id.secure_from_stingray_imageview)
- val secureFromStingrayTextView = findViewById<TextView>(R.id.secure_from_stingray_textview)
- val voiceNetworkTextView = findViewById<TextView>(R.id.voice_network)
- val voiceNetworkDetailsTextView = findViewById<TextView>(R.id.voice_network_details)
- val dataNetworkTextView = findViewById<TextView>(R.id.data_network)
- val dataNetworkDetailsTextView = findViewById<TextView>(R.id.data_network_details)
- val additionalNetworkInfoTextView = findViewById<TextView>(R.id.additional_network_info)
- val additionalNetworkInfoDetailsTextView = findViewById<TextView>(R.id.additional_network_info_details)
-
- // TODO.
- if (ActivityCompat.checkSelfPermission(
- this,
- Manifest.permission.READ_PHONE_STATE
- ) != PackageManager.PERMISSION_GRANTED
- ) {
- // TODO: Consider calling
- // ActivityCompat#requestPermissions
- // here to request the missing permissions, and then overriding
- // public void onRequestPermissionsResult(int requestCode, String[] permissions,
- // int[] grantResults)
- // to handle the case where the user grants the permission. See the documentation
- // for ActivityCompat#requestPermissions for more details.
- return
+ drawerLayout = findViewById(R.id.drawerlayout)
+ val toolbar = findViewById<Toolbar>(R.id.toolbar)
+ secureFromStingrayImageView = findViewById(R.id.secure_from_stingray_imageview)
+ secureFromStingrayTextView = findViewById(R.id.secure_from_stingray_textview)
+ voiceNetworkTextView = findViewById(R.id.voice_network)
+ voiceNetworkDetailsTextView = findViewById(R.id.voice_network_details)
+ dataNetworkTextView = findViewById(R.id.data_network)
+ dataNetworkDetailsTextView = findViewById(R.id.data_network_details)
+ additionalNetworkInfoTextView = findViewById(R.id.additional_network_info)
+ additionalNetworkInfoDetailsTextView = findViewById(R.id.additional_network_info_details)
+ val navigationView = findViewById<NavigationView>(R.id.navigationview)
+
+ // Get handles for the context and the telephony manager.
+ context = this
+ telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+
+ // Set the support action bar.
+ setSupportActionBar(toolbar)
+
+ // Get a handle for the action bar.
+ val actionBar = supportActionBar!!
+
+ // Set a custom view on the action bar.
+ actionBar.setCustomView(R.layout.app_bar_textview)
+
+ // Display the custom view.
+ actionBar.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM
+
+ // Define a hamburger icon at the start of the app bar. It will be populated in `onPostCreate()`.
+ actionBarDrawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_navigation_drawer, R.string.close_navigation_drawer)
+
+ // Listen for touches on the navigation menu.
+ navigationView.setNavigationItemSelectedListener(this)
+
+ // Add a drawer listener.
+ drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
+ override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
+ // Do nothing.
+ }
+
+ override fun onDrawerOpened(drawerView: View) {
+ // Do nothing.
+ }
+
+ override fun onDrawerClosed(drawerView: View) {
+ // Reset the drawer icon when the drawer is closed. Otherwise, it is an arrow if the drawer is open when the app is restarted.
+ actionBarDrawerToggle.syncState()
+ }
+
+ override fun onDrawerStateChanged(newState: Int) {
+ // Do nothing.
+ }
+ })
+ }
+
+ override fun onPostCreate(savedInstanceState: Bundle?) {
+ // Run the default commands.
+ super.onPostCreate(savedInstanceState)
+
+ // Sync the state of the DrawerToggle after the default `onRestoreInstanceState()` has finished. This creates the navigation drawer icon.
+ actionBarDrawerToggle.syncState()
+ }
+
+ override fun onResume() {
+ // Run the default commands.
+ super.onResume()
+
+ // Check to see if the read phone state permission has been granted. These commands need to be run on every resume so that the listener gets reassigned as it is automatically paused.
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { // The storage permission has been granted.
+ // Populate Privacy Cell.
+ populatePrivacyCell()
+ } else { // The phone permission has not been granted.
+ // Check if the user has previously denied the storage permission.
+ if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) { // Show a dialog explaining the request first.
+ // Check to see if a phone permission dialog is already displayed. This happens if the app is restarted when the dialog is shown.
+ if (supportFragmentManager.findFragmentByTag(getString(R.string.phone_permission)) == null) { // No dialog is currently shown.
+ // Instantiate the phone permission dialog fragment.
+ val phonePermissionDialogFragment = PhonePermissionDialog()
+
+ // Show the phone permission alert dialog. The permission will be requested when the dialog is closed.
+ phonePermissionDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission))
+ }
+ } else { // Show the permission request directly.
+ // Request the read phone state permission. There is only one permission request in the app, so it has a request code of 0.
+ ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 0)
+ }
+ }
+ }
+
+ override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean {
+ // Get the menu item ID.
+ val menuItemId = menuItem.itemId
+
+ // Run the commands that correspond to the selected menu item.
+ if (menuItemId == R.id.permissions) { // Permissions.
+ // Instantiate the permissions dialog fragment.
+ val permissionsDialogFragment = PermissionsDialog()
+
+ // Show the permissions alert dialog.
+ permissionsDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission))