From 189a089931502d9fc23533b5c2ffcaf98da8ed6c Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Fri, 20 Aug 2021 10:59:38 -0700 Subject: [PATCH] Create the navigation menu outline. --- .../privacycell/activities/PrivacyCell.kt | 67 +++++++- app/src/main/res/layout/app_bar_textview.xml | 29 ++++ .../res/layout/privacy_cell_drawerlayout.xml | 152 ++++++++++++++++++ .../res/layout/privacy_cell_scrollview.xml | 110 ------------- .../res/menu/navigation_menu_top_appbar.xml | 87 ++++++++++ app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values/strings.xml | 25 ++- app/src/main/res/values/themes.xml | 2 +- build.gradle | 2 +- 9 files changed, 355 insertions(+), 121 deletions(-) create mode 100644 app/src/main/res/layout/app_bar_textview.xml create mode 100644 app/src/main/res/layout/privacy_cell_drawerlayout.xml delete mode 100644 app/src/main/res/layout/privacy_cell_scrollview.xml create mode 100644 app/src/main/res/menu/navigation_menu_top_appbar.xml diff --git a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt index b30d0fd..8f482b0 100644 --- a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt +++ b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt @@ -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(R.id.drawerlayout) + val toolbar = findViewById(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(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 diff --git a/app/src/main/res/layout/app_bar_textview.xml b/app/src/main/res/layout/app_bar_textview.xml new file mode 100644 index 0000000..9f434a8 --- /dev/null +++ b/app/src/main/res/layout/app_bar_textview.xml @@ -0,0 +1,29 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/privacy_cell_drawerlayout.xml b/app/src/main/res/layout/privacy_cell_drawerlayout.xml new file mode 100644 index 0000000..ae018c2 --- /dev/null +++ b/app/src/main/res/layout/privacy_cell_drawerlayout.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/privacy_cell_scrollview.xml b/app/src/main/res/layout/privacy_cell_scrollview.xml deleted file mode 100644 index 77ad82f..0000000 --- a/app/src/main/res/layout/privacy_cell_scrollview.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/navigation_menu_top_appbar.xml b/app/src/main/res/menu/navigation_menu_top_appbar.xml new file mode 100644 index 0000000..bd33b0c --- /dev/null +++ b/app/src/main/res/menu/navigation_menu_top_appbar.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index b8e34ae..5b24de0 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -17,7 +17,7 @@ along with Privacy Browser. If not, see . --> -