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
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)
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() {
else -> arrayOf(getString(R.string.error), "")
}
}
+
+ override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean {
+ // TODO.
+ return true
+ }
}
\ No newline at end of file