]> gitweb.stoutner.com Git - PrivacyCell.git/blobdiff - app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt
Create the navigation menu outline.
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / activities / PrivacyCell.kt
index b30d0fd3f077a1184b6e68acb3a372cb2fde8268..8f482b06a9174581905cdb25248741a69530a180 100644 (file)
@@ -27,21 +27,30 @@ import android.telephony.PhoneStateListener
 import android.telephony.ServiceState
 import android.telephony.TelephonyDisplayInfo
 import android.telephony.TelephonyManager
+import android.view.MenuItem
+import android.view.View
 import android.widget.ImageView
 import android.widget.TextView
 
+import androidx.appcompat.app.ActionBar
+import androidx.appcompat.app.ActionBarDrawerToggle
 import androidx.appcompat.app.AppCompatActivity
 import androidx.appcompat.content.res.AppCompatResources
+import androidx.appcompat.widget.Toolbar
 import androidx.core.app.ActivityCompat
+import androidx.drawerlayout.widget.DrawerLayout
 import androidx.fragment.app.DialogFragment
 
+import com.google.android.material.navigation.NavigationView
+
 import com.stoutner.privacycell.R
 import com.stoutner.privacycell.dialogs.PhonePermissionDialog
 
-class PrivacyCell : AppCompatActivity(), PhonePermissionDialog.StoragePermissionDialogListener {
+class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, PhonePermissionDialog.StoragePermissionDialogListener {
     // Declare the class variables.
     private lateinit var context: Context
     private lateinit var telephonyManager: TelephonyManager
+    private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
 
     // Declare the views.
     lateinit var secureFromStingrayImageView: ImageView
@@ -58,9 +67,11 @@ class PrivacyCell : AppCompatActivity(), PhonePermissionDialog.StoragePermission
         super.onCreate(savedInstanceState)
 
         // Set the content view.
-        setContentView(R.layout.privacy_cell_scrollview)
+        setContentView(R.layout.privacy_cell_drawerlayout)
 
         // Get handles for the views.
+        val drawerLayout = findViewById<DrawerLayout>(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)
@@ -69,10 +80,57 @@ class PrivacyCell : AppCompatActivity(), PhonePermissionDialog.StoragePermission
         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() {
@@ -211,4 +269,9 @@ class PrivacyCell : AppCompatActivity(), PhonePermissionDialog.StoragePermission
             else -> arrayOf(getString(R.string.error), "")
         }
     }
+
+    override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean {
+        // TODO.
+        return true
+    }
 }
\ No newline at end of file